Search in sources :

Example 11 with Statement

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

the class TestAddAndContains method testAddDuplicateLeavesSizeSame.

public void testAddDuplicateLeavesSizeSame() {
    final Statement s = model.createStatement(S, RDF.value, "something");
    model.add(s);
    final long size = model.size();
    model.add(s);
    Assert.assertEquals(size, model.size());
}
Also used : Statement(org.apache.jena.rdf.model.Statement)

Example 12 with Statement

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

the class TestAddAndContains method testAddContainLiteralByStatement.

public void testAddContainLiteralByStatement() {
    final Literal L = model.createTypedLiteral(210);
    final Statement s = model.createStatement(S, RDF.value, L);
    Assert.assertTrue(model.add(s).contains(s));
    Assert.assertTrue(model.contains(S, RDF.value));
}
Also used : Statement(org.apache.jena.rdf.model.Statement) Literal(org.apache.jena.rdf.model.Literal)

Example 13 with Statement

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

the class TestOntTools method testPath.

// Internal implementation methods
//////////////////////////////////
private void testPath(OntTools.Path path, Property[] expected) {
    assertEquals(expected.length, path.size());
    int i = 0;
    for (Statement aPath : path) {
        assertEquals("path position: " + i, expected[i], aPath.getPredicate());
        i++;
    }
}
Also used : Statement(org.apache.jena.rdf.model.Statement)

Example 14 with Statement

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

the class SecurityExample method main.

/**
	 * @param args
	 */
public static void main(String[] args) {
    String[] names = { "alice", "bob", "chuck", "darla" };
    RDFNode msgType = ResourceFactory.createResource("http://example.com/msg");
    Property pTo = ResourceFactory.createProperty("http://example.com/to");
    Property pFrom = ResourceFactory.createProperty("http://example.com/from");
    Property pSubj = ResourceFactory.createProperty("http://example.com/subj");
    Model model = ModelFactory.createDefaultModel();
    URL url = SecurityExample.class.getClassLoader().getResource("org/apache/jena/security/example/example.ttl");
    model.read(url.toExternalForm());
    ResIterator ri = model.listSubjectsWithProperty(RDF.type, msgType);
    System.out.println("All the messages");
    while (ri.hasNext()) {
        Resource msg = ri.next();
        Statement to = msg.getProperty(pTo);
        Statement from = msg.getProperty(pFrom);
        Statement subj = msg.getProperty(pSubj);
        System.out.println(String.format("%s to: %s  from: %s  subj: %s", msg, to.getObject(), from.getObject(), subj.getObject()));
    }
    System.out.println();
    ExampleEvaluator evaluator = new ExampleEvaluator(model);
    model = Factory.getInstance(evaluator, "http://example.com/SecuredModel", model);
    for (String userName : names) {
        evaluator.setPrincipal(userName);
        System.out.println("Messages " + userName + " can manipulate");
        ri = model.listSubjectsWithProperty(RDF.type, msgType);
        while (ri.hasNext()) {
            Resource msg = ri.next();
            Statement to = msg.getProperty(pTo);
            Statement from = msg.getProperty(pFrom);
            Statement subj = msg.getProperty(pSubj);
            System.out.println(String.format("%s to: %s  from: %s  subj: %s", msg, to.getObject(), from.getObject(), subj.getObject()));
        }
        ri.close();
        for (String name : names) {
            System.out.println(String.format("%s messages to %s", model.listSubjectsWithProperty(pTo, name).toList().size(), name));
        }
        System.out.println();
    }
}
Also used : ResIterator(org.apache.jena.rdf.model.ResIterator) Statement(org.apache.jena.rdf.model.Statement) Model(org.apache.jena.rdf.model.Model) Resource(org.apache.jena.rdf.model.Resource) Property(org.apache.jena.rdf.model.Property) RDFNode(org.apache.jena.rdf.model.RDFNode) URL(java.net.URL)

Example 15 with Statement

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

the class TestConcurrentAccess method mrswGraph6.

@Test(expected = ConcurrentModificationException.class)
public void mrswGraph6() {
    Dataset d = TDBFactory.createDataset();
    Model m = d.getNamedModel("http://example");
    GraphUtil.addInto(m.getGraph(), buildGraph());
    Resource r = m.createResource("x");
    ExtendedIterator<Statement> iter1 = m.listStatements(r, null, (RDFNode) null);
    assertNotNull(iter1.next());
    Triple t = SSE.parseTriple("(<y> <p> 99)");
    m.getGraph().delete(t);
    iter1.next();
}
Also used : Triple(org.apache.jena.graph.Triple) Statement(org.apache.jena.rdf.model.Statement) Model(org.apache.jena.rdf.model.Model) Resource(org.apache.jena.rdf.model.Resource) Test(org.junit.Test) BaseTest(org.apache.jena.atlas.junit.BaseTest)

Aggregations

Statement (org.apache.jena.rdf.model.Statement)37 Model (org.apache.jena.rdf.model.Model)17 Resource (org.apache.jena.rdf.model.Resource)14 Test (org.junit.Test)9 StmtIterator (org.apache.jena.rdf.model.StmtIterator)7 ArrayList (java.util.ArrayList)6 BaseTest (org.apache.jena.atlas.junit.BaseTest)6 Triple (org.apache.jena.graph.Triple)6 RDFNode (org.apache.jena.rdf.model.RDFNode)4 Property (org.apache.jena.rdf.model.Property)3 IOException (java.io.IOException)2 Dataset (org.apache.jena.query.Dataset)2 TextIndexException (org.apache.jena.query.text.TextIndexException)2 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 OutputStream (java.io.OutputStream)1 URL (java.net.URL)1 Files.createTempFile (java.nio.file.Files.createTempFile)1 Path (java.nio.file.Path)1