use of org.semanticweb.owlapi.model.OWLOntologyManager 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();
}
use of org.semanticweb.owlapi.model.OWLOntologyManager in project stanbol by apache.
the class GreaterThanAtomTest method setup.
@Before
public void setup() {
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
this.factory = manager.getOWLDataFactory();
variable1 = new VariableAtom(URI.create("http://kres.iks-project.eu/ontology/meta/variables#x"), false);
variable2 = new VariableAtom(URI.create("http://kres.iks-project.eu/ontology/meta/variables#y"), false);
literal1 = new StringAtom("some text");
literal2 = new StringAtom("some other text");
try {
typedLiteral1 = new TypedLiteralAtom(new NumberAtom("3.0"), new ResourceAtom(new URI(XSD.xdouble.getURI())));
typedLiteral2 = new TypedLiteralAtom(new NumberAtom("5.0"), new ResourceAtom(new URI(XSD.xdouble.getURI())));
} catch (URISyntaxException e) {
e.printStackTrace();
}
}
use of org.semanticweb.owlapi.model.OWLOntologyManager in project stanbol by apache.
the class LessThanAtomTest method setup.
@Before
public void setup() {
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
this.factory = manager.getOWLDataFactory();
variable1 = new VariableAtom(URI.create("http://kres.iks-project.eu/ontology/meta/variables#x"), false);
variable2 = new VariableAtom(URI.create("http://kres.iks-project.eu/ontology/meta/variables#y"), false);
literal1 = new StringAtom("some text");
literal2 = new StringAtom("some other text");
try {
typedLiteral1 = new TypedLiteralAtom(new NumberAtom("3.0"), new ResourceAtom(new URI(XSD.xdouble.getURI())));
typedLiteral2 = new TypedLiteralAtom(new NumberAtom("5.0"), new ResourceAtom(new URI(XSD.xdouble.getURI())));
} catch (URISyntaxException e) {
e.printStackTrace();
}
}
use of org.semanticweb.owlapi.model.OWLOntologyManager in project stanbol by apache.
the class ClassAtomTest method setup.
@Before
public void setup() {
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
this.factory = manager.getOWLDataFactory();
classResource = new ResourceAtom(URI.create("http://kres.iks-project.eu/ontology/meta/resource#Test"));
argument1 = new VariableAtom(URI.create("http://kres.iks-project.eu/ontology/meta/variables#x"), true);
}
use of org.semanticweb.owlapi.model.OWLOntologyManager in project stanbol by apache.
the class AtomTest method init.
@Before
public void init() {
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
this.factory = manager.getOWLDataFactory();
}
Aggregations