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

x33g5p2x  于2022-01-20 转载在 其他  
字(11.4k)|赞(0)|评价(0)|浏览(119)

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

Graph.add介绍

[英]Add a triple to the graph.
[中]在图表中添加一个三元组。

代码示例

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

/**
 * Add a triple to the graph.
 *
 * @param triple an RDF Triple
 */
public void add(final Triple triple) {
  graph.add(triple);
}

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

return target(q -> {
  if (!q.getGraphName().isPresent()) {
    graph.add(q.asTriple());

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

@Test
public void add() throws Exception {
  graph.add(new DummyTriple());
}

代码示例来源: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: trellis-ldp/trellis

@BeforeEach
public void setUp() {
  final IRI other = rdf.createIRI("trellis:data/other");
  graph.clear();
  graph.add(rdf.createTriple(subject, ACL.agent, rdf.createIRI("info:agent/foo")));
  graph.add(rdf.createTriple(subject, ACL.agent, rdf.createIRI("info:agent/bar")));
  graph.add(rdf.createTriple(other, ACL.agent, rdf.createIRI("info:agent/baz")));
  graph.add(rdf.createTriple(subject, ACL.agentClass, rdf.createIRI("info:agent/SomeClass")));
  graph.add(rdf.createTriple(other, ACL.agentClass, rdf.createIRI("info:agent/SomeOtherClass")));
  graph.add(rdf.createTriple(subject, ACL.agentGroup, rdf.createIRI("info:group/group1")));
  graph.add(rdf.createTriple(subject, ACL.agentGroup, rdf.createIRI("info:group/group2")));
  graph.add(rdf.createTriple(subject, ACL.agentGroup, rdf.createIRI("info:group/group3")));
  graph.add(rdf.createTriple(subject, ACL.agentGroup, rdf.createIRI("info:group/group4")));
  graph.add(rdf.createTriple(subject, ACL.mode, ACL.Read));
  graph.add(rdf.createTriple(subject, ACL.accessTo, rdf.createIRI("trellis:data/resource2")));
  graph.add(rdf.createTriple(subject, ACL.accessTo, rdf.createIRI("trellis:data/resource3")));
  graph.add(rdf.createTriple(subject, ACL.accessTo, rdf.createIRI("trellis:data/resource4")));
  graph.add(rdf.createTriple(subject, ACL.accessTo, rdf.createIRI("trellis:data/resource4")));
  graph.add(rdf.createTriple(other, ACL.accessTo, rdf.createIRI("trellis:data/resource5")));
  graph.add(rdf.createTriple(subject, ACL.accessToClass, PROV.Activity));
  graph.add(rdf.createTriple(other, ACL.accessToClass, PROV.Entity));
  graph.add(rdf.createTriple(subject, ACL.default_, rdf.createIRI("trellis:data/container")));
}

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

/**
 * Add all triples from the source to the target.
 * <p>
 * The triples may be copied in any order. No special conversion or
 * adaptation of {@link BlankNode}s are performed.
 *
 * @param source
 *            Source Graph to copy triples from
 * @param target
 *            Target Graph where triples will be added
 */
private void addAllTriples(final Graph source, final Graph target) {
  // unordered() as we don't need to preserve triple order
  // sequential() as we don't (currently) require target Graph to be
  // thread-safe
  try (Stream<? extends Triple> stream = source.stream()) {
    stream.unordered().sequential().forEach(t -> target.add(t));
  }
}

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

@Test
public void addSPO() throws Exception {
  graph.add(new DummyIRI(1), new DummyIRI(2), new DummyIRI(3));
}

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

graph.add(rdf.createTriple(subject, DC.title, literal));
graph.add(rdf.createTriple(subject, DC.subject, bnode));
graph.add(rdf.createTriple(bnode, DC.title, literal));

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

graph.add(alice, name, aliceName);
graph.add(alice, knows, bob);
  graph.add(alice, member, bnode1);
    graph.add(bobNameTriple);
  graph.add(factory.createTriple(bob, member, bnode1));
  graph.add(factory.createTriple(bob, member, bnode2));
  if (secretClubName != null) {
    graph.add(bnode1, name, secretClubName);
    graph.add(bnode2, name, companyName);

代码示例来源:origin: commons-rdf/commons-rdf

graph.add(alice, name, aliceName);
graph.add(alice, knows, bob);
  graph.add(alice, member, org1);
    graph.add(bobNameTriple);
  graph.add(factory.createTriple(bob, member, org1));
  graph.add(factory.createTriple(bob, member, org2));
  if (secretClubName != null) {
    graph.add(org1, name, secretClubName);
    graph.add(org2, name, companyName);

代码示例来源:origin: commons-rdf/commons-rdf

@Test
public void remove() throws Exception {
  long fullSize = graph.size();
  graph.remove(alice, knows, bob);
  long shrunkSize = graph.size();
  assertEquals(1, fullSize - shrunkSize);
  graph.remove(alice, knows, bob);
  assertEquals(shrunkSize, graph.size()); // unchanged
  graph.add(alice, knows, bob);
  graph.add(alice, knows, bob);
  graph.add(alice, knows, bob);
  // Undetermined size at this point -- but at least it
  // should be bigger
  assertTrue(graph.size() > shrunkSize);
  // and after a single remove they should all be gone
  graph.remove(alice, knows, bob);
  assertEquals(shrunkSize, graph.size());
  Optional<? extends Triple> anyTriple = graph.getTriples().findAny();
  Assume.assumeTrue(anyTriple.isPresent());
  Triple otherTriple = anyTriple.get();
  graph.remove(otherTriple);
  assertEquals(shrunkSize - 1, graph.size());
  graph.remove(otherTriple);
  assertEquals(shrunkSize - 1, graph.size()); // no change
  graph.add(otherTriple);
  assertEquals(shrunkSize, graph.size());
}

代码示例来源: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

graph.add(alice, knows, bob);
graph.add(alice, knows, bob);
graph.add(alice, knows, bob);
graph.add(otherTriple);

代码示例来源: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-jena

graph.add(bnode1, p1, bnode2);
assertEquals(3, graph.size());
final JenaIRI p2 = factory.createIRI("http://example/p2");
final JenaLiteral foo = factory.createLiteral("foo");
graph.add(s2, p2, foo);
assertEquals(4, graph.size());
assertTrue(graph.contains(s2, p2, foo));

代码示例来源: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: commons-rdf/commons-rdf

@Test
public void testCreateGraph() {
  Graph graph;
  try {
    graph = factory.createGraph();
  } catch (UnsupportedOperationException ex) {
    Assume.assumeNoException(ex);
    return;
  }
  assertEquals("Graph was not empty", 0, graph.size());
  graph.add(factory.createBlankNode(),
      factory.createIRI("http://example.com/"),
      factory.createBlankNode());
  Graph graph2 = factory.createGraph();
  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

final IRI exampleROOT = factory.createIRI("http://example.com/s1");
final IRI greeting = factory.createIRI("http://example.com/greeting");
g.add(exampleROOT, greeting, mixedROOT);
g.add(exampleTR, greeting, upper);
assertTrue(g.contains(factory.createTriple(exampleTR, greeting, upper)));
assertTrue(g.contains(factory.createTriple(exampleTR, greeting, upperROOT)));

代码示例来源: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));
  }
}

相关文章