public boolean contains(OWLDataProperty prop) { if (prop.equals(owlOntologyManager.getOWLDataFactory().getOWLThing())) { return true; } else if (prop.equals(owlOntologyManager.getOWLDataFactory().getOWLNothing())) { return true; } return owlDataProperty2DataPropertyPointerMap.containsKey(prop); }
public boolean contains(OWLClass cls) { if (cls.equals(owlOntologyManager.getOWLDataFactory().getOWLThing())) { return true; } else if (cls.equals(owlOntologyManager.getOWLDataFactory().getOWLNothing())) { return true; } return owlClass2ClassPointerMap.containsKey(cls); }
private OWLDescription createIncludeCoffeeDescription(Set<OWLClass> includeExtras) { OWLObjectProperty prop = this.getNamedObjectProperty(PREFERENCES.getExtrasPropertyName()); // has_extras Set<OWLDescription> classes = new HashSet<OWLDescription>(); classes.add(getCoffeeClass()); // get OWL class for Coffee for (OWLClass extra : includeExtras) { classes.add(manager.getOWLDataFactory().getOWLObjectSomeRestriction(prop, extra)); } return manager.getOWLDataFactory().getOWLObjectIntersectionOf(classes); }
private OWLDescription createExcludeCoffeeDescription(Set<OWLClass> excludeExtras) { OWLObjectProperty prop = this.getNamedObjectProperty(PREFERENCES.getExtrasPropertyName()); // has_extras Set<OWLDescription> classes = new HashSet<OWLDescription>(); // Everything must be a coffee for (OWLClass extra : excludeExtras) { classes.add(manager.getOWLDataFactory().getOWLObjectSomeRestriction(prop, extra)); } // are looking for. return manager.getOWLDataFactory().getOWLObjectUnionOf(classes); }
protected boolean isEntailed( OWLOntologyManager manager, OWLOntology premise, OWLOntology conclusion) throws OWLReasonerException { OWLReasoner reasoner = JcelReasonerManager.getInstance().getJcelReasoner(manager); this.reasoner = reasoner; reasoner.clearOntologies(); reasoner.loadOntologies(Collections.singleton(premise)); reasoner.classify(); JcelEntailmentChecker checker = new JcelEntailmentChecker(reasoner, manager.getOWLDataFactory()); boolean ret = true; for (Iterator<OWLLogicalAxiom> it = conclusion.getLogicalAxioms().iterator(); ret && it.hasNext(); ) { OWLLogicalAxiom axiom = it.next(); if (!checker.isEntailed(axiom)) { ret = false; } } return ret; }
/** * Creates OWLDescription (query) by given included extras and excluded extras * * @param includeExtras * @param excludeExtras * @return */ private OWLDescription createCoffeeDescription( Set<OWLClass> includeExtras, Set<OWLClass> excludeExtras) { // Include means existential restrictions // Exclude means negated existential restrictions OWLObjectProperty prop = this.getNamedObjectProperty(PREFERENCES.getExtrasPropertyName()); // has_extras // Create a hash set to store the components (existential restrictions) // of our description Set<OWLDescription> classes = new HashSet<OWLDescription>(); // Everything must be a coffee classes.add(getCoffeeClass()); // get OWL class for Coffee // Create the existential restrictions that represent the extras // that we want to include. for (OWLClass extra : includeExtras) { // e.g. hasExtras some ex_A , hasExtras some ex_B classes.add(manager.getOWLDataFactory().getOWLObjectSomeRestriction(prop, extra)); } // Create the negated existential restrictions of the extras that we // want to exclude for (OWLClass excludeExtra : excludeExtras) { // has_topping some topping_A OWLDescription restriction = manager.getOWLDataFactory().getOWLObjectSomeRestriction(prop, excludeExtra); // not (has_topping some topping_A) OWLObjectComplementOf neg = manager.getOWLDataFactory().getOWLObjectComplementOf(restriction); classes.add(neg); } // Bind the whole thing up in an intersection class // to create a concept description of the coffee we // are looking for. return manager.getOWLDataFactory().getOWLObjectIntersectionOf(classes); }
public void visit(OWLUntypedConstant node) { try { lastDataValuePointer = owlConstant2DataValuePointerMap.get(node); if (lastDataValuePointer == null) { owlOntologyManager .getOWLDataFactory() .getOWLDataType(XSDVocabulary.STRING.getURI()) .accept((OWLDataVisitor) this); lastDataValuePointer = faCTPlusPlus.getDataValue(node.getLiteral(), getLastDataTypePointer()); owlConstant2DataValuePointerMap.put(node, lastDataValuePointer); dataValuePointerMap.put(lastDataValuePointer, node); } } catch (Exception e) { throw new FaCTPlusPlusRuntimeException(e); } }
public void visit(OWLDataType dataType) { try { lastDataTypeExpressionPointer = null; lastDataTypePointer = (DataTypePointer) owlDataRange2DataTypeExpressionPointerMap.get(dataType); if (lastDataTypePointer == null) { if (owlOntologyManager.getOWLDataFactory().getTopDataType().equals(dataType)) { lastDataTypePointer = faCTPlusPlus.getDataTop(); } else { lastDataTypePointer = faCTPlusPlus.getBuiltInDataType(dataType.getURI().toString()); } owlDataRange2DataTypeExpressionPointerMap.put(dataType, lastDataTypePointer); dataTypeExpressionPointerMap.put(lastDataTypePointer, dataType); } } catch (Exception e) { throw new FaCTPlusPlusRuntimeException(e); } }
/** * Gets the property by given name, e.g. has_topping * * @param propName * @return */ public OWLObjectProperty getNamedObjectProperty(String propName) { if (objPropNameCache == null) { objPropNameCache = new HashMap<String, URI>(); for (OWLOntology ont : reasoner.getLoadedOntologies()) { for (OWLObjectProperty prop : ont.getReferencedObjectProperties()) { objPropNameCache.put(prop.toString(), prop.getURI()); } } } // search the HashMap OWLObjectProperty namedProp = null; URI uri = objPropNameCache.get(propName); if (uri != null) { namedProp = manager.getOWLDataFactory().getOWLObjectProperty(uri); } else { System.err.println("Cannot find object property: " + propName + " in loaded ontologies"); } return namedProp; }
/** * Gets OWL class by given name * * @param className * @return * @throws OWLReasonerException */ public OWLClass getNamedClass(String className) { if (classnameCache == null) { classnameCache = new HashMap<String, URI>(); for (OWLOntology ont : reasoner.getLoadedOntologies()) { for (OWLClass cls : ont.getReferencedClasses()) { classnameCache.put(cls.toString(), cls.getURI()); } } } OWLClass namedCls = null; URI uri = classnameCache.get(className); if (uri != null) { namedCls = manager.getOWLDataFactory().getOWLClass(uri); } else { System.err.println("Cannot find class: " + className + " in loaded ontologies"); } return namedCls; }
private void _createNewOntology() throws Exception { assert namespace.matches(".*(/|#)"); String baseUri = namespace.replaceAll("(/|#)+$", ""); // removing any trailing slash/hash manager = new SKOSManager(); if (namespace.endsWith("#")) { // Ok, OWLAPI v2 works fine with hash separator: dataset = manager.createSKOSDataset(URI.create(baseUri)); } else { ///////////////////////////////////////////////////////////////////////////////////////////// // TODO NOTE: workaround for bug in OWLAPI v2: // Instead of using a baseUri without separator, // use the namespace itself (ie, w/ fragment separator): dataset = manager.createSKOSDataset(URI.create(namespace)); // In this way, the resulting ontology looks OK except that the xml:base is // written with the separator: // // <rdf:RDF xmlns="http://mmisw.org/ont/mmi/cf/parameter/" // xml:base="http://mmisw.org/ont/mmi/cf/parameter/" <<<--- WITH trailing slash // xmlns:owl2xml="http://www.w3.org/2006/12/owl2-xml#" // xmlns:xsd="http://www.w3.org/2001/XMLSchema#" // xmlns:owl2="http://www.w3.org/2006/12/owl2#" // xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" // xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" // xmlns:owl="http://www.w3.org/2002/07/owl#" // xmlns:skos="http://www.w3.org/2004/02/skos/core#"> // <owl:Ontology rdf:about=""/> // ... // <!-- http://mmisw.org/ont/mmi/cf/parameter/CfStdName --> // // <skos:ConceptScheme rdf:about="CfStdName"/> // // // <!-- http://mmisw.org/ont/mmi/cf/parameter/age_of_stratospheric_air --> // // <skos:Concept rdf:about="age_of_stratospheric_air"> // <skos:inScheme rdf:resource="CfStdName"/> // </skos:Concept> // // // <!-- http://mmisw.org/ont/mmi/cf/parameter/air_density --> // // <skos:Concept rdf:about="air_density"> // <skos:inScheme rdf:resource="CfStdName"/> // </skos:Concept> // // ... ///////////////////////////////////////////////////////////////////////////////////////////// } SAXBuilder builder = new SAXBuilder(); Document document = builder.build(new StringReader(inputContents)); standard_name_table = document.getRootElement(); _getProperty(standard_name_table, "version_number"); _getProperty(standard_name_table, "last_modified"); _getProperty(standard_name_table, "institution"); _getProperty(standard_name_table, "contact"); // TODO assign version_number, last_modified as some properties to the ontology itself. dataFactory = manager.getSKOSDataFactory(); allEntities = new ArrayList<SKOSEntity>(); conceptScheme = dataFactory.getSKOSConceptScheme(URI.create(namespace + CONCEPT_SCHEME)); concepts = new HashSet<SKOSConcept>(); URI topConceptUri = URI.create(namespace + TOP_CONCEPT); topConcept = dataFactory.getSKOSConcept(topConceptUri); concepts.add(topConcept); objectRelationAssertions = new ArrayList<SKOSObjectRelationAssertion>(); dataRelationAssertions = new ArrayList<SKOSDataRelationAssertion>(); // skos:hasTopConcept objectRelationAssertions.add( dataFactory.getSKOSObjectRelationAssertion( conceptScheme, dataFactory.getSKOSHasTopConceptProperty(), topConcept)); ///////////////////////////////////////////////// // OWL API stuff owlManager = manager.getOWLManger(); owlOntology = owlManager.getOntology(URI.create(namespace)); owlDataFactory = owlManager.getOWLDataFactory(); canonicalUnitsProp = owlDataFactory.getOWLDataProperty(URI.create(namespace + "canonical_units")); gribProp = owlDataFactory.getOWLDataProperty(URI.create(namespace + "grib")); amipProp = owlDataFactory.getOWLDataProperty(URI.create(namespace + "amip")); rdfsLabel = owlDataFactory.getOWLDataProperty(URI.create("http://www.w3.org/2000/01/rdf-schema#label")); rdfsComment = owlDataFactory.getOWLDataProperty( URI.create("http://www.w3.org/2000/01/rdf-schema#comment")); owlChanges = new ArrayList<AddAxiom>(); _addOwlChange(topConceptUri, TOP_CONCEPT.replace('_', ' '), "", null, null, null); }