protected OWLReasonerBase(OWLOntology rootOntology, OWLReasonerConfiguration configuration, BufferingMode bufferingMode) { this.rootOntology = checkNotNull(rootOntology, "rootOntology cannot be null"); this.bufferingMode = checkNotNull(bufferingMode, "bufferingMode cannot be null"); this.configuration = checkNotNull(configuration, "configuration cannot be null"); timeOut = configuration.getTimeOut(); manager = rootOntology.getOWLOntologyManager(); manager.addOntologyChangeListener(this::handleRawOntologyChanges); reasonerAxioms = asUnorderedSet( rootOntology.importsClosure().flatMap(o -> Stream.concat(o.logicalAxioms(), o .axioms(AxiomType.DECLARATION))) .map(ax -> OWLAxiom.getAxiomWithoutAnnotations(ax))); }
/** * @param ont ontology to use * @return short form of the ontology IRI */ public String getShortForm(OWLOntology ont) { OWLOntologyID ontologyID = ont.getOntologyID(); if (ontologyID.getOntologyIRI().isPresent()) { return getShortForm(verifyNotNull(ontologyID.getOntologyIRI().get())); } else { return ontologyID.toString(); } }
private static Optional<IRI> opt(@Nullable IRI i) { if (i == null || NodeID.isAnonymousNodeIRI(i)) { return emptyOptional(); } if (!i.isAbsolute()) { LOGGER.error( "Ontology IRIs must be absolute; IRI {} is relative and will be made absolute by prefixing urn:absolute: to it", i); return optional(IRI.create("urn:absolute:" + i)); } return optional(i); }
/** * @param suffix suffix to turn to optional. Empty string is the same as null * @return optional value for remainder */ protected Optional<String> asOptional(@Nullable String suffix) { if (suffix == null || suffix.isEmpty()) { return emptyOptional(); } return optional(suffix); }
@Override public OWLDataExactCardinality getOWLDataExactCardinality(int cardinality, OWLDataPropertyExpression property, OWLDataRange dataRange) { checkNotNull(dataRange, DATA_RANGE_CANNOT_BE_NULL); checkNotNull(property, PROPERTY_CANNOT_BE_NULL); checkNotNegative(cardinality, CARDINALITY_CANNOT_BE_NEGATIVE); return new OWLDataExactCardinalityImpl(property, cardinality, dataRange); }
@Override public Optional<OutputStream> getOutputStream() { if (xzOutputStream == null) { try { xzOutputStream = new XZOutputStream(outputStream, filterOptions); } catch (IOException e) { LOGGER.error("Fille cannot be found or opened", e); return emptyOptional(); } } return optional(verifyNotNull(xzOutputStream)); }
/** * Changes the URI of the specified ontology to the new URI. * * @param ontology The ontology whose URI is to be changed. * @param newIRI the new IRI * @return A list of changes, which when applied will change the URI of the specified ontology, * and also update the imports declarations in any ontologies which import the specified * ontology. */ public List<OWLOntologyChange> getChanges(OWLOntology ontology, IRI newIRI) { List<OWLOntologyChange> changes = new ArrayList<>(); changes.add(new SetOntologyID(ontology, new OWLOntologyID(optional(newIRI), ontology.getOntologyID().getVersionIRI()))); OWLImportsDeclaration owlImport = owlOntologyManager.getOWLDataFactory().getOWLImportsDeclaration(newIRI); IRI ontIRI = ontology.getOntologyID().getOntologyIRI().orElse(null); owlOntologyManager.ontologies().forEach(ont -> ont.importsDeclarations() .filter(decl -> decl.getIRI().equals(ontIRI)).forEach(decl -> { changes.add(new RemoveImport(ont, decl)); changes.add(new AddImport(ont, owlImport)); })); return changes; } }
protected void handleImport(Set<OWLImportsDeclaration> imports) { String tok; consumeToken(); tok = peekToken(); Optional<IRI> importedIRI = emptyOptional(); if (tok.startsWith("<")) { importedIRI = optional(parseIRI()); } else if (isOntologyName(tok)) { consumeToken(); OWLOntology ont = getOntology(tok); if (ont != null) { importedIRI = ont.getOntologyID().getOntologyIRI(); } } else { consumeToken(); throw new ExceptionBuilder().withOnto().withKeyword("<$ONTOLOGYYURI$>").build(); } if (!importedIRI.isPresent()) { throw new ExceptionBuilder().withOnto().withKeyword("Imported IRI is null").build(); } IRI importedOntologyIRI = importedIRI.get(); imports.add(df.getOWLImportsDeclaration(importedOntologyIRI)); }
/** * Instantiates a new definition tracker. * * @param ontology ontology to track */ public DefinitionTracker(OWLOntology ontology) { this.ontology = checkNotNull(ontology, "ontology cannot be null"); ontology.importsClosure().flatMap(OWLOntology::axioms).forEach(this::addAxiom); ontology.getOWLOntologyManager().addOntologyChangeListener(this); }
@Override public void visit(OWLOntology ontology) { checkNotNull(ontology, "ontology cannot be null"); ontology.logicalAxioms().sorted().forEach(ax -> { ax.accept(this); write("\n"); }); }
/** * Constructs an ontology input source using the specified file. * * @param file The file from which a concrete representation of an ontology will be obtained. * @param format ontology format. Can be null. * @param mime mime type */ public FileDocumentSource(File file, @Nullable OWLDocumentFormat format, @Nullable String mime) { super(IRI.create(file), format, mime); this.file = checkNotNull(file, "file cannot be null"); }
/** * @param ontology ontology * @param writer writer * @param format format */ public TurtleRenderer(OWLOntology ontology, Writer writer, OWLDocumentFormat format) { super(ontology, format, ontology.getOWLOntologyManager().getOntologyWriterConfiguration()); this.format = checkNotNull(format, "format cannot be null"); this.writer = new PrintWriter(writer); pm = new DefaultPrefixManager(); if (!ontology.isAnonymous()) { String ontologyIRIString = ontology.getOntologyID().getOntologyIRI().get().toString(); String defaultPrefix = ontologyIRIString; if (!ontologyIRIString.endsWith("/") && !ontologyIRIString.endsWith("#")) { defaultPrefix = ontologyIRIString + '#'; } pm.setDefaultPrefix(defaultPrefix); } if (format instanceof PrefixDocumentFormat) { PrefixDocumentFormat prefixFormat = (PrefixDocumentFormat) format; pm.copyPrefixesFrom(prefixFormat); pm.setPrefixComparator(prefixFormat.getPrefixComparator()); } base = ""; }
/** * Instantiates a new amalgamate sub class axioms. * * @param dataFactory the data factory * @param ontologies the ontologies to use */ public AmalgamateSubClassAxioms(OWLDataFactory dataFactory, Collection<OWLOntology> ontologies) { super(dataFactory); checkNotNull(ontologies, "ontologies cannot be null"); ontologies.forEach(o -> o.classesInSignature().forEach(cls -> amalgamate(o, cls))); }
private void generateChanges(OWLEntity entity) { checkNotNull(entity, "entity cannot be null"); for (OWLOntology ont : ontologies) { ont.referencingAxioms(entity).forEach(ax -> changes.add(new RemoveAxiom(ont, ax))); ont.annotationAssertionAxioms(entity.getIRI()) .forEach(ax -> changes.add(new RemoveAxiom(ont, ax))); } }
/** * Add the axiom to all the given ontologies. * * @param axiom the axiom to add * @param ontologies the ontologies to add the axiom to */ public static void addAxiom(OWLAxiom axiom, Stream<OWLOntology> ontologies) { checkNotNull(axiom, AXIOM_CANNOT_BE_NULL); checkNotNull(ontologies, ONTOLOGIES_CANNOT_BE_NULL); ontologies.forEach(o -> o.add(axiom)); } }
@Override public int compare(@Nullable OWLEntity o1, @Nullable OWLEntity o2) { return verifyNotNull(o1).getIRI().compareTo(verifyNotNull(o2).getIRI()); } }
/** * Constructs an ontology identifier specifiying the ontology IRI and * version IRI. Equivalent to OWLOntologyID(Optional * * @param iri The ontology IRI (may be {@code null}) */ public OWLOntologyID(@Nullable IRI iri) { this(opt(iri), emptyOptional(IRI.class)); }
@Override public void endElement(@Nullable String uri, @Nullable String localName, @Nullable String qName) throws SAXException { verifyNotNull(state) .endElement(checkNotNull(uri), checkNotNull(localName), checkNotNull(qName)); baseIRI = baseIRIs.remove(0); language = languages.remove(0); }
@Override public int compareTo(@Nullable OWLImportsDeclaration o) { return iri.compareTo(checkNotNull(o).getIRI()); }
@Override public OWLOntology createOntology(IRI ontologyIRI, Stream<OWLOntology> ontologies, boolean copyLogicalAxiomsOnly) throws OWLOntologyCreationException { writeLock.lock(); try { if (contains(ontologyIRI)) { throw new OWLOntologyAlreadyExistsException( new OWLOntologyID(optional(ontologyIRI), emptyOptional())); } OWLOntology ont = createOntology(ontologyIRI); addAxioms(ont, ontologies.flatMap(o -> copyLogicalAxiomsOnly ? o.logicalAxioms() : o.axioms())); return ont; } finally { writeLock.unlock(); } }