/** * QueryEngineImpl constructor * * @param manager An OWLOntologyManager instance of OWLAPI v3 * @param reasoner An OWLReasoner instance. * @param strictMode If strict mode is enabled the query engine will throw a QueryEngineException if data types withing the query are not correct (e.g. Class(URI_OF_AN_INDIVIDUAL)) */ public QueryEngineImpl(OWLOntologyManager manager, OWLReasoner reasoner, boolean strictMode) { this.manager = manager; this.reasoner = reasoner; this.factory = manager.getOWLDataFactory(); this.strictMode = strictMode; reasoner.getRootOntology() .getAxioms(AxiomType.ANNOTATION_ASSERTION, Imports.INCLUDED) .stream() .filter(ax -> ax.getSubject() instanceof IRI) .forEach(ax -> { unannotatedAxioms.add(ax.getAxiomWithoutAnnotations()); annotationAssertionsBySubject.put((IRI) ax.getSubject(), ax); }); Set<OWLClass> classesInSignature = reasoner.getRootOntology().getClassesInSignature(Imports.INCLUDED); classesInSignature.add(factory.getOWLThing()); classesInSignature.add(factory.getOWLNothing()); classes = ImmutableSet.copyOf(classesInSignature); classIris = ImmutableSet.copyOf(classes.stream().map(OWLClass::getIRI).collect(toSet())); annotationPropertyIris = ImmutableSet.copyOf(reasoner.getRootOntology().getAnnotationPropertiesInSignature(Imports.INCLUDED).stream().map( OWLNamedObject::getIRI).collect(toSet())); }
/** * Params: id * @throws OWLOntologyCreationException * @throws OWLOntologyStorageException * @throws IOException * @throws OWLParserException */ public void getAxiomsCommand() throws OWLOntologyCreationException, OWLOntologyStorageException, IOException, OWLParserException { headerOWL(); boolean direct = getParamAsBoolean(Param.direct, false); OWLObject obj = this.resolveEntity(); LOG.info("finding axioms about: "+obj); Set<OWLAxiom> axioms = new HashSet<OWLAxiom>(); if (obj instanceof OWLClass) { axioms.addAll(graph.getSourceOntology().getAxioms((OWLClass)obj, Imports.EXCLUDED)); } if (obj instanceof OWLIndividual) { axioms.addAll(graph.getSourceOntology().getAxioms((OWLIndividual)obj, Imports.EXCLUDED)); } if (obj instanceof OWLObjectProperty) { axioms.addAll(graph.getSourceOntology().getAxioms((OWLObjectProperty)obj, Imports.EXCLUDED)); } for (OWLAxiom ax : axioms) { output(ax); } }
public Set<OWLClass> getReflexiveSubClasses(OWLClassExpression rootClassExpr) { Set<OWLClass> classes; OWLClass rootClass; if (rootClassExpr instanceof OWLClass) { rootClass = (OWLClass)rootClassExpr; } else { rootClass = materializeClassExpression(rootClassExpr); } if (rootClass.equals(getOWLDataFactory().getOWLThing())) { classes = inputOntology.getClassesInSignature(Imports.INCLUDED); } else { classes = getReasoner().getSubClasses(rootClass, false).getFlattened(); classes.add(rootClass); } return classes; }
public Set<OWLClass> materializeClassExpressionsReferencedBy(OWLObjectProperty p) { Set<OWLClassExpression> xs = new HashSet<OWLClassExpression>(); for (OWLAxiom ax : outputOntology.getReferencingAxioms(p, Imports.INCLUDED)) { if (ax instanceof OWLSubClassOfAxiom) { xs.addAll(getClassExpressionReferencedBy(p, ((OWLSubClassOfAxiom)ax).getSuperClass())); } else if (ax instanceof OWLClassAssertionAxiom) { xs.addAll(getClassExpressionReferencedBy(p, ((OWLClassAssertionAxiom)ax).getClassExpression())); } else if (ax instanceof OWLEquivalentClassesAxiom) { for (OWLClassExpression x : ((OWLEquivalentClassesAxiom)ax).getClassExpressions()) { xs.addAll(getClassExpressionReferencedBy(p,x)); } } } return materializeClassExpressions(xs); }
public static void randomizeClassAssertions(OWLOntology ont, int num) { Set<OWLClassAssertionAxiom> caas = new HashSet<OWLClassAssertionAxiom>(); Set<OWLClassAssertionAxiom> caasNew = new HashSet<OWLClassAssertionAxiom>(); Set<OWLNamedIndividual> inds = ont.getIndividualsInSignature(Imports.INCLUDED); OWLNamedIndividual[] indArr = (OWLNamedIndividual[]) inds.toArray(); for (OWLNamedIndividual ind : inds) { caas.addAll( ont.getClassAssertionAxioms(ind) ); } for (OWLClassAssertionAxiom caa : caas) { OWLIndividual randomIndividual = null; caasNew.add(ont.getOWLOntologyManager().getOWLDataFactory().getOWLClassAssertionAxiom(caa.getClassExpression(), randomIndividual)); } ont.getOWLOntologyManager().removeAxioms(ont, caas); ont.getOWLOntologyManager().addAxioms(ont, caasNew); }
/** * @return 'E' classes */ protected Set<OWLClass> getPhenotypeEntityClasses() { Set<OWLClass> entityClasses = new HashSet<OWLClass>(); // add all that are NOT excluded for (OWLClass c : inputOntology.getClassesInSignature(Imports.INCLUDED)) { if (!isVerbotenEntity(c)) { entityClasses.add(c); continue; } else { LOG.info("Excluding from entity set:"+c); } } // exclude all qualities entityClasses.removeAll(getQualityClasses()); entityClasses.removeAll(classesToSkip); return entityClasses; }
public void createElementAttributeMapFromOntology() { elementToAttributesMap = new HashMap<OWLNamedIndividual,Set<OWLClass>>(); Set<OWLClass> allTypes = new HashSet<OWLClass>(); for (OWLNamedIndividual e : sourceOntology.getIndividualsInSignature(Imports.INCLUDED)) { // The attribute classes for an individual are the direct inferred // named types. We assume that grouping classes have already been // generated. // if they have not then the types may be as general as {Thing} Set<OWLClass> types = getReasoner().getTypes(e, true).getFlattened(); allTypes.addAll(addElement(e, types)); } // need to materialize as classes... LOG.info("Using " + allTypes.size() + " attribute classes, based on individuals: " + sourceOntology.getIndividualsInSignature(Imports.INCLUDED).size()); cachedAttributeClasses = allTypes; }
/** * * returns set of entities that belong to a referenced ontology that are referenced in the source ontology. * * If the source ontology is not explicitly declared, then all entities that are referenced in the source * ontology and declared in a reference ontology are returned. * * Example: if the source ontology is cl, and cl contains axioms that reference go:1, go:2, ... * and go is in the set of referenced ontologies, then {go:1,go:2,...} will be in the returned set. * It is irrelevant whether go:1, ... is declared in the source (e.g. MIREOTed) * * Note this only returns direct references. See * {@link #getClosureOfExternalReferencedEntities()} for closure of references * * @return all objects referenced by source ontology */ public Set<OWLEntity> getExternalReferencedEntities() { OWLOntology ont = graph.getSourceOntology(); Set<OWLEntity> objs = ont.getSignature(Imports.EXCLUDED); Set<OWLEntity> refObjs = new HashSet<OWLEntity>(); LOG.info("testing "+objs.size()+" objs to see if they are contained in: "+getReferencedOntologies()); for (OWLEntity obj : objs) { //LOG.info("considering: "+obj); // a reference ontology may have entities from the source ontology MIREOTed in.. // allow a configuration with the URI prefix specified if (isInExternalOntology(obj)) { refObjs.add(obj); } } LOG.info("#refObjs: "+refObjs.size()); return refObjs; }
/** * Remove all classes *not* in subset. * * This means: * * remove all annotation assertions for that class * * remove all logical axioms about that class * * If removeDangling is true, also remove all axioms that reference this class * * @param subset * @param removeDangling */ public void removeSubsetComplementClasses(Set<OWLClass> subset, boolean removeDangling) { OWLOntology o = getOntology(); Set<OWLClass> rmSet = o.getClassesInSignature(); rmSet.removeAll(subset); // remove all classes not in subset Set<OWLAxiom> rmAxioms = new HashSet<OWLAxiom>(); LOG.info("Num of classes to be removed = "+rmSet.size()); for (OWLClass c : rmSet) { rmAxioms.addAll(o.getAnnotationAssertionAxioms(c.getIRI())); rmAxioms.addAll(o.getAxioms(c, Imports.EXCLUDED)); } graph.getManager().removeAxioms(o, rmAxioms); if (removeDangling) { removeDanglingAxioms(o); } }
/** * Assumes OBO-style IDspaces; specifically URI contains "..../IDSPACE_..." * @param idspace * @param subOnt */ public void transferAxiomsUsingIdSpace(String idspace, OWLOntology subOnt) { Set<OWLAxiom> axioms = new HashSet<OWLAxiom>(); LOG.info("ID Space: "+idspace); for (OWLClass c : getOntology().getClassesInSignature()) { String iriStr = c.getIRI().toString().toLowerCase(); if (iriStr.contains("/"+idspace.toLowerCase()+"_")) { LOG.info("MATCH: "+c); axioms.addAll(getOntology().getDeclarationAxioms(c)); axioms.addAll(getOntology().getAxioms(c, Imports.EXCLUDED)); axioms.addAll(getOntology().getAnnotationAssertionAxioms(c.getIRI())); } } LOG.info("Transferring "+axioms.size()+" axioms from "+getOntology()+" to "+subOnt); this.getManager().removeAxioms(getOntology(), axioms); this.getManager().addAxioms(subOnt, axioms); }
public Set<Mapping> getMappings() { Set<Mapping> ms = new HashSet<Mapping>(); OWLAnnotationProperty vap = getVariableAnnotationProperty(); for (OWLSubClassOfAxiom sca : ontology.getAxioms(AxiomType.SUBCLASS_OF, Imports.INCLUDED)) { Mapping m = new Mapping(); Set<OWLAnnotation> anns = sca.getAnnotations(vap); for (OWLAnnotation ann : anns) { IRI v = (IRI) ann.getValue(); m.vars.add(v); } if (m.vars.size() > 0) { m.src = sca.getSubClass(); m.tgt = sca.getSuperClass(); ms.add(m); LOG.info("MAPPING: "+m); } } return ms; }
public void render(OWLGraphWrapper g) { if (isWriteHeader) { print("IRI"); sep(); print("label"); sep(); print("definition"); nl(); } graph = g; Set<OWLObject> objs = new HashSet<OWLObject>(g.getSourceOntology().getClassesInSignature(Imports.EXCLUDED)); objs.addAll(g.getSourceOntology().getIndividualsInSignature(Imports.EXCLUDED)); for (OWLObject obj : objs) { if (obj.equals(g.getDataFactory().getOWLNothing())) continue; if (obj.equals(g.getDataFactory().getOWLThing())) continue; if (obj instanceof OWLNamedObject) render((OWLNamedObject)obj); } stream.close(); }
public void render(OWLGraphWrapper g) { graph = g; Set<OWLObject> objs = new HashSet<OWLObject>(g.getSourceOntology().getClassesInSignature(Imports.EXCLUDED)); objs.addAll(g.getSourceOntology().getIndividualsInSignature(Imports.EXCLUDED)); for (OWLObject obj : objs) { if (obj.equals(g.getDataFactory().getOWLNothing())) continue; if (obj.equals(g.getDataFactory().getOWLThing())) continue; if (obj instanceof OWLNamedObject) render((OWLNamedObject)obj); } stream.close(); }
private boolean isBridgingOntology(OWLOntology ont) { for (OWLClass c : ont.getClassesInSignature(Imports.INCLUDED)) { if (ont.getDeclarationAxioms(c).size() > 0) { if (mooncat.getOntology().getDeclarationAxioms(c).size() >0) { // class already declared in main ontology - a 2ary ontology MUST // declare at least one of its own classes if it is a bone-fide non-bridging ontology } else if (mooncat.isDangling(ont, c)) { // a dangling class has no OWL annotations. // E.g. bp_xp_cl contains CL classes as dangling } else { logInfo(c+" has declaration axioms, is not in main, and is not dangling, therefore "+ont+" is NOT a bridging ontology"); return false; } } } logInfo(ont+" is a bridging ontology"); return true; }
private void testSpecies(OWLOntology ontology) { IRI iri = IRI.create("http://purl.obolibrary.org/obo/NCBITaxon_species"); OWLDataFactory df = ontology.getOWLOntologyManager(). getOWLDataFactory(); OWLClass taxon = df.getOWLClass(iri); assertTrue("Species class in signature", ontology.containsClassInSignature(iri)); // Check axioms Set<OWLClassAxiom> axioms = ontology.getAxioms(taxon, Imports.EXCLUDED); assertEquals("Count class axioms", 1, axioms.size()); assertEquals("SubClassOf(<http://purl.obolibrary.org/obo/NCBITaxon_species> <http://purl.obolibrary.org/obo/NCBITaxon#_taxonomic_rank>)", axioms.toArray()[0].toString()); // Check annotations List<String> values = new ArrayList<String>(); values.add("AnnotationAssertion(<http://www.geneontology.org/formats/oboInOwl#hasOBONamespace> <http://purl.obolibrary.org/obo/NCBITaxon_species> \"ncbi_taxonomy\"^^xsd:string)"); values.add("AnnotationAssertion(rdfs:label <http://purl.obolibrary.org/obo/NCBITaxon_species> \"species\"^^xsd:string)"); Set<OWLAnnotationAssertionAxiom> annotations = ontology.getAnnotationAssertionAxioms(iri); assertEquals("Count annotations for Species", 2, annotations.size()); checkAnnotations(annotations, values); }
private void testExactSynonym(OWLOntology ontology) { IRI iri = IRI.create("http://www.geneontology.org/formats/oboInOwl#hasExactSynonym"); OWLDataFactory df = ontology.getOWLOntologyManager(). getOWLDataFactory(); OWLAnnotationProperty property = df.getOWLAnnotationProperty(iri); assertTrue("Exact Synonym property in signature", ontology.containsAnnotationPropertyInSignature(iri)); // Check axioms Set<OWLAnnotationAxiom> axioms = ontology.getAxioms(property, Imports.EXCLUDED); assertEquals("Count class axioms", 0, axioms.size()); // Check annotations List<String> values = new ArrayList<String>(); values.add("AnnotationAssertion(rdfs:label <http://www.geneontology.org/formats/oboInOwl#hasExactSynonym> \"has_exact_synonym\"^^xsd:string)"); Set<OWLAnnotationAssertionAxiom> annotations = ontology.getAnnotationAssertionAxioms(iri); assertEquals("Count annotations for Exact", 1, annotations.size()); checkAnnotations(annotations, values); }
public void naffTranslate(PrintWriter output, boolean debugFlag) { clearState(); OWLAxioms axioms = new OWLAxioms(); Collection<OWLOntology> importClosure = rootOntology.getImportsClosure(); if(configuration.getDomainIndividuals() == null) { configuration.setDomainIndividuals(rootOntology.getIndividualsInSignature(Imports.INCLUDED)); } OWLNormalizationWithTracer normalization = new OWLNormalizationWithTracer(rootOntology.getOWLOntologyManager().getOWLDataFactory(), axioms, 0, configuration.getDomainIndividuals()); for (OWLOntology ontology : importClosure) { normalization.processOntology(ontology); } axioms.m_namedIndividuals.clear(); axioms.m_namedIndividuals.addAll(configuration.getDomainIndividuals()); DebugTranslation translation = new DebugTranslation(configuration, output, debugFlag, normalization); translation.translateOntology(axioms); }
private void writeDeclarations(OWLEntity entity, Set<OWLAxiom> alreadyWrittenAxioms, Collection<IRI> illegals) { Collection<OWLDeclarationAxiom> axioms = sortOptionally(ont.declarationAxioms(entity)); 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); } }
@BeforeClass public static void setupRules() throws OWLOntologyCreationException { OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); OWLOntology ont = manager.loadOntologyFromOntologyDocument(GPADSPARQLTest.class.getResourceAsStream("/ro-merged-2017-10-02.ofn")); Set<Rule> rules = new HashSet<>(); rules.addAll(JavaConverters.setAsJavaSetConverter(OWLtoRules.translate(ont, Imports.INCLUDED, true, true, true, true)).asJava()); rules.addAll(JavaConverters.setAsJavaSetConverter(OWLtoRules.indirectRules(ont)).asJava()); arachne = new RuleEngine(Bridge.rulesFromJena(JavaConverters.asScalaSetConverter(rules).asScala()), true); }
ModelCreator(UndoAwareMolecularModelManager models, String defaultModelState) { this.m3 = models; this.curieHandler = models.getCuriHandler(); this.defaultModelState = defaultModelState; Set<IRI> dataPropertyIRIs = new HashSet<IRI>(); for(OWLDataProperty p : m3.getOntology().getDataPropertiesInSignature(Imports.INCLUDED)) { dataPropertyIRIs.add(p.getIRI()); } this.dataPropertyIRIs = Collections.unmodifiableSet(dataPropertyIRIs); }
/** * Return Arachne working memory representing LEGO model combined with inference rules. * This model will not remain synchronized with changes to data. * @param LEGO modelId * @return Jena model */ public WorkingMemory createInferredModel(IRI modelId) { Set<Statement> statements = JavaConverters.setAsJavaSetConverter(SesameJena.ontologyAsTriples(getModelAbox(modelId))).asJava(); Set<Triple> triples = statements.stream().map(s -> Bridge.tripleFromJena(s.asTriple())).collect(Collectors.toSet()); try { // Using model's ontology IRI so that a spurious different ontology declaration triple isn't added OWLOntology schemaOntology = OWLManager.createOWLOntologyManager().createOntology(getOntology().getRBoxAxioms(Imports.INCLUDED), modelId); Set<Statement> schemaStatements = JavaConverters.setAsJavaSetConverter(SesameJena.ontologyAsTriples(schemaOntology)).asJava(); triples.addAll(schemaStatements.stream().map(s -> Bridge.tripleFromJena(s.asTriple())).collect(Collectors.toSet())); } catch (OWLOntologyCreationException e) { LOG.error("Couldn't add rbox statements to data model.", e); } return getRuleEngine().processTriples(JavaConverters.asScalaSetConverter(triples).asScala()); }
public boolean canLearn(OWLEntity entity, AxiomType axiomType) throws NoInstanceDataException { OWLOntology ontology = editorKit.getWorkspace().getOWLModelManager().getActiveOntology(); OWLReasoner reasoner = editorKit.getOWLModelManager().getReasoner(); long instanceDataCnt = 0; if(entity.isOWLClass()) { instanceDataCnt = reasoner.getInstances(entity.asOWLClass(), false).getFlattened().size(); } else if(entity.isOWLObjectProperty()) { Set<OWLObjectPropertyExpression> properties = new HashSet<>(); properties.add(entity.asOWLObjectProperty()); for(Node<OWLObjectPropertyExpression> node : reasoner.getSubObjectProperties(entity.asOWLObjectProperty(), false)) { properties.add(node.getRepresentativeElement().asOWLObjectProperty()); } instanceDataCnt += ontology.getAxioms(AxiomType.OBJECT_PROPERTY_ASSERTION).parallelStream() .filter(axiom -> properties.contains(axiom.getProperty())) .count(); } else if(entity.isOWLDataProperty()) { instanceDataCnt = reasoner.getSubDataProperties(entity.asOWLDataProperty(), false).getNodes().stream() .mapToLong(node -> ontology.getAxioms(node.getRepresentativeElement(), Imports.INCLUDED).stream() .filter(axiom -> axiom.isOfType(AxiomType.DATA_PROPERTY_ASSERTION)) .count() ).sum(); } System.out.println("#INSTANCE DATA for entity " + entity + " : " + instanceDataCnt); if(instanceDataCnt <= 3) { throw new NoInstanceDataException(entity, axiomType); } return true; }
public static void proofCompletenessTest(final OWLProver prover, final OWLAxiom conclusion, final boolean mustNotBeATautology) { final OWLOntology ontology = prover.getRootOntology(); Proof<Inference<OWLAxiom>> proof = Proofs.removeAssertedInferences( prover.getProof(conclusion), ontology.getAxioms(Imports.INCLUDED)); final InferenceJustifier<Inference<OWLAxiom>, ? extends Set<? extends OWLAxiom>> justifier = InferenceJustifiers .justifyAssertedInferences(); proofCompletenessTest(prover, conclusion, conclusion, proof, justifier, mustNotBeATautology); }
/** * Params: direct * @throws OWLOntologyCreationException * @throws OWLOntologyStorageException * @throws IOException */ public void allSubClassOfCommand() throws OWLOntologyCreationException, OWLOntologyStorageException, IOException { headerOWL(); boolean direct = getParamAsBoolean(Param.direct, true); OWLReasoner r = getReasoner(); for (OWLClass c : getOWLOntology().getClassesInSignature(Imports.INCLUDED)) { for (OWLClass sc : r.getSuperClasses(c, direct).getFlattened()) { output(graph.getDataFactory().getOWLSubClassOfAxiom(c, sc)); } } }
private Set<OWLClass> removeUnreachableAxioms(OWLOntology src, Set<OWLClass> seedClasses) { Stack<OWLClass> stack = new Stack<OWLClass>(); stack.addAll(seedClasses); Set<OWLClass> visited = new HashSet<OWLClass>(); visited.addAll(stack); while (!stack.isEmpty()) { OWLClass elt = stack.pop(); Set<OWLClass> parents = new HashSet<OWLClass>(); Set<OWLClassExpression> xparents = OwlHelper.getSuperClasses(elt, src); xparents.addAll(OwlHelper.getEquivalentClasses(elt, src)); for (OWLClassExpression x : xparents) { parents.addAll(x.getClassesInSignature()); } //parents.addAll(getReasoner().getSuperClasses(elt, true).getFlattened()); //parents.addAll(getReasoner().getEquivalentClasses(elt).getEntities()); parents.removeAll(visited); stack.addAll(parents); visited.addAll(parents); } LOG.info("# in closure set to keep: "+visited.size()); Set<OWLAxiom> rmAxioms = new HashSet<OWLAxiom>(); for (OWLClass c : src.getClassesInSignature()) { if (!visited.contains(c)) { //LOG.info("removing axioms for EL-unreachable class: "+c); rmAxioms.addAll(src.getAxioms(c, Imports.EXCLUDED)); rmAxioms.add(src.getOWLOntologyManager().getOWLDataFactory().getOWLDeclarationAxiom(c)); } } src.getOWLOntologyManager().removeAxioms(src, rmAxioms); LOG.info("Removed "+rmAxioms.size()+" axioms. Remaining: "+src.getAxiomCount()); return visited; }
public Set<GeneAnnotation> generateAssociations(OWLOntology ont) { Set<GeneAnnotation> assocs = new HashSet<GeneAnnotation>(); for (OWLNamedIndividual i : ont.getIndividualsInSignature(Imports.INCLUDED)) { assocs.addAll(generateAssociations(i, ont)); } return assocs; }
/** * assumes that the ontology contains both attributes (TBox) and elements + associations (ABox) */ public void createElementAttributeMapFromOntology() { Set<OWLClass> allTypes = new HashSet<OWLClass>(); for (OWLNamedIndividual e : sourceOntology.getIndividualsInSignature(Imports.INCLUDED)) { // NEW: we assume that grouping classes have already been generated Set<OWLClass> types = getReasoner().getTypes(e, true).getFlattened(); allTypes.addAll(addElement(e, types)); /* // find all attributes for an individual. May be // direct named parent classes; // parent class expressions Set<OWLClassExpression> types = e.getTypes(sourceOntology); // role-bounded MSC for k=1. TODO k>1 Map<OWLObjectPropertyExpression, Set<OWLIndividual>> pvs = e.getObjectPropertyValues(sourceOntology); for (OWLObjectPropertyExpression pe : pvs.keySet()) { for (OWLIndividual j : pvs.get(pe)) { for (OWLClassExpression t : j.getTypes(sourceOntology)) { types.add(owlDataFactory.getOWLObjectSomeValuesFrom(pe, t)); } } } allTypes.addAll(addElement(e, types)); */ } // need to materialize as classes... LOG.info("Using "+allTypes.size()+" attribute classes"); fixedAttributeClasses = allTypes; }
@Override public void assignDefaultInformationContentForAllClasses() { for (OWLClass c : getSourceOntology().getClassesInSignature(Imports.INCLUDED) ) { try { getInformationContentForAttribute(c); } catch (UnknownOWLClassException e) { LOG.error("Unknown class: "+c); } } }
public void trim() { Set<OWLClass> retainedClasses = assertInferredForAttributeClasses(); Set<OWLClass> unused = outputOntology.getClassesInSignature(Imports.INCLUDED); LOG.info("Keeping "+retainedClasses.size()+" out of "+unused.size()); unused.removeAll( retainedClasses ); Set<OWLAxiom> rmAxioms = new HashSet<OWLAxiom>(); for (OWLClass c : unused) { rmAxioms.addAll(outputOntology.getReferencingAxioms(c)); rmAxioms.addAll(outputOntology.getAnnotationAssertionAxioms(c.getIRI())); } LOG.info("Removing unused: "+rmAxioms.size()); getOWLOntologyManager().removeAxioms(outputOntology, rmAxioms); flush(); }
/** * @return all named classes inferred to be direct types for the set of individuals */ protected Set<OWLClass> getAttributeClasses() { Set<OWLClass> types = new HashSet<OWLClass>(); for (OWLNamedIndividual ind : this.outputOntology.getIndividualsInSignature(Imports.INCLUDED)) { types.addAll(getReasoner().getTypes(ind, true).getFlattened()); } return types; }
@Deprecated public Set<OWLClassExpression> getDirectAttributeClassExpressions() { Set<OWLClassExpression> types = new HashSet<OWLClassExpression>(); for (OWLNamedIndividual ind : inputOntology.getIndividualsInSignature(Imports.INCLUDED)) { types.addAll(OwlHelper.getTypes(ind, inputOntology)); } LOG.info("Num attribute expressions = "+types.size()); return types; }
protected void ignoreClasses(Set<String> labels) { for (OWLClass c : inputOntology.getClassesInSignature(Imports.INCLUDED)) { String label = this.getAnyLabel(c); if (labels.contains(label)) { classesToSkip.add(c); } } }
public void preprocess() { // TODO - this generates a cross-product of all properties.... for (OWLObjectProperty p : inputOntology.getObjectPropertiesInSignature(Imports.INCLUDED)) { createPropertyView(p); } }
public static void createRandomClassAssertions(OWLOntology ont, int num, int maxAssertionsPerInstance) { Set<OWLClassAssertionAxiom> caasNew = new HashSet<OWLClassAssertionAxiom>(); Vector<OWLClass> clist = new Vector<OWLClass>(ont.getClassesInSignature(Imports.INCLUDED)); for (int i=0; i<num; i++) { OWLNamedIndividual ind = ont.getOWLOntologyManager().getOWLDataFactory(). getOWLNamedIndividual(IRI.create("http://x.org/"+i)); for (int j=0; j< Math.random() * maxAssertionsPerInstance; j++) { OWLClass c = clist.get((int)(Math.random() * clist.size())); caasNew.add(ont.getOWLOntologyManager().getOWLDataFactory(). getOWLClassAssertionAxiom(c, ind)); } } ont.getOWLOntologyManager().addAxioms(ont, caasNew); }
/** * Creates a "fake" individual for every class. * * ABox IRI = TBox IRI + suffix * * if suffix == null, then we are punning * * @param srcOnt * @param iriSuffix * @throws OWLOntologyCreationException */ public static void makeDefaultIndividuals(OWLOntology srcOnt, String iriSuffix) throws OWLOntologyCreationException { OWLOntologyManager m = srcOnt.getOWLOntologyManager(); OWLDataFactory df = m.getOWLDataFactory(); for (OWLClass c : srcOnt.getClassesInSignature(Imports.INCLUDED)) { IRI iri; if (iriSuffix == null || iriSuffix.equals("")) iri = c.getIRI(); else iri = IRI.create(c.getIRI().toString()+iriSuffix); OWLNamedIndividual ind = df.getOWLNamedIndividual(iri); m.addAxiom(srcOnt, df.getOWLDeclarationAxiom(ind)); m.addAxiom(srcOnt, df.getOWLClassAssertionAxiom(c, ind)); } }
public void preprocess() { for (OWLIndividual ind : inputOntology.getIndividualsInSignature(Imports.INCLUDED)) { gatherProperties(ind); } for (OWLObjectProperty p : viewProperties) { createPropertyView(p); } flush(); }
/** * * @param newIRI * @return ontology * @throws OWLOntologyCreationException */ public OWLOntology extractPropertyOntology(IRI newIRI) throws OWLOntologyCreationException { Set<OWLProperty> props = new HashSet<OWLProperty>(); for (OWLObjectProperty p : mainOntology.getObjectPropertiesInSignature(Imports.INCLUDED)) { LOG.info("mainOntology contains: "+p); props.add(p); } return extractPropertyOntology(newIRI, props); }
/** * Remove a set of classes from the ontology * * @param rmSet * @param removeDangling */ public void removeSubsetClasses(Set<OWLClass> rmSet, boolean removeDangling) { OWLOntology o = getOntology(); Set<OWLAxiom> rmAxioms = new HashSet<OWLAxiom>(); for (OWLClass c : rmSet) { rmAxioms.addAll(o.getAnnotationAssertionAxioms(c.getIRI())); rmAxioms.addAll(o.getAxioms(c, Imports.EXCLUDED)); } LOG.info("Removing "+rmAxioms.size() +" axioms"); graph.getManager().removeAxioms(o, rmAxioms); if (removeDangling) { LOG.info("Removing dangling axioms"); removeDanglingAxioms(o); } }
/** * For every pair X DisjointWith Y, generate an axiom * A and Y = Nothing * * (may become deprecated after Elk supports disjoints) * * @param ont * @param manager * @param dataFactory */ public static void translateDisjointsToEquivalents(OWLOntology ont, OWLOntologyManager manager, OWLDataFactory dataFactory) { for (OWLDisjointClassesAxiom dca : ont.getAxioms(AxiomType.DISJOINT_CLASSES, Imports.INCLUDED)) { for (OWLClassExpression ce1 : dca.getClassExpressions()) { for (OWLClassExpression ce2 : dca.getClassExpressions()) { if (ce1.compareTo(ce2) <= 0) continue; OWLEquivalentClassesAxiom eca = dataFactory.getOWLEquivalentClassesAxiom(dataFactory.getOWLNothing(), dataFactory.getOWLObjectIntersectionOf(ce1, ce2)); manager.addAxiom(ont, eca); // TODO - remove if requested } } } }
public void extractModules(OWLOntology ont) { Set<OWLOntology> ionts = ont.getImports(); Set<OWLClass> iclasses = new HashSet<OWLClass>(); for (OWLOntology iont : ionts) { iclasses.addAll(iont.getClassesInSignature(Imports.INCLUDED)); } extractModules(ont.getClassesInSignature(), iclasses); }