ontologyindices.java
来自「Semantic Web Ontology Editor」· Java 代码 · 共 933 行 · 第 1/3 页
JAVA
933 行
lookInsideDescription(andOperand, entity, checkingDomain, checkingRange, checkingNestedRestriction); } } if(desc instanceof OWLOr){ this.unions.add(desc); //For expressivity this.isDLLite = false; this.isEL = false; this.isELpp = false; this.isRDFS = false; if (DEBUG_UNIONS) System.out.println("<Has Union>: in " + entity + " using " + desc); this.hasUnion = true; // Iterator it = ((OWLNaryBooleanDescription)desc).getOperands().iterator(); while(it.hasNext()) { // add to classes in unions map OWLDescription orOperand = (OWLDescription) it.next(); this.addToMap(this.classesInUnions, orOperand, desc); lookInsideDescription(orOperand, entity, checkingDomain, checkingRange, checkingNestedRestriction); } } if(desc instanceof OWLNot){ //For expressivity OWLDescription de = ((OWLNot)desc).getOperand(); if(!(de instanceof OWLClass)){ this.isDLLite = false; } // OWLNothing complementOf OWLThing does not count for 'hasNegation' tw7 if ( ( de instanceof OWLClass ) && ( entity instanceof OWLClass )) { OWLClass a = (OWLClass)entity; OWLClass b = (OWLClass)de; if (! ((a.equals(owlThing) && b.equals(owlNothing)) || (a.equals(owlNothing) && b.equals(owlThing))) ) { if (DEBUG_NEGATIONS) System.out.println("<Has Negation>: in " + a + " using " + b); this.hasNegation = true; this.isRDFS = false; if (DEBUG_IS_EL) System.out.println("Not EL! Complement Found: in " + entity + " using " +de ); this.isEL = false; this.isELpp = false; } } else { if (DEBUG_NEGATIONS) System.out.println("<Has Negation>: in " + entity + " using " + desc ); this.hasNegation = true; this.isRDFS = false; if (DEBUG_IS_EL) System.out.println("Not EL! Complement Found: in " + entity + " using " +de ); this.isEL = false; this.isELpp = false; } lookInsideDescription(((OWLNot)desc).getOperand(), entity, checkingDomain, checkingRange, checkingNestedRestriction); } if (desc instanceof OWLEnumeration) { // add individual->enumeration to corresponding hashmap OWLEnumeration enu = (OWLEnumeration) desc; if ( DEBUG_NOMINALS ) { System.out.println( "<Nominals>: " + entity + " Has Enumeration " + desc); Set inds = enu.getIndividuals(); for ( Iterator it = inds.iterator(); it.hasNext();) { OWLIndividual ind = (OWLIndividual)it.next(); System.out.println(" " + ind.toString() ); } /* ConcisePlainVisitor visitor = new ConcisePlainVisitor( new ConciseFormatEntityRenderer(), null); desc.accept( visitor ); String str = visitor.result(); System.out.println( " = " + str); */ } //For expressivity this.isRDFS = false; this.isDLLite = false; this.hasNominals = true; if (DEBUG_IS_EL) System.out.println( entity + "Not EL! has Enumeration: " + desc ); this.isEL = false; if ( enu.getIndividuals().size() > 1) { if (DEBUG_UNIONS) System.out.println("<Has Union>: Enumeration in " + entity + " using " + desc); this.hasUnion = true; //(tw7) OneOf that has more than 1 element is disjunction this.isELpp = false; //(tw7) EL++ only allows for enum of single element } // for (Iterator iter = enu.getIndividuals().iterator(); iter.hasNext();) { OWLIndividual ind = (OWLIndividual) iter.next(); this.addToMap(this.individualsInEnumerations, ind, desc); } } if(desc instanceof OWLRestriction){ // add to prop->Description map OWLProperty prop = ((OWLRestriction) desc).getProperty(); //For expressivity this.isRDFS = false; //RDFS has no restrictions // only check for object restrictions because datatype restrictins are handled // by datatype reasoners and don't necessaritly cause compexity jump (?) (from Bijan) if ( desc instanceof OWLObjectQuantifiedRestriction) { if ( desc instanceof OWLObjectQuantifiedRestriction ) { if(!(((OWLObjectQuantifiedRestriction)desc).getDescription().equals(owlThing))) this.isDLLite = false; } if ((desc instanceof OWLObjectAllRestriction) || (desc instanceof OWLDataQuantifiedRestriction)) { this.isDLLite = false; // causes intractability (tw7) if (DEBUG_IS_EL) System.out.println("Not EL! AllValue Restriction Found: in " + entity ); this.isEL = false; // causes intractability this.isELpp = false; // causes intractability (tw7) } } else if ( desc instanceof OWLObjectValueRestriction ) { if ( DEBUG_NOMINALS ) System.out.println( "<Nominals>: " + entity + " Has ValueRestriction" + desc); this.isDLLite = false; this.hasNominals = true; if (DEBUG_IS_EL) System.out.println("Not EL! Nominals Found: in " + entity ); this.isEL = false; } else if(desc instanceof OWLCardinalityRestriction ) { if (DEBUG_IS_EL) System.out.println("Not EL! Card Restriction Found: in " + entity ); isEL = false; //EL has no functionality construct // ELF is not tractable (tw7) isELpp = false; // causes intracability (tw7) isRDFS = false; //RDFS has no functional or cardinality restrictions (tw7) if(((OWLCardinalityRestriction)desc).isAtMost()){ int m = ((OWLCardinalityRestriction)desc).getAtMost(); if(m <= 1) { if (! (desc instanceof OWLDataCardinalityRestriction) ) hasFunctionality = true; } else { hasCardinality = true; isDLLite = false; //DLLite has no cardinality construct // (DLLite is subset of OWL Lite) (tw7) } } if(((OWLCardinalityRestriction)desc).isAtLeast()){ int m = ((OWLCardinalityRestriction)desc).getAtLeast(); // [BUGBUG] need to check if user is using Not(atLeast(2)) to represent less than 2. if(m <= 1 ) { if (! (desc instanceof OWLDataCardinalityRestriction) ) hasFunctionality = true; } else { hasCardinality = true ; isDLLite = false; //DLLite has no cardinality construct // (DLLite is subset of OWL Lite) (tw7) } } } //end expressivity this.addToMap(this.propToDescriptionRestrictions, prop, desc); this.lookInsideRestriction((OWLRestriction) desc, entity); } } catch (OWLException ex) { ex.printStackTrace(); } } private void lookInsideRestriction(OWLRestriction rest, OWLEntity entity) { // add to Restriction->Entity map this.addToMap(this.restrictionToEntity, rest, entity); if (rest instanceof OWLObjectQuantifiedRestriction) { try { // add to Class->Properties in Restriction map OWLDescription d = ((OWLObjectQuantifiedRestriction) rest).getDescription(); // also add it to the main descriptions set this.descriptions.add(d); //for expressivity if(!(d instanceof OWLClass)) { if (DEBUG_HASCOMPLEXRESTRICTION) System.out.println("<Has Complex Restriction>: in " + entity + " using " + d); hasComplexRestriction = true; isDLLite = false; } // this.addToMap(this.classesToPropertiesRestriction, d, rest.getProperty()); // also look inside descriptions which appear in some/all restrictions on object properties this.lookInsideDescription(d, entity, false, false, false); // finally, also compute nestedRestrictions map here // ** set checkingNestedRestriction = true here ** this.lookInsideDescription(d, rest.getProperty(), false, false, true); } catch (OWLException e) { e.printStackTrace(); } } else if (rest instanceof OWLObjectValueRestriction) { try { // add to Individual->Properties in Restriction map OWLIndividual ind = ((OWLObjectValueRestriction) rest).getIndividual(); this.addToMap(this.individualsToPropertiesRestriction, ind, rest.getProperty()); } catch (OWLException e) { e.printStackTrace(); } } } /** * Given a map and a key-value pair, add the value to the hashset * indexed by the key in the map. * @param map * @param key * @param value */ private void addToMap(Map map, Object key, Object value) { Set index = new HashSet(); if (map.containsKey(key)) index.addAll((HashSet) map.get(key)); if (value instanceof Set) index.addAll((HashSet) value); else index.add(value); map.put(key, index); } /** * Look inside all the descriptions inside a set and obtain * all pair-wise cross-references. Used for equivalent and disjoint sets * specified as OWLClassAxioms * @param set */ private void lookInsideSet(Set set) throws OWLException { for (Iterator iter = set.iterator(); iter.hasNext();) { OWLDescription desc = (OWLDescription) iter.next(); this.lookInsideDescription(desc, null);// descriptions.add(desc);// Set copy = new HashSet(set);// copy.remove(desc);// for (Iterator iter2=copy.iterator(); iter2.hasNext();) {// OWLDescription desc2 = (OWLDescription) iter2.next();// if (desc instanceof OWLClass) this.lookInsideDescription(desc2, (OWLClass) desc);// if (desc2 instanceof OWLClass) this.lookInsideDescription(desc, (OWLClass) desc2);// } } } /** * For a given set of equivalent descriptions, add each equivalent * pairwise to the hashmap - equivalentClasses. * @param set */ private void addEquivalentSet(Set origSet, OWLDescription cla) { Set set = new HashSet(origSet); if (cla!=null) set.add(cla); for (Iterator iter = set.iterator(); iter.hasNext();) { OWLDescription desc = (OWLDescription) iter.next(); Set copy = new HashSet(set); copy.remove(desc); for (Iterator iter2=copy.iterator(); iter2.hasNext();) { OWLDescription desc2 = (OWLDescription) iter2.next(); this.addToMap(this.equivalents, desc, desc2); } } } private void addEquivalentPropSet(Set origSet) { Set set = new HashSet(origSet); for (Iterator iter = set.iterator(); iter.hasNext();) { OWLProperty prop = (OWLProperty) iter.next(); Set copy = new HashSet(set); copy.remove(prop); for (Iterator iter2=copy.iterator(); iter2.hasNext();) { OWLProperty prop2 = (OWLProperty) iter2.next(); this.addToMap(this.equivalents, prop, prop2); } } } }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?