Search in sources :

Example 21 with Property

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

the class TestLangTurtle method optionalDotInBase.

@Test
public void optionalDotInBase() {
    Model model = ModelFactory.createDefaultModel();
    StringReader reader = new StringReader("@base <http://example/> <x> <p> <o> .");
    RDFDataMgr.read(model, reader, null, RDFLanguages.TURTLE);
    assertEquals(1, model.size());
    Resource r = model.createResource("http://example/x");
    Property p = model.createProperty("http://example/p");
    assertTrue(model.contains(r, p));
}
Also used : Model(org.apache.jena.rdf.model.Model) StringReader(java.io.StringReader) Resource(org.apache.jena.rdf.model.Resource) Property(org.apache.jena.rdf.model.Property) Test(org.junit.Test)

Example 22 with Property

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

the class TestAPI method testExecJsonItems.

/**
 * Test that a JSON query returns an array with the correct data values, given a pre-populated
 * model.
 */
@Test
public void testExecJsonItems() {
    // JENA-632
    Model model = ModelFactory.createDefaultModel();
    {
        Resource r = model.createResource(AnonId.create("first"));
        Property p = model.getProperty("");
        RDFNode node = ResourceFactory.createTypedLiteral("123", XSDDatatype.XSDdecimal);
        model.add(r, p, node);
        r = model.createResource(AnonId.create("second"));
        p = model.getProperty("");
        node = ResourceFactory.createTypedLiteral("abc", XSDDatatype.XSDstring);
        model.add(r, p, node);
        r = model.createResource(AnonId.create("third"));
        p = model.getProperty("");
        node = ResourceFactory.createLangLiteral("def", "en");
        model.add(r, p, node);
    }
    Query query = QueryFactory.create("JSON { \"s\": ?s , \"p\": ?p , \"o\" : ?o } " + "WHERE { ?s ?p ?o }", Syntax.syntaxARQ);
    try (QueryExecution qexec = QueryExecutionFactory.create(query, model)) {
        Iterator<JsonObject> execJsonItems = qexec.execJsonItems();
        int size = 0;
        while (execJsonItems.hasNext()) {
            JsonObject next = execJsonItems.next();
            if (next.get("s").toString().contains("first")) {
                assertEquals(123, next.get("o").getAsNumber().value().intValue());
            } else if (next.get("s").toString().contains("second")) {
                assertEquals("abc", next.get("o").getAsString().value());
            } else if (next.get("s").toString().contains("third")) {
                assertEquals("def", next.get("o").getAsString().value());
            }
            size++;
        }
        assertEquals(3, size);
    }
}
Also used : Query(org.apache.jena.query.Query) Model(org.apache.jena.rdf.model.Model) Resource(org.apache.jena.rdf.model.Resource) JsonObject(org.apache.jena.atlas.json.JsonObject) Property(org.apache.jena.rdf.model.Property) RDFNode(org.apache.jena.rdf.model.RDFNode) QueryExecution(org.apache.jena.query.QueryExecution) Test(org.junit.Test)

Example 23 with Property

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

the class TestModelPolymorphism method testPoly.

public void testPoly() {
    final Resource r = model.createResource("http://www.electric-hedgehog.net/a-o-s.html");
    Assert.assertFalse("the Resouce should not be null", r == null);
    Assert.assertTrue("the Resource can be a Property", r.canAs(Property.class));
    final Property p = r.as(Property.class);
    Assert.assertFalse("the Property should not be null", p == null);
    Assert.assertFalse("the Resource and Property should not be identical", r == p);
}
Also used : Resource(org.apache.jena.rdf.model.Resource) Property(org.apache.jena.rdf.model.Property)

Example 24 with Property

use of org.apache.jena.rdf.model.Property 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)

Example 25 with Property

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

the class ModelHelper method statement.

public static Statement statement(String fact) {
    StringTokenizer st = new StringTokenizer(fact);
    Resource sub = resource(st.nextToken());
    Property pred = property(st.nextToken());
    RDFNode obj = rdfNode(st.nextToken());
    return builderModel.createStatement(sub, pred, obj);
}
Also used : StringTokenizer(java.util.StringTokenizer) Resource(org.apache.jena.rdf.model.Resource) Property(org.apache.jena.rdf.model.Property) RDFNode(org.apache.jena.rdf.model.RDFNode)

Aggregations

Property (org.apache.jena.rdf.model.Property)89 Resource (org.apache.jena.rdf.model.Resource)58 Model (org.apache.jena.rdf.model.Model)45 RDFNode (org.apache.jena.rdf.model.RDFNode)18 Test (org.junit.Test)18 Statement (org.apache.jena.rdf.model.Statement)17 StmtIterator (org.apache.jena.rdf.model.StmtIterator)14 ArrayList (java.util.ArrayList)13 Literal (org.apache.jena.rdf.model.Literal)11 Node (org.apache.jena.graph.Node)6 Triple (org.apache.jena.graph.Triple)6 Iterator (java.util.Iterator)5 OntModel (org.apache.jena.ontology.OntModel)5 Dataset (org.apache.jena.query.Dataset)5 QueryExecution (org.apache.jena.query.QueryExecution)5 InfModel (org.apache.jena.rdf.model.InfModel)4 Store (org.apache.jena.sdb.Store)4 HashSet (java.util.HashSet)3 LEGATO (legato.LEGATO)3 RDFDatatype (org.apache.jena.datatypes.RDFDatatype)3