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