use of org.apache.jena.rdf.model.Property in project jena by apache.
the class UpdateBuilderExampleTests method example6.
/**
* Example 6:
*
* @see <a href=
* "https://www.w3.org/TR/sparql11-update/#example_6">sparql11-update
* example_6</a>
*/
@Test
public void example6() {
Resource book1 = ResourceFactory.createResource("http://example/book1");
Resource book2 = ResourceFactory.createResource("http://example/book2");
Resource book3 = ResourceFactory.createResource("http://example/book3");
Literal d1977 = ResourceFactory.createTypedLiteral("1977-01-01T00:00:00-02:00", XSDDatatype.XSDdateTime);
Literal d1970 = ResourceFactory.createTypedLiteral("1970-01-01T00:00:00-02:00", XSDDatatype.XSDdateTime);
Literal d1948 = ResourceFactory.createTypedLiteral("1948-01-01T00:00:00-02:00", XSDDatatype.XSDdateTime);
Property price = ResourceFactory.createProperty(NS_prefix + "price");
Literal priceV = ResourceFactory.createPlainLiteral("42");
m.setNsPrefix("dc", DC_11.NS);
m.setNsPrefix("ns", NS_prefix);
m.add(book1, DC_11.title, "Principles of Compiler Design");
m.add(book1, DC_11.date, d1977);
m.add(book2, price, priceV);
m.add(book2, DC_11.title, "David Copperfield");
m.add(book2, DC_11.creator, "Edmund Wells");
m.add(book2, DC_11.date, d1948);
m.add(book3, DC_11.title, "SPARQL 1.1 Tutorial");
UpdateBuilder builder = new UpdateBuilder().addPrefix("dc", DC_11.NS).addPrefix("xsd", "http://www.w3.org/2001/XMLSchema#").addDelete("?book", "?p", "?v").addWhere("?book", "dc:date", "?date");
ExprFactory exprFact = builder.getExprFactory();
builder.addFilter(exprFact.gt(exprFact.asExpr("?date"), d1970)).addWhere("?book", "?p", "?v");
UpdateRequest req = builder.buildRequest();
UpdateAction.execute(req, m);
assertTrue(m.contains(book2, price, priceV));
assertTrue(m.contains(book2, DC_11.title, "David Copperfield"));
assertTrue(m.contains(book2, DC_11.creator, "Edmund Wells"));
assertTrue(m.contains(book2, DC_11.date, d1948));
assertTrue(m.contains(book3, DC_11.title, "SPARQL 1.1 Tutorial"));
assertEquals(5, triples.size());
}
use of org.apache.jena.rdf.model.Property in project jena by apache.
the class TestJsonIterator method testIterator.
@Test
public void testIterator() {
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)) {
JsonIterator execJsonItems = (JsonIterator) qexec.execJsonItems();
assertTrue(execJsonItems.hasNext());
assertNotNull(execJsonItems.next());
}
}
use of org.apache.jena.rdf.model.Property in project jena by apache.
the class TestResultSetFormatter method testIterator.
@Test
public void testIterator() throws IOException {
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);
r = model.createResource(AnonId.create("fourth"));
p = model.getProperty("");
node = ResourceFactory.createTypedLiteral("true", XSDDatatype.XSDboolean);
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)) {
JsonIterator execJsonItems = (JsonIterator) qexec.execJsonItems();
try (final ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
ResultSetFormatter.output(baos, execJsonItems);
String output = baos.toString(Charset.forName("UTF-8"));
assertTrue(output.contains("\"_:first\""));
assertTrue(output.contains("\"_:second\""));
assertTrue(output.contains("\"_:third\""));
assertTrue(output.contains("\"_:fourth\""));
assertFalse(output.contains("\"true\""));
assertTrue(output.contains("true"));
assertTrue(output.contains("123"));
assertFalse(output.contains("\"123\""));
assertTrue(output.contains("\"abc\""));
}
}
}
use of org.apache.jena.rdf.model.Property in project jena by apache.
the class TestDatasetTDB method load2.
private static void load2(Model model) {
Resource r2 = model.createResource(base1 + "r2");
Property p1 = model.createProperty(baseNS + "p1");
model.add(r2, p1, "x1");
model.add(r2, p1, "x2");
}
use of org.apache.jena.rdf.model.Property in project jena by apache.
the class TestDatasetTDB method load1.
private static void load1(Model model) {
model.setNsPrefix("", base1);
Resource r1 = model.createResource(base1 + "r1");
Property p1 = model.createProperty(baseNS + "p1");
model.add(r1, p1, "x1");
model.add(r1, p1, "x2");
}
Aggregations