Search in sources :

Example 66 with Property

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 });
}
Also used : Property(org.apache.jena.rdf.model.Property)

Example 67 with Property

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 });
}
Also used : Property(org.apache.jena.rdf.model.Property)

Example 68 with Property

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 });
}
Also used : Property(org.apache.jena.rdf.model.Property)

Example 69 with Property

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"));
}
Also used : Literal(org.apache.jena.rdf.model.Literal) Resource(org.apache.jena.rdf.model.Resource) Property(org.apache.jena.rdf.model.Property) Test(org.junit.Test)

Example 70 with Property

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"));
}
Also used : Literal(org.apache.jena.rdf.model.Literal) Resource(org.apache.jena.rdf.model.Resource) Property(org.apache.jena.rdf.model.Property) Test(org.junit.Test)

Aggregations

Property (org.apache.jena.rdf.model.Property)90 Resource (org.apache.jena.rdf.model.Resource)59 Model (org.apache.jena.rdf.model.Model)46 RDFNode (org.apache.jena.rdf.model.RDFNode)19 Test (org.junit.Test)18 Statement (org.apache.jena.rdf.model.Statement)17 ArrayList (java.util.ArrayList)14 StmtIterator (org.apache.jena.rdf.model.StmtIterator)14 Literal (org.apache.jena.rdf.model.Literal)11 Iterator (java.util.Iterator)6 Node (org.apache.jena.graph.Node)6 Triple (org.apache.jena.graph.Triple)6 QueryExecution (org.apache.jena.query.QueryExecution)6 OntModel (org.apache.jena.ontology.OntModel)5 Dataset (org.apache.jena.query.Dataset)5 Query (org.apache.jena.query.Query)4 InfModel (org.apache.jena.rdf.model.InfModel)4 Store (org.apache.jena.sdb.Store)4 IOException (java.io.IOException)3 LEGATO (legato.LEGATO)3