org.apache.commons.rdf.api.RDF.createGraph()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(10.2k)|赞(0)|评价(0)|浏览(128)

本文整理了Java中org.apache.commons.rdf.api.RDF.createGraph方法的一些代码示例,展示了RDF.createGraph的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。RDF.createGraph方法的具体详情如下:
包路径:org.apache.commons.rdf.api.RDF
类名称:RDF
方法名:createGraph

RDF.createGraph介绍

[英]Create a new graph. It is undefined if the graph will be persisted by any underlying storage mechanism.
[中]创建一个新的图表。未定义图形是否由任何底层存储机制持久化。

代码示例

代码示例来源:origin: eu.optique-project/r2rml-api-core

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;
}

代码示例来源:origin: trellis-ldp/trellis

/**
   * Create a new graph.
   *
   * @return a graph
   */
  public static TrellisGraph createGraph() {
    return new TrellisGraph(getInstance().createGraph());
  }
}

代码示例来源:origin: org.trellisldp/trellis-test

/**
 * 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;
}

代码示例来源:origin: trellis-ldp/trellis

/**
 * 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;
}

代码示例来源:origin: trellis-ldp/trellis

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

代码示例来源:origin: trellis-ldp/trellis

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

代码示例来源:origin: org.trellisldp/trellis-test

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");

代码示例来源:origin: trellis-ldp/trellis

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");

代码示例来源:origin: org.trellisldp/trellis-test

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");

代码示例来源:origin: trellis-ldp/trellis

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");

代码示例来源:origin: trellis-ldp/trellis

final Graph graph = rdf.createGraph();
graph.add(rdf.createTriple(subject, DC.title, literal));
graph.add(rdf.createTriple(subject, DC.subject, bnode));

代码示例来源:origin: org.trellisldp/trellis-test

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");

代码示例来源:origin: org.apache.commons/commons-rdf-api

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

代码示例来源:origin: org.apache.commons/commons-rdf-api

@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));
  }
}

代码示例来源:origin: org.apache.commons/commons-rdf-api

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;
}

代码示例来源:origin: org.apache.commons/commons-rdf-api

/**
 * 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;
}

代码示例来源:origin: org.apache.commons/commons-rdf-api

@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));
  }
}

代码示例来源:origin: org.apache.commons/commons-rdf-api

try (final Graph g = factory.createGraph()) {
  Locale.setDefault(Locale.ROOT);
  final Literal lowerROOT = factory.createLiteral("moi", "fi");

代码示例来源:origin: org.apache.commons/commons-rdf-api

@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));
  }
}

代码示例来源:origin: org.apache.commons/commons-rdf-api

@Before
public void createGraphAndAdd() {
  factory = createFactory();
  graph = factory.createGraph();
  assertEquals(0, graph.size());

相关文章