econniterativepartitioning.java
来自「Semantic Web Ontology Editor」· Java 代码 · 共 1,353 行 · 第 1/5 页
JAVA
1,353 行
//The MIT License//// Copyright (c) 2004 Mindswap Research Group, University of Maryland, College Park//// Permission is hereby granted, free of charge, to any person obtaining a copy// of this software and associated documentation files (the "Software"), to// deal in the Software without restriction, including without limitation the// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or// sell copies of the Software, and to permit persons to whom the Software is// furnished to do so, subject to the following conditions://// The above copyright notice and this permission notice shall be included in// all copies or substantial portions of the Software.//// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS// IN THE SOFTWARE.package org.mindswap.swoop.refactoring;import java.io.OutputStream;import java.io.OutputStreamWriter;import java.io.StringWriter;import java.io.Writer;import java.net.URI;import java.util.ArrayList;import java.util.HashMap;import java.util.HashSet;import java.util.Iterator;import java.util.List;import java.util.Map;import java.util.Set;import org.mindswap.pellet.utils.Timer;import org.mindswap.swoop.SwoopModel;import org.mindswap.swoop.reasoner.SwoopReasoner;import org.mindswap.swoop.utils.SetUtils;import org.mindswap.swoop.utils.change.EnumElementChange;import org.mindswap.swoop.utils.owlapi.IndicesLibrary;import org.mindswap.swoop.utils.owlapi.OntologyIndices;import org.semanticweb.owl.io.vocabulary.OWLVocabularyAdapter;import org.semanticweb.owl.model.OWLAnd;import org.semanticweb.owl.model.OWLClass;import org.semanticweb.owl.model.OWLDataProperty;import org.semanticweb.owl.model.OWLDataType;import org.semanticweb.owl.model.OWLDataValue;import org.semanticweb.owl.model.OWLDescription;import org.semanticweb.owl.model.OWLDisjointClassesAxiom;import org.semanticweb.owl.model.OWLEntity;import org.semanticweb.owl.model.OWLEnumeration;import org.semanticweb.owl.model.OWLEquivalentPropertiesAxiom;import org.semanticweb.owl.model.OWLException;import org.semanticweb.owl.model.OWLIndividual;import org.semanticweb.owl.model.OWLNamedObject;import org.semanticweb.owl.model.OWLNaryBooleanDescription;import org.semanticweb.owl.model.OWLNot;import org.semanticweb.owl.model.OWLObject;import org.semanticweb.owl.model.OWLObjectProperty;import org.semanticweb.owl.model.OWLObjectQuantifiedRestriction;import org.semanticweb.owl.model.OWLObjectRestriction;import org.semanticweb.owl.model.OWLObjectValueRestriction;import org.semanticweb.owl.model.OWLOntology;import org.semanticweb.owl.model.OWLOr;import org.semanticweb.owl.model.OWLProperty;import org.semanticweb.owl.model.OWLPropertyAxiom;import org.semanticweb.owl.model.OWLRestriction;import org.semanticweb.owl.model.OWLSubClassAxiom;import org.semanticweb.owl.model.OWLSubPropertyAxiom;import org.semanticweb.owl.model.change.AddClassAxiom;import org.semanticweb.owl.model.change.AddDataPropertyInstance;import org.semanticweb.owl.model.change.AddDataPropertyRange;import org.semanticweb.owl.model.change.AddDomain;import org.semanticweb.owl.model.change.AddEntity;import org.semanticweb.owl.model.change.AddEquivalentClass;import org.semanticweb.owl.model.change.AddForeignEntity;import org.semanticweb.owl.model.change.AddIndividualClass;import org.semanticweb.owl.model.change.AddInverse;import org.semanticweb.owl.model.change.AddObjectPropertyInstance;import org.semanticweb.owl.model.change.AddObjectPropertyRange;import org.semanticweb.owl.model.change.AddPropertyAxiom;import org.semanticweb.owl.model.change.AddSuperClass;import org.semanticweb.owl.model.change.AddSuperProperty;import org.semanticweb.owl.model.change.ChangeVisitor;import org.semanticweb.owl.model.change.OntologyChange;import org.semanticweb.owl.model.change.RemoveClassAxiom;import org.semanticweb.owl.model.change.RemoveDataPropertyInstance;import org.semanticweb.owl.model.change.RemoveDataPropertyRange;import org.semanticweb.owl.model.change.RemoveDomain;import org.semanticweb.owl.model.change.RemoveEntity;import org.semanticweb.owl.model.change.RemoveEquivalentClass;import org.semanticweb.owl.model.change.RemoveForeignEntity;import org.semanticweb.owl.model.change.RemoveIndividualClass;import org.semanticweb.owl.model.change.RemoveInverse;import org.semanticweb.owl.model.change.RemoveObjectPropertyInstance;import org.semanticweb.owl.model.change.RemoveObjectPropertyRange;import org.semanticweb.owl.model.change.RemovePropertyAxiom;import org.semanticweb.owl.model.change.RemoveSuperClass;import org.semanticweb.owl.model.change.RemoveSuperProperty;import org.semanticweb.owl.model.change.SetFunctional;import org.semanticweb.owl.model.change.SetInverseFunctional;import org.semanticweb.owl.model.change.SetLinkTarget;import org.semanticweb.owl.model.change.SetSymmetric;import org.semanticweb.owl.model.change.SetTransitive;/** * @author bernardo, aditya * */public class EconnIterativePartitioning { protected SwoopModel swoopModel; protected SwoopReasoner reasoner; private boolean DEBUG = false; private boolean APPLY = false; ArrayList changes ; Timer timers = new Timer("Iteration"); Timer timers2 = new Timer("Copying a large description set"); Timer timers4 = new Timer("SubClasses/SuperClasses/EquClasses"); Timer timers8 = new Timer("Actual Computation of Indices"); Timer timers9 = new Timer("Handling Descendants"); protected StringWriter out; protected OWLOntology source; protected OWLOntology target;// ********************************************************** //Sets storing the foreign entities created in the partitioning //Step //*********************************************************** protected Set addedForeignEntitiesInSource; protected Set addedForeignEntitiesInTarget; //************************************************************ //Indexes storing general information about the SOURCE ontology //********************************************************** protected Set Restrictions; // All Restrictions protected Set classesInRestriction; //Classes and Class descriptions appearing in a restrictions protected Map classesAndPropertiesRestriction;//Key: elements of classes in Restrictions //Content: properties in those restrictions protected Map propToIndividualAssertions; // key - prop R; value - individual a, such that R(a,b) protected Map propToDescriptionRestrictions; // key: property R, value: Description C which is a restriction on property R protected Set individualsInRestriction; //Individuals appearing in a restriction protected Map individualsAndPropertiesRestriction;//Key: Elements of individualsInRestriction //Content: properties in those restrictions protected Map individualsAndPropertiesAssertions; // Key: individuals, Value: properties related to it by abox assertions public Map individualsInEnumerations; // key - individual a, value - enumeration which contains a protected Map classesWithDomain; //Key: Classes and class descriptions that are domain of some property //Content: The properties they are domain of protected Map classesWithRange; protected Set Unions; protected Set Intersections; protected Set disjointAxioms; protected Map ClassesInUnions; // Class descriptions appearing in Unions protected Map ClassesInIntersections; // Class Descriptions appearing in intersections protected Map linksToSource; //Link properties pointing at the source ontology protected HashSet updatedLP; // link properties that need to be updated because link target has been moved to a new ontology protected Map nestedRestrictions; // Key: An object property R // Value: A Set S1,...,Sn of object properties // Means that S1,...,Sn appear in a restriction nested inside a restriction on R protected Set LinkProperties; //The set of link properties in SOURCE protected Map equivalents; protected Map subClasses, superClasses, subProperties, superProperties, instancesOf; protected Map boundedInverses; protected Map updatedInverses; //***set of descriptions left in source - first time computed using OntologyIndices // then its modified at the end of each partition protected Set descriptionsLeft; protected IndicesLibrary indexedLibrary; //State map // key: OWL Object, value - State integer Map State; OWLEntity owlThing; // 4 possible states static String STATE_O1 = "1"; // in O1 static String STATE_O2 = "2"; // in O2 static String STATE_L12 = "3"; // link from 1 to 2 static String STATE_L21 = "4"; // link from 2 to 1 //Sets for making changes.. // Notation: // O1 = OWL Object in Ontology 1 (source) // O2 = OWL Object in Ontology 2 (target) // S1 = Object Property in Ontology 1 // S2 = Link Property from O1 to O2 // S3 = Link Property from O2 to O1 // S4 = Object Property in Ontology 2 Set DescriptionsO1,DescriptionsO2,IndividualsO1,IndividualsO2; Set DataPropO1, DataPropO2, LinkPropO1, LinkPropO2; Set ObjPropS1, ObjPropS2,ObjPropS3,ObjPropS4; Set removedForeignEntitiesInSource; String Expressivity = " "; public EconnIterativePartitioning(SwoopModel swoopModel) { this.swoopModel = swoopModel; this.reasoner = swoopModel.getReasoner(); this.indexedLibrary = new IndicesLibrary(swoopModel); } public void reset(OWLOntology source, OWLOntology target, Map linksToSource, Map boundedInverses) throws OWLException { // reset all parameters for any new partitioning step this.source = source; this.target = target; this.State = new HashMap(); this.DescriptionsO1 = new HashSet(); this.DescriptionsO2 = new HashSet(); this.IndividualsO1 = new HashSet(); this.IndividualsO2 = new HashSet(); this.DataPropO1 = new HashSet(); this.DataPropO2 = new HashSet(); this.LinkPropO1 = new HashSet(); this.LinkPropO2 = new HashSet(); this.ObjPropS1 = new HashSet(); this.ObjPropS2 = new HashSet(); this.ObjPropS3 = new HashSet(); this.ObjPropS4 = new HashSet(); this.updatedLP = new HashSet(); this.linksToSource = linksToSource; this.boundedInverses = boundedInverses; this.updatedInverses = new HashMap(); this.addedForeignEntitiesInSource = new HashSet(); this.addedForeignEntitiesInTarget = new HashSet(); this.removedForeignEntitiesInSource = new HashSet(); this.changes = new ArrayList(); // populate OWL object sets Set all = new HashSet(); this.DescriptionsO1 = this.descriptionsLeft; all.addAll(this.DescriptionsO1); this.IndividualsO1.addAll(source.getIndividuals()); all.addAll(this.IndividualsO1); this.DataPropO1.addAll(source.getDataProperties()); all.addAll(this.DataPropO1); this.ObjPropS1.addAll(source.getObjectProperties()); this.LinkPropO1.addAll(source.getLinkProperties()); all.addAll(this.LinkPropO1); this.ObjPropS1.removeAll(this.LinkPropO1); all.addAll(this.ObjPropS1); // populate state map using the set "all" created above // i.e. for each entity in "all", set its initial state to O1 for (Iterator iter = all.iterator(); iter.hasNext();) { OWLObject obj = (OWLObject) iter.next(); this.State.put(obj, this.STATE_O1); } } /** * Call init only once!! * */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?