use of org.apache.jena.rdf.model.Property in project jena by apache.
the class TestOntTools method testShortestPath5.
/**
* Reflexive loop is allowed
*/
public void testShortestPath5() {
Property p = m_model.createProperty(NS + "p");
m_a.addProperty(p, m_a);
testPath(OntTools.findShortestPath(m_model, m_a, m_a, ANY), new Property[] { p });
}
use of org.apache.jena.rdf.model.Property in project jena by apache.
the class TestOntTools method testShortestPath1.
public void testShortestPath1() {
Property p = m_model.createProperty(NS + "p");
m_a.addProperty(p, m_b);
m_b.addProperty(p, m_c);
testPath(OntTools.findShortestPath(m_model, m_a, m_c, ANY), new Property[] { p, p });
}
use of org.apache.jena.rdf.model.Property in project jena by apache.
the class TestOntTools method testShortestPath4.
public void testShortestPath4() {
Property p = m_model.createProperty(NS + "p");
Property q = m_model.createProperty(NS + "q");
// a - b - c by q
m_a.addProperty(q, m_b);
m_b.addProperty(q, m_c);
// a - d - e - f by p
m_a.addProperty(p, m_d);
m_d.addProperty(p, m_e);
m_e.addProperty(p, m_f);
assertNull(OntTools.findShortestPath(m_model, m_a, m_c, new OntTools.PredicatesFilter(p)));
testPath(OntTools.findShortestPath(m_model, m_a, m_f, new OntTools.PredicatesFilter(p)), new Property[] { p, p, p });
}
use of org.apache.jena.rdf.model.Property in project jena by apache.
the class UpdateBuilderExampleTests method example1.
/**
* Example 1: Adding some triples to a graph
*
* @see <a href=
* "https://www.w3.org/TR/sparql11-update/#example_1">sparql11-update
* example_1</a>
*/
@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.Property in project jena by apache.
the class UpdateBuilderExampleTests method example3.
/**
* Example 3: Removing triples from a graph
*
* @see <a href=
* "https://www.w3.org/TR/sparql11-update/#example_3">sparql11-update
* example_3</a>
*/
@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"));
}
Aggregations