private static RDFTerm getObject(final String value, final String lang, final String datatype) { if (nonNull(lang)) { return rdf.createLiteral(value, lang); } else if (nonNull(datatype)) { return rdf.createLiteral(value, rdf.createIRI(datatype)); } return rdf.createIRI(value); } }
@Test(expected = IllegalArgumentException.class) public void testInvalidLiteralLang() throws Exception { factory.createLiteral("Example", "with space"); }
@Override public Set<Triple> serialize() { Set<Triple> stmtSet = new HashSet<Triple>(); stmtSet.add(getRDF().createTriple(node, getRDF().createIRI("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"), getRDF().createIRI(R2RMLVocabulary.TYPE_JOIN))); stmtSet.add(getRDF().createTriple(node, getRDF().createIRI(R2RMLVocabulary.PROP_CHILD), getRDF().createLiteral(child))); stmtSet.add(getRDF().createTriple(node, getRDF().createIRI(R2RMLVocabulary.PROP_PARENT), getRDF().createLiteral(parent))); return stmtSet; }
@Override public Set<Triple> serialize() { Set<Triple> stmtSet = new HashSet<Triple>(); stmtSet.add(getRDF().createTriple(node, getRDF().createIRI("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"), getRDF().createIRI(R2RMLVocabulary.TYPE_BASE_TABLE_OR_VIEW))); stmtSet.add(getRDF().createTriple(node, getRDF().createIRI(R2RMLVocabulary.PROP_TABLE_NAME), getRDF().createLiteral(getTableName()))); return stmtSet; }
@Test public void testResourceWithQuads() { final IRI subject = rdf.createIRI("ex:subject"); when(mockResource.stream()).thenAnswer((x) -> of( rdf.createQuad(prefer, subject, DC.title, rdf.createLiteral("A title")), rdf.createQuad(PreferUserManaged, subject, DC.title, rdf.createLiteral("Other title")))); assertEquals(1L, mockResource.stream(prefer).count(), "Resource stream has wrong number of triples!"); assertEquals(1L, mockResource.stream(singleton(prefer)).count(), "Resource has wrong number of triples!"); }
@Override public Set<Triple> serialize() { Set<Triple> stmtSet = new HashSet<>(); stmtSet.add(getRDF().createTriple(getNode(), getRDF().createIRI("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"), getRDF().createIRI(R2RMLVocabulary.TYPE_R2RML_VIEW))); stmtSet.add(getRDF().createTriple(getNode(), getRDF().createIRI(R2RMLVocabulary.PROP_SQL_QUERY), getRDF().createLiteral(getSQLQuery()))); for (IRI version : versionList) { stmtSet.add(getRDF().createTriple(getNode(), getRDF().createIRI(R2RMLVocabulary.PROP_SQL_VERSION), version)); } return stmtSet; }
@Test public void testBaseIRIliteral() { final Literal l = jenaRdf.createLiteral("a literal"); assertEquals(l, TriplestoreUtils.getBaseIRI(l), "Incorrect literal value!"); } }
@Test public void hashCodeLiteral() throws Exception { final Literal literal = factory.createLiteral("Hello"); assertEquals(Objects.hash(literal.getLexicalForm(), literal.getDatatype(), literal.getLanguageTag()), literal.hashCode()); }
@Test public void testToQuad() { final IRI subject = rdf.createIRI("http://example.com/resource"); final Literal object = rdf.createLiteral("title"); final Triple triple = rdf.createTriple(subject, DC.title, object); final Quad quad = rdf.createQuad(Trellis.PreferUserManaged, subject, DC.title, object); assertEquals(quad, toQuad(Trellis.PreferUserManaged).apply(triple), "Incorrect quad from triple!"); }
private Dataset createDataset2() { final RDF factory2 = createFactory(); final IRI name = factory2.createIRI("http://xmlns.com/foaf/0.1/name"); final Dataset g2 = factory2.createDataset(); final BlankNode b1 = createOwnBlankNode("b1", "bc8d3e45-a08f-421d-85b3-c25b373abf87"); g2.add(b1, b1, name, factory2.createLiteral("Charlie")); final BlankNode b2 = createOwnBlankNode("b2", "2209097a-5078-4b03-801a-6a2d2f50d739"); g2.add(b2, b2, name, factory2.createLiteral("Dave")); final IRI hasChild = factory2.createIRI("http://example.com/hasChild"); // NOTE: Opposite direction of loadDataset1 g2.add(b2, b2, hasChild, b1); return g2; }
private Graph createGraph2() { final RDF factory2 = createFactory(); final IRI name = factory2.createIRI("http://xmlns.com/foaf/0.1/name"); final Graph g2 = factory2.createGraph(); final BlankNode b1 = createOwnBlankNode("b1", "bc8d3e45-a08f-421d-85b3-c25b373abf87"); g2.add(b1, name, factory2.createLiteral("Charlie")); final BlankNode b2 = createOwnBlankNode("b2", "2209097a-5078-4b03-801a-6a2d2f50d739"); g2.add(b2, name, factory2.createLiteral("Dave")); final IRI hasChild = factory2.createIRI("http://example.com/hasChild"); // NOTE: Opposite direction of loadGraph1 g2.add(b2, hasChild, b1); return g2; }
@Test public void testCreateLiteralLangISO693_3() throws Exception { // see https://issues.apache.org/jira/browse/JENA-827 final Literal vls = factory.createLiteral("Herbert Van de Sompel", "vls"); // JENA-827 assertEquals("vls", vls.getLanguageTag().get()); assertEquals("http://www.w3.org/1999/02/22-rdf-syntax-ns#langString", vls.getDatatype().getIRIString()); assertEquals("\"Herbert Van de Sompel\"@vls", vls.ntriplesString()); }
@Test public void testCreateLiteral() throws Exception { final Literal example = factory.createLiteral("Example"); assertEquals("Example", example.getLexicalForm()); assertFalse(example.getLanguageTag().isPresent()); assertEquals("http://www.w3.org/2001/XMLSchema#string", example.getDatatype().getIRIString()); // http://lists.w3.org/Archives/Public/public-rdf-comments/2014Dec/0004.html assertEquals("\"Example\"", example.ntriplesString()); }
@Test public void testCreateLiteralLang() throws Exception { final Literal example = factory.createLiteral("Example", "en"); assertEquals("Example", example.getLexicalForm()); assertEquals("en", example.getLanguageTag().get()); assertEquals("http://www.w3.org/1999/02/22-rdf-syntax-ns#langString", example.getDatatype().getIRIString()); assertEquals("\"Example\"@en", example.ntriplesString()); }
@Test public void testCreateLiteralDateTime() throws Exception { final Literal dateTime = factory.createLiteral("2014-12-27T00:50:00T-0600", factory.createIRI("http://www.w3.org/2001/XMLSchema#dateTime")); assertEquals("2014-12-27T00:50:00T-0600", dateTime.getLexicalForm()); assertFalse(dateTime.getLanguageTag().isPresent()); assertEquals("http://www.w3.org/2001/XMLSchema#dateTime", dateTime.getDatatype().getIRIString()); assertEquals("\"2014-12-27T00:50:00T-0600\"^^<http://www.w3.org/2001/XMLSchema#dateTime>", dateTime.ntriplesString()); }
@Test public void testCreateLiteralString() throws Exception { final Literal example = factory.createLiteral("Example", factory.createIRI("http://www.w3.org/2001/XMLSchema#string")); assertEquals("Example", example.getLexicalForm()); assertFalse(example.getLanguageTag().isPresent()); assertEquals("http://www.w3.org/2001/XMLSchema#string", example.getDatatype().getIRIString()); // http://lists.w3.org/Archives/Public/public-rdf-comments/2014Dec/0004.html assertEquals("\"Example\"", example.ntriplesString()); }
@Test public void testCreateTripleBnodeTriple() { final BlankNode subject = factory.createBlankNode(); final IRI predicate = factory.createIRI("http://example.com/pred"); final Literal object = factory.createLiteral("Example", "en"); final Triple triple = factory.createTriple(subject, predicate, object); // bnode equivalence should be OK as we used the same // factory and have not yet inserted Triple into a Graph assertEquals(subject, triple.getSubject()); assertEquals(predicate, triple.getPredicate()); assertEquals(object, triple.getObject()); }
@Test public void testOrdinaryLabelledTriple() { final Triple triple = rdf.createTriple( rdf.createIRI("test:value"), DC.title, rdf.createLiteral("A title")); final LabelledTriple t = new LabelledTriple(triple, "title", null); assertEquals("title", t.getPredicateLabel(), "Predicate label doesn't match!"); assertEquals(DC.title.getIRIString(), t.getPredicate(), "Predicate value doesn't match!"); assertEquals("A title", t.getObjectLabel(), "Object label doesn't match!"); assertEquals("A title", t.getObject(), "Object value doesn't match!"); }
@Test public void testOrdinaryLabelledTriple2() { final Triple triple = rdf.createTriple( rdf.createIRI("test:value"), DC.title, rdf.createLiteral("A title")); final LabelledTriple t = new LabelledTriple(triple, null, null); assertEquals(DC.title.getIRIString(), t.getPredicateLabel(), "Predicate label doesn't match!"); assertEquals(DC.title.getIRIString(), t.getPredicate(), "Predicate value doesn't match!"); assertEquals("A title", t.getObjectLabel(), "Object label doesn't match!"); assertEquals("A title", t.getObject(), "Object value doesn't match!"); }
@Test public void testOrdinaryLabelledTriple3() { final Triple triple = rdf.createTriple( rdf.createIRI("test:value"), DC.title, rdf.createLiteral("A title")); final LabelledTriple t = new LabelledTriple(triple, null, null); assertEquals("test:value", t.getSubject(), "Subject value doesn't match!"); assertEquals(DC.title.getIRIString(), t.getPredicateLabel(), "Predicate label doesn't match!"); assertEquals(DC.title.getIRIString(), t.getPredicate(), "Predicate value doesn't match!"); assertEquals("A title", t.getObjectLabel(), "Object label doesn't match!"); assertEquals("A title", t.getObject(), "Object value doesn't match!"); }