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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations