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