use of org.openrdf.model.impl.StatementImpl in project incubator-rya by apache.
the class StatementSerializerTest method testObjectLiteralWithAtSignGarbage.
@Test
public void testObjectLiteralWithAtSignGarbage() throws Exception {
// test with some garbage in the literal that may throw off the parser
ValueFactory vf = new ValueFactoryImpl();
Statement s;
String str;
str = "Alice @en";
s = new StatementImpl(vf.createURI("foo:subject"), vf.createURI("foo:predicate"), vf.createLiteral(str));
Assert.assertEquals(s, StatementSerializer.readStatement(StatementSerializer.writeStatement(s)));
s = new StatementImpl(vf.createURI("foo:subject"), vf.createURI("foo:predicate"), vf.createLiteral(str, "en"));
Assert.assertEquals(s, StatementSerializer.readStatement(StatementSerializer.writeStatement(s)));
s = new StatementImpl(vf.createURI("foo:subject"), vf.createURI("foo:predicate"), vf.createLiteral(str, vf.createURI("xsd:string")));
Assert.assertEquals(s, StatementSerializer.readStatement(StatementSerializer.writeStatement(s)));
}
use of org.openrdf.model.impl.StatementImpl in project incubator-rya by apache.
the class StatementSerializerTest method testSimpleObjectLiteral.
@Test
public void testSimpleObjectLiteral() throws Exception {
ValueFactory vf = new ValueFactoryImpl();
Statement s;
String str;
s = new StatementImpl(vf.createURI("foo:subject"), vf.createURI("foo:predicate"), vf.createURI("foo:object"));
Assert.assertEquals(s, StatementSerializer.readStatement(StatementSerializer.writeStatement(s)));
str = "Alice Palace";
s = new StatementImpl(vf.createURI("foo:subject"), vf.createURI("foo:predicate"), vf.createLiteral(str));
Assert.assertEquals(s, StatementSerializer.readStatement(StatementSerializer.writeStatement(s)));
s = new StatementImpl(vf.createURI("foo:subject"), vf.createURI("foo:predicate"), vf.createLiteral(str, "en"));
Assert.assertEquals(s, StatementSerializer.readStatement(StatementSerializer.writeStatement(s)));
s = new StatementImpl(vf.createURI("foo:subject"), vf.createURI("foo:predicate"), vf.createLiteral(str, vf.createURI("xsd:string")));
Assert.assertEquals(s, StatementSerializer.readStatement(StatementSerializer.writeStatement(s)));
}
use of org.openrdf.model.impl.StatementImpl in project incubator-rya by apache.
the class Fact method readFields.
@Override
public void readFields(DataInput in) throws IOException {
derivation = null;
int tripleLength = in.readInt();
if (tripleLength == 0) {
triple = null;
} else {
byte[] tripleBytes = new byte[tripleLength];
in.readFully(tripleBytes);
String tripleString = new String(tripleBytes, StandardCharsets.UTF_8);
String[] parts = tripleString.split(SEP);
ValueFactory factory = ValueFactoryImpl.getInstance();
String context = parts[0];
Resource s = null;
URI p = factory.createURI(parts[2]);
Value o = null;
// Subject: either bnode or URI
if (parts[1].startsWith("_")) {
s = factory.createBNode(parts[1].substring(2));
} else {
s = factory.createURI(parts[1]);
}
// Object: literal, bnode, or URI
if (parts[3].startsWith("_")) {
o = factory.createBNode(parts[3].substring(2));
} else if (parts[3].startsWith("\"")) {
// literal: may have language or datatype
int close = parts[3].lastIndexOf("\"");
int length = parts[3].length();
String label = parts[3].substring(1, close);
if (close == length - 1) {
// Just a string enclosed in quotes
o = factory.createLiteral(label);
} else {
String data = parts[3].substring(close + 1);
if (data.startsWith("@")) {
String lang = data.substring(1);
o = factory.createLiteral(label, lang);
} else if (data.startsWith("^^<")) {
o = factory.createLiteral(label, factory.createURI(data.substring(3, data.length() - 1)));
}
}
} else {
o = factory.createURI(parts[3]);
}
// Create a statement with or without context
if (context.isEmpty()) {
triple = new StatementImpl(s, p, o);
} else {
triple = new ContextStatementImpl(s, p, o, factory.createURI(context));
}
}
useful = in.readBoolean();
if (in.readBoolean()) {
derivation = new Derivation();
derivation.readFields(in);
}
}
use of org.openrdf.model.impl.StatementImpl in project incubator-rya by apache.
the class GeoFilterIT method statement.
private static Statement statement(final Geometry geo) {
final ValueFactory vf = new ValueFactoryImpl();
final Resource subject = vf.createURI("urn:event1");
final URI predicate = GeoConstants.GEO_AS_WKT;
final WKTWriter w = new WKTWriter();
final Value object = vf.createLiteral(w.write(geo), GeoConstants.XMLSCHEMA_OGC_WKT);
return new StatementImpl(subject, predicate, object);
}
use of org.openrdf.model.impl.StatementImpl in project blueprints by tinkerpop.
the class SailGraph method addEdge.
public Edge addEdge(final Object id, final Vertex outVertex, final Vertex inVertex, final String label) {
if (label == null)
throw ExceptionFactory.edgeLabelCanNotBeNull();
Value outVertexValue = ((SailVertex) outVertex).getRawVertex();
Value inVertexValue = ((SailVertex) inVertex).getRawVertex();
if (!(outVertexValue instanceof Resource)) {
throw new IllegalArgumentException(outVertex.toString() + " is not a legal URI or blank node");
}
try {
URI labelURI = new URIImpl(this.expandPrefix(label));
Statement statement = new StatementImpl((Resource) outVertexValue, labelURI, inVertexValue);
SailHelper.addStatement(statement, this.sailConnection.get());
return new SailEdge(statement, this);
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
}
Aggregations