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

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

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

Graph.size介绍

[英]Number of triples contained by the graph.

The count of a set does not include duplicates, as determined by the equals method for each Triple.
[中]图形包含的三元组数。
集合的计数不包括重复项,由每个三元组的equals方法确定。

代码示例

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

/**
 * Check the absense of audit triples.
 */
@Test
@DisplayName("Check the absense of audit triples.")
default void testNoAuditTriples() {
  try (final Response res = target(getResourceLocation()).request().get()) {
    final Graph g = readEntityAsGraph(res.getEntity(), getBaseURL(), TURTLE);
    assertEquals(2L, g.size(), "Check that the graph has 2 triples");
  }
}

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

/**
 * Check the absense of audit triples.
 */
@Test
@DisplayName("Check the absense of audit triples.")
default void testNoAuditTriples() {
  try (final Response res = target(getResourceLocation()).request().get()) {
    final Graph g = readEntityAsGraph(res.getEntity(), getBaseURL(), TURTLE);
    assertEquals(2L, g.size(), "Check that the graph has 2 triples");
  }
}

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

/**
 * Check the explicit absense of audit triples.
 */
@Test
@DisplayName("Check the explicit absense of audit triples.")
default void testOmitAuditTriples() {
  try (final Response res = target(getResourceLocation()).request().header("Prefer",
        "return=representation; omit=\"" + Trellis.PreferAudit.getIRIString() + "\"").get()) {
    final Graph g = readEntityAsGraph(res.getEntity(), getBaseURL(), TURTLE);
    assertEquals(2L, g.size(), "Check that the graph has only 2 triples");
  }
}

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

/**
 * Check the explicit absense of audit triples.
 */
@Test
@DisplayName("Check the explicit absense of audit triples.")
default void testOmitAuditTriples() {
  try (final Response res = target(getResourceLocation()).request().header("Prefer",
        "return=representation; omit=\"" + Trellis.PreferAudit.getIRIString() + "\"").get()) {
    final Graph g = readEntityAsGraph(res.getEntity(), getBaseURL(), TURTLE);
    assertEquals(2L, g.size(), "Check that the graph has only 2 triples");
  }
}

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

@Test
public void size() throws Exception {
  assertEquals(1, graph.size());
}

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

@Test
public void size() throws Exception {
  assertTrue(graph.size() > 0);
  Assume.assumeNotNull(org1, org2, aliceName, bobName, secretClubName,
      companyName, bobNameTriple);
  // Can only reliably predict size if we could create all triples
  assertEquals(8, graph.size());
}

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

@Test
public void size() throws Exception {
  assertTrue(graph.size() > 0);
  Assume.assumeNotNull(bnode1, bnode2, aliceName, bobName, secretClubName, companyName, bobNameTriple);
  // Can only reliably predict size if we could create all triples
  assertEquals(8, graph.size());
}

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

@Test
public void clear() throws Exception {
  graph.clear();
  assertFalse(graph.contains(alice, knows, bob));
  assertEquals(0, graph.size());
  graph.clear(); // no-op
  assertEquals(0, graph.size());
}

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

@Test
public void clear() throws Exception {
  graph.clear();
  assertFalse(graph.contains(alice, knows, bob));
  assertEquals(0, graph.size());
  graph.clear(); // no-op
  assertEquals(0, graph.size());
}

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

@Test
public void testCollectGraph() {
  final Graph graph = generate(() -> rdf.createTriple(getIRI(), getIRI(), getIRI()))
    .parallel().limit(size).collect(toGraph());
  assertTrue(size >= graph.size(), "Generated graph has too many triples!");
}

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

@Test
public void testUpdateError() {
  final Graph graph = rdf.createGraph();
  getTriples().forEach(graph::add);
  assertEquals(3L, graph.size(), "Incorrect graph size!");
  assertThrows(RuntimeTrellisException.class, () ->
      service.update(graph, "blah blah blah blah blah", SPARQL_UPDATE, null), "no exception on bad update!");
}

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

@Test
public void testAuditUpdate() {
  final Dataset dataset = rdf.createDataset();
  final AuditService svc = new DefaultAuditService() {};
  svc.update(subject, mockSession).forEach(dataset::add);
  assertTrue(dataset.getGraph(Trellis.PreferAudit).filter(graph -> graph.size() == dataset.size()).isPresent());
  assertTrue(dataset.contains(null, null, type, AS.Update));
  assertAll("Event property check", checkEventProperties(dataset));
}

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

@Test
public void testAuditDeletion() {
  final Dataset dataset = rdf.createDataset();
  final AuditService svc = new DefaultAuditService() {};
  svc.deletion(subject, mockSession).forEach(dataset::add);
  assertTrue(dataset.getGraph(Trellis.PreferAudit).filter(graph -> graph.size() == dataset.size()).isPresent(),
      "Graph and dataset sizes don't match for deletion event!");
  assertTrue(dataset.contains(null, null, type, AS.Delete), "as:Delete type not in delete dataset!");
  assertAll("Event property check", checkEventProperties(dataset));
}

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

@Test
public void testAuditCreation() {
  final Dataset dataset = rdf.createDataset();
  final AuditService svc = new DefaultAuditService() {};
  svc.creation(subject, mockSession).forEach(dataset::add);
  assertTrue(dataset.getGraph(Trellis.PreferAudit).filter(graph -> graph.size() == dataset.size()).isPresent(),
      "Graph and dataset sizes don't match for creation event!");
  assertTrue(dataset.contains(null, null, type, AS.Create), "as:Create type not in create dataset!");
  assertAll("Event property check", checkEventProperties(dataset));
}

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

@Test
public void getGraphNull() throws Exception {
  // Default graph should be present
  try (final Graph defaultGraph = dataset.getGraph(null).get()) {
    // TODO: Can we assume the default graph was empty before our new triples?
    assertEquals(2, defaultGraph.size());
    assertTrue(defaultGraph.contains(alice, isPrimaryTopicOf, graph1));
    // NOTE: wildcard as graph2 is a (potentially mapped) BlankNode
    assertTrue(defaultGraph.contains(bob, isPrimaryTopicOf, null));
  }
}

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

@Test
public void getGraph2() throws Exception {
  // graph2 should be present, even if is named by a BlankNode
  // We'll look up the potentially mapped graph2 blanknode
  final BlankNodeOrIRI graph2Name = (BlankNodeOrIRI) dataset.stream(Optional.empty(), bob, isPrimaryTopicOf, null)
      .map(Quad::getObject).findAny().get();
  try (final Graph g2 = dataset.getGraph(graph2Name).get()) {
    assertEquals(4, g2.size());
    final Triple bobNameTriple = bobNameQuad.asTriple();
    assertTrue(g2.contains(bobNameTriple));
    assertTrue(g2.contains(bob, member, bnode1));
    assertTrue(g2.contains(bob, member, bnode2));
    assertFalse(g2.contains(bnode1, name, secretClubName));
    assertTrue(g2.contains(bnode2, name, companyName));
  }
}

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

@Test
  public void parseTurtle() throws Exception {
    try (final Graph g = new JenaRDF().createGraph()) {
      final Future<ParseResult> gFuture = new JenaRDFParser().contentType(RDFSyntax.TURTLE).source(turtleFile)
          .target(g).parse();
      gFuture.get(5, TimeUnit.SECONDS);
      assertEquals(3, g.size());
    }
  }
}

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

@Test
public void getGraph() throws Exception {
  try (final Graph defaultGraph = dataset.getGraph()) {
    // TODO: Can we assume the default graph was empty before our new triples?
    assertEquals(2, defaultGraph.size());
    assertTrue(defaultGraph.contains(alice, isPrimaryTopicOf, graph1));
    // NOTE: graph2 is a BlankNode
    assertTrue(defaultGraph.contains(bob, isPrimaryTopicOf, null));
  }
}

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

@Test
public void getGraph1() throws Exception {
  // graph1 should be present
  try (final Graph g1 = dataset.getGraph(graph1).get()) {
    assertEquals(4, g1.size());
    assertTrue(g1.contains(alice, name, aliceName));
    assertTrue(g1.contains(alice, knows, bob));
    assertTrue(g1.contains(alice, member, null));
    assertTrue(g1.contains(null, name, secretClubName));
  }
}

相关文章