public OWLEntity getOWLEntity(IRI iri, OWLDataFactory df){ switch(this){ case classes: return df.getOWLClass(iri); case objectproperties: df.getOWLObjectProperty(iri); case dataproperties: return df.getOWLDataProperty(iri); case annotationproperties: return df.getOWLAnnotationProperty(iri); case individuals: return df.getOWLNamedIndividual(iri); case datatypes: return df.getOWLDatatype(iri); } throw new RuntimeException("Unknown named object type: " + this); }
private void generateChanges(OWLClass cls, OWLObjectPropertyExpression property, Collection<OWLOntology> ontologies, OWLOntology targetOntology) { // We collect all of the fillers for existential restrictions along // the target property and all of the fillers for hasValue restrictions // as nominals FillerCollector collector = new FillerCollector(property); ontologies.forEach(o -> o.subClassAxiomsForSubClass(cls) .forEach(ax -> ax.getSuperClass().accept(collector))); if (collector.fillers.isEmpty()) { return; } OWLObjectUnionOf union = df.getOWLObjectUnionOf(collector.fillers); OWLClassExpression closureAxiomDesc = df.getOWLObjectAllValuesFrom(property, union); addChange(new AddAxiom(targetOntology, df.getOWLSubClassOfAxiom(cls, closureAxiomDesc))); }
@Override protected void addAxioms(OWLNamedIndividual entity, OWLReasoner reasoner, OWLDataFactory dataFactory, Set<OWLClassAssertionAxiom> result) { reasoner.getTypes(entity, false).entities() .forEach(t -> result.add(dataFactory.getOWLClassAssertionAxiom(t, entity))); }
/** * Shorthand for * {@code getOWLAnnotation(getRDFSComment(), getOWLLiteral(value))} * * @param value The annotation value. * @return an rdfs:comment annotation with provided value */ default OWLAnnotation getRDFSComment(String value) { return getOWLAnnotation(getRDFSComment(), getOWLLiteral(value)); }
@Override public void handleTriple(IRI s, IRI p, IRI o) { OWLIndividual ind = df.getOWLNamedIndividual(s); OWLClass skosConcept = df.getOWLClass(o); add(df.getOWLClassAssertionAxiom(skosConcept, ind)); } }
protected void expandAssertions(OWLOntology o, OWLAnnotationProperty p) { OWLAnnotationProperty ap425 = df.getOWLAnnotationProperty(IRI_IAO_0000425.getIRI()); getAnnotationObjects(p, o.importsClosure(), ap425).map(a -> a.getValue().asLiteral()) .filter(v -> v.isPresent()) .forEach(v -> { String str = v.get().getLiteral(); LOG.info("assertion mapping {} to {}", p, str); expandAssertionToMap.put(p.getIRI(), str); }); }
@Override public void visit(OWLOntology ontology) { checkNotNull(ontology, "ontology cannot be null"); ontology.importsDeclarations().sorted().forEach(decl -> { writer.writeStartElement(IMPORT); writer.writeTextContent(decl.getIRI().toString()); writer.writeEndElement(); }); render(ontology.annotations()); Set<OWLEntity> declared = asUnorderedSet(ontology.unsortedSignature()); ontology.axioms(AxiomType.DECLARATION).sorted().forEach(ax -> { ax.accept(this); declared.remove(ax.getEntity()); if (!e.isBuiltIn() && !illegalPunnings.contains(e.getIRI()) && !ontology.isDeclared(e, Imports.INCLUDED)) { ontology.getOWLOntologyManager().getOWLDataFactory() .getOWLDeclarationAxiom(e).accept(this);
for(OWLOntology ontology : rootOntology.getImportsClosure()) { for(OWLClassAssertionAxiom ax : rootOntology.getClassAssertionAxioms(individual)) { if (!ax.getClassExpression().isAnonymous()) { OWLClass typeCls = ax.getClassExpression().asOWLClass(); if(ax.getClassExpression().equals(thePreferredType)) { actualType = EntitySearcher.getTypes(individual, rootOntology.getImportsClosure()) .stream() .filter(ClassExpression::isOWLClass) .map(ClassExpression::asOWLClass) .findFirst() .orElse(dataFactory.getOWLThing());
private void writeDeclarations(OWLEntity entity, Set<OWLAxiom> alreadyWrittenAxioms, Collection<IRI> illegals) { Collection<OWLDeclarationAxiom> axioms = asList(ont.declarationAxioms(entity).sorted()); axioms.stream().filter(alreadyWrittenAxioms::add).forEach(this::acceptAndReturn); // if multiple illegal declarations already exist, they have already // been outputted the renderer cannot take responsibility for removing // them. It should not add declarations for illegally punned entities // here, though if (addMissingDeclarations && axioms.isEmpty() && !entity.isBuiltIn() && !illegals.contains(entity.getIRI()) && !ont.isDeclared(entity, Imports.INCLUDED)) { OWLDeclarationAxiom declaration = ont.getOWLOntologyManager().getOWLDataFactory().getOWLDeclarationAxiom(entity); acceptAndReturn(declaration); } }
/** * Tr term frame. * * @param termFrame the term frame * @return the oWL class expression */ public OWLClassExpression trTermFrame(Frame termFrame) { OWLClass cls = trClass(checkNotNull(termFrame.getId())); add(fac.getOWLDeclarationAxiom(cls)); termFrame.getTags().stream().filter(OboFormatTag.TAG_ALT_ID.getTag()::equals).forEach(t -> // Generate deprecated and replaced_by details for alternate // identifier add(translateAltIds(termFrame.getClauses(t), cls.getIRI(), true))); termFrame.getTags().forEach(t -> add(trTermFrameClauses(cls, termFrame.getClauses(t), t))); return cls; }
tree.getEdges().stream().filter(edge -> !edge.equals(RDF.type.asNode())).forEach(edge -> { List<RDFResourceTree> children = tree.getChildren(edge); types.remove(df.getOWLThing()); if(!type.isAnonymous()) { addTypeChild.accept(type.asOWLClass()); } else { if(type.getClassExpressionType() == ClassExpressionType.OBJECT_INTERSECTION_OF) { type.getNestedClassExpressions().stream() .filter(ce -> !ce.isAnonymous()) .map(OWLClassExpression::asOWLClass) .forEach(addTypeChild);
if (reasoner.getSubClasses(getFactory().getOWLThing(), true).getFlattened().contains(owlClass)) { addRootsTerms(owlClass.getIRI()); if (reasoner.getSubClasses(getFactory().getOWLClass(Namespaces.OBOINOWL.createIRI("ObsoleteClass")), false).getFlattened().contains(owlClass)) { addObsoleteTerms(owlClass.getIRI()); reasoner.getSubClasses(owlClass, true).getFlattened().stream() .map(OWLNamedObject::getIRI) .collect(Collectors.toSet()), owlVocabulary); if (ct.size() >0) addDirectChildren(owlClass.getIRI(), ct) ; reasoner.getSubClasses(owlClass, false).getFlattened().stream() .map(OWLNamedObject::getIRI) .collect(Collectors.toSet()), owlVocabulary); for (OWLClassExpression expression : owlClass.getSuperClasses(getManager().getOntologies())) { if (expression.isAnonymous()) { if (!someValuesFrom.getFiller().isAnonymous()) { IRI propertyIRI = someValuesFrom.getProperty().asOWLObjectProperty().getIRI(); IRI relatedTerm = someValuesFrom.getFiller().asOWLClass().getIRI(); if (!relatedTerms.containsKey(propertyIRI)) { relatedTerms.put(propertyIRI, new HashSet<>());
/** * @param dataFactory data factory to use * @return set of SKOS data properties */ public static Set<OWLDataProperty> getDataProperties(OWLDataFactory dataFactory) { return asSet(stream().filter(v -> v.entityType.equals(DATA_PROPERTY)) .map(v -> dataFactory.getOWLDataProperty( v.iri))); }
OWLOntology ont = man.createOntology(axioms); toSave = ont; OWLDataFactory df=man.getOWLDataFactory(); unsatDesc.signature() .filter(ent->!ent.isBuiltIn() && !ont.containsEntityInSignature(ent)) .forEach(ent -> ont.add(df.getOWLDeclarationAxiom(ent))); OWLClass namingCls = man.getOWLDataFactory().getOWLClass(IRI.create(clsName)); OWLAxiom namingAxiom = man.getOWLDataFactory().getOWLSubClassOfAxiom(namingCls, unsatDesc); man.addAxiom(ont, namingAxiom); for (OWLEntity freshEntity : freshEntities) { man.addAxiom(ont, man.getOWLDataFactory().getOWLDeclarationAxiom(freshEntity)); entailmentCheckTimer.start(); OWLReasoner reasoner = reasonerFactory.createReasoner(ont, new SimpleConfiguration(new NullReasonerProgressMonitor(), FreshEntityPolicy.ALLOW, timeOutMS, IndividualNodeSetPolicy.BY_SAME_AS)); entailed = !reasoner.isSatisfiable(unsatDesc); entailmentCheckTimer.stop(); reasoner.dispose(); man.removeOntology(ont); if (entailed) { lastEntailingAxioms.remove(namingAxiom); add(lastEntailingAxioms, ont.logicalAxioms());
protected void amalgamate(OWLOntology ont, OWLClass cls) { List<OWLSubClassOfAxiom> axioms = asList(ont.subClassAxiomsForSubClass(cls)); if (axioms.size() < 2) { return; } axioms.forEach(ax -> addChange(new RemoveAxiom(ont, ax))); Stream<OWLClassExpression> superclasses = axioms.stream() .map(OWLSubClassOfAxiom::getSuperClass); OWLObjectIntersectionOf intersection = df.getOWLObjectIntersectionOf(superclasses); addChange(new AddAxiom(ont, df.getOWLSubClassOfAxiom(cls, intersection))); } }
@SuppressWarnings("null") protected AbstractMacroExpansionVisitor(OWLOntology o) { df = o.getOWLOntologyManager().getOWLDataFactory(); expandExpressionMap = new HashMap<>(); expandAssertionToMap = new HashMap<>(); OWLAnnotationProperty ap424 = df.getOWLAnnotationProperty(IRI_IAO_0000424.getIRI()); o.objectPropertiesInSignature() .forEach(p -> getAnnotationObjects(p, o.importsClosure(), ap424).forEach( a -> mapToExpand(p, a))); o.annotationPropertiesInSignature().forEach(p -> expandAssertions(o, p)); OIO_ISEXPANSION = df.getOWLAnnotationProperty( IRI.create(Obo2OWLConstants.OIOVOCAB_IRI_PREFIX, "is_expansion")); expansionMarkerAnnotation = df.getOWLAnnotation(OIO_ISEXPANSION, df.getOWLLiteral(true)); }
/** * Retrieve the {@link OWLNamedIndividual} for a given {@link IRI}, if * it has at least one corresponding {@link OWLDeclarationAxiom}. * * @param iri iri * @return {@link OWLNamedIndividual} or null */ @Nullable protected OWLNamedIndividual getOWLIndividual(IRI iri) { for (OWLOntology o : ontologies) { OWLNamedIndividual c = o.getOWLOntologyManager().getOWLDataFactory() .getOWLNamedIndividual(iri); Optional<OWLDeclarationAxiom> found = o.declarationAxioms(c) .filter(da -> da.getEntity() .isOWLNamedIndividual()).findAny(); if (found.isPresent()) { return found.get().getEntity().asOWLNamedIndividual(); } } return null; }
@Override protected void addAxioms(OWLClass entity, OWLReasoner reasoner, OWLDataFactory dataFactory, Set<OWLSubClassOfAxiom> result) { checkNotNull(dataFactory, "dataFactory cannot be null"); checkNotNull(reasoner, "reasoner cannot be null"); checkNotNull(result, "result cannot be null"); checkNotNull(entity, "entity cannot be null"); if (reasoner.isSatisfiable(entity)) { reasoner.getSuperClasses(entity, true).entities() .forEach(sup -> result.add(dataFactory.getOWLSubClassOfAxiom(entity, sup))); } else { result.add(dataFactory.getOWLSubClassOfAxiom(entity, dataFactory.getOWLNothing())); } }
private void generateChanges() { Set<OWLClassExpression> supers = new HashSet<>(); for (OWLOntology o : ontologies) { o.equivalentClassesAxioms(cls).forEach(ax -> { addChange(new RemoveAxiom(o, ax)); ax.classExpressions().forEach(c -> collectClassExpressions(c, supers)); }); } supers.remove(cls); supers.forEach( sup -> addChange(new AddAxiom(targetOntology, df.getOWLSubClassOfAxiom(cls, sup)))); }
@Override public void visit(OWLOntology ontology) { List<OWLClass> classes1 = asList(ontology.classesInSignature()); classes1.remove(ontology.getOWLOntologyManager().getOWLDataFactory().getOWLThing()); classes1.remove(ontology.getOWLOntologyManager().getOWLDataFactory().getOWLNothing()); classes1.sort(null); for (OWLClass eachClass : classes1) { write(EQUIVALENT); writeSpace(); classExpression.accept(this); writeCloseBracket(); writeln(); write(eachClass); writeSpace(); iter.next().accept(this); writeCloseBracket(); writeln(); ontology.generalClassAxioms().forEach(a -> a.accept(this)); for (OWLObjectProperty property : asList(ontology.objectPropertiesInSignature())) { writeOpenBracket(); sup(ontology.axioms(Filters.subObjectPropertyWithSub, property, INCLUDED), OWLObjectPropertyExpression.class); Iterator<OWLObjectPropertyExpression> it = superProperties.iterator(); if (it.hasNext()) { writeAttribute(PARENTS_ATTR);