use of org.semanticweb.owlapi.model.OWLDataFactory in project stanbol by apache.
the class RegistryManagerImpl method populateLibrary.
protected Library populateLibrary(OWLNamedObject ind, Set<OWLOntology> registries) throws RegistryContentException {
IRI libId = ind.getIRI();
RegistryItem lib = null;
if (population.containsKey(libId)) {
// We are not allowing multityping either.
lib = population.get(libId);
if (!(lib instanceof Library))
throw new RegistryContentException("Inconsistent multityping: for item " + libId + " : {" + Library.class + ", " + lib.getClass() + "}");
} else {
lib = riFactory.createLibrary(ind);
try {
population.put(lib.getIRI(), lib);
} catch (Exception e) {
log.error("Invalid identifier for library item " + lib, e);
return null;
}
}
// EXIT nodes.
Set<OWLNamedObject> ironts = new HashSet<OWLNamedObject>();
OWLDataFactory df = OWLManager.getOWLDataFactory();
for (OWLOntology o : registries) {
if (ind instanceof OWLIndividual) {
// Get usages of hasOntology as an object property
for (OWLIndividual value : ((OWLIndividual) ind).getObjectPropertyValues(hasOntology, o)) if (value.isNamed())
ironts.add(value.asOWLNamedIndividual());
// Get usages of hasOntology as an annotation property
for (OWLAnnotationAssertionAxiom ann : o.getAnnotationAssertionAxioms(ind.getIRI())) if (hasOntologyAnn.equals(ann.getProperty())) {
OWLAnnotationValue value = ann.getValue();
if (value instanceof OWLNamedObject)
ironts.add((OWLNamedObject) value);
else if (value instanceof IRI)
ironts.add(df.getOWLNamedIndividual((IRI) value));
}
}
}
for (OWLNamedObject iront : ironts) {
IRI childId = iront.getIRI();
// If some populate*() method has created it, it will be there.
RegistryItem ront = population.get(childId);
// Otherwise populating it will also put it in population.
if (ront == null)
ront = populateOntology(iront, registries);
lib.addChild(ront);
if (ontologyIndex.get(childId) == null)
ontologyIndex.put(childId, new HashSet<IRI>());
ontologyIndex.get(childId).add(libId);
}
return (Library) lib;
}
use of org.semanticweb.owlapi.model.OWLDataFactory in project stanbol by apache.
the class TestOntologySpaces method setup.
@BeforeClass
public static void setup() throws Exception {
factory = onManager.getOntologySpaceFactory();
if (factory == null)
fail("Could not instantiate ontology space factory");
OWLOntologyManager mgr = OWLOntologyManagerFactory.createOWLOntologyManager(onManager.getOfflineConfiguration().getOntologySourceLocations().toArray(new IRI[0]));
OWLDataFactory df = mgr.getOWLDataFactory();
ont = mgr.createOntology(baseIri);
inMemorySrc = new RootOntologySource(ont);
// Let's state that Linus is a human being
OWLClass cHuman = df.getOWLClass(IRI.create(baseIri + "/" + Constants.humanBeing));
OWLIndividual iLinus = df.getOWLNamedIndividual(IRI.create(baseIri + "/" + Constants.linus));
linusIsHuman = df.getOWLClassAssertionAxiom(cHuman, iLinus);
mgr.applyChange(new AddAxiom(ont, linusIsHuman));
ont2 = mgr.createOntology(baseIri2);
minorSrc = new RootOntologySource(ont2);
dropSrc = getLocalSource("/ontologies/droppedcharacters.owl", mgr);
nonexSrc = getLocalSource("/ontologies/nonexistentcharacters.owl", mgr);
minorSrc = new RootOntologySource(ont2);
}
use of org.semanticweb.owlapi.model.OWLDataFactory in project stanbol by apache.
the class RuleListWriter method writeTo.
@Override
public void writeTo(RuleList ruleList, 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.");
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLDataFactory factory = OWLManager.getOWLDataFactory();
OWLOntology ontology;
try {
ontology = manager.createOntology();
String recipeClassURI = Symbols.Recipe.toString().replace("<", "").replace(">", "");
IRI recipeClassIRI = IRI.create(recipeClassURI);
OWLClass owlRecipeClass = factory.getOWLClass(recipeClassIRI);
String ruleClassURI = Symbols.Rule.toString().replace("<", "").replace(">", "");
IRI ruleClassIRI = IRI.create(ruleClassURI);
OWLClass owlRuleClass = factory.getOWLClass(ruleClassIRI);
String descriptionURI = Symbols.description.toString().replace("<", "").replace(">", "");
IRI descriptionIRI = IRI.create(descriptionURI);
OWLDataProperty descriptionProperty = factory.getOWLDataProperty(descriptionIRI);
String hasRuleURI = Symbols.hasRule.toString().replace("<", "").replace(">", "");
IRI hasRuleIRI = IRI.create(hasRuleURI);
OWLObjectProperty hasRule = factory.getOWLObjectProperty(hasRuleIRI);
String ruleBodyURI = Symbols.ruleBody.toString().replace("<", "").replace(">", "");
IRI ruleBodyIRI = IRI.create(ruleBodyURI);
OWLDataProperty ruleBody = factory.getOWLDataProperty(ruleBodyIRI);
String ruleHeadURI = Symbols.ruleHead.toString().replace("<", "").replace(">", "");
IRI ruleHeadIRI = IRI.create(ruleHeadURI);
OWLDataProperty ruleHead = factory.getOWLDataProperty(ruleHeadIRI);
if (ruleList != null) {
for (Rule rule : ruleList) {
String recipeId = rule.getRecipe().getRecipeID().toString().replace("<", "").replace(">", "");
IRI reicpeIRI = IRI.create(recipeId);
OWLIndividual owlRecipe = factory.getOWLNamedIndividual(reicpeIRI);
String ruleId = rule.getRuleID().toString().replace("<", "").replace(">", "");
IRI ruleIRI = IRI.create(ruleId);
OWLIndividual owlRule = factory.getOWLNamedIndividual(ruleIRI);
OWLAxiom axiom = factory.getOWLClassAssertionAxiom(owlRecipeClass, owlRecipe);
manager.addAxiom(ontology, axiom);
axiom = factory.getOWLClassAssertionAxiom(owlRuleClass, owlRule);
manager.addAxiom(ontology, axiom);
axiom = factory.getOWLObjectPropertyAssertionAxiom(hasRule, owlRecipe, owlRule);
manager.addAxiom(ontology, axiom);
String recipeDescription = rule.getRecipe().getRecipeDescription();
String ruleDescription = rule.getDescription();
if (recipeDescription != null) {
axiom = factory.getOWLDataPropertyAssertionAxiom(descriptionProperty, owlRecipe, recipeDescription);
manager.addAxiom(ontology, axiom);
}
if (ruleDescription != null) {
axiom = factory.getOWLDataPropertyAssertionAxiom(descriptionProperty, owlRule, ruleDescription);
manager.addAxiom(ontology, axiom);
}
String ruleContent = rule.toString();
String[] parts = ruleContent.split("\\->");
axiom = factory.getOWLDataPropertyAssertionAxiom(ruleBody, owlRule, parts[0]);
manager.addAxiom(ontology, axiom);
axiom = factory.getOWLDataPropertyAssertionAxiom(ruleHead, owlRule, parts[1]);
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