@Override default ChangeApplied addAxioms(Collection<? extends OWLAxiom> axioms) { return getOWLOntologyManager().addAxioms(this, axioms.stream()); }
@Override public ChangeApplied addAxioms(OWLOntology ont, Set<? extends OWLAxiom> axioms) { if (sealed) { throw new DirectChangeApplicationNotAllowedException(); } return delegate.addAxioms(ont, axioms); }
@Override default ChangeApplied addAxioms(Stream<? extends OWLAxiom> axioms) { return getOWLOntologyManager().addAxioms(this, axioms); }
@Override default ChangeApplied addAxioms(Stream<? extends OWLAxiom> axioms) { return getOWLOntologyManager().addAxioms(this, axioms); }
@Override default ChangeApplied addAxioms(Stream<? extends OWLAxiom> axioms) { return getOWLOntologyManager().addAxioms(this, axioms); }
@Override default ChangeApplied addAxioms(Collection<? extends OWLAxiom> axioms) { return getOWLOntologyManager().addAxioms(this, axioms.stream()); }
@Override default ChangeApplied addAxioms(Collection<? extends OWLAxiom> axioms) { return getOWLOntologyManager().addAxioms(this, axioms.stream()); }
private static void writeUntranslatableAxioms(final String path, Collection<OWLAxiom> untranslatableAxioms, OWLOntologyManager manager) throws IOException, OWLOntologyCreationException, OWLOntologyStorageException { // create temporary ontology with untranslatable axioms OWLOntology ontology = manager.createOntology(); Set<OWLAxiom> axioms = new HashSet<OWLAxiom>(untranslatableAxioms); manager.addAxioms(ontology, axioms); // write temporary ontology to file final FileOutputStream outputStream = new FileOutputStream(new File(path)); OWLOntologyFormat format = new RDFXMLOntologyFormat(); // TODO make this configurable manager.saveOntology(ontology, format, outputStream); outputStream.close(); }
public void run() { try { Set<OWLAxiom> setAxioms = Sets.newHashSet(); while(graphResultSet.hasNext()) { setAxioms.add(graphResultSet.next()); } graphResultSet.close(); ontologyManager.addAxioms(currentOntology, setAxioms); latch.countDown(); if (!bCancel) { JOptionPane.showMessageDialog(cont, "Task is completed", "Done", JOptionPane.INFORMATION_MESSAGE); } } catch (Exception e) { latch.countDown(); log.error("Materialization of Abox failed", e); } catch (Error e) { latch.countDown(); log.error("Materialization of Abox failed", e); JOptionPane.showMessageDialog(null, "An error occurred. For more info, see the logs."); } } };
protected static OWLOntology extractDeclarations(OWLOntologyManager manager, OWLOntology ontology) throws OWLOntologyCreationException { IRI ontologyIRI = ontology.getOntologyID().getOntologyIRI().get(); System.err.println("Ontology " + ontologyIRI); Set<OWLDeclarationAxiom> declarationAxioms = ontology.getAxioms(AxiomType.DECLARATION); manager.removeOntology(ontology); OWLOntology newOntology = manager.createOntology(ontologyIRI); manager.addAxioms(newOntology, declarationAxioms); return newOntology; }
public static void main (String[] args) throws Exception { OWLOntologyManager man = OWLManager.createOWLOntologyManager(); OWLDataFactory factory = man.getOWLDataFactory(); logger.info("Loading ontology..."); OWLOntology ontology = man.loadOntologyFromOntologyDocument(new File(dumpFilePath)); logger.info("Done"); OWLAxiomCBDGenerator cbdGenartor = new OWLAxiomCBDGenerator(ontology); cbdGenartor.setFetchCompleteRelatedTBox(true); OWLOntology cbdOnt = man.createOntology(); for (String uri : exampleUris) { logger.info("Creating cbd for " + uri + "..."); Set<OWLAxiom> cbdAxioms = cbdGenartor.getCBD(factory.getOWLNamedIndividual(IRI.create(uri)), cbdDepth); logger.info(" Done. Adding {} axioms to main CBD dataset...", cbdAxioms.size()); man.addAxioms(cbdOnt, cbdAxioms); logger.info(" Also done"); } man.saveOntology(cbdOnt, new RDFXMLDocumentFormat(), new FileOutputStream(new File(cbdFilePath))); } }
/** * NOT THREAD-SAFE (not reentrant) */ private BootstrappingResults bootstrapMappingAndOntology(String baseIRI, Optional<SQLPPMapping> inputPPMapping, Optional<OWLOntology> inputOntology) throws MappingBootstrappingException { this.baseIRI = fixBaseURI(baseIRI); try { SQLPPMapping newPPMapping = extractPPMapping(inputPPMapping); OWLOntology ontology = inputOntology.isPresent() ? inputOntology.get() : OWLManager.createOWLOntologyManager().createOntology(IRI.create(baseIRI)); // update ontology OWLOntologyManager manager = ontology.getOWLOntologyManager(); Set<OWLDeclarationAxiom> declarationAxioms = extractDeclarationAxioms(manager, newPPMapping.getTripleMaps().stream() .flatMap(ax -> ax.getTargetAtoms().stream())); manager.addAxioms(ontology, declarationAxioms); return new DefaultBootstrappingResults(newPPMapping, ontology); } catch (SQLException | MappingException | OWLOntologyCreationException e) { throw new MappingBootstrappingException(e); } }
private OWLOntology generateOntologyFromRevision(OWLOntology ontology, Revision revision) { try { OWLOntology revisionedOntology = BundleUtilities.copyOntology(ontology); Set<OWLSubClassOfAxiom> learnedAxioms = revision.getLearnedAxioms(); OWLOntologyManager manager = revisionedOntology.getOWLOntologyManager(); manager.addAxioms(revisionedOntology, revision.getLearnedAxioms()); int i = 0; for (OWLAxiom axiom : revision.getTargetAxioms()) { if (!revision.getBoolVars().get(i)) { manager.removeAxiom(revisionedOntology, axiom); } } return revisionedOntology; } catch (OWLOntologyCreationException e) { logger.error("Cannot refine ontology"); throw new StructureLearningException(e); } }
/** * It tries to add a set of axioms into the ontology. If there is an inconsistency * after adding the axiom the axiom is removed from the ontology and an * InconsistencyException is thrown. * * @param ontology ontology to modify * @param axioms axioms to add * @throws InconsistencyException if adding the exceptions leads to an * inconsistency */ protected void addAxioms(OWLOntology ontology, List<? extends OWLAxiom> axioms) throws InconsistencyException { OWLOntologyManager manager = ontology.getOWLOntologyManager(); manager.addAxioms(ontology, new HashSet<>(axioms)); // PelletReasoner pelletReasoner = new PelletReasonerFactory().createReasoner(ontology); PelletReasoner pelletReasoner = PelletReasonerFactory.getInstance().createNonBufferingReasoner(ontology); if (!pelletReasoner.isConsistent()) { String message = "The axiom will make the KB inconsistent.\n" + "It will NOT be added"; logger.warn(message); manager.removeAxioms(ontology, new HashSet<>(axioms)); pelletReasoner.dispose(); throw new InconsistencyException(message); } pelletReasoner.dispose(); }
/** * NOT THREAD-SAFE (not reentrant) */ private BootstrappingResults bootstrapMappingAndOntology(String baseIRI, Optional<SQLPPMapping> inputPPMapping, Optional<OWLOntology> inputOntology) throws MappingBootstrappingException { this.baseIRI = fixBaseURI(baseIRI); try { SQLPPMapping newPPMapping = extractPPMapping(inputPPMapping); OWLOntology ontology = inputOntology.isPresent() ? inputOntology.get() : OWLManager.createOWLOntologyManager().createOntology(IRI.create(baseIRI)); // update ontology OWLOntologyManager manager = ontology.getOWLOntologyManager(); Set<OWLDeclarationAxiom> declarationAxioms = extractDeclarationAxioms(manager, newPPMapping.getTripleMaps().stream() .flatMap(ax -> ax.getTargetAtoms().stream())); manager.addAxioms(ontology, declarationAxioms); return new DefaultBootstrappingResults(newPPMapping, ontology); } catch (SQLException | MappingException | OWLOntologyCreationException e) { throw new MappingBootstrappingException(e); } }
public static void saveAxioms(Set<OWLAxiom> axioms, String outputFile, String outFormat) throws OWLOntologyStorageException, OWLOntologyCreationException { OWLOntologyManager man = OWLManager.createOWLOntologyManager(); OWLOntology resultOntology = man.createOntology(); man.addAxioms(resultOntology, axioms); OWLDocumentFormat formatter; switch (outFormat) { case "OWLXML": formatter = new OWLXMLDocumentFormat(); break; case "OWLFUNCTIONAL": formatter = new FunctionalSyntaxDocumentFormat(); break; default: formatter = new OWLXMLDocumentFormat(); break; } resultOntology.getOWLOntologyManager().saveOntology(resultOntology, formatter, IRI.create(new File(outputFile))); }
/** * Compute the types of an individual. Use this function only if you mix Named and Anonymous individuals. * * @param ind the individual named _or_ anonymous * @return the classes of the individual. * @since 2.5.1 */ default public NodeSet<OWLClass> getTypes(final OWLIndividual ind) { if (ind instanceof OWLAnonymousIndividual) { // We create a temporary named Individual to allow the reasoner to work. final OWLNamedIndividual individual = getFactory().getOWLNamedIndividual(IRI.create(_protocol + OWLHelper.class.getPackage().getName() + _webSeparator + OWLHelper.class.getSimpleName() + _entitySeparator + IRIUtils.randId(OWLHelper.class.getSimpleName()))); final Stream<OWLAxiom> axioms = Stream.of( // getFactory().getOWLDeclarationAxiom(individual), // getFactory().getOWLSameIndividualAxiom(individual, ind) // The temporary named is the same as the anonymous one. ); getManager().addAxioms(getOntology(), axioms); final NodeSet<OWLClass> result = getReasoner().getTypes(individual, false); getManager().removeAxioms(getOntology(), axioms); return result; } else return getReasoner().getTypes((OWLNamedIndividual) ind, false); }
public static OWLOntology load(File... inputFiles) throws OWLOntologyCreationException { OWLOntologyManager manager= OWLManager.createOWLOntologyManager(); OWLOntology ont = manager.createOntology(); for (File f:inputFiles) { manager= OWLManager.createOWLOntologyManager(); manager.setSilentMissingImportsHandling(false); IRI documentIRI = IRI.create(f); OWLOntology ontology = manager.loadOntologyFromOntologyDocument(documentIRI); ont.getOWLOntologyManager().addAxioms(ont, ontology.getAxioms()); } return ont; }
/** * Compute the types of an individual. Use this function only if you mix Named and Anonymous individuals. * * @param ind the individual named _or_ anonymous * @return the classes of the individual. * @since 2.5.1 */ default public NodeSet<OWLClass> getTypes(final OWLIndividual ind) { if (ind instanceof OWLAnonymousIndividual) { // We create a temporary named Individual to allow the reasoner to work. final OWLNamedIndividual individual = getFactory().getOWLNamedIndividual(IRI.create(_protocol + OWLHelper.class.getPackage().getName() + _webSeparator + OWLHelper.class.getSimpleName() + _entitySeparator + IRIUtils.randId(OWLHelper.class.getSimpleName()))); final Stream<OWLAxiom> axioms = Stream.of( // getFactory().getOWLDeclarationAxiom(individual), // getFactory().getOWLSameIndividualAxiom(individual, ind) // The temporary named is the same as the anonymous one. ); getManager().addAxioms(getOntology(), axioms); final NodeSet<OWLClass> result = getReasoner().getTypes(individual, false); getManager().removeAxioms(getOntology(), axioms); return result; } else return getReasoner().getTypes((OWLNamedIndividual) ind, false); }
@Test public void doesNotReason_whenOntologyIsInconsistent() throws Exception{ OWLClass c0 = dataFactory.getOWLClass(IRI.generateDocumentIRI()); OWLClass c1 = dataFactory.getOWLClass(IRI.generateDocumentIRI()); OWLDisjointClassesAxiom disjoint = dataFactory.getOWLDisjointClassesAxiom(c0, c1); OWLIndividual i1 = dataFactory.getOWLNamedIndividual(IRI.generateDocumentIRI()); OWLClassAssertionAxiom a1 = dataFactory.getOWLClassAssertionAxiom(c0, i1); OWLClassAssertionAxiom a2 = dataFactory.getOWLClassAssertionAxiom(c1, i1); manager.addAxioms(ont, newHashSet(disjoint, a1, a2)); util.flush(); assertThat(util.shouldReason(), is(false)); }