use of org.semanticweb.owlapi.model.OWLOntologyManager in project webprotege by protegeproject.
the class RootOntologyLoader method loadRootOntology.
public OWLOntology loadRootOntology() {
// The delegate - we use the concurrent ontology manager
OWLOntologyManager delegateManager = WebProtegeOWLManager.createConcurrentOWLOntologyManager();
// We only support the binary format for speed
delegateManager.getOntologyStorers().add(new RDFXMLStorerFactory());
delegateManager.getOntologyStorers().add(new OWLXMLStorerFactory());
delegateManager.getOntologyStorers().add(new FunctionalSyntaxStorerFactory());
delegateManager.getOntologyStorers().add(new ManchesterSyntaxStorerFactory());
delegateManager.getOntologyParsers().add(new BinaryOWLOntologyDocumentParserFactory());
// The wrapper manager
ProjectOWLOntologyManager manager = new ProjectOWLOntologyManager();
manager.setDelegate(delegateManager);
int threadPriority = Thread.currentThread().getPriority();
try {
Thread.currentThread().setPriority(3);
OWLOntology rootOntology = documentStore.initialiseOntologyManagerWithProject(manager.getDelegate());
manager.sealDelegate();
return rootOntology;
} catch (OWLOntologyCreationException | OWLOntologyStorageException e) {
throw new RuntimeException("Failed to load project: " + e.getMessage(), e);
} finally {
Thread.currentThread().setPriority(threadPriority);
}
}
use of org.semanticweb.owlapi.model.OWLOntologyManager in project goci by EBISPOT.
the class DefaultGWASOWLPublisher method saveGWASDataInferredView.
public void saveGWASDataInferredView(OWLReasoner reasoner, File outputFile) throws OWLConversionException {
try {
// create new ontology to hold inferred axioms
OWLOntology inferredOntology = getConverter().createConversionOntology();
getLog().info("Saving inferred view...");
List<InferredAxiomGenerator<? extends OWLAxiom>> gens = new ArrayList<InferredAxiomGenerator<? extends OWLAxiom>>();
// we require all inferred stuff except for disjoints...
gens.add(new InferredClassAssertionAxiomGenerator());
gens.add(new InferredDataPropertyCharacteristicAxiomGenerator());
gens.add(new InferredEquivalentClassAxiomGenerator());
gens.add(new InferredEquivalentDataPropertiesAxiomGenerator());
gens.add(new InferredEquivalentObjectPropertyAxiomGenerator());
gens.add(new InferredInverseObjectPropertiesAxiomGenerator());
gens.add(new InferredObjectPropertyCharacteristicAxiomGenerator());
gens.add(new InferredPropertyAssertionGenerator());
gens.add(new InferredSubClassAxiomGenerator());
gens.add(new InferredSubDataPropertyAxiomGenerator());
gens.add(new InferredSubObjectPropertyAxiomGenerator());
// now create the target ontology and save
OWLOntologyManager inferredManager = inferredOntology.getOWLOntologyManager();
InferredOntologyGenerator iog = new InferredOntologyGenerator(reasoner, gens);
iog.fillOntology(inferredManager, inferredOntology);
inferredManager.saveOntology(inferredOntology, IRI.create(outputFile));
getLog().info("Inferred view saved ok");
} catch (OWLOntologyStorageException e) {
throw new OWLConversionException("Failed to save GWAS data (inferred view)", e);
}
}
use of org.semanticweb.owlapi.model.OWLOntologyManager in project goci by EBISPOT.
the class KBLoader method getTraitClass.
private Set<IRI> getTraitClass(OWLOntology ontology, OWLNamedIndividual individual) {
OWLOntologyManager manager = ontology.getOWLOntologyManager();
OWLDataFactory dataFactory = manager.getOWLDataFactory();
Set<IRI> results = new HashSet<IRI>();
// get all individuals related to this one by "is_about"
OWLObjectProperty has_object = dataFactory.getOWLObjectProperty(IRI.create(OntologyConstants.HAS_OBJECT_IRI));
Set<OWLIndividual> relatedInds = individual.getObjectPropertyValues(has_object, ontology);
// for each related individual, get all types
for (OWLIndividual related : relatedInds) {
Set<OWLClassExpression> types = related.getTypes(ontology);
for (OWLClassExpression type : types) {
results.add(type.asOWLClass().getIRI());
}
}
return results;
}
use of org.semanticweb.owlapi.model.OWLOntologyManager 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.model.OWLOntologyManager in project stanbol by apache.
the class RecipeWriter method writeTo.
@Override
public void writeTo(Recipe recipe, Class<?> arg1, Type arg2, Annotation[] arg3, MediaType mediaType, MultivaluedMap<String, Object> arg5, OutputStream out) throws IOException, WebApplicationException {
Logger log = LoggerFactory.getLogger(getClass());
log.debug("Rendering the list of recipes.");
if (mediaType.toString().equals(MediaType.TEXT_PLAIN)) {
String recipeString = recipe.toString();
out.write(recipeString.getBytes());
} else if (mediaType.toString().equals(MediaType.TEXT_HTML)) {
String recipeString = recipe.toString();
out.write(recipeString.getBytes());
} else {
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLDataFactory factory = OWLManager.getOWLDataFactory();
OWLOntology ontology;
try {
ontology = manager.createOntology();
RuleList rules = recipe.getRuleList();
IRI recipeID = recipe.getRecipeID();
String recipeURI = recipeID.toString().replace("<", "").replace(">", "");
org.semanticweb.owlapi.model.IRI recipeIRI = org.semanticweb.owlapi.model.IRI.create(recipeURI);
OWLIndividual recipeIndividual = factory.getOWLNamedIndividual(recipeIRI);
String descriptionURI = Symbols.description.toString().replace("<", "").replace(">", "");
org.semanticweb.owlapi.model.IRI descriptionIRI = org.semanticweb.owlapi.model.IRI.create(descriptionURI);
OWLDataProperty descriptionProperty = factory.getOWLDataProperty(descriptionIRI);
OWLAxiom axiom;
String recipeDescription = recipe.getRecipeDescription();
if (recipeDescription != null) {
axiom = factory.getOWLDataPropertyAssertionAxiom(descriptionProperty, recipeIndividual, recipeDescription);
manager.addAxiom(ontology, axiom);
}
if (rules != null) {
for (Rule rule : rules) {
IRI ruleID = rule.getRuleID();
String ruleName = rule.getRuleName();
String ruleDescription = rule.getDescription();
String ruleURI = ruleID.toString().replace("<", "").replace(">", "");
String ruleNameURI = Symbols.ruleName.toString().replace("<", "").replace(">", "");
String ruleBodyURI = Symbols.ruleBody.toString().replace("<", "").replace(">", "");
String ruleHeadURI = Symbols.ruleHead.toString().replace("<", "").replace(">", "");
String hasRuleURI = Symbols.hasRule.toString().replace("<", "").replace(">", "");
String ruleContent = rule.toString();
String[] ruleParts = ruleContent.split("\\->");
org.semanticweb.owlapi.model.IRI ruleIRI = org.semanticweb.owlapi.model.IRI.create(ruleURI);
org.semanticweb.owlapi.model.IRI ruleNameIRI = org.semanticweb.owlapi.model.IRI.create(ruleNameURI);
org.semanticweb.owlapi.model.IRI ruleBodyIRI = org.semanticweb.owlapi.model.IRI.create(ruleBodyURI);
org.semanticweb.owlapi.model.IRI ruleHeadIRI = org.semanticweb.owlapi.model.IRI.create(ruleHeadURI);
org.semanticweb.owlapi.model.IRI hasRuleIRI = org.semanticweb.owlapi.model.IRI.create(hasRuleURI);
OWLIndividual ruleIndividual = factory.getOWLNamedIndividual(ruleIRI);
OWLObjectProperty hasRule = factory.getOWLObjectProperty(hasRuleIRI);
OWLDataProperty nameProperty = factory.getOWLDataProperty(ruleNameIRI);
OWLDataProperty ruleBodyProperty = factory.getOWLDataProperty(ruleBodyIRI);
OWLDataProperty ruleHeadProperty = factory.getOWLDataProperty(ruleHeadIRI);
// add the name to the rule individual
axiom = factory.getOWLDataPropertyAssertionAxiom(nameProperty, ruleIndividual, ruleName);
manager.addAxiom(ontology, axiom);
// add the description to the rule individual
if (ruleDescription != null) {
axiom = factory.getOWLDataPropertyAssertionAxiom(descriptionProperty, ruleIndividual, ruleDescription);
manager.addAxiom(ontology, axiom);
}
// add the rule body to the rule individual
axiom = factory.getOWLDataPropertyAssertionAxiom(ruleBodyProperty, ruleIndividual, ruleParts[0]);
manager.addAxiom(ontology, axiom);
// add the rule head to the rule individual
axiom = factory.getOWLDataPropertyAssertionAxiom(ruleHeadProperty, ruleIndividual, ruleParts[1]);
manager.addAxiom(ontology, axiom);
// bind the rule to the recipe
axiom = factory.getOWLObjectPropertyAssertionAxiom(hasRule, recipeIndividual, ruleIndividual);
manager.addAxiom(ontology, axiom);
}
}
if (mediaType.toString().equals(KRFormat.RDF_XML)) {
try {
manager.saveOntology(ontology, new RDFXMLOntologyFormat(), out);
} catch (OWLOntologyStorageException e) {
log.error("Failed to store ontology for rendering.", e);
}
} else if (mediaType.toString().equals(KRFormat.OWL_XML)) {
try {
manager.saveOntology(ontology, new OWLXMLOntologyFormat(), out);
} catch (OWLOntologyStorageException e) {
log.error("Failed to store ontology for rendering.", e);
}
} else if (mediaType.toString().equals(KRFormat.MANCHESTER_OWL)) {
try {
manager.saveOntology(ontology, new ManchesterOWLSyntaxOntologyFormat(), out);
} catch (OWLOntologyStorageException e) {
log.error("Failed to store ontology for rendering.", e);
}
} else if (mediaType.toString().equals(KRFormat.FUNCTIONAL_OWL)) {
try {
manager.saveOntology(ontology, new OWLFunctionalSyntaxOntologyFormat(), out);
} catch (OWLOntologyStorageException e) {
log.error("Failed to store ontology for rendering.", e);
}
} else if (mediaType.toString().equals(KRFormat.TURTLE)) {
try {
manager.saveOntology(ontology, new TurtleOntologyFormat(), out);
} catch (OWLOntologyStorageException e) {
log.error("Failed to store ontology for rendering.", e);
}
} else if (mediaType.toString().equals(KRFormat.RDF_JSON)) {
Graph mGraph = OWLAPIToClerezzaConverter.owlOntologyToClerezzaGraph(ontology);
RdfJsonSerializingProvider provider = new RdfJsonSerializingProvider();
provider.serialize(out, mGraph, SupportedFormat.RDF_JSON);
}
} catch (OWLOntologyCreationException e1) {
log.error("An error occurred.", e1);
}
}
out.flush();
}
Aggregations