owlentityremover.java
来自「Semantic Web Ontology Editor」· Java 代码 · 共 957 行 · 第 1/3 页
JAVA
957 行
AddDataPropertyRange adpr = new AddDataPropertyRange(ontology, (OWLDataProperty) replEntity, dt, null); changes.add(adpr); } } else if (prop instanceof OWLObjectProperty) { // check range, inverse-props, and prop attributes for (Iterator iter2 = prop.getRanges(ontology).iterator(); iter2.hasNext();) { OWLDescription ran = (OWLDescription) iter2.next(); this.addChange(replEntity, ran, this.RANGE); } for (Iterator iter2 = ((OWLObjectProperty) prop).getInverses(ontology).iterator(); iter2.hasNext();) { OWLObjectProperty inv = (OWLObjectProperty) iter2.next(); this.addChange(replEntity, inv, this.INVERSE); } if (((OWLObjectProperty) prop).isInverseFunctional(ontology)) { SetInverseFunctional sif = new SetInverseFunctional(ontology, (OWLObjectProperty) replEntity, true, null); changes.add(sif); } if (((OWLObjectProperty) prop).isTransitive(ontology)) { SetTransitive st = new SetTransitive(ontology, (OWLObjectProperty) replEntity, true, null); changes.add(st); } if (((OWLObjectProperty) prop).isSymmetric(ontology)) { SetSymmetric ss = new SetSymmetric(ontology, (OWLObjectProperty) replEntity, true, null); changes.add(ss); } } } // check all super properties // *** different from adding superprops *of* remProp as done above, // *** below checks if superProp = remProp for (Iterator iter2=prop.getSuperProperties(ontology).iterator(); iter2.hasNext();) { OWLProperty sup = (OWLProperty) iter2.next(); if (sup.equals(remEntity)) { this.removeChange(prop, sup, SUPERPROPERTY); if (replEntity!=null) this.addChange(prop, replEntity, SUPERPROPERTY); } } // check all property domains for (Iterator iter2=prop.getDomains(ontology).iterator(); iter2.hasNext();) { OWLDescription desc = (OWLDescription) iter2.next(); Object check = this.traceDescription(desc); if (check!=null) { this.removeChange(prop, desc, DOMAIN); if (check instanceof OWLDescription) { this.addChange(prop, check, DOMAIN); } } } // check for all object properties if (prop instanceof OWLObjectProperty && !((OWLObjectProperty) prop).isLink()) { // check property ranges for (Iterator iter2=prop.getRanges(ontology).iterator(); iter2.hasNext();) { OWLDescription desc = (OWLDescription) iter2.next(); Object check = this.traceDescription(desc); if (check!=null) { this.removeChange(prop, desc, RANGE); if (check instanceof OWLDescription) { this.addChange(prop, check, RANGE); } } } // check inverses for (Iterator iter2=((OWLObjectProperty) prop).getInverses(ontology).iterator(); iter2.hasNext();) { OWLObjectProperty invProp = (OWLObjectProperty) iter2.next(); if (invProp.equals(remEntity)) { this.removeChange(prop, invProp, INVERSE); if (replEntity!=null) this.addChange(prop, replEntity, INVERSE); } } } } // check property axioms for (Iterator iter = ontology.getPropertyAxioms().iterator(); iter.hasNext();) { OWLPropertyAxiom axiom = (OWLPropertyAxiom) iter.next(); // check sub prop axioms if (axiom instanceof OWLSubPropertyAxiom) { OWLSubPropertyAxiom subAxiom = (OWLSubPropertyAxiom) axiom; OWLProperty sub = subAxiom.getSubProperty(); OWLProperty sup = subAxiom.getSuperProperty(); if (sub.equals(remEntity) || sup.equals(remEntity)) { this.removeChange(sub, sup, SUBPROPAXIOM); if (replEntity!=null && !sub.equals(remEntity)) this.addChange(sub, replEntity, SUBPROPAXIOM); if (replEntity!=null && !sup.equals(remEntity)) this.addChange(replEntity, sup, SUBPROPAXIOM); } } // check equivalent property axioms else if (axiom instanceof OWLEquivalentPropertiesAxiom) { OWLEquivalentPropertiesAxiom equAxiom = (OWLEquivalentPropertiesAxiom) axiom; Set equOps = equAxiom.getProperties(); boolean changed = false; for (Iterator iter2=new HashSet(equOps).iterator(); iter2.hasNext();) { OWLProperty prop = (OWLProperty) iter2.next(); if (prop.equals(remEntity)) { changed = true; equOps.remove(prop); if (replEntity!=null) equOps.add(replEntity); } } if (changed) { this.removeChange(equAxiom.getProperties(), null, EQUPROPAXIOM); this.addChange(equOps, null, EQUPROPAXIOM); } } } // check all individuals for (Iterator iter = ontology.getIndividuals().iterator(); iter.hasNext();) { OWLIndividual ind = (OWLIndividual) iter.next(); // check all basic stuff that would get removed automatically // by using RemoveEntity on individual if (ind.equals(remEntity) && replEntity!=null) { // move types, obj/data prop-values, annotations for (Iterator iter2=ind.getTypes(ontology).iterator(); iter2.hasNext();) { OWLDescription desc = (OWLDescription) iter2.next(); this.addChange(replEntity, desc, this.INDIVIDUALCLASS); } Map dValues = ind.getDataPropertyValues(ontology); for (Iterator iter2 = dValues.keySet().iterator(); iter2.hasNext();) { OWLDataProperty prop = (OWLDataProperty) iter2.next(); Set vals = (HashSet) dValues.get(prop); for (Iterator valIter = vals.iterator(); valIter.hasNext();) { OWLDataValue value = (OWLDataValue) valIter.next(); OntologyChange change = new AddDataPropertyInstance(ontology, (OWLIndividual) replEntity, prop, value, null); changes.add(change); } } Map oValues = ind.getObjectPropertyValues(ontology); for (Iterator iter2 = oValues.keySet().iterator(); iter2.hasNext();) { OWLObjectProperty prop = (OWLObjectProperty) iter2.next(); Set vals = (HashSet) oValues.get(prop); for (Iterator valIter = vals.iterator(); valIter.hasNext();) { OWLIndividual value = (OWLIndividual) valIter.next(); OntologyChange change = new AddObjectPropertyInstance(ontology, (OWLIndividual) replEntity, prop, value, null); changes.add(change); } } for (Iterator iter2=ind.getAnnotations(ontology).iterator(); iter2.hasNext();) { OWLAnnotationInstance oai = (OWLAnnotationInstance) iter2.next(); this.addChange(replEntity, oai, this.ANNOTATION); } } // check all individual types for (Iterator iter2=ind.getTypes(ontology).iterator(); iter2.hasNext();) { OWLDescription desc = (OWLDescription) iter2.next(); Object check = this.traceDescription(desc); if (check!=null) { this.removeChange(ind, desc, INDIVIDUALCLASS); if (check instanceof OWLDescription) { this.addChange(ind, check, INDIVIDUALCLASS); } } } // check data property value instances Map dValues = ind.getDataPropertyValues(ontology); for (Iterator iter2 = dValues.keySet().iterator(); iter2.hasNext();) { OWLDataProperty prop = (OWLDataProperty) iter2.next(); Set vals = (HashSet) dValues.get(prop); for (Iterator valIter = vals.iterator(); valIter.hasNext();) { OWLDataValue value = (OWLDataValue) valIter.next(); if (prop.equals(remEntity)) { OntologyChange change = new RemoveDataPropertyInstance(ontology, ind, prop, value, null); changes.add(change); if (replEntity!=null) { OntologyChange change2 = new AddDataPropertyInstance(ontology, ind, (OWLDataProperty) replEntity, value, null); changes.add(change2); } } } } // check object property value instances Map oValues = ind.getObjectPropertyValues(ontology); for (Iterator iter2 = oValues.keySet().iterator(); iter2.hasNext();) { OWLObjectProperty prop = (OWLObjectProperty) iter2.next(); Set vals = (HashSet) oValues.get(prop); for (Iterator valIter = vals.iterator(); valIter.hasNext();) { OWLIndividual value = (OWLIndividual) valIter.next(); if (prop.equals(remEntity) || value.equals(remEntity)) { OntologyChange change = new RemoveObjectPropertyInstance(ontology, ind, prop, value, null); changes.add(change); if (prop.equals(remEntity) && replEntity!=null) { OntologyChange change2 = new AddObjectPropertyInstance(ontology, ind, (OWLObjectProperty) replEntity, value, null); changes.add(change2); } if (value.equals(remEntity) && replEntity!=null) { OntologyChange change2 = new AddObjectPropertyInstance(ontology, ind, prop, (OWLIndividual) replEntity, null); changes.add(change2); } } } } } // check individual axioms for (Iterator iter = ontology.getIndividualAxioms().iterator(); iter.hasNext();) { OWLIndividualAxiom axiom = (OWLIndividualAxiom) iter.next(); // check sameAs b/w individuals if (axiom instanceof OWLSameIndividualsAxiom) { OWLSameIndividualsAxiom sameAxiom = (OWLSameIndividualsAxiom) axiom; Set sameOps = sameAxiom.getIndividuals(); boolean changed = false; for (Iterator iter2 = new HashSet(sameOps).iterator(); iter2.hasNext();) { OWLIndividual ind = (OWLIndividual) iter2.next(); if (ind.equals(remEntity)) { changed = true; sameOps.remove(ind); if (replEntity!=null) sameOps.add(replEntity); } } if (changed) { this.removeChange(sameAxiom.getIndividuals(), null, SAMEAS); this.addChange(sameOps, null, SAMEAS); } } // check differentFrom b/w individuals if (axiom instanceof OWLDifferentIndividualsAxiom) { OWLDifferentIndividualsAxiom diffAxiom = (OWLDifferentIndividualsAxiom) axiom; Set diffOps = diffAxiom.getIndividuals(); boolean changed = false; for (Iterator iter2 = new HashSet(diffOps).iterator(); iter2.hasNext();) { OWLIndividual ind = (OWLIndividual) iter2.next(); if (ind.equals(remEntity)) { changed = true; diffOps.remove(ind); if (replEntity!=null) diffOps.add(replEntity); } } if (changed) { this.removeChange(diffAxiom.getIndividuals(), null, DIFFFROM); this.addChange(diffOps, null, DIFFFROM); } } } // add removeEntity change right at the end OntologyChange change = new RemoveEntity(ontology, remEntity, null); changes.add(change); // finally apply changes for (Iterator iter = changes.iterator(); iter.hasNext();) { change = (OntologyChange) iter.next(); change.accept((ChangeVisitor) ontology); } } catch (OWLException ex) { ex.printStackTrace(); } } /** * Updates class relation (type: subclass/equivalent..) as follows: * Traces contents of desc1 to see if entity found inside * and contents of desc2 to see if entity found inside * Based on checks made, adds/removes changes based on relation type specified * @param desc1 * @param desc2 * @param relType * @throws OWLException */ public void checkClassRelation(OWLDescription desc1, OWLDescription desc2, int relType) throws OWLException { boolean changed = false; OWLDescription addDesc1 = null; OWLDescription addDesc2 = null; // verify contents of description 1 Object check = this.traceDescription(desc1); if (check!=null) { // match found for entity changed = true; // get updated desc if any if (check instanceof OWLDescription) addDesc1 = (OWLDescription) check; } // verify contents of description 2 check = this.traceDescription(desc2); if (check!=null) { // match found for entity changed = true; // get updated desc if any if (check instanceof OWLDescription) addDesc2 = (OWLDescription) check; } // make changes based on verification check above if (changed || addDesc1!=null || addDesc2!=null) this.removeChange(desc1, desc2, relType); if (addDesc1!=null && addDesc2!=null) this.addChange(addDesc1, addDesc2, relType); else if (addDesc1!=null) this.addChange(addDesc1, desc2, relType); else if (addDesc2!=null) this.addChange(desc1, addDesc2, relType); } /** * Traces the contents of an OWLDescription (desc) as follows: * - if desc matches entity [A, ~A, restr(P,*) or hasValue(*,I)], returns DISCARD * - else if desc contains entity, returns newDesc (minus entity) * In all other cases (no match for entity at all), returns Null * * @param desc * @return */ public Object traceDescription(OWLDescription desc) { try { // // testing// if (desc instanceof OWLClass) System.out.println("tracing: "+((OWLClass) desc).getURI());
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?