ontologyindices.java
来自「Semantic Web Ontology Editor」· Java 代码 · 共 933 行 · 第 1/3 页
JAVA
933 行
/* * Created on Feb 14, 2005 * */package org.mindswap.swoop.utils.owlapi;import java.io.Serializable;import java.util.ArrayList;import java.util.Collections;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.swoop.SwoopModel;import org.mindswap.swoop.reasoner.SwoopRDFSReasoner;import org.mindswap.swoop.reasoner.SwoopReasoner;import org.mindswap.swoop.renderer.entity.ConciseFormatEntityRenderer;import org.mindswap.swoop.utils.SetUtils;import org.mindswap.swoop.utils.graph.hierarchy.popup.ConcisePlainVisitor;import org.semanticweb.owl.model.OWLAnd;import org.semanticweb.owl.model.OWLCardinalityRestriction;import org.semanticweb.owl.model.OWLClass;import org.semanticweb.owl.model.OWLClassAxiom;import org.semanticweb.owl.model.OWLDataAllRestriction;import org.semanticweb.owl.model.OWLDataCardinalityRestriction;import org.semanticweb.owl.model.OWLDataEnumeration;import org.semanticweb.owl.model.OWLDataProperty;import org.semanticweb.owl.model.OWLDataQuantifiedRestriction;import org.semanticweb.owl.model.OWLDataRange;import org.semanticweb.owl.model.OWLDataType;import org.semanticweb.owl.model.OWLDataValueRestriction;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.OWLEquivalentClassesAxiom;import org.semanticweb.owl.model.OWLEquivalentPropertiesAxiom;import org.semanticweb.owl.model.OWLException;import org.semanticweb.owl.model.OWLIndividual;import org.semanticweb.owl.model.OWLNaryBooleanDescription;import org.semanticweb.owl.model.OWLNot;import org.semanticweb.owl.model.OWLObject;import org.semanticweb.owl.model.OWLObjectAllRestriction;import org.semanticweb.owl.model.OWLObjectCardinalityRestriction;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.helper.OntologyHelper;/** * @author Aditya * * Defines what types of cross-references need to be indexed * for a particular ontology. Used in BuildIndices.java where ontology * and the computed indices are finally stored */public class OntologyIndices implements Serializable { private Set ontologies; // current ontology set being indexed private List classes, properties, individuals; private List classAxioms, propAxioms, indAxioms; public Set unions, intersections, disjointAxioms; public Set descriptions; public Map descriptionToEntity; //Key: description, Value: any named entity - Class, Property, Individual where the description appears public Map restrictionToEntity; //Key: restriction, Value: any named entity - Class, Property, Individual where the restriction appears public Map equivalents; //Key: OWL Object, Value: OWL Object public Map classesToPropertiesRestriction;//Key: elements of classes in Restrictions //Content: properties in those restrictions public Map individualsToPropertiesRestriction;//Key: Elements of individualsInRestriction //Content: properties in those restrictions public Map individualsToPropertiesAssertions; // key: Individuals b, // Value: properties related to it by abox assertions // *** but R(a,b) *** public Map individualsInEnumerations; // key - a, value - enumeration which contains a public Map propToIndividualAssertions; //key: property R, value: individual a, such that R(a,b) public Map propToDescriptionRestrictions; // key: property R, value: Description C which is a restriction on property R public Map classesToDomain; //Key: Classes and class descriptions that are domain of some property //Value: The properties they are domain of public Map classesToRange; // analogous to domain public Map classesInUnions; // Class descriptions appearing in Unions public Map classesInIntersections; // Class Descriptions appearing in intersections public 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 public SwoopReasoner reasoner; // need the below to obtain sub/super for descriptions as well // cannot use reasoner because it returns only named classes // and no need to use OWLDescriptionFinder because it will loop // over all entities/axioms again public Map subClasses, superClasses, subProperties, superProperties, instancesOf; // This is for computing expressivity boolean hasNegation = false; boolean hasTransitivity = false; boolean hasRoleHierarchy = false; boolean hasInverse = false; boolean hasNominals = false; boolean hasCardinality = false; boolean hasFunctionality = false; boolean hasDatatype = false; boolean hasUnion = false; boolean hasIntersection = false; boolean hasRange = false; boolean hasComplexRestriction = false; boolean isDLLite = true; boolean isRDFS = true; boolean isEL = true; boolean isELpp = true; //EL++ // DEBUGGING TAGS (construct tags) boolean DEBUG_NOMINALS = false; boolean DEBUG_NEGATIONS = false; boolean DEBUG_UNIONS = false; boolean DEBUG_HASCOMPLEXRESTRICTION = false; // DEBUGGING TAGS (expressivity tags) boolean DEBUG_IS_EL = false; public OntologyIndices(SwoopReasoner reasoner) { if (reasoner==null) this.reasoner = new SwoopRDFSReasoner(); else this.reasoner = reasoner; } public void buildIndex( OWLOntology ontology, boolean indexImports, // consider imported ontologies? boolean skipReasoning // can be called by reasoner directly after it does its classification ) { if (!skipReasoning) { try { // set reasoner to classify ontology reasoner.setOntology(ontology); } catch (OWLException e2) { e2.printStackTrace(); } } // first determine set of ontologies if (indexImports) try { ontologies = OntologyHelper.importClosure(ontology); } catch (OWLException e) { e.printStackTrace(); } else ontologies = Collections.singleton(ontology); try { // initialize to get list of entities and axioms in ontologies // also reset all maps this.init(); // parse ontology and build corresponding indices this.parseOntology(); } catch (OWLException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } /** * Compute expressivity for a single OWL ontology according to the information * in the Maps * @param ontology */ public String getExpressivity(OWLOntology ont) { String dl = ""; if(isRDFS == true){ dl = "RDFS(DL)"; return dl; } if(isDLLite == true){ dl= "DL-Lite"; return dl; } if ( (isELpp) && (isEL == false)) return "EL++"; if((isEL == true)){ dl = "EL"; if(hasUnion == true) dl += "U"; if(hasInverse == true) dl += "I"; if(hasRoleHierarchy == true) dl += "H"; if(hasCardinality == true) dl += "N"; else if(hasFunctionality == true) dl += "F"; if(hasDatatype == true) dl += "(D)"; return dl; } if(hasNegation==true || hasUnion ==true || hasComplexRestriction == true) dl = "ALC"; else dl = "AL"; if(hasTransitivity == true) dl += "R+"; if(dl.equals("ALCR+")) dl = "S"; if(hasRoleHierarchy == true) dl += "H"; if(hasInverse == true) dl += "I"; if(hasNominals == true) dl += "O"; if(hasCardinality == true) dl += "N"; else if(hasFunctionality == true) dl += "F"; if(hasDatatype == true) dl += "(D)"; return dl; } /** * Obtain classes, properties, individuals and axioms in the set * of ontologies to be indexed. Also, reset all index maps * @throws OWLException */ private void init() throws OWLException { classes = new ArrayList(); properties = new ArrayList(); individuals = new ArrayList(); classAxioms = new ArrayList(); propAxioms = new ArrayList(); indAxioms = new ArrayList(); Iterator ont = ontologies.iterator(); while(ont.hasNext()) { OWLOntology o = (OWLOntology) ont.next(); classes.addAll(o.getClasses()); properties.addAll(o.getObjectProperties()); properties.addAll(o.getDataProperties()); individuals.addAll(o.getIndividuals()); classAxioms.addAll(o.getClassAxioms()); propAxioms.addAll(o.getPropertyAxioms()); indAxioms.addAll(o.getIndividualAxioms()); //For expressivity if(!(o.getDataProperties().isEmpty())) hasDatatype = true; } // reset all index maps this.descriptions = new HashSet(); this.unions = new HashSet(); this.intersections = new HashSet(); this.disjointAxioms = new HashSet(); this.descriptionToEntity = new HashMap(); this.restrictionToEntity = new HashMap(); this.equivalents = new HashMap(); this.classesToPropertiesRestriction = new HashMap(); this.individualsToPropertiesRestriction = new HashMap(); this.individualsToPropertiesAssertions = new HashMap(); this.individualsInEnumerations = new HashMap(); this.propToIndividualAssertions = new HashMap(); this.propToDescriptionRestrictions = new HashMap(); this.classesInIntersections = new HashMap(); this.classesInUnions = new HashMap(); this.classesToDomain = new HashMap(); this.classesToRange = new HashMap(); this.nestedRestrictions = new HashMap(); this.subClasses = new HashMap(); this.superClasses = new HashMap(); this.subProperties = new HashMap(); this.superProperties = new HashMap(); this.instancesOf = new HashMap(); } private void parseOntology() throws OWLException{
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?