Search in sources :

Example 56 with OWLOntologyManager

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();
}
Also used : IRI(org.semanticweb.owlapi.model.IRI) ManchesterOWLSyntaxOntologyFormat(org.coode.owlapi.manchesterowlsyntax.ManchesterOWLSyntaxOntologyFormat) TurtleOntologyFormat(org.coode.owlapi.turtle.TurtleOntologyFormat) OWLFunctionalSyntaxOntologyFormat(org.semanticweb.owlapi.io.OWLFunctionalSyntaxOntologyFormat) RDFXMLOntologyFormat(org.semanticweb.owlapi.io.RDFXMLOntologyFormat) Logger(org.slf4j.Logger) OWLObjectProperty(org.semanticweb.owlapi.model.OWLObjectProperty) OWLDataProperty(org.semanticweb.owlapi.model.OWLDataProperty) Graph(org.apache.clerezza.commons.rdf.Graph) RdfJsonSerializingProvider(org.apache.clerezza.rdf.rdfjson.serializer.RdfJsonSerializingProvider) OWLXMLOntologyFormat(org.semanticweb.owlapi.io.OWLXMLOntologyFormat) OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) OWLClass(org.semanticweb.owlapi.model.OWLClass) OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager) Rule(org.apache.stanbol.rules.base.api.Rule) OWLAxiom(org.semanticweb.owlapi.model.OWLAxiom) OWLDataFactory(org.semanticweb.owlapi.model.OWLDataFactory) OWLIndividual(org.semanticweb.owlapi.model.OWLIndividual) OWLOntologyStorageException(org.semanticweb.owlapi.model.OWLOntologyStorageException)

Example 57 with OWLOntologyManager

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();
    }
}
Also used : OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) Before(org.junit.Before)

Example 58 with OWLOntologyManager

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();
    }
}
Also used : OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) Before(org.junit.Before)

Example 59 with OWLOntologyManager

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);
}
Also used : OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager) Before(org.junit.Before)

Example 60 with OWLOntologyManager

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();
}
Also used : OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager) Before(org.junit.Before)

Aggregations

OWLOntologyManager (org.semanticweb.owlapi.model.OWLOntologyManager)83 OWLOntology (org.semanticweb.owlapi.model.OWLOntology)52 OWLOntologyCreationException (org.semanticweb.owlapi.model.OWLOntologyCreationException)42 OWLDataFactory (org.semanticweb.owlapi.model.OWLDataFactory)23 OWLOntologyID (org.semanticweb.owlapi.model.OWLOntologyID)21 OWLAxiom (org.semanticweb.owlapi.model.OWLAxiom)17 IRI (org.semanticweb.owlapi.model.IRI)14 HashSet (java.util.HashSet)13 AddImport (org.semanticweb.owlapi.model.AddImport)12 OWLClass (org.semanticweb.owlapi.model.OWLClass)12 Test (org.junit.Test)11 ReasoningServiceException (org.apache.stanbol.reasoners.servicesapi.ReasoningServiceException)10 OWLObjectProperty (org.semanticweb.owlapi.model.OWLObjectProperty)10 OntModel (com.hp.hpl.jena.ontology.OntModel)9 InputStream (java.io.InputStream)9 OWLDataProperty (org.semanticweb.owlapi.model.OWLDataProperty)9 OWLOntologyStorageException (org.semanticweb.owlapi.model.OWLOntologyStorageException)9 ArrayList (java.util.ArrayList)8 InconsistentInputException (org.apache.stanbol.reasoners.servicesapi.InconsistentInputException)8 OWLOntologyChange (org.semanticweb.owlapi.model.OWLOntologyChange)8