static ObjectIntHashMap<IRI> initMap() { ObjectIntHashMap<IRI> predicates = new ObjectIntHashMap<>(); AtomicInteger nextId = new AtomicInteger(1); List<OWLRDFVocabulary> ORDERED_URIS = Arrays.asList(RDF_TYPE, RDFS_LABEL, OWL_DEPRECATED, RDFS_COMMENT, RDFS_IS_DEFINED_BY, RDF_FIRST, RDF_REST, OWL_EQUIVALENT_CLASS, OWL_EQUIVALENT_PROPERTY, RDFS_SUBCLASS_OF, RDFS_SUB_PROPERTY_OF, RDFS_DOMAIN, RDFS_RANGE, OWL_DISJOINT_WITH, OWL_ON_PROPERTY, OWL_DATA_RANGE, OWL_ON_CLASS, OWL_ANNOTATED_SOURCE, OWL_ANNOTATED_PROPERTY, OWL_ANNOTATED_TARGET); ORDERED_URIS.forEach(iri -> predicates.put(iri.getIRI(), nextId.getAndIncrement())); Stream.of(OWLRDFVocabulary.values()) .forEach(iri -> predicates.putIfAbsent(iri.getIRI(), nextId.getAndIncrement())); return predicates; }
private void addOWLRDFVocabulary(OWLRDFVocabulary vocabulary) { wellKnownRenderings.put(vocabulary.getIRI(), vocabulary.getPrefixedName()); }
public void statementWithResourceValue(String subject, String predicate, String object) throws SAXException { if (ontologyProperties.contains(predicate)) { notPossibleOntologyNames.add(object); possibleOntologyNames.remove(object); } else if (predicate.equals(OWLRDFVocabulary.RDF_TYPE.toString()) && object.equals("http://www.w3.org/2002/07/owl#OntologyProperty")) { ontologyProperties.add(subject); } else if (predicate.equals(OWLRDFVocabulary.RDF_TYPE.toString()) && object.equals(OWLRDFVocabulary.OWL_ONTOLOGY.toString()) && !notPossibleOntologyNames.contains(subject)) { possibleOntologyNames.add(subject); } else if (predicate.equals(OWLRDFVocabulary.OWL_VERSION_IRI.toString())) { nameToVersionMap.put(subject, object); } }
@Override public boolean isDeprecated(OWLEntity entity) { if (!rootOntology.containsAnnotationPropertyInSignature(OWLRDFVocabulary.OWL_DEPRECATED.getIRI(), Imports.INCLUDED)) { return false; } var entityIRI = entity.getIRI(); return rootOntology.getImportsClosure() .stream() .flatMap(ont -> ont.getAnnotationAssertionAxioms(entityIRI).stream()) .anyMatch(OWLAnnotationAssertionAxiom::isDeprecatedIRIAssertion); } }
@Override public void visit(OWLDisjointObjectPropertiesAxiom axiom) { if (axiom.properties().count() == 2) { addPairwise(axiom, axiom.properties(), OWL_PROPERTY_DISJOINT_WITH.getIRI()); } else { translateAnonymousNode(axiom); translateAnnotations(axiom); addTriple(axiom, RDF_TYPE.getIRI(), OWL_ALL_DISJOINT_PROPERTIES.getIRI()); addListTriples(axiom, OWL_MEMBERS.getIRI(), axiom.properties()); } }
protected boolean isObjectList(RDFResource node) { for (RDFTriple triple : getRDFGraph().getTriplesForSubject(node)) { if (triple.getPredicate().getIRI().equals(RDF_TYPE.getIRI()) && !triple.getObject().isAnonymous() && triple.getObject().getIRI().equals(RDF_LIST.getIRI())) { List<RDFNode> items = new ArrayList<>(); toJavaList(node, items); return items.stream().noneMatch(RDFNode::isLiteral); } } return false; }
@Override public void handleTriple(IRI s, IRI p, IRI o) { if (o.equals(OWL_CLASS.getIRI())) { add(df.getOWLDeclarationAxiom(df.getOWLClass(s), anns())); } else if (o.equals(OWL_OBJECT_PROPERTY.getIRI())) { add(df.getOWLDeclarationAxiom(df.getOWLObjectProperty(s), anns())); } else if (o.equals(OWL_DATA_PROPERTY.getIRI())) { add(df.getOWLDeclarationAxiom(df.getOWLDataProperty(s), anns())); } else if (o.equals(OWL_DATATYPE.getIRI())) { add(df.getOWLDeclarationAxiom(df.getOWLDatatype(s), anns())); } } }
public OWLEntity guessResourceType(String resource) { SortedSet<String> types = retrieveObjectsForSubjectAndRole(resource, OWLRDFVocabulary.RDF_TYPE.getIRI().toString(), 10000); // System.out.println(types); if(types.contains(OWLRDFVocabulary.OWL_OBJECT_PROPERTY.getIRI().toString())) { return df.getOWLObjectProperty(IRI.create(resource)); } else if(types.contains(OWLRDFVocabulary.OWL_DATA_PROPERTY.getIRI().toString())) { return df.getOWLDataProperty(IRI.create(resource)); } else if(types.contains(OWLRDFVocabulary.OWL_CLASS.getIRI().toString())) { return df.getOWLClass(IRI.create(resource)); } else { return null; } }
/** * @param iri property iri */ public OWLDataPropertyImpl(IRI iri) { this.iri = checkNotNull(iri, "iri cannot be null"); builtin = iri.equals(OWLRDFVocabulary.OWL_TOP_DATA_PROPERTY.getIRI()) || iri.equals( OWLRDFVocabulary.OWL_BOTTOM_DATA_PROPERTY.getIRI()); }
@Override public void handleTriple(IRI subject, IRI predicate, IRI object) throws UnloadableImportException { if (OWLRDFVocabulary.BUILT_IN_VOCABULARY_IRIS.contains(object)) { if (!object.equals(OWLRDFVocabulary.OWL_THING.getIRI())) { // Can't have instance of built in vocabulary! // Shall we throw an exception here? logger.fine("Individual of builtin type " + object); } } addAxiom(getDataFactory().getOWLClassAssertionAxiom(translateClassExpression(object), translateIndividual(subject), getPendingAnnotations())); consumeTriple(subject, predicate, object); } }
/** * There may be some ontologies floating about that use early versions * of the OWL 1.1 vocabulary. We can map early versions of the vocabulary * to the current OWL 1.1 vocabulary. */ private void setupLegacyOWLSpecStuff() { for (OWLRDFVocabulary v : OWLRDFVocabulary.values()) { addLegacyMapping(v); } for (OWLFacet v : OWLFacet.values()) { synonymMap.put(IRI.create(Namespaces.OWL.toString() + v.getShortName()), v.getIRI()); synonymMap.put(IRI.create(Namespaces.OWL11.toString() + v.getShortName()), v.getIRI()); synonymMap.put(IRI.create(Namespaces.OWL2.toString() + v.getShortName()), v.getIRI()); } for (OWLFacet v : OWLFacet.values()) { synonymMap.put(IRI.create(Namespaces.OWL2.toString() + v.getShortName()), v.getIRI()); } synonymMap.put(OWLRDFVocabulary.OWL_NEGATIVE_DATA_PROPERTY_ASSERTION.getIRI(), OWLRDFVocabulary.OWL_NEGATIVE_PROPERTY_ASSERTION.getIRI()); synonymMap.put(OWLRDFVocabulary.OWL_NEGATIVE_OBJECT_PROPERTY_ASSERTION.getIRI(), OWLRDFVocabulary.OWL_NEGATIVE_PROPERTY_ASSERTION.getIRI()); }
public RDFSLabelGetter(OWLOntology ontology, IRI subject, boolean strict) { this.subject = subject; this.strict = strict; Set<OWLAnnotationAssertionAxiom> individualAnnotations = ontology .getAnnotationAssertionAxioms(subject); allLabels = new HashMap<String, String>(); for (OWLAnnotationAssertionAxiom annotation : individualAnnotations) { if (annotation.getProperty().equals( owlFactory .getOWLAnnotationProperty( OWLRDFVocabulary.RDFS_LABEL.getIRI()))) { OWLAnnotationValue value = annotation.getValue(); if (value instanceof IRI) { IRI asIRI = (IRI) value; allLabels.put(asIRI.toQuotedString(), null); } else if (value instanceof OWLLiteral) { OWLLiteral sLiteral = (OWLLiteral) value; allLabels.put(sLiteral.getLiteral(), sLiteral.getLang()); } } } }
@Override public OWLObjectExactCardinality translate(IRI mainNode) { getConsumer().consumeTriple(mainNode, RDF_TYPE.getIRI(), OWL_RESTRICTION.getIRI()); int cardi = translateInteger(mainNode, OWL_CARDINALITY); IRI propertyIRI = getConsumer().getResourceObject(mainNode, OWL_ON_PROPERTY, true); OWLObjectPropertyExpression property = getConsumer() .translateObjectPropertyExpression(verifyNotNull(propertyIRI)); IRI fillerIRI = getConsumer().getResourceObject(mainNode, OWL_ON_CLASS, true); if (fillerIRI != null && !getConsumer().getConfiguration().isStrict()) { // Be tolerant OWLClassExpression filler = accessor.translateClassExpression(fillerIRI); return getDataFactory().getOWLObjectExactCardinality(cardi, property, filler); } else { return getDataFactory().getOWLObjectExactCardinality(cardi, property); } } }
@Override public OWLDataMaxCardinality translate(IRI mainNode) { getConsumer().consumeTriple(mainNode, RDF_TYPE.getIRI(), OWL_RESTRICTION.getIRI()); int cardi = translateInteger(mainNode, OWL_MAX_CARDINALITY); IRI propertyIRI = getConsumer().getResourceObject(mainNode, OWL_ON_PROPERTY, true); OWLDataPropertyExpression property = getConsumer() .translateDataPropertyExpression(verifyNotNull(propertyIRI)); IRI fillerIRI = getConsumer().getResourceObject(mainNode, OWL_ON_DATA_RANGE, true); if (fillerIRI != null && !getConsumer().getConfiguration().isStrict()) { // Be tolerant OWLDataRange filler = getConsumer().translateDataRange(fillerIRI); return getDataFactory().getOWLDataMaxCardinality(cardi, property, filler); } else { return getDataFactory().getOWLDataMaxCardinality(cardi, property); } } }
@Override public OWLObjectMaxCardinality translate(IRI mainNode) { getConsumer().consumeTriple(mainNode, RDF_TYPE.getIRI(), OWL_RESTRICTION.getIRI()); int cardi = translateInteger(mainNode, OWL_MAX_CARDINALITY); IRI propertyIRI = getConsumer().getResourceObject(mainNode, OWL_ON_PROPERTY, true); OWLObjectPropertyExpression property = getConsumer() .translateObjectPropertyExpression(verifyNotNull(propertyIRI)); IRI fillerIRI = getConsumer().getResourceObject(mainNode, OWL_ON_CLASS, true); if (fillerIRI != null && !getConsumer().getConfiguration().isStrict()) { // Be tolerant OWLClassExpression filler = accessor.translateClassExpression(fillerIRI); return getDataFactory().getOWLObjectMaxCardinality(cardi, property, filler); } else { return getDataFactory().getOWLObjectMaxCardinality(cardi, property); } } }
@Override public OWLObjectAllValuesFrom translate(IRI mainNode) { getConsumer().consumeTriple(mainNode, RDF_TYPE.getIRI(), OWL_RESTRICTION.getIRI()); IRI propertyIRI = getConsumer().getResourceObject(mainNode, OWL_ON_PROPERTY, true); OWLObjectPropertyExpression property = getConsumer() .translateObjectPropertyExpression(verifyNotNull(propertyIRI)); IRI fillerIRI = getConsumer().getResourceObject(mainNode, OWL_ALL_VALUES_FROM, true); OWLClassExpression filler = accessor.translateClassExpression(verifyNotNull(fillerIRI)); return getDataFactory().getOWLObjectAllValuesFrom(property, filler); } }
@Override public OWLDataSomeValuesFrom translate(IRI mainNode) { getConsumer().consumeTriple(mainNode, RDF_TYPE.getIRI(), OWL_RESTRICTION.getIRI()); IRI propertyIRI = getConsumer().getResourceObject(mainNode, OWL_ON_PROPERTY, true); OWLDataPropertyExpression property = getConsumer() .translateDataPropertyExpression(verifyNotNull(propertyIRI)); IRI fillerIRI = getConsumer().getResourceObject(mainNode, OWL_SOME_VALUES_FROM, true); OWLDataRange filler = getConsumer().translateDataRange(verifyNotNull(fillerIRI)); return getDataFactory().getOWLDataSomeValuesFrom(property, filler); } }