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

x33g5p2x  于2022-01-18 转载在 其他  
字(14.2k)|赞(0)|评价(0)|浏览(249)

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

Dataset.contains介绍

暂无

代码示例

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

@Override
public boolean contains(final BlankNodeOrIRI subject, final IRI predicate, final RDFTerm object) {
  return dataset.contains(unionOrNamedGraph(), subject, predicate, object);
}

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

/**
 * Stream out the removed quads
 * @return the removed quads
 */
public Stream<Quad> getRemoved() {
  return existing.stream().filter(q -> !dataset.contains(q))
    // exclude the server-managed modified triple
    .filter(q -> !q.getGraphName().equals(of(PreferServerManaged)) || !modified.equals(q.getPredicate()))
    .map(q -> (Quad) q);
}

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

private Consumer<Resource> emitToParent(final IRI identifier, final Dataset dataset,
    final List<Future<RecordMetadata>> results) {
  final Boolean isCreate = dataset.contains(of(PreferAudit), null, type, Create);
  final Boolean isDelete = dataset.contains(of(PreferAudit), null, type, Delete);
  final String containmentTopic = isDelete ? TOPIC_LDP_CONTAINMENT_DELETE : TOPIC_LDP_CONTAINMENT_ADD;
  final String membershipTopic = isDelete ? TOPIC_LDP_MEMBERSHIP_DELETE : TOPIC_LDP_MEMBERSHIP_ADD;
  return container -> {
    if (isDelete || isCreate) {
      try {
        LOGGER.info("Sending to parent: {}", container.getIdentifier());
        results.add(producer.send(buildContainmentMessage(containmentTopic, identifier, container,
                dataset)));
        buildMembershipMessage(membershipTopic, identifier, container, dataset).ifPresent(msg -> {
            LOGGER.info("Sending to member resource: {}", container.getMembershipResource());
            results.add(producer.send(msg));
        });
      } catch (final Exception ex) {
        LOGGER.error("Error processing dataset: {}", ex.getMessage());
      }
    }
  };
}

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

@Override
public boolean contains(final Triple triple) {
  return dataset.contains(unionOrNamedGraph(), triple.getSubject(), triple.getPredicate(), triple.getObject());
}

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

private Stream<Executable> checkEventProperties(final Dataset dataset) {
    return Stream.of(
        () -> assertTrue(dataset.contains(null, null, type, PROV.Activity), "missing prov:Activity triple!"),
        () -> assertTrue(dataset.contains(null, subject, PROV.wasGeneratedBy, null),
                 "missing prov:wasGeneratedBy triple!"),
        () -> assertTrue(dataset.contains(null, null, PROV.wasAssociatedWith, Trellis.AnonymousAgent),
                 "missing prov:wasAssociatedWith triple!"),
        () -> assertTrue(dataset.contains(null, null, PROV.actedOnBehalfOf, Trellis.AdministratorAgent),
                 "missing prov:actedOnBehalfOf triple!"),
        () -> assertTrue(dataset.contains(null, null, PROV.atTime,
            rdf.createLiteral(created.toString(), XSD.dateTime)), "missing prov:atTime triple!"),
        () -> assertEquals(6L, dataset.size(), "Incorrect dataset size!"));
  }
}

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

@Test
public void contains() throws Exception {
  assertFalse(dataset.contains(null, bob, knows, alice)); // or so he claims..
  assertTrue(dataset.contains(Optional.of(graph1), alice, knows, bob));
  try (Stream<? extends Quad> stream = dataset.stream()) {
    final Optional<? extends Quad> first = stream.skip(4).findFirst();
    Assume.assumeTrue(first.isPresent());
    final Quad existingQuad = first.get();
    assertTrue(dataset.contains(existingQuad));
  }
  final Quad nonExistingQuad = factory.createQuad(graph2, bob, knows, alice);
  assertFalse(dataset.contains(nonExistingQuad));
  // An existing quad
  final Quad quad = factory.createQuad(graph1, alice, knows, bob);
  // FIXME: Should not this always be true?
   assertTrue(dataset.contains(quad));
}

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

/**
 * Ensure {@link Dataset#getGraphNames()} contains our two graphs.
 *
 * @throws Exception
 *             If test fails
 */
@Test
public void getGraphNames() throws Exception {
  final Set<BlankNodeOrIRI> names = dataset.getGraphNames().collect(Collectors.toSet());
  assertTrue("Can't find graph name " + graph1, names.contains(graph1));
  assertTrue("Found no quads in graph1", dataset.contains(Optional.of(graph1), null, null, null));
  final Optional<BlankNodeOrIRI> graphName2 = dataset.getGraphNames().filter(BlankNode.class::isInstance).findAny();
  assertTrue("Could not find graph2-like BlankNode", graphName2.isPresent());
  assertTrue("Found no quads in graph2", dataset.contains(graphName2, null, null, null));
  // Some implementations like Virtuoso might have additional internal graphs,
  // so we can't assume this:
  //assertEquals(2, names.size());
}

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

/**
 * Test creating a resource.
 * @throws Exception if the operation failed
 */
@Test
@DisplayName("Test creating resource")
default void testCreateResource() throws Exception {
  final RDF rdf = getInstance();
  final IRI identifier = rdf.createIRI(TRELLIS_DATA_PREFIX + getResourceService().generateIdentifier());
  final Dataset dataset = buildDataset(identifier, "Creation Test", SUBJECT1);
  assertEquals(MISSING_RESOURCE, getResourceService().get(identifier).toCompletableFuture().join(),
      "Check for no pre-existing LDP-RS");
  assertDoesNotThrow(() -> getResourceService().create(Metadata.builder(identifier)
        .interactionModel(LDP.RDFSource).container(ROOT_CONTAINER).build(), dataset)
      .toCompletableFuture().join(), "Check that the resource was successfully created");
  final Resource res = getResourceService().get(identifier).toCompletableFuture().join();
  assertAll("Check resource stream", res.stream(Trellis.PreferUserManaged).map(toQuad(Trellis.PreferUserManaged))
      .map(q -> () -> assertTrue(dataset.contains(q), "Verify that the quad is from the dataset: " + q)));
}

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

/**
 * Test creating a resource.
 * @throws Exception if the operation failed
 */
@Test
@DisplayName("Test creating resource")
default void testCreateResource() throws Exception {
  final RDF rdf = getInstance();
  final IRI identifier = rdf.createIRI(TRELLIS_DATA_PREFIX + getResourceService().generateIdentifier());
  final Dataset dataset = buildDataset(identifier, "Creation Test", SUBJECT1);
  assertEquals(MISSING_RESOURCE, getResourceService().get(identifier).toCompletableFuture().join(),
      "Check for no pre-existing LDP-RS");
  assertDoesNotThrow(() -> getResourceService().create(Metadata.builder(identifier)
        .interactionModel(LDP.RDFSource).container(ROOT_CONTAINER).build(), dataset)
      .toCompletableFuture().join(), "Check that the resource was successfully created");
  final Resource res = getResourceService().get(identifier).toCompletableFuture().join();
  assertAll("Check resource stream", res.stream(Trellis.PreferUserManaged).map(toQuad(Trellis.PreferUserManaged))
      .map(q -> () -> assertTrue(dataset.contains(q), "Verify that the quad is from the dataset: " + q)));
}

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

@Test
public void containsSPO() throws Exception {
  assertTrue(dataset.contains(null, null, null, null));
  assertTrue(dataset.contains(null, new DummyIRI(1), new DummyIRI(2), new DummyIRI(3)));
  assertFalse(dataset.contains(null, new DummyIRI(0), new DummyIRI(0), new DummyIRI(0)));
}

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

@Test
public void contains() throws Exception {
  assertTrue(dataset.contains(new DummyQuad()));
}

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

@Test
public void containsLanguageTagsCaseInsensitive() {
  // COMMONSRDF-51: Ensure we can add/contains/remove with any casing
  // of literal language tag
  final Literal lower = factory.createLiteral("Hello there", "en-gb");
  final Literal upper = factory.createLiteral("Hello there", "EN-GB");
  final Literal mixed = factory.createLiteral("Hello there", "en-GB");
  final IRI example1 = factory.createIRI("http://example.com/s1");
  final IRI greeting = factory.createIRI("http://example.com/greeting");
  dataset.add(null, example1, greeting, upper);
  // any kind of Triple should match
  assertTrue(dataset.contains(factory.createQuad(null, example1, greeting, upper)));
  assertTrue(dataset.contains(factory.createQuad(null, example1, greeting, lower)));
  assertTrue(dataset.contains(factory.createQuad(null, example1, greeting, mixed)));
  // or as patterns
  assertTrue(dataset.contains(null, null, null, upper));
  assertTrue(dataset.contains(null, null, null, lower));
  assertTrue(dataset.contains(null, null, null, mixed));
}

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

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

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

@Test
public void getQuads() throws Exception {
  long quadCount;
  try (Stream<? extends Quad> stream = dataset.stream()) {
    quadCount = stream.count();
  }
  assertTrue(quadCount > 0);
  try (Stream<? extends Quad> stream = dataset.stream()) {
    assertTrue(stream.allMatch(t -> dataset.contains(t)));
  }
  // Check exact count
  Assume.assumeNotNull(bnode1, bnode2, aliceName, bobName, secretClubName, companyName, bobNameQuad);
  assertEquals(10, quadCount);
}

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

@Test
public void testAppendSemantics() {
  final Quad testFirstQuad = createQuad(testResourceId3, testResourceId2, testResourceId1, badId);
  final Quad testSecondQuad = createQuad(testResourceId3, testResourceId2, testResourceId1, badId);
  // store some data in mutable and immutable sides under the same resource ID
  final Resource testFirstResource = new TestResource(testResourceId3, testFirstQuad);
  assertNull(testable.add(testResourceId3, testFirstResource.dataset()).toCompletableFuture().join(),
          "Couldn't create an immutable resource!");
  final Resource testSecondResource = new TestResource(testResourceId3, testSecondQuad);
  assertNull(testable.add(testResourceId3, testSecondResource.dataset()).toCompletableFuture().join(),
          "Couldn't add to an immutable resource!");
  final Resource retrieved = testable.get(testResourceId3).toCompletableFuture().join();
  assertEquals(testResourceId3, retrieved.getIdentifier(), "Resource was retrieved with wrong ID!");
  final Dataset quads = retrieved.dataset();
  assertTrue(quads.contains(testFirstQuad), "Resource was retrieved without its immutable data!");
  assertTrue(quads.contains(testSecondQuad), "Resource was retrieved without its mutable data!");
  quads.remove(testFirstQuad);
  quads.remove(testSecondQuad);
  assertEquals(0, quads.size(), "Resource was retrieved with too much data!");
}

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

@Test
public void testMergingBehavior() {
  final Quad testMutableQuad = createQuad(testResourceId2, testResourceId2, testResourceId1, badId);
  final Quad testImmutableQuad = createQuad(testResourceId2, testResourceId2, testResourceId1, badId);
  // store some data in mutable and immutable sides under the same resource ID
  final Resource testMutableResource = new TestResource(testResourceId2, testMutableQuad);
  assertNull(testable.create(Metadata.builder(testMutableResource).build(), testMutableResource.dataset())
      .toCompletableFuture().join(), "Couldn't create a resource!");
  final Resource testImmutableResource = new TestResource(testResourceId2, testImmutableQuad);
  assertNull(testable.add(testResourceId2, testImmutableResource.dataset()).toCompletableFuture().join(),
          "Couldn't create an immutable resource!");
  final Resource retrieved = testable.get(testResourceId2).toCompletableFuture().join();
  assertEquals(testMutableResource.getIdentifier(), retrieved.getIdentifier(),
          "Resource was retrieved with wrong ID!");
  final Dataset quads = retrieved.dataset();
  assertTrue(quads.contains(testImmutableQuad), "Resource was retrieved without its immutable data!");
  assertTrue(quads.contains(testMutableQuad), "Resource was retrieved without its mutable data!");
  quads.remove(testImmutableQuad);
  quads.remove(testMutableQuad);
  assertEquals(0, quads.size(), "Resource was retrieved with too much data!");
}

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

@Test
public void removeLanguageTagsCaseInsensitive() {
  // COMMONSRDF-51: Ensure we can remove with any casing
  // of literal language tag
  final Literal lower = factory.createLiteral("Howdy", "en-us");
  final Literal upper = factory.createLiteral("Howdy", "EN-US");
  final Literal mixed = factory.createLiteral("Howdy", "en-US");
  final IRI example1 = factory.createIRI("http://example.com/s1");
  final IRI greeting = factory.createIRI("http://example.com/greeting");
  dataset.add(null, example1, greeting, upper);
  // Remove should also honour any case
  dataset.remove(null, example1, null, mixed);
  assertFalse(dataset.contains(null, null, greeting, null));
  dataset.add(null, example1, greeting, lower);
  dataset.remove(null, example1, null, upper);
  // Check with Triple
  dataset.add(factory.createQuad(null, example1, greeting, mixed));
  dataset.remove(factory.createQuad(null, example1, greeting, upper));
  assertFalse(dataset.contains(null, null, greeting, null));
}

相关文章