Search in sources :

Example 1 with Ontology

use of org.apache.jena.ontology.Ontology in project Processor by AtomGraph.

the class SkolemizerTest method testHasValueRestrictionParent.

@Test
public void testHasValueRestrictionParent() {
    String hasValue = "http://restricted/";
    Ontology ontology = ModelFactory.createOntologyModel().createOntology("http://test/ontology");
    HasValueRestriction hvr = ontology.getOntModel().createHasValueRestriction("http://test/ontology/hvr", SIOC.HAS_CONTAINER, ontology.getOntModel().createResource(hasValue));
    // use inheritance as well
    OntClass superCls = ontology.getOntModel().createClass("http://test/ontology/super-class");
    superCls.addLiteral(LDT.path, "hv-{identifier}");
    OntClass cls = ontology.getOntModel().createClass("http://test/ontology/class");
    cls.addProperty(RDFS.subClassOf, hvr).addProperty(RDFS.subClassOf, superCls);
    // sioc:has_container has to be an owl:ObjectProperty, otherwise we'll get ConversionException
    ontology.getOntModel().createResource(SIOC.HAS_CONTAINER.getURI()).addProperty(RDF.type, OWL.ObjectProperty);
    String id = "987654321";
    Resource inst = ModelFactory.createDefaultModel().createResource().addProperty(RDF.type, cls).addLiteral(DCTerms.identifier, id);
    URI expected = UriBuilder.fromUri(hasValue).path("hv-" + id).build();
    URI actual = getSkolemizer(new OntDocumentManager(), ontology.getOntModel(), ontology.getURI()).build(inst);
    assertEquals(expected, actual);
}
Also used : Ontology(org.apache.jena.ontology.Ontology) Resource(org.apache.jena.rdf.model.Resource) OntDocumentManager(org.apache.jena.ontology.OntDocumentManager) OntClass(org.apache.jena.ontology.OntClass) URI(java.net.URI) HasValueRestriction(org.apache.jena.ontology.HasValueRestriction) Test(org.junit.Test)

Example 2 with Ontology

use of org.apache.jena.ontology.Ontology in project Processor by AtomGraph.

the class SkolemizerTest method testFragment.

@Test
public void testFragment() {
    String fragment = "something";
    // use inheritance as well
    Ontology ontology = ModelFactory.createOntologyModel().createOntology("http://test/ontology");
    OntClass superCls = ontology.getOntModel().createClass("http://test/ontology/super-class");
    superCls.addLiteral(LDT.fragment, fragment);
    OntClass cls = ontology.getOntModel().createClass("http://test/ontology/class");
    cls.addLiteral(LDT.path, "{identifier}").addProperty(RDFS.subClassOf, superCls);
    String id = "ABCDEFGHI";
    Resource inst = ModelFactory.createDefaultModel().createResource().addProperty(RDF.type, cls).addLiteral(DCTerms.identifier, id);
    URI expected = absolutePathBuilder.clone().path(id).fragment(fragment).build();
    URI actual = getSkolemizer(new OntDocumentManager(), ontology.getOntModel(), ontology.getURI()).build(inst);
    assertEquals(expected, actual);
}
Also used : Ontology(org.apache.jena.ontology.Ontology) Resource(org.apache.jena.rdf.model.Resource) OntDocumentManager(org.apache.jena.ontology.OntDocumentManager) OntClass(org.apache.jena.ontology.OntClass) URI(java.net.URI) Test(org.junit.Test)

Example 3 with Ontology

use of org.apache.jena.ontology.Ontology in project Processor by AtomGraph.

the class SkolemizerTest method testInvalidPath.

@Test(expected = OntologyException.class)
public void testInvalidPath() {
    Ontology ontology = ModelFactory.createOntologyModel().createOntology("http://test/ontology");
    OntClass cls = ontology.getOntModel().createClass("http://test/ontology/class");
    cls.addLiteral(LDT.path, 123);
    Resource invalid = ModelFactory.createDefaultModel().createResource().addProperty(RDF.type, cls);
    getSkolemizer(new OntDocumentManager(), ontology.getOntModel(), ontology.getURI()).build(invalid);
}
Also used : Ontology(org.apache.jena.ontology.Ontology) Resource(org.apache.jena.rdf.model.Resource) OntDocumentManager(org.apache.jena.ontology.OntDocumentManager) OntClass(org.apache.jena.ontology.OntClass) Test(org.junit.Test)

Example 4 with Ontology

use of org.apache.jena.ontology.Ontology in project Processor by AtomGraph.

the class SkolemizerTest method testInheritance.

@Test
public void testInheritance() {
    Ontology ontology = ModelFactory.createOntologyModel().createOntology("http://test/ontology");
    Ontology importedOntology = ontology.getOntModel().createOntology("http://test/ontology/import");
    ontology.addImport(importedOntology);
    OntClass superClass = importedOntology.getOntModel().createClass("http://test/ontology/super-class");
    superClass.addLiteral(LDT.path, "super-{title}");
    OntClass cls = ontology.getOntModel().createClass("http://test/ontology/class");
    cls.addProperty(RDFS.subClassOf, FOAF.Document).addProperty(RDFS.subClassOf, superClass);
    String title = "Whateverest";
    Resource subInst = ModelFactory.createDefaultModel().createResource().addProperty(RDF.type, cls).addLiteral(DCTerms.title, title);
    URI expected = absolutePathBuilder.clone().path("super-" + title).build();
    URI actual = getSkolemizer(new OntDocumentManager(), ontology.getOntModel(), ontology.getURI()).build(subInst);
    assertEquals(expected, actual);
}
Also used : Ontology(org.apache.jena.ontology.Ontology) Resource(org.apache.jena.rdf.model.Resource) OntDocumentManager(org.apache.jena.ontology.OntDocumentManager) OntClass(org.apache.jena.ontology.OntClass) URI(java.net.URI) Test(org.junit.Test)

Example 5 with Ontology

use of org.apache.jena.ontology.Ontology in project Processor by AtomGraph.

the class SkolemizerTest method getSkolemizer.

// we do not want to share the OntDocumentManager between tests because we'll get race conditions
public Skolemizer getSkolemizer(OntDocumentManager ontMgr, OntModel ontModel, String ontologyURI) {
    // Ontology ontology = ontModel.getOntology(ontologyURI);
    // load the ontology the same way Application loads it
    ontMgr.addModel(ontologyURI, ontModel);
    Ontology ontology = new OntologyLoader(ontMgr, ontologyURI, ontModel.getSpecification(), true).getOntology();
    return new Skolemizer(ontology, baseUriBuilder, absolutePathBuilder);
}
Also used : OntologyLoader(com.atomgraph.server.util.OntologyLoader) Ontology(org.apache.jena.ontology.Ontology)

Aggregations

Ontology (org.apache.jena.ontology.Ontology)18 Test (org.junit.Test)13 Resource (org.apache.jena.rdf.model.Resource)12 OntClass (org.apache.jena.ontology.OntClass)11 OntDocumentManager (org.apache.jena.ontology.OntDocumentManager)11 URI (java.net.URI)10 Template (com.atomgraph.processor.model.Template)4 OntModel (org.apache.jena.ontology.OntModel)3 HasValueRestriction (org.apache.jena.ontology.HasValueRestriction)2 Model (org.apache.jena.rdf.model.Model)2 MediaTypes (com.atomgraph.core.MediaTypes)1 DataManagerFactory (com.atomgraph.core.factory.DataManagerFactory)1 QueryProvider (com.atomgraph.core.io.QueryProvider)1 ResultSetProvider (com.atomgraph.core.io.ResultSetProvider)1 UpdateRequestProvider (com.atomgraph.core.io.UpdateRequestProvider)1 Service (com.atomgraph.core.model.Service)1 QueryParamProvider (com.atomgraph.core.provider.QueryParamProvider)1 OntologyException (com.atomgraph.processor.exception.OntologyException)1 Parameter (com.atomgraph.processor.model.Parameter)1 OntologyFactory (com.atomgraph.server.factory.OntologyFactory)1