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);
}
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);
}
}
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);
}
}
}
};
}
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();
}
}
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);
}
}
}
};
}
Aggregations