Search in sources :

Example 6 with Statement

use of org.openrdf.model.Statement in project blueprints by tinkerpop.

the class PropertyGraphSailTest method assertExpected.

private void assertExpected(final Collection<Statement> graph, final Statement... expectedStatements) throws Exception {
    Set<Statement> expected = new TreeSet<Statement>(new StatementComparator());
    for (Statement st : expectedStatements) {
        expected.add(st);
    }
    Set<Statement> actual = new TreeSet<Statement>(new StatementComparator());
    for (Statement st : graph) {
        actual.add(st);
    }
    for (Statement t : expected) {
        if (!actual.contains(t)) {
            fail("expected statement not found: " + t);
        }
    }
    for (Statement t : actual) {
        if (!expected.contains(t)) {
            fail("unexpected statement found: " + t);
        }
    }
}
Also used : TreeSet(java.util.TreeSet) Statement(org.openrdf.model.Statement) StatementComparator(net.fortytwo.sesametools.StatementComparator)

Example 7 with Statement

use of org.openrdf.model.Statement in project blueprints by tinkerpop.

the class PropertyGraphSailTest method testSimpleEdges.

@Test
public void testSimpleEdges() throws Exception {
    sail.setFirstClassEdges(false);
    sc.close();
    sc = sail.getConnection();
    for (Statement st : get(null, null, null)) {
        System.out.println("st: " + st);
    }
    assertEquals(30, sc.size());
    assertEquals(30, count(null, null, null));
    assertEquals(6, count(null, RDF.TYPE, vertex));
    assertEquals(0, count(null, RDF.TYPE, edge));
    assertEquals(0, count(null, label, null));
    assertEquals(0, count(null, head, null));
    assertEquals(0, count(null, tail, null));
    // ... absence of other patterns could be tested, as well
    // s ? ?
    assertExpected(get(marko, null, null), vf.createStatement(marko, id, vf.createLiteral("1")), vf.createStatement(marko, RDF.TYPE, vertex), vf.createStatement(marko, age, vf.createLiteral(29)), vf.createStatement(marko, name, vf.createLiteral("marko")), vf.createStatement(marko, knows, vadas), vf.createStatement(marko, created, lop), vf.createStatement(marko, knows, josh));
    // s p ?
    assertExpected(get(marko, knows, null), vf.createStatement(marko, knows, vadas), vf.createStatement(marko, knows, josh));
    // s ? o
    assertExpected(get(marko, null, josh), vf.createStatement(marko, knows, josh));
    // s p o
    assertExpected(get(marko, knows, josh), vf.createStatement(marko, knows, josh));
    assertExpected(get(marko, name, vf.createLiteral("marko")), vf.createStatement(marko, name, vf.createLiteral("marko")));
    // ? ? o
    assertExpected(get(null, null, josh), vf.createStatement(marko, knows, josh));
    // ? p o
    assertExpected(get(null, knows, josh), vf.createStatement(marko, knows, josh));
    // ? p ?
    assertExpected(get(null, knows, null), vf.createStatement(marko, knows, vadas), vf.createStatement(marko, knows, josh));
}
Also used : Statement(org.openrdf.model.Statement) Test(org.junit.Test)

Example 8 with Statement

use of org.openrdf.model.Statement in project blueprints by tinkerpop.

the class SailHelper method addStatement.

protected static void addStatement(final Resource subject, final URI predicate, final Value object, final Resource context, final SailConnection sailConnection) {
    Statement statement;
    if (null != context) {
        statement = new ContextStatementImpl(subject, predicate, object, context);
    } else {
        statement = new StatementImpl(subject, predicate, object);
    }
    SailHelper.addStatement(statement, sailConnection);
}
Also used : ContextStatementImpl(org.openrdf.model.impl.ContextStatementImpl) Statement(org.openrdf.model.Statement) StatementImpl(org.openrdf.model.impl.StatementImpl) ContextStatementImpl(org.openrdf.model.impl.ContextStatementImpl)

Example 9 with Statement

use of org.openrdf.model.Statement in project qi4j-sdk by Qi4j.

the class SolrEntityIndexerMixin method indexEntityState.

private SolrInputDocument indexEntityState(final EntityState entityState, final SolrServer server) throws IOException, SolrServerException, JSONException {
    Graph graph = new GraphImpl();
    stateSerializer.serialize(entityState, false, graph);
    SolrInputDocument input = new SolrInputDocument();
    input.addField("id", entityState.identity().identity());
    input.addField("type", first(entityState.entityDescriptor().types()).getName());
    input.addField("lastModified", new Date(entityState.lastModified()));
    for (Statement statement : graph) {
        SchemaField field = indexedFields.get(statement.getPredicate().getLocalName());
        if (field != null) {
            if (statement.getObject() instanceof Literal) {
                String value = statement.getObject().stringValue();
                if (field.getType().getTypeName().equals("json")) {
                    if (value.charAt(0) == '[') {
                        JSONArray array = new JSONArray(value);
                        indexJson(input, array);
                    } else if (value.charAt(0) == '{') {
                        JSONObject object = new JSONObject(value);
                        indexJson(input, object);
                    }
                } else {
                    input.addField(field.getName(), value);
                }
            } else if (statement.getObject() instanceof URI && !"type".equals(field.getName())) {
                String value = statement.getObject().stringValue();
                value = value.substring(value.lastIndexOf(':') + 1, value.length());
                String name = field.getName();
                input.addField(name, value);
            } else if (statement.getObject() instanceof BNode) {
                Iterator<Statement> seq = graph.match((Resource) statement.getObject(), new URIImpl("http://www.w3.org/1999/02/22-rdf-syntax-ns#li"), null, (Resource) null);
                while (seq.hasNext()) {
                    Statement seqStatement = seq.next();
                    String value = seqStatement.getObject().stringValue();
                    value = value.substring(value.lastIndexOf(':') + 1, value.length());
                    input.addField(field.getName(), value);
                }
            }
        }
    }
    return input;
}
Also used : BNode(org.openrdf.model.BNode) Statement(org.openrdf.model.Statement) JSONArray(org.json.JSONArray) URIImpl(org.openrdf.model.impl.URIImpl) URI(org.openrdf.model.URI) Date(java.util.Date) SchemaField(org.apache.solr.schema.SchemaField) SolrInputDocument(org.apache.solr.common.SolrInputDocument) Graph(org.openrdf.model.Graph) JSONObject(org.json.JSONObject) GraphImpl(org.openrdf.model.impl.GraphImpl) Literal(org.openrdf.model.Literal)

Example 10 with Statement

use of org.openrdf.model.Statement in project qi4j-sdk by Qi4j.

the class ApplicationXmlTest method testApplicationXml.

@Test
public void testApplicationXml() throws Exception {
    FileConfiguration fileConfig = (FileConfiguration) module.findService(FileConfiguration.class).get();
    ApplicationSerializer parser = new ApplicationSerializer();
    // TODO Fix this
    Iterable<Statement> graph = parser.serialize(application);
    writeN3(graph);
    writeXml(graph);
}
Also used : FileConfiguration(org.qi4j.library.fileconfig.FileConfiguration) Statement(org.openrdf.model.Statement) ApplicationSerializer(org.qi4j.library.rdf.model.ApplicationSerializer) AbstractQi4jTest(org.qi4j.test.AbstractQi4jTest) Test(org.junit.Test)

Aggregations

Statement (org.openrdf.model.Statement)67 Resource (org.openrdf.model.Resource)22 Value (org.openrdf.model.Value)22 URI (org.openrdf.model.URI)21 HashSet (java.util.HashSet)16 SailException (org.openrdf.sail.SailException)10 Collection (java.util.Collection)9 Literal (org.openrdf.model.Literal)9 Graph (org.openrdf.model.Graph)7 Edge (com.tinkerpop.blueprints.Edge)6 Test (org.junit.Test)6 Vertex (com.tinkerpop.blueprints.Vertex)5 HashMap (java.util.HashMap)5 Map (java.util.Map)4 PrintWriter (java.io.PrintWriter)3 Set (java.util.Set)3 BNode (org.openrdf.model.BNode)3 ValueFactory (org.openrdf.model.ValueFactory)3 RDFHandlerException (org.openrdf.rio.RDFHandlerException)3 RdfXmlSerializer (org.qi4j.library.rdf.serializer.RdfXmlSerializer)3