swooprdfsreasoner.java
来自「Semantic Web Ontology Editor」· Java 代码 · 共 1,175 行 · 第 1/3 页
JAVA
1,175 行
return set; } public Set getDataProperties() { Set set = new HashSet(); for(int i = 0; i < properties.size(); i++) if(properties.get(i) instanceof OWLDataProperty) set.add(properties.get(i)); return set; } public Set getAnnotationProperties() { Set set = new HashSet(); for(int i = 0; i < properties.size(); i++) if(properties.get(i) instanceof OWLAnnotationProperty) set.add(properties.get(i)); return set; } public Set getIndividuals() { return new HashSet(individuals); } public boolean supportsExplanation() { return false; } public void setDoExplanation(boolean explain) { } public boolean getDoExplanation() { return false; } public String getExplanation(ShortFormProvider shortForms) { return null; } public Set getExplanationSet() { return null; } public Set instancesOf(OWLClass c) throws OWLException { return this.instancesOf((OWLDescription) c); } public Set allInstancesOf(OWLClass c) throws OWLException { // get all descendents of class c List classTracker = new ArrayList(); Set descendants = this.getClassHierarchy(c, classTracker, "SUB"); descendants.add(c); Set resultSet = new HashSet(); for (Iterator iter = descendants.iterator(); iter.hasNext();) { OWLClass cla = (OWLClass) iter.next(); resultSet.addAll(this.instancesOf(cla)); } return resultSet; } public OWLOntology getOntology() throws OWLException { return ontology; } public boolean isSubClassOf(OWLDescription d1, OWLDescription d2) throws OWLException { if (d1 instanceof OWLClass && d2 instanceof OWLClass) { OWLClass cl = (OWLClass) d1; List classTracker = new ArrayList(); Set ancestors = this.getClassHierarchy(cl, classTracker, "SUPER"); return (ancestors.contains(d2)); } else return false; } public boolean isEquivalentClass(OWLDescription d1, OWLDescription d2) throws OWLException { if (this.equivalents.containsKey(d1)) { return ((HashSet) equivalents.get(d1)).contains(d2); } else return false; } public boolean isConsistent(OWLDescription d1) throws OWLException { return true; } public Set superClassesOf(OWLDescription d) throws OWLException { Set resultSet = new HashSet(); Set claSet = new HashSet(); claSet.add(d); // also find equivalents if (equivalents.containsKey(d)) { claSet.addAll((HashSet) equivalents.get(d)); } // get direct superclasses of all classes in claSet for (Iterator iter = claSet.iterator(); iter.hasNext();) { OWLDescription desc = (OWLDescription) iter.next(); if (desc instanceof OWLClass && outLinks.containsKey(desc)) { Set superClaSet = (HashSet) this.outLinks.get(desc); resultSet.addAll(this.getSetofEquivalentSets(superClaSet)); } } return resultSet; } public Set ancestorClassesOf(OWLDescription d) throws OWLException { Set resultSet = new HashSet(); if (d instanceof OWLClass) { OWLClass cl = (OWLClass) d; List classTracker = new ArrayList(); resultSet = this.getClassHierarchy(cl, classTracker, "SUPER"); } return this.getSetofEquivalentSets(resultSet); } public Set getClassHierarchy(OWLClass cl, List tracker, String dirn) throws OWLException { Set setOfSets = new HashSet(); if (dirn.equals("SUPER")) setOfSets = this.superClassesOf(cl); // return superclass sets else setOfSets = this.subClassesOf(cl); // return subclass sets for (Iterator iter = setOfSets.iterator(); iter.hasNext();) { Set set = (HashSet) iter.next(); // get each equivalent superClass set for (Iterator iter2=set.iterator(); iter2.hasNext();) { OWLClass cla = (OWLClass) iter2.next(); if (!tracker.contains(cla)) { tracker.add(cla); // recurse getClassHierarchy(cla, tracker, dirn); } else { // cycle found! // verify cycle: check for a subclass from supCla to cl // i.e. check if owl:Thing is one of the links inbetween int pos1 = tracker.indexOf(cla); int pos2 = tracker.indexOf(cl); boolean cycle = true; OWLClass thing = ontology.getOWLDataFactory().getOWLThing(); OWLClass nothing = ontology.getOWLDataFactory().getOWLNothing(); for (int i=pos1; i<pos2; i++) { if (dirn.equals("SUPER")) { if (tracker.get(i).equals(thing)) cycle = false; } else { if (tracker.get(i).equals(nothing)) cycle = false; } } if (cycle) { this.addEquivalentClass( cl, cla ); } } } } return new HashSet(tracker); } public Set subClassesOf(OWLDescription d) throws OWLException { Set resultSet = new HashSet(); Set claSet = new HashSet(); claSet.add(d); // also find equivalents if (equivalents.containsKey(d)) { claSet.addAll((HashSet) equivalents.get(d)); } // get direct subclasses of all classes in claSet for (Iterator iter = claSet.iterator(); iter.hasNext();) { OWLDescription desc = (OWLDescription) iter.next(); if (desc instanceof OWLClass && incLinks.containsKey(desc)) { Set subClaSet = (HashSet) this.incLinks.get(desc); resultSet.addAll(this.getSetofEquivalentSets(subClaSet)); } } return resultSet; } public Set descendantClassesOf(OWLDescription d) throws OWLException { Set resultSet = new HashSet(); if (d instanceof OWLClass) { OWLClass cl = (OWLClass) d; List classTracker = new ArrayList(); resultSet = this.getClassHierarchy(cl, classTracker, "SUB"); } return this.getSetofEquivalentSets(resultSet); } public Set equivalentClassesOf(OWLDescription d) throws OWLException { if (d instanceof OWLClass && equivalents.containsKey(d)) { Set equSet = new HashSet((HashSet) equivalents.get(d)); equSet.remove(d); return equSet; } return new HashSet(); } public boolean isInstanceOf(OWLIndividual i, OWLDescription d) throws OWLException { return false; } public Set instancesOf(OWLDescription d) throws OWLException { Set resultSet = new HashSet(); Set claSet = new HashSet(); claSet.add(d); // also find equivalents if (equivalents.containsKey(d)) { claSet.addAll((HashSet) equivalents.get(d)); } // get individuals of all classes in claSet for (Iterator iter = claSet.iterator(); iter.hasNext();) { OWLClass cla = (OWLClass) iter.next(); if (classInds.containsKey(cla)) { Set inds = (HashSet) classInds.get(cla); resultSet.addAll(inds); } } return resultSet; } public boolean isSubPropertyOf(OWLProperty p1, OWLProperty p2) throws OWLException { Set ancestors = this.getPropertyHierarchy(p1, new ArrayList(), "SUPER"); return ancestors.contains(p2); } public Set superPropertiesOf(OWLProperty prop) throws OWLException { Set resultSet = new HashSet(); Set propSet = new HashSet(); propSet.add(prop); // also find equivalents if (equivalents.containsKey(prop)) { propSet.addAll((HashSet) equivalents.get(prop)); } // get direct superproperties of all properties in propSet for (Iterator iter = propSet.iterator(); iter.hasNext();) { OWLProperty p = (OWLProperty) iter.next(); if (outLinks.containsKey(p)) { Set subPropSet = (HashSet) this.outLinks.get(p); resultSet.addAll(this.getSetofEquivalentSets(subPropSet)); } } return resultSet; } public Set ancestorPropertiesOf(OWLProperty prop) throws OWLException { List propTracker = new ArrayList(); Set ancestors = this.getPropertyHierarchy(prop, propTracker, "SUPER"); return this.getSetofEquivalentSets(ancestors); } public Set getPropertyHierarchy(OWLProperty p, List tracker, String dirn) throws OWLException { Set setOfSets = new HashSet(); if (dirn.equals("SUPER")) setOfSets = this.superPropertiesOf(p); // return superclass sets else setOfSets = this.subPropertiesOf(p); // return subclass sets for (Iterator iter = setOfSets.iterator(); iter.hasNext();) { Set set = (HashSet) iter.next(); // get each equivalent superClass set for (Iterator iter2=set.iterator(); iter2.hasNext();) { OWLProperty prop = (OWLProperty) iter2.next(); if (!tracker.contains(prop)) { tracker.add(prop); // recurse getPropertyHierarchy(prop, tracker, dirn); } else { // cycle found! } } } return new HashSet(tracker); } /** * Return a 'set of equivalent sets' given a set of objects i.e. for each * object 'obj' in the input set, get its equivalent set (using the hashmap * 'equivalents') and add it to result set * @param set - set of objects whose equivalents have to be determined * @return */ public Set getSetofEquivalentSets(Set set) { Set resultSet = new HashSet(); for (Iterator iter = set.iterator(); iter.hasNext(); ) { Object obj = iter.next(); Set equObjs = new HashSet(); equObjs.add(obj); if (equivalents.containsKey(obj)) equObjs = (HashSet) equivalents.get(obj); resultSet.add(equObjs); } return resultSet; } public Set subPropertiesOf(OWLProperty prop) throws OWLException { Set resultSet = new HashSet(); Set propSet = new HashSet(); propSet.add(prop); // also find equivalents if (equivalents.containsKey(prop)) { propSet.addAll((HashSet) equivalents.get(prop)); } // get direct subproperties of all properties in propSet for (Iterator iter = propSet.iterator(); iter.hasNext();) { OWLProperty p = (OWLProperty) iter.next(); if (incLinks.containsKey(p)) { Set subPropSet = (HashSet) this.incLinks.get(p); resultSet.addAll(this.getSetofEquivalentSets(subPropSet)); } } return resultSet; } public Set descendantPropertiesOf(OWLProperty prop) throws OWLException { List propTracker = new ArrayList(); Set descendents = this.getPropertyHierarchy(prop, propTracker, "SUB"); return this.getSetofEquivalentSets(descendents); } public Set equivalentPropertiesOf(OWLProperty prop) throws OWLException { if (equivalents.containsKey(prop)) { Set equSet = new HashSet((HashSet) equivalents.get(prop)); equSet.remove(prop); return equSet; } return new HashSet(); } public Set inversePropertiesOf(OWLObjectProperty prop) throws OWLException { if (this.inverses.containsKey(prop)) { Set inverses = (Set) this.inverses.get(prop); return this.getSetofEquivalentSets(inverses); } else return this.getSetofEquivalentSets(new HashSet()); } public Set rangesOf(OWLProperty prop) throws OWLException { Set ranges = prop.getRanges(ontologies);// return ranges; return SetUtils.union(this.getSetofEquivalentSets(ranges)); } public Set domainsOf(OWLProperty prop) throws OWLException { Set domains = prop.getDomains(ontologies);// return domains; return SetUtils.union(this.getSetofEquivalentSets(domains)); } public Set superClassesOf(OWLClass cl) throws OWLException { return this.superClassesOf((OWLDescription) cl); } public Set ancestorClassesOf(OWLClass cl) throws OWLException { return this.ancestorClassesOf((OWLDescription) cl); } public Set subClassesOf(OWLClass cl) throws OWLException { return this.subClassesOf((OWLDescription) cl); } public Set descendantClassesOf(OWLClass cl) throws OWLException { return this.descendantClassesOf((OWLDescription) cl); } public Set equivalentClassesOf(OWLClass cl) throws OWLException { return this.equivalentClassesOf((OWLDescription) cl); } public void buildIndices() { indices = new OntologyIndices(this); indices.buildIndex(ontology, loadImports, true);// System.out.println("Expressivity:" +indices.getExpressivity(ontology)); } public Map getDataPropertyValues(OWLIndividual ind) throws OWLException { return ind.getDataPropertyValues( getOntologies() ); } public Map getObjectPropertyValues(OWLIndividual ind) throws OWLException{ return ind.getObjectPropertyValues( getOntologies() ); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?