use of org.apache.jena.rdf.model.Literal in project jena by apache.
the class UpdateBuilderExampleTests method example6.
/**
* Example 6:
*
* @see https://www.w3.org/TR/sparql11-update/#example_6
*/
@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.Literal in project jena by apache.
the class UpdateBuilderExampleTests method example1.
/**
* Example 1: Adding some triples to a graph
*
* @see https://www.w3.org/TR/sparql11-update/#example_1
*/
@Test
public void example1() {
Resource r = ResourceFactory.createResource("http://example/book1");
Property price = ResourceFactory.createProperty(NS_prefix + "price");
Literal priceV = ResourceFactory.createPlainLiteral("42");
m.add(r, price, priceV);
m.setNsPrefix("dc", DC_11.NS);
m.setNsPrefix("ns", NS_prefix);
UpdateBuilder builder = new UpdateBuilder().addPrefix("dc", DC_11.NS).addInsert(r, DC_11.title, "A new book").addInsert(r, DC_11.creator, "A.N.Other");
UpdateAction.execute(builder.buildRequest(), m);
assertTrue(m.contains(r, price, priceV));
assertTrue(m.contains(r, DC_11.title, "A new book"));
assertTrue(m.contains(r, DC_11.creator, "A.N.Other"));
assertEquals(3, triples.size());
assertEquals(2, m.getNsPrefixMap().size());
assertEquals(NS_prefix, m.getNsPrefixMap().get("ns"));
assertEquals(DC_11.NS, m.getNsPrefixMap().get("dc"));
}
use of org.apache.jena.rdf.model.Literal in project jena by apache.
the class UpdateBuilderExampleTests method example3.
/**
* Example 3: Removing triples from a graph
*
* @see https://www.w3.org/TR/sparql11-update/#example_3
*/
@Test
public void example3() {
Resource r = ResourceFactory.createResource("http://example/book2");
Property price = ResourceFactory.createProperty(NS_prefix + "price");
Literal priceV = ResourceFactory.createTypedLiteral(42);
m.setNsPrefix("dc", DC_11.NS);
m.setNsPrefix("ns", NS_prefix);
m.add(r, price, priceV);
m.add(r, DC_11.title, "David Copperfield");
m.add(r, DC_11.creator, "Edmund Wells");
UpdateBuilder builder = new UpdateBuilder().addPrefix("dc", DC_11.NS).addDelete(r, DC_11.title, "David Copperfield").addDelete(r, DC_11.creator, "Edmund Wells");
UpdateAction.execute(builder.buildRequest(), m);
assertTrue(m.contains(r, price, priceV));
assertEquals(1, triples.size());
assertEquals(2, m.getNsPrefixMap().size());
assertEquals(NS_prefix, m.getNsPrefixMap().get("ns"));
assertEquals(DC_11.NS, m.getNsPrefixMap().get("dc"));
}
use of org.apache.jena.rdf.model.Literal in project jena by apache.
the class TestLiteralImpl method testSameAdhocClassUS.
public void testSameAdhocClassUS() {
try {
final UniqueValueClass1 ra = new UniqueValueClass1("rhubarb");
final UniqueValueClass1 rb = new UniqueValueClass1("cottage");
Assert.assertNull("not expecting registered RDF Datatype", TypeMapper.getInstance().getTypeByValue(ra));
// Sets the type
final Literal la = model.createTypedLiteral(ra);
// mapper
// - contaminates it
// with
// UniqueValueClass1
final Literal lb = model.createTypedLiteral(rb);
JenaTestBase.assertInstanceOf(AdhocDatatype.class, la.getDatatype());
Assert.assertSame(la.getDatatype(), lb.getDatatype());
Assert.assertNotNull(TypeMapper.getInstance().getTypeByValue(ra));
} finally {
TypeMapper.reset();
}
}
use of org.apache.jena.rdf.model.Literal in project jena by apache.
the class TestLiterals method testInt.
// public void testLiteralObjects()
// {
// // testLiteralObject( model, 0 );
// // testLiteralObject( model, 12345 );
// // testLiteralObject( model, -67890 );
// }
protected void testInt(final Model model, final int tv) {
final Literal l = model.createTypedLiteral(tv);
try {
Assert.assertEquals(tv, l.getByte());
assertInRange(Byte.MIN_VALUE, tv, Byte.MAX_VALUE);
} catch (final IllegalArgumentException e) {
assertOutsideRange(Byte.MIN_VALUE, tv, Byte.MAX_VALUE);
}
try {
Assert.assertEquals(tv, l.getShort());
assertInRange(Short.MIN_VALUE, tv, Short.MAX_VALUE);
} catch (final IllegalArgumentException e) {
assertOutsideRange(Short.MIN_VALUE, tv, Short.MAX_VALUE);
}
Assert.assertEquals(tv, l.getInt());
Assert.assertEquals(tv, l.getLong());
}
Aggregations