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