Search in sources :

Example 66 with URIImpl

use of org.openrdf.model.impl.URIImpl in project incubator-rya by apache.

the class FluoStringConverterTest method statementPatternToString.

@Test
public void statementPatternToString() throws MalformedQueryException {
    // Setup a StatementPattern that represents "?x <http://worksAt> <http://Chipotle>."
    final Var subject = new Var("x");
    final Var predicate = new Var("-const-http://worksAt", new URIImpl("http://worksAt"));
    predicate.setConstant(true);
    final Var object = new Var("-const-http://Chipotle", new URIImpl("http://Chipotle"));
    object.setConstant(true);
    final StatementPattern pattern = new StatementPattern(subject, predicate, object);
    // Convert the pattern to a String.
    final String spString = FluoStringConverter.toStatementPatternString(pattern);
    // Ensure it converted to the expected result.
    final String expected = "x:::" + "-const-http://worksAt<<~>>http://www.w3.org/2001/XMLSchema#anyURI:::" + "-const-http://Chipotle<<~>>http://www.w3.org/2001/XMLSchema#anyURI";
    assertEquals(spString, expected);
}
Also used : StatementPattern(org.openrdf.query.algebra.StatementPattern) Var(org.openrdf.query.algebra.Var) URIImpl(org.openrdf.model.impl.URIImpl) Test(org.junit.Test)

Example 67 with URIImpl

use of org.openrdf.model.impl.URIImpl in project incubator-rya by apache.

the class CustomDatatypeResolverTest method testCustomDataTypeSerialization.

public void testCustomDataTypeSerialization() throws Exception {
    RyaType ryaType = new RyaType(new URIImpl("urn:test#datatype"), "testdata");
    byte[] serialize = new CustomDatatypeResolver().serialize(ryaType);
    RyaType deserialize = new CustomDatatypeResolver().deserialize(serialize);
    assertEquals(ryaType, deserialize);
}
Also used : URIImpl(org.openrdf.model.impl.URIImpl) RyaType(org.apache.rya.api.domain.RyaType)

Example 68 with URIImpl

use of org.openrdf.model.impl.URIImpl 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 69 with URIImpl

use of org.openrdf.model.impl.URIImpl in project stanbol by apache.

the class RdfRepresentationTest method testBNodeFiltering.

/**
 * Test for STANBOL-1301
 */
@Test
public void testBNodeFiltering() {
    URI concept = new URIImpl("http://example.org/mySkos#Concept123");
    Representation r = createRepresentation(concept.stringValue());
    assertTrue(r instanceof RdfRepresentation);
    RdfRepresentation rep = (RdfRepresentation) r;
    // add the example as listed in STANBOL-1301 to directly to the
    // Sesame Model backing the created Representation
    Model m = rep.getModel();
    m.add(concept, RDF.TYPE, SKOS.CONCEPT);
    m.add(concept, DCTERMS.IDENTIFIER, new LiteralImpl("123"));
    m.add(concept, SKOS.PREF_LABEL, new LiteralImpl("Concept123", "en"));
    BNode note1 = new BNodeImpl("5d8580be71044a88bcfe9852d1e9cfb6node17c4j452vx19576");
    m.add(concept, SKOS.SCOPE_NOTE, note1);
    m.add(note1, DCTERMS.CREATOR, new LiteralImpl("User1"));
    m.add(note1, DCTERMS.CREATED, new LiteralImpl("2013-03-03T02:02:02Z", XMLSchema.DATETIME));
    m.add(note1, RDFS.COMMENT, new LiteralImpl("The scope of this example global", "en"));
    BNode note2 = new BNodeImpl("5d8580be71044a88bcfe9852d1e9cfb6node17c4j452vx19634");
    m.add(concept, SKOS.SCOPE_NOTE, note2);
    m.add(note2, DCTERMS.CREATOR, new LiteralImpl("User2"));
    m.add(note2, DCTERMS.CREATED, new LiteralImpl("2013-03-03T04:04:04Z", XMLSchema.DATETIME));
    m.add(note2, RDFS.COMMENT, new LiteralImpl("Der Geltungsbereich ist Global", "de"));
    // now assert that BNodes are not reported via the Representation API
    Iterator<Object> scopeNotes = rep.get(SKOS.SCOPE_NOTE.stringValue());
    assertFalse(scopeNotes.hasNext());
    Iterator<Reference> scopeNoteRefs = rep.getReferences(SKOS.SCOPE_NOTE.stringValue());
    assertFalse(scopeNoteRefs.hasNext());
}
Also used : LiteralImpl(org.openrdf.model.impl.LiteralImpl) BNode(org.openrdf.model.BNode) Reference(org.apache.stanbol.entityhub.servicesapi.model.Reference) Model(org.openrdf.model.Model) URIImpl(org.openrdf.model.impl.URIImpl) Representation(org.apache.stanbol.entityhub.servicesapi.model.Representation) URI(org.openrdf.model.URI) BNodeImpl(org.openrdf.model.impl.BNodeImpl) RepresentationTest(org.apache.stanbol.entityhub.test.model.RepresentationTest) Test(org.junit.Test)

Example 70 with URIImpl

use of org.openrdf.model.impl.URIImpl in project blueprints by tinkerpop.

the class GraphSailTest method testIsolatedVerticesAutomaticallyDeleted.

@Test
public void testIsolatedVerticesAutomaticallyDeleted() throws Exception {
    String ex = "http://example.org/ns#";
    URI ref = new URIImpl(ex + "Ref");
    clear();
    int edgesBefore, verticesBefore;
    SailConnection sc = sail.getConnection();
    try {
        sc.begin();
        edgesBefore = countEdges();
        verticesBefore = countVertices();
    } finally {
        sc.commit();
        sc.close();
    }
    addFile(SailTest.class.getResourceAsStream("graph-example-bnodes.trig"), RDFFormat.TRIG);
    sc = sail.getConnection();
    // showStatements(sc, null, null, null);
    try {
        sc.begin();
        assertEquals(14, countStatements(sc, null, null, null, false));
        assertEquals(edgesBefore + 14, countEdges());
        assertEquals(verticesBefore + 10, countVertices());
        sc.removeStatements(ref, null, null);
        sc.commit();
        sc.begin();
        assertEquals(13, countStatements(sc, null, null, null, false));
        assertEquals(edgesBefore + 13, countEdges());
        assertEquals(verticesBefore + 9, countVertices());
        sc.clear();
        sc.commit();
        sc.begin();
        assertEquals(0, countStatements(sc, null, null, null, false));
        assertEquals(0, countEdges());
        // Namespaces vertex is still present.
        assertEquals(verticesBefore, countVertices());
    } finally {
        sc.rollback();
        sc.close();
    }
}
Also used : SailConnection(org.openrdf.sail.SailConnection) URIImpl(org.openrdf.model.impl.URIImpl) URI(org.openrdf.model.URI) Test(org.junit.Test)

Aggregations

URIImpl (org.openrdf.model.impl.URIImpl)170 Test (org.junit.Test)120 LiteralImpl (org.openrdf.model.impl.LiteralImpl)62 URI (org.openrdf.model.URI)58 BindingSet (org.openrdf.query.BindingSet)50 MapBindingSet (org.openrdf.query.impl.MapBindingSet)36 RyaURI (org.apache.rya.api.domain.RyaURI)33 HashSet (java.util.HashSet)31 Statement (org.openrdf.model.Statement)30 QueryBindingSet (org.openrdf.query.algebra.evaluation.QueryBindingSet)30 ArrayList (java.util.ArrayList)29 RyaType (org.apache.rya.api.domain.RyaType)25 VisibilityBindingSet (org.apache.rya.api.model.VisibilityBindingSet)24 RyaStatement (org.apache.rya.api.domain.RyaStatement)23 Value (org.openrdf.model.Value)22 NumericLiteralImpl (org.openrdf.model.impl.NumericLiteralImpl)22 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)21 StatementPattern (org.openrdf.query.algebra.StatementPattern)20 StatementImpl (org.openrdf.model.impl.StatementImpl)19 PcjMetadata (org.apache.rya.indexing.pcj.storage.PcjMetadata)16