public Graph exportMappings(Collection<TriplesMap> maps) { requireNonNull(maps, "The mapping collection is null."); if (maps.isEmpty()) throw new IllegalArgumentException("The mapping collection is empty"); Graph m = rdf.createGraph(); for (TriplesMap tm : maps) { tm.serialize().forEach(m::add); } return m; }
/** * Create a new graph. * * @return a graph */ public static TrellisGraph createGraph() { return new TrellisGraph(getInstance().createGraph()); } }
/** * Read an entity as an RDF Graph. * @param entity the HTTP entity * @param baseURL the base URL * @param syntax the RDF syntax * @return the graph */ public static Graph readEntityAsGraph(final Object entity, final String baseURL, final RDFSyntax syntax) { final Graph g = getInstance().createGraph(); getIOService().read((InputStream) entity, syntax, baseURL).forEach(g::add); return g; }
/** * Read an entity as an RDF Graph. * @param entity the HTTP entity * @param baseURL the base URL * @param syntax the RDF syntax * @return the graph */ public static Graph readEntityAsGraph(final Object entity, final String baseURL, final RDFSyntax syntax) { final Graph g = getInstance().createGraph(); getIOService().read((InputStream) entity, syntax, baseURL).forEach(g::add); return g; }
private Graph convertToGraph(final Message msg) { try { final String body = ((TextMessage) msg).getText(); return readEntityAsGraph(new ByteArrayInputStream(body.getBytes(UTF_8)), "http://localhost:" + APP.getLocalPort() + "/", JSONLD); } catch (final Exception ex) { LOGGER.error("Error processing message: {}", ex.getMessage()); } return rdf.createGraph(); } }
@Test public void testConstrainedBy() { final ConstraintService svc = mock(ConstraintService.class); doCallRealMethod().when(svc).constrainedBy(eq(LDP.RDFSource), any(Graph.class)); when(svc.constrainedBy(any(IRI.class), any(Graph.class), eq(TrellisUtils.TRELLIS_DATA_PREFIX))) .thenAnswer(inv -> Stream.empty()); assertEquals(0L, svc.constrainedBy(LDP.RDFSource, rdf.createGraph()).count(), "Unexpected constraint found"); } }
assertAll("Check the LDP-BC resource", checkResource(res, identifier, LDP.BasicContainer, time, dataset0)); assertEquals(2L, res.stream(LDP.PreferContainment).count(), "Check the containment triple count"); final Graph graph = rdf.createGraph(); res.stream(LDP.PreferContainment).forEach(graph::add); assertTrue(graph.contains(identifier, LDP.contains, child1), "Check that child1 is contained in the LDP-BC");
assertAll("Check the LDP-C resource", checkResource(res, identifier, LDP.Container, time, dataset0)); assertEquals(2L, res.stream(LDP.PreferContainment).count(), "Check the containment triple count"); final Graph graph = rdf.createGraph(); res.stream(LDP.PreferContainment).forEach(graph::add); assertTrue(graph.contains(identifier, LDP.contains, child1), "Check that child1 is contained in the LDP-C");
assertAll("Check the LDP-C resource", checkResource(res, identifier, LDP.Container, time, dataset0)); assertEquals(2L, res.stream(LDP.PreferContainment).count(), "Check the containment triple count"); final Graph graph = rdf.createGraph(); res.stream(LDP.PreferContainment).forEach(graph::add); assertTrue(graph.contains(identifier, LDP.contains, child1), "Check that child1 is contained in the LDP-C");
assertAll("Check the LDP-BC resource", checkResource(res, identifier, LDP.BasicContainer, time, dataset0)); assertEquals(2L, res.stream(LDP.PreferContainment).count(), "Check the containment triple count"); final Graph graph = rdf.createGraph(); res.stream(LDP.PreferContainment).forEach(graph::add); assertTrue(graph.contains(identifier, LDP.contains, child1), "Check that child1 is contained in the LDP-BC");
final Graph graph = rdf.createGraph(); graph.add(rdf.createTriple(subject, DC.title, literal)); graph.add(rdf.createTriple(subject, DC.subject, bnode));
assertFalse(res.getMemberOfRelation().isPresent(), "Check for no ldp:isMemberOfRelation"); assertEquals(2L, res.stream(LDP.PreferContainment).count(), "Check the containment triple count"); final Graph graph = rdf.createGraph(); res.stream(LDP.PreferContainment).forEach(graph::add); assertTrue(graph.contains(identifier, LDP.contains, child1), "Check that child1 is contained in the LDP-IC");
@Test public void testCreateGraph() throws Exception { try (final Graph graph = factory.createGraph(); final Graph graph2 = factory.createGraph()) { assertEquals("Graph was not empty", 0, graph.size()); graph.add(factory.createBlankNode(), factory.createIRI("http://example.com/"), factory.createBlankNode()); assertNotSame(graph, graph2); assertEquals("Graph was empty after adding", 1, graph.size()); assertEquals("New graph was not empty", 0, graph2.size()); } }
@Test public void streamLanguageTagsCaseInsensitive() throws Exception { // COMMONSRDF-51: Ensure we can add/contains/remove with any casing // of literal language tag final Literal lower = factory.createLiteral("Hello", "en-gb"); final Literal upper = factory.createLiteral("Hello", "EN-GB"); final Literal mixed = factory.createLiteral("Hello", "en-GB"); final IRI example1 = factory.createIRI("http://example.com/s1"); final IRI greeting = factory.createIRI("http://example.com/greeting"); try (final Graph graph = factory.createGraph()) { graph.add(example1, greeting, upper); // or as patterns assertTrue(closableFindAny(graph.stream(null, null, upper)).isPresent()); assertTrue(closableFindAny(graph.stream(null, null, lower)).isPresent()); assertTrue(closableFindAny(graph.stream(null, null, mixed)).isPresent()); // Check the triples returned equal a new triple final Triple t = closableFindAny(graph.stream(null, null, lower)).get(); assertEquals(t, factory.createTriple(example1, greeting, mixed)); } }
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; }
/** * Make a new graph with two BlankNodes - each with a different * uniqueReference */ private Graph createGraph1() { final RDF factory1 = createFactory(); final IRI name = factory1.createIRI("http://xmlns.com/foaf/0.1/name"); final Graph g1 = factory1.createGraph(); final BlankNode b1 = createOwnBlankNode("b1", "0240eaaa-d33e-4fc0-a4f1-169d6ced3680"); g1.add(b1, name, factory1.createLiteral("Alice")); final BlankNode b2 = createOwnBlankNode("b2", "9de7db45-0ce7-4b0f-a1ce-c9680ffcfd9f"); g1.add(b2, name, factory1.createLiteral("Bob")); final IRI hasChild = factory1.createIRI("http://example.com/hasChild"); g1.add(b1, hasChild, b2); return g1; }
@Test public void removeLanguageTagsCaseInsensitive() throws Exception { // COMMONSRDF-51: Ensure we can remove with any casing // of literal language tag final Literal lower = factory.createLiteral("Hello", "en-gb"); final Literal upper = factory.createLiteral("Hello", "EN-GB"); final Literal mixed = factory.createLiteral("Hello", "en-GB"); final IRI example1 = factory.createIRI("http://example.com/s1"); final IRI greeting = factory.createIRI("http://example.com/greeting"); try (final Graph graph = factory.createGraph()) { graph.add(example1, greeting, upper); // Remove should also honour any case graph.remove(example1, null, mixed); assertFalse(graph.contains(null, greeting, null)); graph.add(example1, greeting, lower); graph.remove(example1, null, upper); // Check with Triple graph.add(factory.createTriple(example1, greeting, mixed)); graph.remove(factory.createTriple(example1, greeting, upper)); assertFalse(graph.contains(null, greeting, null)); } }
try (final Graph g = factory.createGraph()) { Locale.setDefault(Locale.ROOT); final Literal lowerROOT = factory.createLiteral("moi", "fi");
@Test public void containsLanguageTagsCaseInsensitive() throws Exception { // COMMONSRDF-51: Ensure we can add/contains/remove with any casing // of literal language tag final Literal lower = factory.createLiteral("Hello", "en-gb"); final Literal upper = factory.createLiteral("Hello", "EN-GB"); final Literal mixed = factory.createLiteral("Hello", "en-GB"); final IRI example1 = factory.createIRI("http://example.com/s1"); final IRI greeting = factory.createIRI("http://example.com/greeting"); try (final Graph graph = factory.createGraph()) { graph.add(example1, greeting, upper); // any kind of Triple should match assertTrue(graph.contains(factory.createTriple(example1, greeting, upper))); assertTrue(graph.contains(factory.createTriple(example1, greeting, lower))); assertTrue(graph.contains(factory.createTriple(example1, greeting, mixed))); // or as patterns assertTrue(graph.contains(null, null, upper)); assertTrue(graph.contains(null, null, lower)); assertTrue(graph.contains(null, null, mixed)); } }
@Before public void createGraphAndAdd() { factory = createFactory(); graph = factory.createGraph(); assertEquals(0, graph.size());