Search in sources :

Example 26 with Property

use of org.apache.jena.rdf.model.Property in project jena by apache.

the class ModelQuadHolderTest method anonymousTest.

@Test
public void anonymousTest() {
    model = ModelFactory.createDefaultModel();
    List<Triple> tLst = new ArrayList<Triple>();
    Resource s = ResourceFactory.createResource("s");
    Property p = ResourceFactory.createProperty("p");
    Resource o = ResourceFactory.createResource("o");
    tLst.add(new Triple(s.asNode(), p.asNode(), o.asNode()));
    model.add(s, p, o);
    Resource s2 = ResourceFactory.createResource("s2");
    Property p2 = ResourceFactory.createProperty("p2");
    Resource o2 = ResourceFactory.createResource("o2");
    tLst.add(new Triple(s2.asNode(), p2.asNode(), o2.asNode()));
    model.add(s2, p2, o2);
    holder = new ModelQuadHolder(model);
    List<Quad> lst = holder.getQuads().toList();
    assertEquals(2, lst.size());
    Quad q = new Quad(Quad.defaultGraphNodeGenerated, tLst.get(0));
    assertTrue("missing " + q, lst.contains(q));
    q = new Quad(Quad.defaultGraphNodeGenerated, tLst.get(1));
    assertTrue("missing " + q, lst.contains(q));
}
Also used : Triple(org.apache.jena.graph.Triple) Quad(org.apache.jena.sparql.core.Quad) ArrayList(java.util.ArrayList) Resource(org.apache.jena.rdf.model.Resource) Property(org.apache.jena.rdf.model.Property) Test(org.junit.Test)

Example 27 with Property

use of org.apache.jena.rdf.model.Property in project jena by apache.

the class ModelQuadHolderTest method namedTest.

@Test
public void namedTest() {
    model = ModelFactory.createDefaultModel();
    Node g = NodeFactory.createURI("g");
    List<Triple> tLst = new ArrayList<Triple>();
    Resource s = ResourceFactory.createResource("s");
    Property p = ResourceFactory.createProperty("p");
    Resource o = ResourceFactory.createResource("o");
    tLst.add(new Triple(s.asNode(), p.asNode(), o.asNode()));
    model.add(s, p, o);
    Resource s2 = ResourceFactory.createResource("s2");
    Property p2 = ResourceFactory.createProperty("p2");
    Resource o2 = ResourceFactory.createResource("o2");
    tLst.add(new Triple(s2.asNode(), p2.asNode(), o2.asNode()));
    model.add(s2, p2, o2);
    holder = new ModelQuadHolder(g, model);
    List<Quad> lst = holder.getQuads().toList();
    assertEquals(2, lst.size());
    Quad q = new Quad(g, tLst.get(0));
    assertTrue("missing " + q, lst.contains(q));
    q = new Quad(g, tLst.get(1));
    assertTrue("missing " + q, lst.contains(q));
}
Also used : Triple(org.apache.jena.graph.Triple) Quad(org.apache.jena.sparql.core.Quad) Node(org.apache.jena.graph.Node) ArrayList(java.util.ArrayList) Resource(org.apache.jena.rdf.model.Resource) Property(org.apache.jena.rdf.model.Property) Test(org.junit.Test)

Example 28 with Property

use of org.apache.jena.rdf.model.Property in project jena by apache.

the class TestOntTools method testShortestPath6.

public void testShortestPath6() {
    Property p = m_model.createProperty(NS + "p");
    Property q = m_model.createProperty(NS + "q");
    // a - b - a by q
    // tests loop detection
    m_a.addProperty(q, m_b);
    m_b.addProperty(q, m_a);
    assertNull(OntTools.findShortestPath(m_model, m_a, m_c, new OntTools.PredicatesFilter(new Property[] { p, q })));
}
Also used : Property(org.apache.jena.rdf.model.Property)

Example 29 with Property

use of org.apache.jena.rdf.model.Property in project jena by apache.

the class TestOntTools method testShortestPath7.

public void testShortestPath7() {
    Property p = m_model.createProperty(NS + "p");
    Property q = m_model.createProperty(NS + "q");
    // a - d - e - f by p and q
    m_a.addProperty(p, m_d);
    m_d.addProperty(q, m_e);
    m_d.addProperty(q, m_b);
    m_e.addProperty(p, m_f);
    testPath(OntTools.findShortestPath(m_model, m_a, m_f, new OntTools.PredicatesFilter(new Property[] { p, q })), new Property[] { p, q, p });
}
Also used : Property(org.apache.jena.rdf.model.Property)

Example 30 with Property

use of org.apache.jena.rdf.model.Property in project jena by apache.

the class TestOntTools method testShortestPath0.

public void testShortestPath0() {
    Property p = m_model.createProperty(NS + "p");
    m_a.addProperty(p, m_b);
    testPath(OntTools.findShortestPath(m_model, m_a, m_b, ANY), new Property[] { p });
}
Also used : Property(org.apache.jena.rdf.model.Property)

Aggregations

Property (org.apache.jena.rdf.model.Property)89 Resource (org.apache.jena.rdf.model.Resource)58 Model (org.apache.jena.rdf.model.Model)45 RDFNode (org.apache.jena.rdf.model.RDFNode)18 Test (org.junit.Test)18 Statement (org.apache.jena.rdf.model.Statement)17 StmtIterator (org.apache.jena.rdf.model.StmtIterator)14 ArrayList (java.util.ArrayList)13 Literal (org.apache.jena.rdf.model.Literal)11 Node (org.apache.jena.graph.Node)6 Triple (org.apache.jena.graph.Triple)6 Iterator (java.util.Iterator)5 OntModel (org.apache.jena.ontology.OntModel)5 Dataset (org.apache.jena.query.Dataset)5 QueryExecution (org.apache.jena.query.QueryExecution)5 InfModel (org.apache.jena.rdf.model.InfModel)4 Store (org.apache.jena.sdb.Store)4 HashSet (java.util.HashSet)3 LEGATO (legato.LEGATO)3 RDFDatatype (org.apache.jena.datatypes.RDFDatatype)3