ontologyindices.java
来自「Semantic Web Ontology Editor」· Java 代码 · 共 933 行 · 第 1/3 页
JAVA
933 行
Iterator it = classes.iterator(); while(it.hasNext()){ OWLClass cla = (OWLClass)it.next(); // handle class equivalents Set eqs = cla.getEquivalentClasses(ontologies); // add to equivalentClasses map this.addEquivalentSet(eqs, cla); Iterator i = eqs.iterator(); while(i.hasNext()) { OWLDescription desc = (OWLDescription) i.next(); lookInsideDescription(desc, cla); } // handle subclasses http://www.gnowsis.org/ont/vcard Set subs = cla.getSubClasses(ontologies); // add to subClasses map this.addToMap(this.subClasses, cla, subs); Iterator j = subs.iterator(); while(j.hasNext()) { OWLDescription desc = (OWLDescription) j.next(); lookInsideDescription(desc, cla); } // handle superclasses Set sups = cla.getSuperClasses(ontologies); // add to superClasses map this.addToMap(this.superClasses, cla, sups); Iterator k = sups.iterator(); while(k.hasNext()) { OWLDescription desc = (OWLDescription) k.next(); lookInsideDescription(desc, cla); } // adding enumerations checking (tw7) Set enumerations = cla.getEnumerations(ontologies); Iterator l = enumerations.iterator(); while(l.hasNext()) { OWLDescription desc = (OWLDescription) l.next(); lookInsideDescription(desc, cla); } } // handle class axioms for (Iterator iter = classAxioms.iterator(); iter.hasNext();) { OWLClassAxiom axiom = (OWLClassAxiom) iter.next(); if (axiom instanceof OWLSubClassAxiom) { OWLSubClassAxiom subAxiom = (OWLSubClassAxiom) axiom; OWLDescription sub = subAxiom.getSubClass(); OWLDescription sup = subAxiom.getSuperClass(); // add to sub/super classes map this.addToMap(this.subClasses, sup, sub); this.addToMap(this.superClasses, sub, sup); descriptions.add(sub); descriptions.add(sup); // and also look inside description lookInsideDescription(sub, null); lookInsideDescription(sup, null); } else if (axiom instanceof OWLEquivalentClassesAxiom) { OWLEquivalentClassesAxiom equAxiom = (OWLEquivalentClassesAxiom) axiom; // add to equivalentClasses map this.addEquivalentSet(equAxiom.getEquivalentClasses(), null); this.lookInsideSet(equAxiom.getEquivalentClasses()); } else if (axiom instanceof OWLDisjointClassesAxiom) { //OWLDIsjointClassAxiom implies existence of OWL:ComplementOf // Note that we can have disjoints without having disjoint axioms // if we have GCIs. e.g. (intersection(C,D) subclassOf OWL:Nothing) // this says that C and D are disjoint. No negation used. //For expressivity this.hasNegation = true; this.isRDFS = false; // no disjoint construct if (DEBUG_IS_EL) System.out.println("Not EL! Disjoint Axiom Found: in " + axiom); this.isEL = false; //EL has no bottom concept // add to disjointAxioms set this.disjointAxioms.add(axiom); OWLDisjointClassesAxiom disAxiom = (OWLDisjointClassesAxiom) axiom; this.lookInsideSet(disAxiom.getDisjointClasses()); } } // handle property domains/ranges Iterator t = properties.iterator(); while(t.hasNext()) { OWLProperty prop = (OWLProperty)t.next(); //For expressivity if (prop instanceof OWLObjectProperty){ if(((OWLObjectProperty)prop).isTransitive(ontologies)) { isDLLite = false; isRDFS = false; if (DEBUG_IS_EL) System.out.println("Not EL! Transitivity Found: in " + prop ); isEL = false; hasTransitivity = true; } if(((OWLObjectProperty)prop).isSymmetric(ontologies)){ hasInverse = true; isRDFS = false; if (DEBUG_IS_EL) System.out.println("Not EL! Symmetry Found: in " + prop ); isEL = false; isELpp = false; } if(!(((OWLObjectProperty)prop).getInverses(ontologies).isEmpty())){ hasInverse = true; isRDFS = false; if (DEBUG_IS_EL) System.out.println("Not EL! Inverse Found: in " + prop ); isEL = false; isELpp = false; } if(((OWLObjectProperty)prop).isFunctional(ontologies)){ isRDFS = false; if (DEBUG_IS_EL) System.out.println("Not EL! Functionality Found: in " + prop ); isEL = false; isELpp = false; hasFunctionality = true; } /* tw7 * Inverse functional can be simulated using a property that has * an inverse, and that inverse is functional. * * */ if (((OWLObjectProperty)prop).isInverseFunctional(ontologies)) { hasFunctionality = true; hasInverse = true; isRDFS = false; if (DEBUG_IS_EL) System.out.println("Not EL! InverseFunctionality Found: in " + prop ); isEL = false; isELpp = false; } } /* else { // also check for datatype properties // though for OWL Lite and DL, datatype properties are not supposed to // be transitive, symmetric, inverse, or inverse functional // OWLAPI does not provide methods for these attributes, only functional // (tw7) if(((OWLDataProperty)prop).isFunctional(ontologies)){ hasFunctionality = true; if (DEBUG_IS_EL) System.out.println("Not EL! Functionality Found: in " + prop ); isEL = false; isELpp = false; isRDFS = false; } } */ // handle prop domains and ranges Iterator g = prop.getDomains(ontologies).iterator(); while(g.hasNext()){ OWLDescription desc = (OWLDescription)g.next(); lookInsideDescription(desc, prop, true, false, false); } Iterator b = prop.getRanges(ontologies).iterator(); if(prop instanceof OWLObjectProperty) { while(b.hasNext()) { //expressivity hasRange = true; OWLDescription desc = (OWLDescription)b.next(); lookInsideDescription(desc, prop, false, true, false); } } // get superprops and add it to corresponding maps Set supProp = prop.getSuperProperties(ontologies); this.addToMap(this.superProperties, prop, supProp); for (Iterator iter = supProp.iterator(); iter.hasNext();) { OWLProperty sup = (OWLProperty) iter.next(); this.addToMap(this.subProperties, sup, prop); } } // handle property axioms for (Iterator iter = propAxioms.iterator(); iter.hasNext();) { OWLPropertyAxiom axiom = (OWLPropertyAxiom) iter.next(); //For expressivity this.isDLLite = false; this.hasRoleHierarchy = true; // add subproperty axiom info to hashmaps if (axiom instanceof OWLSubPropertyAxiom) { OWLSubPropertyAxiom subAxiom = (OWLSubPropertyAxiom) axiom; this.addToMap(this.superProperties, subAxiom.getSubProperty(), subAxiom.getSuperProperty()); this.addToMap(this.subProperties, subAxiom.getSuperProperty(), subAxiom.getSubProperty()); } // add equivalent props axiom info to hashmap if (axiom instanceof OWLEquivalentPropertiesAxiom) { OWLEquivalentPropertiesAxiom equAxiom = (OWLEquivalentPropertiesAxiom) axiom; this.addEquivalentPropSet(equAxiom.getProperties()); } } // handle individuals for (Iterator iter = individuals.iterator(); iter.hasNext(); ) { OWLIndividual ind = (OWLIndividual) iter.next(); // get types Set types = ind.getTypes(ontologies); for (Iterator iter2= types.iterator(); iter2.hasNext();) { OWLDescription desc = (OWLDescription) iter2.next(); //Test descriptions.add(desc); this.addToMap(this.instancesOf, desc, ind); } // get object property-value assertions Map oValues = ind.getObjectPropertyValues(ontologies); for (Iterator iter2 = oValues.keySet().iterator(); iter2.hasNext();) { OWLObjectProperty prop = (OWLObjectProperty) iter2.next(); // add to prop->ind map this.addToMap(this.propToIndividualAssertions, prop, ind); Set vals = (HashSet) oValues.get(prop); for (Iterator iter3 = vals.iterator(); iter3.hasNext();) { OWLIndividual valueInd = (OWLIndividual) iter3.next(); // add to ind->prop map such that R(b,a): b->R this.addToMap(this.individualsToPropertiesAssertions, valueInd, prop); } } // get data property-value assertions Map dValues = ind.getDataPropertyValues(ontologies); for (Iterator iter2 = dValues.keySet().iterator(); iter2.hasNext();) { OWLDataProperty prop = (OWLDataProperty) iter2.next(); // add to prop->ind map this.addToMap(this.propToIndividualAssertions, prop, ind); } } //expressivity; if(hasInverse == false && hasRange == true) { if (DEBUG_IS_EL) System.out.println("Not EL! Has no Inverse, but has Range."); isEL = false; } } private void lookInsideDescription(OWLDescription desc, OWLEntity entity) throws OWLException { this.lookInsideDescription(desc, entity, false, false, false); } private void lookInsideDescription( OWLDescription desc, OWLEntity entity, boolean checkingDomain, boolean checkingRange, boolean checkingNestedRestriction ) throws OWLException { OWLClass owlThing = reasoner.getOntology().getOWLDataFactory().getOWLThing(); OWLClass owlNothing = reasoner.getOntology().getOWLDataFactory().getOWLNothing(); try { // add to description set anyway this.descriptions.add(desc); // add to Description->Entity map if (entity!=null) this.addToMap(this.descriptionToEntity, desc, entity); // add to Classes/Descriptions -> property map for domain/range if (entity!=null && entity instanceof OWLProperty) { if (checkingDomain) { this.addToMap(this.classesToDomain, desc, entity); // also if P has domain C, then any subproperty of P has domain C Set descendants = SetUtils.union(reasoner.descendantPropertiesOf((OWLProperty) entity)); for (Iterator iter = descendants.iterator(); iter.hasNext();) { this.addToMap(this.classesToDomain, desc, (OWLProperty) iter.next()); } } if (checkingRange) { this.addToMap(this.classesToRange, desc, entity); // also if P has range C, then any subproperty of P has range C Set descendants = SetUtils.union(reasoner.descendantPropertiesOf((OWLProperty) entity)); for (Iterator iter = descendants.iterator(); iter.hasNext();) { this.addToMap(this.classesToRange, desc, (OWLProperty) iter.next()); } } // also check and add to nestedRestrictions map if (checkingNestedRestriction && desc instanceof OWLObjectRestriction) { this.addToMap(this.nestedRestrictions, entity, ((OWLObjectRestriction) desc).getObjectProperty()); //For expressivity this.isDLLite = false; this.isRDFS = false; } } if(desc instanceof OWLAnd){ this.intersections.add(desc); Iterator it = ((OWLNaryBooleanDescription)desc).getOperands().iterator(); while(it.hasNext()) { // add to classes in intersections map OWLDescription andOperand = (OWLDescription) it.next(); this.addToMap(this.classesInIntersections, andOperand, desc);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?