I've written this code to replace object property value from Ontology:
public void changeObjectPropertyValue(String file, OWLOntology ontology, String ind, String propertyFragment, String newValueFragment) throws OWLOntologyCreationException {
File ontologyFile = new File(file);
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLOntology ontology1 = manager.loadOntologyFromOntologyDocument(ontologyFile);
OWLDataFactory factory = manager.getOWLDataFactory();
IRI ontologyIRI = ontology1.getOntologyID().getOntologyIRI();
OWLNamedIndividual individualToReplaceValueOn = factory.getOWLNamedIndividual(IRI.create(ontologyIRI + "#" + ind));
OWLNamedIndividual newValueInd = factory.getOWLNamedIndividual(IRI.create(ontologyIRI + "#" + newValueFragment));
OWLObjectProperty theObjectProperty = factory.getOWLObjectProperty(IRI.create(ontologyIRI + "#" + propertyFragment));
OWLIndividual theOldValue = EntitySearcher.getObjectPropertyValues(individualToReplaceValueOn, theObjectProperty, ontology1).findFirst().get();
OWLAxiom oldAxiom = factory.getOWLObjectPropertyAssertionAxiom(
theObjectProperty,
individualToReplaceValueOn,
theOldValue);
OWLAxiom newAxiom = factory.getOWLObjectPropertyAssertionAxiom(
theObjectProperty,
individualToReplaceValueOn,
newValueInd);
List<OWLOntologyChange> changes = new Vector<OWLOntologyChange>();
changes.add(new RemoveAxiom(ontology1, oldAxiom));
changes.add(new AddAxiom(ontology1, newAxiom));
man.applyChanges(changes);
}
To try to execute the above code appears the following error:
Exception in thread "main" java.lang.NoSuchMethodError: 'java.util.stream.Stream org.semanticweb.owlapi.model.OWLOntology.objectPropertyAssertionAxioms(org.semanticweb.owlapi.model.OWLIndividual)'
at org.semanticweb.owlapi.search.EntitySearcher.getObjectPropertyValues(EntitySearcher.java:1245)
OWLIndividual theOldValue = EntitySearcher
.getObjectPropertyValues(individualToReplaceValueOn, theObjectProperty, ontology1).findFirst().get();
When executing, the method appears or an error appears for that line. Is it a library error? Is there a jar missing?
Below are the jars dependencies:
<dependencies>
<dependency>
<groupId>net.sourceforge.owlapi</groupId>
<artifactId>owlapi-parsers</artifactId>
<version>4.5.24</version>
</dependency>
<dependency>
<groupId>net.sourceforge.owlapi</groupId>
<artifactId>owlapi-osgidistribution</artifactId>
<version>4.5.24</version>
</dependency>
<dependency>
<groupId>net.sourceforge.owlapi</groupId>
<artifactId>owlapi-impl</artifactId>
<version>4.5.24</version>
</dependency>
<dependency>
<groupId>net.sourceforge.owlapi</groupId>
<artifactId>owlapi-apibinding</artifactId>
<version>4.5.24</version>
</dependency>
<dependency>
<groupId>net.sourceforge.owlapi</groupId>
<artifactId>org.semanticweb.hermit</artifactId>
<version>1.3.8.500</version>
</dependency>
<dependency>
<groupId>net.sourceforge.owlapi</groupId>
<artifactId>owlapi-distribution</artifactId>
<version>4.5.24</version>
</dependency>
<dependency>
<groupId>net.sourceforge.owlapi</groupId>
<artifactId>owlapi-api</artifactId>
<version>4.5.24</version>
</dependency>
<dependency>
<groupId>net.sourceforge.owlapi</groupId>
<artifactId>owlapi-osgidistribution</artifactId>
<version>5.5.0</version>
</dependency>
</dependencies>
What should I do now to run all the code? Even with the dependencies, errors still appear. Could you please help me?