use of org.semanticweb.owlapi.util.SimpleIRIMapper in project goci by EBISPOT.
the class AbstractOntologyLoader method doInitialization.
@Override
protected void doInitialization() throws Exception {
// init owl fields
this.manager = OWLManager.createOWLOntologyManager();
if (getOntologyResource() != null) {
getLog().info("Mapping ontology IRI from " + getOntologyURI() + " to " + getOntologyResource().getURI());
this.manager.addIRIMapper(new SimpleIRIMapper(IRI.create(getOntologyURI()), IRI.create(getOntologyResource().getURI())));
}
if (getOntologyImportMappings() != null) {
for (IRI from : getOntologyImportMappings().keySet()) {
IRI to = getOntologyImportMappings().get(from);
getLog().info("Mapping imported ontology IRI from " + from + " to " + to);
this.manager.addIRIMapper(new SimpleIRIMapper(from, to));
}
}
this.factory = manager.getOWLDataFactory();
// init cache fields
this.ontologyAccessions = new HashMap<>();
this.ontologyLabels = new HashMap<>();
this.ontologyParentLabels = new HashMap<>();
this.ontologyChildLabels = new HashMap<>();
this.ontologySynonyms = new HashMap<>();
this.ontologyRelationships = new HashMap<>();
// init other fields (label, synonym annotation properties)
this.rdfsLabelAnnotationProperty = getFactory().getOWLAnnotationProperty(OWLRDFVocabulary.RDFS_LABEL.getIRI());
this.synonymAnnotationProperties = getSynonymURIs().stream().map(ap -> getFactory().getOWLAnnotationProperty(IRI.create(ap))).collect(Collectors.toSet());
// load the ontology
this.ontology = loadOntology();
}
use of org.semanticweb.owlapi.util.SimpleIRIMapper in project goci by EBISPOT.
the class KBLoader method quantifyKnowledgeBase.
public Map<IRI, Integer> quantifyKnowledgeBase(URL efoLocation, URL gwasSchemaLocation, URL kbLocation) throws OWLOntologyCreationException, URISyntaxException {
Map<IRI, Integer> results = new HashMap<IRI, Integer>();
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
// do iri mapping
URI efoURI = efoLocation.toURI();
URI gwasSchemaURI = gwasSchemaLocation.toURI();
URI kbURI = kbLocation.toURI();
getLog().info("Mapping EFO to " + efoURI);
manager.addIRIMapper(new SimpleIRIMapper(IRI.create(OntologyConstants.EFO_ONTOLOGY_SCHEMA_IRI), IRI.create(efoURI)));
getLog().info("Mapping GWAS schema to " + gwasSchemaURI);
manager.addIRIMapper(new SimpleIRIMapper(IRI.create(OntologyConstants.GWAS_ONTOLOGY_SCHEMA_IRI), IRI.create(gwasSchemaURI)));
System.out.println("Loading knowledge base " + kbURI);
getLog().info("Loading knowledge base " + kbURI);
// load the knowledgebase
OWLOntology kb = manager.loadOntology(IRI.create(kbURI));
System.out.println("Processing knowledge base");
getLog().info("Processing knowledge base");
// retrieve all individuals
Set<OWLNamedIndividual> inds = kb.getIndividualsInSignature();
System.out.println("The knowledge base contains " + inds.size() + " individuals");
getLog().info("The knowledge base contains " + inds.size() + " individuals");
for (OWLNamedIndividual ind : inds) {
// for each individual, check if it is an association
boolean isAssociation = false;
Set<OWLClassExpression> types = ind.getTypes(kb);
for (OWLClassExpression type : types) {
if (type.asOWLClass().getIRI().toString().equals(OntologyConstants.TRAIT_ASSOCIATION_CLASS_IRI)) {
isAssociation = true;
break;
}
}
if (isAssociation) {
// get the IRI of the trait class (from EFO) this individual is associated with
Set<IRI> traitClasses = getTraitClass(kb, ind);
for (IRI traitClass : traitClasses) {
// skip SNPs
if (traitClass.toString().equals(OntologyConstants.SNP_CLASS_IRI)) {
continue;
}
// increment count
if (results.containsKey(traitClass)) {
int count = results.get(traitClass) + 1;
results.put(traitClass, count);
} else {
results.put(traitClass, 1);
}
}
}
}
return results;
}
use of org.semanticweb.owlapi.util.SimpleIRIMapper in project webprotege by protegeproject.
the class ProjectDocumentStore method createFreshProjectOntology.
private OWLOntology createFreshProjectOntology(OWLOntologyManager manager) throws OWLOntologyCreationException, OWLOntologyStorageException {
logger.info("Creating a fresh project with an Id of {}", projectId);
File parentDirectory = rootOntologyDocument.getParentFile();
parentDirectory.mkdirs();
IRI ontologyIRI = createUniqueOntologyIRI();
IRI documentIRI = IRI.create(rootOntologyDocument);
SimpleIRIMapper mapper = new SimpleIRIMapper(ontologyIRI, documentIRI);
manager.addIRIMapper(mapper);
OWLOntology ontology = manager.createOntology(ontologyIRI);
manager.removeIRIMapper(mapper);
writeNewProject(manager, ontology);
return ontology;
}
Aggregations