Search in sources :

Example 46 with LiteralImpl

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

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

the class SailVertex method setProperty.

public void setProperty(final String key, final Object value) {
    if (this.rawVertex instanceof Resource) {
        throw new RuntimeException(URI_BLANK_NODE_PROPERTIES);
    } else {
        boolean update = false;
        final Literal oldLiteral = (Literal) this.rawVertex;
        if (key.equals(SailTokens.DATATYPE)) {
            this.rawVertex = new LiteralImpl(oldLiteral.getLabel(), new URIImpl(this.graph.expandPrefix(value.toString())));
            update = true;
        } else if (key.equals(SailTokens.LANGUAGE)) {
            this.rawVertex = new LiteralImpl(oldLiteral.getLabel(), value.toString());
            update = true;
        }
        if (update) {
            this.updateLiteral(oldLiteral, (Literal) this.rawVertex);
        }
    }
}
Also used : LiteralImpl(org.openrdf.model.impl.LiteralImpl) Literal(org.openrdf.model.Literal) Resource(org.openrdf.model.Resource) URIImpl(org.openrdf.model.impl.URIImpl)

Example 48 with LiteralImpl

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

the class SailVertex method removeProperty.

public <T> T removeProperty(final String key) {
    if (this.rawVertex instanceof Resource) {
        throw new RuntimeException(URI_BLANK_NODE_PROPERTIES);
    } else {
        final Literal oldLiteral = (Literal) this.rawVertex;
        if (key.equals(SailTokens.DATATYPE) || key.equals(SailTokens.LANGUAGE)) {
            this.rawVertex = new LiteralImpl(oldLiteral.getLabel());
            this.updateLiteral(oldLiteral, (Literal) this.rawVertex);
        }
        if (key.equals(SailTokens.DATATYPE)) {
            return (T) oldLiteral.getDatatype().toString();
        } else if (key.equals(SailTokens.LANGUAGE)) {
            return (T) oldLiteral.getLanguage();
        }
    }
    return null;
}
Also used : LiteralImpl(org.openrdf.model.impl.LiteralImpl) Literal(org.openrdf.model.Literal) Resource(org.openrdf.model.Resource)

Example 49 with LiteralImpl

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

the class SailGraphSpecificTestSuite method testNavigateThroughLiteralVertex.

public void testNavigateThroughLiteralVertex() {
    SailGraph graph = (SailGraph) graphTest.generateGraph();
    SailGraphFactory.createTinkerGraph(graph);
    Vertex v1 = graph.getVertex("tg:1");
    SailVertex vx = new SailVertex(new LiteralImpl("Marko"), graph);
    graph.addEdge(null, v1, vx, "tg:name");
    Vertex v = v1.getEdges(Direction.OUT, "tg:name").iterator().next().getVertex(Direction.IN);
    assertEquals("Marko", v.getProperty(SailTokens.VALUE));
    v1 = v.getEdges(Direction.IN, "tg:name").iterator().next().getVertex(Direction.OUT);
    assertEquals("http://tinkerpop.com#1", v1.getId());
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) LiteralImpl(org.openrdf.model.impl.LiteralImpl)

Example 50 with LiteralImpl

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

the class SailGraphSpecificTestSuite method testTypeConversion.

public void testTypeConversion() {
    assertEquals(SailVertex.castLiteral(new LiteralImpl("marko", new URIImpl("http://www.w3.org/2001/XMLSchema#string"))).getClass(), String.class);
    assertEquals(SailVertex.castLiteral(new LiteralImpl("marko")).getClass(), String.class);
    assertEquals(SailVertex.castLiteral(new LiteralImpl("27", new URIImpl("http://www.w3.org/2001/XMLSchema#int"))).getClass(), Integer.class);
    assertEquals(SailVertex.castLiteral(new LiteralImpl("27", new URIImpl("http://www.w3.org/2001/XMLSchema#float"))).getClass(), Float.class);
    assertEquals(SailVertex.castLiteral(new LiteralImpl("27.0134", new URIImpl("http://www.w3.org/2001/XMLSchema#double"))).getClass(), Double.class);
    assertEquals(SailVertex.castLiteral(new LiteralImpl("hello", "en")), "hello");
}
Also used : LiteralImpl(org.openrdf.model.impl.LiteralImpl) URIImpl(org.openrdf.model.impl.URIImpl)

Aggregations

LiteralImpl (org.openrdf.model.impl.LiteralImpl)155 Test (org.junit.Test)124 URIImpl (org.openrdf.model.impl.URIImpl)62 BindingSet (org.openrdf.query.BindingSet)58 Statement (org.openrdf.model.Statement)40 ArrayList (java.util.ArrayList)34 TupleQueryResult (org.openrdf.query.TupleQueryResult)34 QueryBindingSet (org.openrdf.query.algebra.evaluation.QueryBindingSet)33 URI (org.openrdf.model.URI)29 IntegerLiteralImpl (org.openrdf.model.impl.IntegerLiteralImpl)23 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)22 HashSet (java.util.HashSet)21 RyaStatement (org.apache.rya.api.domain.RyaStatement)19 RyaType (org.apache.rya.api.domain.RyaType)19 RyaURI (org.apache.rya.api.domain.RyaURI)19 ParsedQuery (org.openrdf.query.parser.ParsedQuery)19 SPARQLParser (org.openrdf.query.parser.sparql.SPARQLParser)19 StatementMetadata (org.apache.rya.api.domain.StatementMetadata)17 StatementImpl (org.openrdf.model.impl.StatementImpl)16 NumericLiteralImpl (org.openrdf.model.impl.NumericLiteralImpl)15