Java Code Examples for org.semanticweb.owlapi.model.OWLSubClassOfAxiom#getSuperClass()
The following examples show how to use
org.semanticweb.owlapi.model.OWLSubClassOfAxiom#getSuperClass() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NormalizedOWLQLTbox.java From quetzal with Eclipse Public License 2.0 | 6 votes |
public Set<OWLClass> getUnsatisfiableNamedClasses() { if (unsatisfiableClasses == null) { unsatisfiableClasses = new HashSet<OWLClass>(); // unsatisfiabe named classes C are in the negative closure in the form // subclass( C, not(C)) for (OWLSubClassOfAxiom ax: getNegativeInclInNegClosure()) { OWLClassExpression sub = ax.getSubClass(); OWLClassExpression sup = ax.getSuperClass(); if (!sub.isAnonymous() && sup.getClassExpressionType().equals(ClassExpressionType.OBJECT_COMPLEMENT_OF) && ((OWLObjectComplementOf) sup).getOperand().equals(sub)) { unsatisfiableClasses.add(sub.asOWLClass()); } } } return Collections.unmodifiableSet(unsatisfiableClasses); //return new HashSet<OWLClass>(); }
Example 2
Source File: SubClassComputation.java From quetzal with Eclipse Public License 2.0 | 6 votes |
public SubClassComputation(NormalizedOWLQLTbox tbox) { super(); numOfDirectSubsumptionTests =0; this.tbox = tbox; sub2ToldSubsumers = new HashMap<OWLClassExpression, Set<OWLClassExpression>>(); Set<OWLSubClassOfAxiom> axioms = tbox.getNormalizedOntology().getAxioms(AxiomType.SUBCLASS_OF); int maxToldSubsumers =0; if (axioms!=null) { for (OWLSubClassOfAxiom ax: axioms) { OWLClassExpression sub = ax.getSubClass(); OWLClassExpression sup = ax.getSuperClass(); //if (!sub.isAnonymous()) { Set<OWLClassExpression> s = sub2ToldSubsumers.get(sub); if (s == null) { s = new HashSet<OWLClassExpression>(); sub2ToldSubsumers.put(sub, s); } s.add(sup); maxToldSubsumers = Math.max(s.size(), maxToldSubsumers); } } } logger.debug("Max told subsumers: {}", maxToldSubsumers); }
Example 3
Source File: CycleCheck.java From owltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public List<OWLClass> getAdjacent(OWLClass cls) { Set<OWLClass> results = new HashSet<OWLClass>(); Set<OWLOntology> allOntologies = graph.getAllOntologies(); for (OWLOntology owlOntology : allOntologies) { Set<OWLSubClassOfAxiom> axioms = owlOntology.getSubClassAxiomsForSubClass(cls); if (axioms != null && !axioms.isEmpty()) { for (OWLSubClassOfAxiom axiom : axioms) { OWLClassExpression expression = axiom.getSuperClass(); if (!expression.isAnonymous()) { results.add(expression.asOWLClass()); } } } } if (results.isEmpty()) { return Collections.emptyList(); } return new ArrayList<OWLClass>(results); }
Example 4
Source File: LinkMaker.java From owltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Check that the given subClass does not already has a matching subClass axiom. * * @param subCls * @param p * @param superCls * @return existing axiom or null */ private OWLAxiom hasLinks(OWLClass subCls, OWLObjectProperty p, OWLClass superCls) { for(OWLOntology o : allOntologies) { Set<OWLSubClassOfAxiom> subClsAxioms = o.getSubClassAxiomsForSubClass(subCls); for (OWLSubClassOfAxiom subClsAxiom : subClsAxioms) { OWLClassExpression ce = subClsAxiom.getSuperClass(); if (ce instanceof OWLObjectSomeValuesFrom) { OWLObjectSomeValuesFrom someValuesFrom = (OWLObjectSomeValuesFrom) ce; OWLObjectPropertyExpression property = someValuesFrom.getProperty(); if (p.equals(property)) { OWLClassExpression filler = someValuesFrom.getFiller(); if (superCls.equals(filler)) { return subClsAxiom; } } } } } return null; }
Example 5
Source File: TemplatedTransformer.java From owltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
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; }
Example 6
Source File: CardinalityContraintsTools.java From owltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void visit(OWLSubClassOfAxiom axiom) { OWLClassExpression subClass = axiom.getSubClass(); OWLClassExpression superClass = axiom.getSuperClass(); HandlerResult modifiedSubClass = subClass.accept(handler); HandlerResult modifiedSuperClass = superClass.accept(handler); if (modifiedSubClass != null || modifiedSuperClass != null) { if (modifiedSubClass != null) { if (modifiedSubClass.remove) { remove(ontology, axiom); return; } subClass = modifiedSubClass.modified; } if (modifiedSuperClass != null) { if (modifiedSuperClass.remove) { remove(ontology, axiom); return; } superClass = modifiedSuperClass.modified; } remove(ontology, axiom); OWLSubClassOfAxiom newAxiom = factory.getOWLSubClassOfAxiom(subClass, superClass, axiom.getAnnotations()); add(ontology, newAxiom); } }
Example 7
Source File: OWLGraphWrapperEdgesAdvanced.java From owltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
Set<OWLClass> getSvfClasses(OWLClass c, OWLObjectProperty p) { Set<OWLSubClassOfAxiom> axioms = new HashSet<OWLSubClassOfAxiom>(); for(OWLOntology ont : getAllOntologies()) { axioms.addAll(ont.getSubClassAxiomsForSubClass(c)); } Set<OWLClass> superClasses = new HashSet<OWLClass>(); for (OWLSubClassOfAxiom axiom : axioms) { OWLClassExpression expr = axiom.getSuperClass(); if (expr instanceof OWLObjectSomeValuesFrom) { OWLObjectSomeValuesFrom svf = (OWLObjectSomeValuesFrom) expr; if (p.equals(svf.getProperty())) { OWLClassExpression filler = svf.getFiller(); if (filler instanceof OWLClass) { superClasses.add((OWLClass) filler); } } } } return superClasses; }
Example 8
Source File: OntologyHelper.java From BioSolr with Apache License 2.0 | 5 votes |
/** * Retrieve a map of related classes for a particular class. * * @param owlClass * @return a map of relation type to a list of IRIs for nodes with that * relationship. */ public Map<String, List<String>> getRestrictions(OWLClass owlClass) { RestrictionVisitor visitor = new RestrictionVisitor(Collections.singleton(ontology)); for (OWLSubClassOfAxiom ax : ontology.getSubClassAxiomsForSubClass(owlClass)) { OWLClassExpression superCls = ax.getSuperClass(); // Ask our superclass to accept a visit from the RestrictionVisitor // - if it is an existential restriction then our restriction visitor // will answer it - if not our visitor will ignore it superCls.accept(visitor); } Map<String, List<String>> restrictions = new HashMap<>(); for (OWLObjectSomeValuesFrom val : visitor.getSomeValues()) { OWLClassExpression exp = val.getFiller(); // Get the shortname of the property expression String shortForm = null; Set<OWLObjectProperty> signatureProps = val.getProperty().getObjectPropertiesInSignature(); for (OWLObjectProperty sigProp : signatureProps) { Collection<String> labels = findLabels(sigProp.getIRI()); if (labels.size() > 0) { shortForm = new ArrayList<String>(labels).get(0); } } if (shortForm != null && !exp.isAnonymous()) { IRI iri = exp.asOWLClass().getIRI(); if (!restrictions.containsKey(shortForm)) { restrictions.put(shortForm, new ArrayList<String>()); } restrictions.get(shortForm).add(iri.toString()); } } return restrictions; }
Example 9
Source File: AssertInferredClassExpressions.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
private static Set<OWLObjectSomeValuesFrom> getSuperSVFs(Set<OWLSubClassOfAxiom> axioms) { final Set<OWLObjectSomeValuesFrom> svfs = new HashSet<OWLObjectSomeValuesFrom>(); for (OWLSubClassOfAxiom existing : axioms) { OWLClassExpression superCE = existing.getSuperClass(); superCE.accept(new OWLClassExpressionVisitorAdapter() { @Override public void visit(OWLObjectSomeValuesFrom svf) { svfs.add(svf); } }); } return svfs; }
Example 10
Source File: GCIUtilTest.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void testOrganismPair() throws Exception{ g = getOntologyWrapper("limb_gci.owl"); ElkReasonerFactory rf = new ElkReasonerFactory(); OWLReasoner r = rf.createReasoner(g.getSourceOntology()); try { Set<OWLSubClassOfAxiom> axioms = GCIUtil.getSubClassOfSomeValuesFromAxioms(r); int n = 0; for (OWLSubClassOfAxiom axiom : axioms) { String c = ((OWLClass) axiom.getSubClass()).getIRI().toString(); OWLObjectSomeValuesFrom svf = (OWLObjectSomeValuesFrom) axiom.getSuperClass(); String rel = ((OWLObjectProperty) svf.getProperty()).getIRI().toString(); String p = ((OWLClass) svf.getFiller()).getIRI().toString(); String axstr = c + " " + rel + " " + p; System.out.println(axstr); if ("http://x.org/phalanx-development http://x.org/part-of http://x.org/digit-development".equals(axstr)) { n |= 1; } if ("http://x.org/digit-development http://x.org/part-of http://x.org/autopod-development".equals(axstr)) { n |= 2; } if ("http://x.org/limb-development http://x.org/part-of http://x.org/organism-development".equals(axstr)) { n |= 4; } if ("http://x.org/autopod-development http://x.org/part-of http://x.org/limb-development".equals(axstr)) { n |= 8; } } assertEquals(4, axioms.size()); assertEquals(15, n); } finally { r.dispose(); } }
Example 11
Source File: InferenceBuilder.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Check all classes for potential redundant subClass axioms of type: * <pre> * A SubClassOf R some B * and * A SubClassOf B * </pre> * * @return list of axiom pairs */ public List<PotentialRedundant> checkPotentialRedundantSubClassAxioms() { List<PotentialRedundant> result = new ArrayList<PotentialRedundant>(); for(OWLClass cls : graph.getAllOWLClasses()) { Set<OWLSubClassOfAxiom> axioms = graph.getAllOWLSubClassOfAxiomsForSubClass(cls); if (axioms.size() > 1) { // only check sets with more than one axiom for (OWLSubClassOfAxiom main : axioms) { OWLClassExpression mainSuperClassCE = main.getSuperClass(); if (mainSuperClassCE.isAnonymous()) { continue; } OWLClass mainSuperClass = mainSuperClassCE.asOWLClass(); for (OWLSubClassOfAxiom current : axioms) { if (main == current) { continue; } OWLClassExpression currentSuperClass = current.getSuperClass(); if (currentSuperClass.isAnonymous() && currentSuperClass instanceof OWLObjectSomeValuesFrom) { OWLObjectSomeValuesFrom someValuesFrom = (OWLObjectSomeValuesFrom) currentSuperClass; final OWLClassExpression filler = someValuesFrom.getFiller(); if (mainSuperClass.equals(someValuesFrom.getFiller())) { final OWLObjectPropertyExpression property = someValuesFrom.getProperty(); final OWLClassExpression subClass = current.getSubClass(); final PotentialRedundant redundant = new PotentialRedundant(main, current, subClass.asOWLClass(), property.asOWLObjectProperty(), filler.asOWLClass()); result.add(redundant); } } } } } } if (!result.isEmpty()) { return result; } return null; }
Example 12
Source File: InferenceBuilder.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Update the set of redundant axioms for the given {@link OWLClass} cls. * * @param cls * @param ontology * @param redundantAxioms * @param reasoner * @param dataFactory */ protected static void updateRedundant(OWLClass cls, OWLOntology ontology, Set<OWLAxiom> redundantAxioms, OWLReasoner reasoner, OWLDataFactory dataFactory) { final OWLClass owlThing = dataFactory.getOWLThing(); // get all direct super classes final Set<OWLClass> direct = reasoner.getSuperClasses(cls, true).getFlattened(); direct.remove(owlThing); // get all super classes (includes direct ones) final Set<OWLClass> indirect = reasoner.getSuperClasses(cls, false).getFlattened(); indirect.remove(owlThing); // remove direct super classes from all -> redundant super classes indirect.removeAll(direct); // rename final Set<OWLClass> redundant = indirect; // filter // subclass of axioms, which have a super class in the redundant set Set<OWLSubClassOfAxiom> axioms = ontology.getSubClassAxiomsForSubClass(cls); for (OWLSubClassOfAxiom subClassOfAxiom : axioms) { OWLClassExpression ce = subClassOfAxiom.getSuperClass(); if (!ce.isAnonymous()) { OWLClass superClass = ce.asOWLClass(); if (redundant.contains(superClass)) { redundantAxioms.add(subClassOfAxiom); } } } }
Example 13
Source File: RedundantAxiomTagger.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static void tagRedundantAxioms(OWLReasoner reasoner) { OWLOntology ont = reasoner.getRootOntology(); OWLOntologyManager mgr = ont.getOWLOntologyManager(); OWLDataFactory df = mgr.getOWLDataFactory(); OWLAnnotationProperty anProp = df.getOWLAnnotationProperty(IRI.create("http://www.geneontology.org/formats/oboInOwl#source")); for (OWLSubClassOfAxiom ax : ont.getAxioms(AxiomType.SUBCLASS_OF)) { if (!ax.getSuperClass().isAnonymous()) { OWLClass supc = (OWLClass) ax.getSuperClass(); mgr.removeAxiom(ont, ax); reasoner.flush(); NodeSet<OWLClass> ancs = reasoner.getSuperClasses(ax.getSubClass(), false); //LOG.info(ax + " ANCS="+ancs); if (ancs.containsEntity( supc)) { String direct = "indirect"; if (reasoner.getSuperClasses(ax.getSubClass(), true).containsEntity( supc)) { direct = "direct"; } LOG.info("SCA = "+ax+" D="+direct); OWLAnnotation ann = df.getOWLAnnotation(anProp, df.getOWLLiteral(direct)); OWLAxiom newAxiom = changeAxiomAnnotations(ax, Collections.singleton(ann), df); mgr.addAxiom(ont, newAxiom); } else { // put it back mgr.addAxiom(ont, ax); } } } }
Example 14
Source File: OWLGraphManipulator.java From owltools with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Relaxes all {@code OWLObjectIntersectionOf}s. This method will relax * {@code OWLSubClassOfAxiom}s, whose superclass is an {@code OWLObjectIntersectionOf}, * into multiple {@code OWLSubClassOfAxiom}s, using a <a * href='http://owlapi.sourceforge.net/javadoc/org/semanticweb/owlapi/SplitSubClassAxioms.html'> * SplitSubClassAxioms</a>. It will also relax {@code OWLSubClassOfAxiom}s, whose * superclass is an {@code OWLObjectSomeValuesFrom} with a filler being an * {@code OWLObjectIntersectionOf}, into multiple {@code OWLSubClassOfAxiom}s with * an {@code OWLObjectSomeValuesFrom} as superclass, with the same * {@code OWLPropertyExpression}, and individual operands as filler. * <p> * Note that it is likely that the {@code OWLObjectIntersectionOf}s where used in * {@code OWLEquivalentClassesAxiom}s, rather than in {@code OWLSubClassOfAxiom}s. * But the method {@link #convertEquivalentClassesToSuperClasses()} would have transformed * them into {@code OWLSubClassOfAxiom}s. It must be called before this method. * * @see #performDefaultModifications() * @see #convertEquivalentClassesToSuperClasses() */ private void splitSubClassAxioms() { log.info("Relaxing OWLSubClassOfAxioms whose superclass is an OWLObjectIntersectionOf"); //first, split subClassOf axioms whose superclass is an OWLObjectIntersectionOf SplitSubClassAxioms split = new SplitSubClassAxioms( this.getOwlGraphWrapper().getAllOntologies(), this.getOwlGraphWrapper().getDataFactory()); this.getOwlGraphWrapper().getManager().applyChanges(split.getChanges()); this.triggerWrapperUpdate(); //some ontologies use an OWLObjectIntersectionOf as the filler of //an OWLObjectSomeValuesFrom class expression. We go only one level down //(i.e., we would not translate another OWLObjectSomeValuesFrom part of the //OWLObjectIntersectionOf) OWLDataFactory dataFactory = this.getOwlGraphWrapper().getDataFactory(); List<OWLOntologyChange> changes = new ArrayList<OWLOntologyChange>(); for (OWLOntology ont : this.getOwlGraphWrapper().getAllOntologies()) { for (OWLSubClassOfAxiom ax : ont.getAxioms(AxiomType.SUBCLASS_OF)) { OWLClassExpression superClsExpr = ax.getSuperClass(); if (superClsExpr instanceof OWLObjectSomeValuesFrom) { OWLObjectSomeValuesFrom someValuesFrom = (OWLObjectSomeValuesFrom) superClsExpr; if (someValuesFrom.getFiller() instanceof OWLObjectIntersectionOf) { //remove original axiom changes.add(new RemoveAxiom(ont, ax)); OWLObjectIntersectionOf filler = (OWLObjectIntersectionOf) someValuesFrom.getFiller(); for (OWLClassExpression op : filler.getOperands()) { //we accept only OWLClasses, otherwise we would need to compose //OWLObjectPropertyExpressions if (op instanceof OWLClass) { OWLAxiom replAx = dataFactory. getOWLSubClassOfAxiom(ax.getSubClass(), dataFactory.getOWLObjectSomeValuesFrom( someValuesFrom.getProperty(), op)); changes.add(new AddAxiom(ont, replAx)); } } } } } } this.getOwlGraphWrapper().getManager().applyChanges(changes); this.triggerWrapperUpdate(); log.info("OWLObjectIntersectionOf relaxation done."); }
Example 15
Source File: GCIUtil.java From owltools with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Generates trivial SVF axioms from existing GCIs * * <pre> * For each GCI of the form CX SubClassOf R some DX * for each C that is an inferred direct subclass of or equivalent to CX * for each D that is an inferred direct superclass of or equivalent to DX * add an axiom C SubClassOf R some D * </pre> * @param ontology * @param reasoner * @return axioms */ public static Set<OWLSubClassOfAxiom> getSubClassOfSomeValuesFromAxioms(OWLOntology ontology, OWLReasoner reasoner) { Set<OWLSubClassOfAxiom> axioms = new HashSet<OWLSubClassOfAxiom>(); OWLDataFactory df = ontology.getOWLOntologyManager().getOWLDataFactory(); for (OWLSubClassOfAxiom ax : ontology.getAxioms(AxiomType.SUBCLASS_OF)) { OWLClassExpression c = ax.getSubClass(); if (ax.getSuperClass() instanceof OWLObjectSomeValuesFrom) { OWLObjectSomeValuesFrom svf = (OWLObjectSomeValuesFrom)ax.getSuperClass(); OWLObjectPropertyExpression p = svf.getProperty(); OWLClassExpression filler = svf.getFiller(); if (filler.isAnonymous() || c.isAnonymous()) { if (c.isBottomEntity()) continue; if (filler.isTopEntity()) continue; Set<OWLClass> childSet = reasoner.getEquivalentClasses(c).getEntities(); if (childSet.size() == 0) { childSet = reasoner.getSubClasses(c, true).getFlattened(); } for (OWLClass childClass : childSet) { if (childClass.isBottomEntity()) continue; Set<OWLClass> childClassSuperClasses = reasoner.getSuperClasses(childClass, false).getFlattened(); childClassSuperClasses.addAll(reasoner.getEquivalentClasses(childClass).getEntities()); Set<OWLClass> parentSet = reasoner.getEquivalentClasses(filler).getEntities(); if (parentSet.size() == 0) { parentSet = reasoner.getSuperClasses(filler, true).getFlattened(); } // TODO: remove additional redundancy (R some X) SubClassOf (R some Y) // Elk cannot test arbitrary entailments for (OWLClass parentClass : parentSet) { if (parentClass.isTopEntity()) continue; // do not assert C SubClassOf part-of some D, if C SubClassOf D is entailed if (childClassSuperClasses.contains(parentClass)) continue; axioms.add(df.getOWLSubClassOfAxiom(childClass, df.getOWLObjectSomeValuesFrom(p, parentClass))); } } } } } LOG.info("Inferred SVFs: "+axioms.size()); return axioms; }
Example 16
Source File: InferenceBuilder.java From owltools with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Check the list of axioms for potential redundant subClass axioms of type: * <pre> * A SubClassOf R some B * and * A SubClassOf B * </pre> * * @param inferredAxioms * @return list of axiom pairs */ public List<PotentialRedundant> checkPotentialRedundantSubClassAxioms(Collection<? extends OWLAxiom> inferredAxioms) { List<PotentialRedundant> result = new ArrayList<PotentialRedundant>(); for(OWLAxiom axiom : inferredAxioms) { if (axiom instanceof OWLSubClassOfAxiom) { OWLSubClassOfAxiom main = (OWLSubClassOfAxiom) axiom; OWLClassExpression mainSuperClassCE = main.getSuperClass(); if (mainSuperClassCE.isAnonymous()) { continue; } OWLClassExpression mainSubClassCE = main.getSubClass(); if (mainSubClassCE.isAnonymous()) { continue; } OWLClass mainSuperClass = mainSuperClassCE.asOWLClass(); OWLClass mainSubClass = mainSubClassCE.asOWLClass(); Set<OWLSubClassOfAxiom> subClassAxioms = graph.getAllOWLSubClassOfAxiomsForSubClass(mainSubClass); if (subClassAxioms != null && subClassAxioms.size() > 1) { for (OWLSubClassOfAxiom current : subClassAxioms) { if (main == current) { continue; } OWLClassExpression currentSuperClass = current.getSuperClass(); if (currentSuperClass.isAnonymous() && currentSuperClass instanceof OWLObjectSomeValuesFrom) { OWLObjectSomeValuesFrom someValuesFrom = (OWLObjectSomeValuesFrom) currentSuperClass; final OWLClassExpression filler = someValuesFrom.getFiller(); if (mainSuperClass.equals(filler)) { final OWLObjectPropertyExpression property = someValuesFrom.getProperty(); final OWLClassExpression subClass = current.getSubClass(); result.add(new PotentialRedundant(main, current, subClass.asOWLClass(), property.asOWLObjectProperty(), filler.asOWLClass())); } } } } } } if (!result.isEmpty()) { return result; } return null; }
Example 17
Source File: Mooncat.java From owltools with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * given an ontology *ont* and a set of object properties *filterProps*, remove all axioms from ontology that * have an object property P in their signature where P is not in *filterProps* * * use basic reasoning to map up more specific relationships * * @param ont * @param filterProps * @param reasoner */ public static void retainAxiomsInPropertySubset(OWLOntology ont, Set<OWLObjectProperty> filterProps, OWLReasoner reasoner) { LOG.info("Removing axioms that use properties not in set: "+filterProps); Set<OWLAxiom> rmAxioms = new HashSet<OWLAxiom>(); Set<OWLAxiom> newAxioms = new HashSet<OWLAxiom>(); OWLDataFactory df = ont.getOWLOntologyManager().getOWLDataFactory(); for (OWLAxiom ax : ont.getAxioms()) { Set<OWLObjectProperty> ps = ax.getObjectPropertiesInSignature(); ps.removeAll(filterProps); if (ps.size() > 0) { rmAxioms.add(ax); // if p not-in SubSet, and // A = X SubClassOf p Some Y, // then rewrite as // A = X SubClassOf p' some Y, where p' SubPropertyOf p // rewrite as weaker axioms. // TOOD - Elk does not support superobjectprops - do in wrapper for now? if (ax instanceof OWLSubClassOfAxiom) { OWLSubClassOfAxiom sca = (OWLSubClassOfAxiom)ax; if (!sca.getSubClass().isAnonymous()) { if (sca.getSuperClass() instanceof OWLObjectSomeValuesFrom) { OWLObjectSomeValuesFrom svf = (OWLObjectSomeValuesFrom) sca.getSuperClass(); OWLObjectPropertyExpression p = svf.getProperty(); Set<OWLObjectPropertyExpression> sps = getSuperObjectProperties(p, reasoner, ont); sps.retainAll(filterProps); for (OWLObjectPropertyExpression sp : sps) { OWLObjectSomeValuesFrom newSvf = df.getOWLObjectSomeValuesFrom(sp, svf.getFiller()); OWLSubClassOfAxiom newSca = df.getOWLSubClassOfAxiom(sca.getSubClass(), newSvf); LOG.info("REWRITE: "+sca+" --> "+newSca); newAxioms.add(newSca); } } } } //else if (ax instanceof OWLEquivalentClassesAxiom) { // ((OWLEquivalentClassesAxiom)ax).getClassExpressions(); //} } } LOG.info("Removing "+rmAxioms.size()+" axioms"); ont.getOWLOntologyManager().removeAxioms(ont, rmAxioms); LOG.info("Adding "+newAxioms.size()+" axioms"); ont.getOWLOntologyManager().addAxioms(ont, newAxioms); }
Example 18
Source File: BioChebiGenerator.java From owltools with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Create the GCIs for BioChEBI. Add the axioms into the given ontology. * * @param ontology * @param ignoredClasses */ public void expand(OWLOntology ontology, Set<OWLClass> ignoredClasses) { final OWLOntologyManager manager = ontology.getOWLOntologyManager(); final OWLDataFactory factory = manager.getOWLDataFactory(); // scan axioms Set<OWLSubClassOfAxiom> axioms = ontology.getAxioms(AxiomType.SUBCLASS_OF, Imports.INCLUDED); for (OWLSubClassOfAxiom axiom : axioms) { OWLClassExpression superCE = axiom.getSuperClass(); OWLClassExpression subCE = axiom.getSubClass(); if (subCE.isAnonymous()) { // sub class needs to be an named OWLClass continue; } if (superCE instanceof OWLObjectSomeValuesFrom == false) { continue; } OWLObjectSomeValuesFrom some = (OWLObjectSomeValuesFrom) superCE; OWLObjectPropertyExpression expression = some.getProperty(); if (expression.isAnonymous()) { // object property expression needs to be a named OWLObjectProperty continue; } OWLObjectProperty p = (OWLObjectProperty) expression; Set<OWLObjectProperty> expansions = expansionMap.get(p); if (expansions == null) { continue; } // get content for GCI OWLClassExpression y = some.getFiller(); OWLClass x = subCE.asOWLClass(); if (ignoredClasses.contains(x)) { continue; } for (OWLObjectProperty createProperty : expansions) { OWLClassExpression ce1 = factory.getOWLObjectSomeValuesFrom(createProperty, x); OWLClassExpression ce2 = factory.getOWLObjectSomeValuesFrom(createProperty, y); OWLEquivalentClassesAxiom eq = factory.getOWLEquivalentClassesAxiom(ce1, ce2); manager.addAxiom(ontology, eq); } } Set<OWLOntology> imports = ontology.getImports(); StringBuilder sb = new StringBuilder(); DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); sb.append("Generated on ").append(dateFormat.format(new Date())).append(" using the following import chain:"); for (OWLOntology owlOntology : imports) { OWLOntologyID ontologyID = owlOntology.getOntologyID(); sb.append(" "); appendOntologyId(ontologyID, sb); } addComment(sb.toString(), ontology); }