Search in sources :

Example 11 with Literal

use of org.openrdf.model.Literal in project stanbol by apache.

the class SesameModelWriter method addEntityTriplesToGraph.

/**
     * Adds the Triples that represent the Sign to the parsed graph. Note that
     * this method does not add triples for the representation. However it adds
     * the triple (sign,singRepresentation,representation)
     *
     * @param graph the graph to add the triples
     * @param sign the sign
     */
private void addEntityTriplesToGraph(Model graph, Entity sign) {
    URI id = sesameFactory.createURI(sign.getId());
    URI metaId = sesameFactory.createURI(sign.getMetadata().getId());
    //add the FOAF triples between metadata and content
    graph.add(id, FOAF_PRIMARY_TOPIC_OF, metaId);
    graph.add(metaId, FOAF_PRIMARY_TOPIC, metaId);
    graph.add(metaId, RDF_TYPE, FOAF_DOCUMENT);
    //add the site to the metadata
    //TODO: this should be the HTTP URI and not the id of the referenced site
    Literal siteName = sesameFactory.createLiteral(sign.getSite());
    graph.add(metaId, EH_SIGN_SITE, siteName);
}
Also used : Literal(org.openrdf.model.Literal) URI(org.openrdf.model.URI)

Example 12 with Literal

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

the class EntityStateSerializer method serializeProperty.

private void serializeProperty(PropertyDescriptor persistentProperty, Object property, Resource subject, Graph graph, boolean includeNonQueryable) {
    if (!(includeNonQueryable || persistentProperty.queryable())) {
        // Skip non-queryable
        return;
    }
    ValueType valueType = persistentProperty.valueType();
    final ValueFactory valueFactory = graph.getValueFactory();
    String propertyURI = persistentProperty.qualifiedName().toURI();
    URI predicate = valueFactory.createURI(propertyURI);
    String baseURI = propertyURI.substring(0, propertyURI.indexOf('#')) + "/";
    if (valueType instanceof ValueCompositeType) {
        serializeValueComposite(subject, predicate, (ValueComposite) property, valueType, graph, baseURI, includeNonQueryable);
    } else {
        String stringProperty = valueSerializer.serialize(new Options().withoutTypeInfo(), property);
        final Literal object = valueFactory.createLiteral(stringProperty);
        graph.add(subject, predicate, object);
    }
}
Also used : Options(org.qi4j.api.value.ValueSerializer.Options) ValueType(org.qi4j.api.type.ValueType) Literal(org.openrdf.model.Literal) ValueFactory(org.openrdf.model.ValueFactory) URI(org.openrdf.model.URI) ValueCompositeType(org.qi4j.api.type.ValueCompositeType)

Example 13 with Literal

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

the class PropertyGraphSailConnection method vertexPropertiesWithKey.

private StatementGenerator<Vertex> vertexPropertiesWithKey(final String key, final URI pred) {
    return new StatementGenerator<Vertex>() {

        public void generate(Vertex source, Collection<Statement> results) {
            Object o = source.getProperty(key);
            if (null != o) {
                Literal object = toLiteral(o);
                if (null != object) {
                    Statement s = context.valueFactory.createStatement(uriForVertex(source), pred, object);
                    results.add(s);
                }
            }
        }
    };
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) Statement(org.openrdf.model.Statement) Literal(org.openrdf.model.Literal) Collection(java.util.Collection)

Example 14 with Literal

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

the class PropertyGraphSailConnection method getStatements_SxO.

private CloseableIteration<Statement, SailException> getStatements_SxO(final Resource subject, final Value object) throws SailException {
    if (subject instanceof URI) {
        Collection<Source> sources = new LinkedList<Source>();
        Vertex v = vertexForURI((URI) subject);
        Edge e = edgeForURI((URI) subject);
        Object val = literalToObject(object);
        Vertex vObj = object instanceof URI ? vertexForURI((URI) object) : null;
        // vertex id
        if (null != val && null != v) {
            if (v.getId().equals(val)) {
                Source<Vertex> s = new Source<Vertex>(new SingleItemIterator<Vertex>(v), vertexIds);
                sources.add(s);
            }
        }
        // vertex type
        if (null != v && object instanceof URI && ((URI) object).equals(PropertyGraphSail.VERTEX)) {
            Source<Vertex> s = new Source<Vertex>(new SingleItemIterator<Vertex>(v), vertexTypes);
            sources.add(s);
        }
        // vertex properties
        if (null != val && null != v) {
            Source<Vertex> vertices = new Source<Vertex>(new SingleItemIterator<Vertex>(v), vertexPropertiesWithValue(val, (Literal) object));
            sources.add(vertices);
        }
        if (firstClassEdges) {
            // edge id
            if (null != val && null != e) {
                if (e.getId().equals(val)) {
                    Source<Edge> s = new Source<Edge>(new SingleItemIterator<Edge>(e), edgeIds);
                    sources.add(s);
                }
            }
            // label
            if (null != val && (val instanceof String)) {
                if (null != e && e.getLabel().equals(val)) {
                    Source<Edge> s = new Source<Edge>(new SingleItemIterator<Edge>(e), labels);
                    sources.add(s);
                }
            }
            // head
            if (null != e && null != vObj && e.getVertex(Direction.IN).equals(vObj)) {
                Source<Edge> s = new Source<Edge>(new SingleItemIterator<Edge>(e), heads);
                sources.add(s);
            }
            // tail
            if (null != e && null != vObj && e.getVertex(Direction.OUT).equals(vObj)) {
                Source<Edge> s = new Source<Edge>(new SingleItemIterator<Edge>(e), tails);
                sources.add(s);
            }
            // edge type
            if (null != e && object instanceof URI && ((URI) object).equals(PropertyGraphSail.VERTEX)) {
                Source<Edge> s = new Source<Edge>(new SingleItemIterator<Edge>(e), edgeTypes);
                sources.add(s);
            }
            // edge properties
            if (null != val && null != e) {
                Source<Edge> edges = new Source<Edge>(new SingleItemIterator<Edge>(e), edgePropertiesWithValue(val, (Literal) object));
                sources.add(edges);
            }
        } else {
            if (null != v && null != vObj) {
                Collection<Edge> edges = new LinkedList<Edge>();
                for (Edge ev : v.getEdges(Direction.OUT)) {
                    if (ev.getVertex(Direction.IN).equals(vObj)) {
                        edges.add(ev);
                    }
                }
                if (edges.size() > 0) {
                    sources.add(new Source<Edge>(edges.iterator(), allEdgeStatements));
                }
            }
        }
        if (sources.size() > 0) {
            Source[] s = new Source[sources.size()];
            sources.toArray(s);
            return new StatementIteration(s);
        } else {
            return new StatementIteration();
        }
    } else {
        return new StatementIteration();
    }
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) URI(org.openrdf.model.URI) LinkedList(java.util.LinkedList) SailConnectionTripleSource(net.fortytwo.sesametools.SailConnectionTripleSource) TripleSource(org.openrdf.query.algebra.evaluation.TripleSource) Literal(org.openrdf.model.Literal) Edge(com.tinkerpop.blueprints.Edge)

Example 15 with Literal

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

the class PropertyGraphSailConnection method edgePropertiesWithKey.

private StatementGenerator<Edge> edgePropertiesWithKey(final String key, final URI pred) {
    return new StatementGenerator<Edge>() {

        public void generate(Edge source, Collection<Statement> results) {
            Object o = source.getProperty(key);
            if (null != o) {
                Literal object = toLiteral(o);
                if (null != object) {
                    Statement s = context.valueFactory.createStatement(uriForEdge(source), pred, object);
                    results.add(s);
                }
            }
        }
    };
}
Also used : Statement(org.openrdf.model.Statement) Literal(org.openrdf.model.Literal) Collection(java.util.Collection) Edge(com.tinkerpop.blueprints.Edge)

Aggregations

Literal (org.openrdf.model.Literal)23 URI (org.openrdf.model.URI)12 Test (org.junit.Test)10 Statement (org.openrdf.model.Statement)5 NotifyingSailConnection (org.openrdf.sail.NotifyingSailConnection)5 SailConnection (org.openrdf.sail.SailConnection)5 Representation (org.apache.stanbol.entityhub.servicesapi.model.Representation)3 RepresentationTest (org.apache.stanbol.entityhub.test.model.RepresentationTest)3 ValueFactory (org.openrdf.model.ValueFactory)3 BindingSet (org.openrdf.query.BindingSet)3 Edge (com.tinkerpop.blueprints.Edge)2 Vertex (com.tinkerpop.blueprints.Vertex)2 Collection (java.util.Collection)2 Date (java.util.Date)2 HashSet (java.util.HashSet)2 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)2 Text (org.apache.stanbol.entityhub.servicesapi.model.Text)2 Resource (org.openrdf.model.Resource)2 Value (org.openrdf.model.Value)2 LiteralImpl (org.openrdf.model.impl.LiteralImpl)2