use of org.semanticweb.owlapi.model.OWLOntologyManager in project webprotege by protegeproject.
the class RevisionReverterChangeListGenerator method generateChanges.
@Override
public OntologyChangeList<Boolean> generateChanges(ChangeGenerationContext context) {
Optional<Revision> revision = revisionManager.getRevision(revisionNumber);
if (!revision.isPresent()) {
return OntologyChangeList.<Boolean>builder().build(false);
}
List<OWLOntologyChange> changes = new ArrayList<>();
for (OWLOntologyChangeRecord record : revision.get()) {
OWLOntologyChangeData revertingChangeData = changeDataReverter.getRevertingChange(record);
OWLOntologyChangeRecord revertingRecord = new OWLOntologyChangeRecord(record.getOntologyID(), revertingChangeData);
OWLOntologyManager manager = rootOntology.getOWLOntologyManager();
OWLOntologyChange change = revertingRecord.createOntologyChange(manager);
changes.add(0, change);
}
return OntologyChangeList.<Boolean>builder().addAll(changes).build(true);
}
use of org.semanticweb.owlapi.model.OWLOntologyManager in project webprotege by protegeproject.
the class WebProtegeOWLManager method createOWLOntologyManager.
public static OWLOntologyManager createOWLOntologyManager() {
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
augmentManager(manager);
return manager;
}
use of org.semanticweb.owlapi.model.OWLOntologyManager in project webprotege by protegeproject.
the class WebProtegeOWLManager method createConcurrentOWLOntologyManager.
public static OWLOntologyManager createConcurrentOWLOntologyManager() {
OWLOntologyManager manager = OWLManager.createConcurrentOWLOntologyManager();
augmentManager(manager);
return manager;
}
use of org.semanticweb.owlapi.model.OWLOntologyManager in project edammap by edamontology.
the class Edam method load.
public static Map<EdamUri, Concept> load(String edamPath) throws IOException {
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLOntology ontology;
try {
ontology = manager.loadOntologyFromOntologyDocument(new File(edamPath));
} catch (OWLOntologyCreationException e) {
throw new IOException(e);
}
String prefix = ontology.getOntologyID().getOntologyIRI().get().toString();
return ontology.classesInSignature().filter(c -> EdamUri.isEdamUri(c.getIRI().toString(), prefix)).collect(Collectors.toMap(c -> new EdamUri(c.getIRI().toString(), prefix), c -> {
Concept concept = new Concept();
EntitySearcher.getAnnotations(c, ontology).forEachOrdered(a -> {
if (a.getProperty().isLabel())
concept.setLabel(a.getValue().asLiteral().get().getLiteral());
else if (a.getProperty().isDeprecated())
concept.setObsolete(true);
else if (a.getProperty().toStringID().equals("http://www.geneontology.org/formats/oboInOwl#hasExactSynonym") && a.getValue().asLiteral().isPresent())
concept.addExactSynonym(a.getValue().asLiteral().get().getLiteral());
else if (a.getProperty().toStringID().equals("http://www.geneontology.org/formats/oboInOwl#hasNarrowSynonym") && a.getValue().asLiteral().isPresent())
concept.addNarrowSynonym(a.getValue().asLiteral().get().getLiteral());
else if (a.getProperty().toStringID().equals("http://www.geneontology.org/formats/oboInOwl#hasBroadSynonym") && a.getValue().asLiteral().isPresent())
concept.addBroadSynonym(a.getValue().asLiteral().get().getLiteral());
else if (a.getProperty().toStringID().equals("http://www.geneontology.org/formats/oboInOwl#hasDefinition") && a.getValue().asLiteral().isPresent())
concept.setDefinition(a.getValue().asLiteral().get().getLiteral());
else if (a.getProperty().isComment() && a.getValue().asLiteral().isPresent())
concept.setComment(a.getValue().asLiteral().get().getLiteral());
});
concept.setDirectParents(EntitySearcher.getSuperClasses(c, ontology).filter(a -> a.isOWLClass() && !a.asOWLClass().getIRI().toString().equals("http://www.w3.org/2002/07/owl#DeprecatedClass")).map(a -> new EdamUri(a.asOWLClass().getIRI().toString(), prefix)).collect(Collectors.toList()));
concept.setDirectChildren(EntitySearcher.getSubClasses(c, ontology).filter(a -> a.isOWLClass()).map(a -> new EdamUri(a.asOWLClass().getIRI().toString(), prefix)).collect(Collectors.toList()));
if (concept.getLabel() == null)
throw new IllegalStateException(String.format("Label of concept %s is empty", c.getIRI()));
return concept;
}, (u, v) -> {
throw new IllegalStateException(String.format("Duplicate key %s", u));
}, LinkedHashMap::new));
}
use of org.semanticweb.owlapi.model.OWLOntologyManager in project goci by EBISPOT.
the class IRITreeBuilder method buildIRITree.
// OntologyLoader ontologyLoader;
//
// @Autowired
// public IRITreeBuilder(OntologyLoader ontologyLoader){
// this.ontologyLoader = ontologyLoader;
// }
public IRITree buildIRITree(URL efoLocation) throws URISyntaxException, OWLOntologyCreationException {
// load efo
getLog().info("Loading efo...");
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLOntology efo = manager.loadOntology(IRI.create(efoLocation));
owlNothingIRI = manager.getOWLDataFactory().getOWLNothing().getIRI().toString();
// create a reasoner over efo
getLog().info("Reasoning over efo...");
OWLReasonerFactory factory = new Reasoner.ReasonerFactory();
ConsoleProgressMonitor progressMonitor = new ConsoleProgressMonitor();
OWLReasonerConfiguration config = new SimpleConfiguration(progressMonitor);
OWLReasoner reasoner = factory.createReasoner(efo, config);
getLog().info("Precomputing inferences...");
reasoner.precomputeInferences();
getLog().info("Checking ontology consistency...");
reasoner.isConsistent();
// get 'top' class
OWLClass topClass = reasoner.getTopClassNode().getRepresentativeElement();
getLog().info("Reasoner 'top class' element is " + topClass.getIRI());
IRITree tree = new IRITree();
// do one level deep manually - should only be experimental factor
IRINode rootNode = null;
OWLClass efClass = null;
NodeSet<OWLClass> subclasses = reasoner.getSubClasses(topClass, true);
for (Node<OWLClass> node : subclasses) {
OWLClass cls = node.getRepresentativeElement();
getLog().debug("Next child of " + topClass + " is " + cls);
if (cls.getIRI().toString().equals(OntologyConstants.EXPERIMENTAL_FACTOR_CLASS_IRI)) {
efClass = cls;
rootNode = new IRINode(cls.getIRI(), getClassLabel(efo, cls));
}
}
if (rootNode != null) {
getLog().info("Building tree... walking ontology from " + rootNode.getLabel() + " down...");
tree.setRootNode(rootNode);
recurse(reasoner, efo, efClass, rootNode);
getLog().info("...Tree build complete!");
} else {
throw new RuntimeException("Could not find Experimental Factor as a child of OWL:Thing");
}
return tree;
}
Aggregations