Search in sources :

Example 31 with Resource

use of org.apache.jena.rdf.model.Resource in project jena by apache.

the class TestPrefixMappingAssembler method testIncludesSingleMapping.

public void testIncludesSingleMapping() {
    PrefixMapping wanted = PrefixMapping.Factory.create().setNsPrefix("pre", "some:prefix/");
    Assembler a = new PrefixMappingAssembler();
    Resource root = resourceInModel("root rdf:type ja:PrefixMapping; root ja:includes pm" + "; pm rdf:type ja:PrefixMapping; pm ja:prefix 'pre'; pm ja:namespace 'some:prefix/'");
    PrefixMapping pm = (PrefixMapping) a.open(root);
    assertSamePrefixMapping(wanted, pm);
}
Also used : PrefixMapping(org.apache.jena.shared.PrefixMapping) PrefixMappingAssembler(org.apache.jena.assembler.assemblers.PrefixMappingAssembler) Resource(org.apache.jena.rdf.model.Resource) PrefixMappingAssembler(org.apache.jena.assembler.assemblers.PrefixMappingAssembler)

Example 32 with Resource

use of org.apache.jena.rdf.model.Resource in project jena by apache.

the class TestLocationMapperAssembler method testCreatesLocationMapper.

public void testCreatesLocationMapper() {
    Resource root = resourceInModel("r rdf:type ja:LocationMapper");
    Assembler a = new LocationMapperAssembler();
    Object x = a.open(root);
    assertInstanceOf(LocationMapper.class, x);
}
Also used : LocationMapperAssembler(org.apache.jena.assembler.assemblers.LocationMapperAssembler) Resource(org.apache.jena.rdf.model.Resource) LocationMapperAssembler(org.apache.jena.assembler.assemblers.LocationMapperAssembler)

Example 33 with Resource

use of org.apache.jena.rdf.model.Resource in project jena by apache.

the class TestReasoners method testTransitiveBindReuse.

/**
     * The reasoner contract for bind(data) is not quite precise. It allows for
     * reasoners which have state so that reusing the same reasoner on a second data
     * model might lead to interference. This in fact used to happen with the transitive
     * reasoner. This is a test to check that the transitive reasoner state reuse has been fixed at source.
     */
public void testTransitiveBindReuse() {
    Reasoner r = ReasonerRegistry.getTransitiveReasoner();
    InfModel om1 = ModelFactory.createInfModel(r, ModelFactory.createDefaultModel());
    Resource c1 = om1.createResource(PrintUtil.egNS + "Class1");
    Resource c2 = om1.createResource(PrintUtil.egNS + "Class2");
    Resource c3 = om1.createResource(PrintUtil.egNS + "Class3");
    om1.add(c1, RDFS.subClassOf, c2);
    om1.add(c2, RDFS.subClassOf, c3);
    om1.prepare();
    assertFalse(om1.isEmpty());
    InfModel om2 = ModelFactory.createInfModel(r, ModelFactory.createDefaultModel());
    StmtIterator si = om2.listStatements();
    boolean ok = !si.hasNext();
    si.close();
    assertTrue("Transitive reasoner state leak", ok);
}
Also used : StmtIterator(org.apache.jena.rdf.model.StmtIterator) TransitiveReasoner(org.apache.jena.reasoner.transitiveReasoner.TransitiveReasoner) Reasoner(org.apache.jena.reasoner.Reasoner) Resource(org.apache.jena.rdf.model.Resource) InfModel(org.apache.jena.rdf.model.InfModel)

Example 34 with Resource

use of org.apache.jena.rdf.model.Resource in project jena by apache.

the class TestReasoners method testTransitiveCycleBug.

/**
     * Cycle bug in transitive reasoner
     */
public void testTransitiveCycleBug() {
    Model m = FileManager.get().loadModel("file:testing/reasoners/bugs/unbroken.n3");
    OntModel om = ModelFactory.createOntologyModel(OntModelSpec.RDFS_MEM_TRANS_INF, m);
    OntClass rootClass = om.getOntClass(RDFS.Resource.getURI());
    Resource c = m.getResource("c");
    Set<OntClass> direct = rootClass.listSubClasses(true).toSet();
    assertFalse(direct.contains(c));
}
Also used : OntModel(org.apache.jena.ontology.OntModel) InfModel(org.apache.jena.rdf.model.InfModel) Model(org.apache.jena.rdf.model.Model) Resource(org.apache.jena.rdf.model.Resource) OntModel(org.apache.jena.ontology.OntModel) OntClass(org.apache.jena.ontology.OntClass)

Example 35 with Resource

use of org.apache.jena.rdf.model.Resource in project jena by apache.

the class TestReasoners method testTransitiveEngineSeparation.

/**
     * Test that two transitive engines are independent.
     * See JENA-1260
     */
public void testTransitiveEngineSeparation() throws InterruptedException {
    String NS = "http://example.com/test#";
    Property sp = ResourceFactory.createProperty(NS, "sp");
    Property p = ResourceFactory.createProperty(NS, "p");
    Property s = ResourceFactory.createProperty(NS, "s");
    Resource q = ResourceFactory.createProperty(NS, "q");
    Reasoner reasoner = ReasonerRegistry.getTransitiveReasoner();
    InfModel simple = ModelFactory.createInfModel(reasoner, ModelFactory.createDefaultModel());
    simple.add(s, sp, p);
    assertFalse(simple.contains(s, RDFS.subPropertyOf, p));
    InfModel withSP = ModelFactory.createInfModel(reasoner, ModelFactory.createDefaultModel());
    withSP.add(sp, RDFS.subPropertyOf, RDFS.subPropertyOf);
    withSP.add(s, sp, p);
    assertTrue(withSP.contains(s, RDFS.subPropertyOf, p));
    simple.add(q, sp, p);
    assertFalse(simple.contains(q, RDFS.subPropertyOf, p));
}
Also used : TransitiveReasoner(org.apache.jena.reasoner.transitiveReasoner.TransitiveReasoner) Reasoner(org.apache.jena.reasoner.Reasoner) Resource(org.apache.jena.rdf.model.Resource) InfModel(org.apache.jena.rdf.model.InfModel) Property(org.apache.jena.rdf.model.Property)

Aggregations

Resource (org.apache.jena.rdf.model.Resource)178 Model (org.apache.jena.rdf.model.Model)86 Test (org.junit.Test)55 Property (org.apache.jena.rdf.model.Property)34 RDFNode (org.apache.jena.rdf.model.RDFNode)24 Dataset (org.apache.jena.query.Dataset)20 Literal (org.apache.jena.rdf.model.Literal)17 BaseTest (org.apache.jena.atlas.junit.BaseTest)16 Node (org.apache.jena.graph.Node)16 Statement (org.apache.jena.rdf.model.Statement)14 UpdateBuilder (org.apache.jena.arq.querybuilder.UpdateBuilder)13 StringReader (java.io.StringReader)9 InfModel (org.apache.jena.rdf.model.InfModel)9 Reader (java.io.Reader)8 ArrayList (java.util.ArrayList)8 JsonString (org.apache.jena.atlas.json.JsonString)8 Triple (org.apache.jena.graph.Triple)8 JsonLDWriteContext (org.apache.jena.riot.JsonLDWriteContext)6 PrefixMapping (org.apache.jena.shared.PrefixMapping)6 SelectBuilder (org.apache.jena.arq.querybuilder.SelectBuilder)5