本文整理了Java中org.apache.commons.rdf.api.Graph.contains()
方法的一些代码示例,展示了Graph.contains()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Graph.contains()
方法的具体详情如下:
包路径:org.apache.commons.rdf.api.Graph
类名称:Graph
方法名:contains
[英]Check if graph contains a pattern of triples.
[中]检查图形是否包含三元组模式。
代码示例来源:origin: org.trellisldp/trellis-constraint-rules
private static boolean hasMembershipProps(final Graph graph) {
return graph.contains(null, LDP.membershipResource, null)
&& (graph.stream(null, LDP.hasMemberRelation, null).count()
+ graph.stream(null, LDP.isMemberOfRelation, null).count() == 1L);
}
代码示例来源:origin: trellis-ldp/trellis
private static boolean hasMembershipProps(final Graph graph) {
return graph.contains(null, LDP.membershipResource, null)
&& (graph.stream(null, LDP.hasMemberRelation, null).count()
+ graph.stream(null, LDP.isMemberOfRelation, null).count() == 1L);
}
代码示例来源:origin: trellis-ldp/trellis
/**
* Check an RDF graph.
* @param graph the graph
* @param identifier the identifier
* @return a stream of testable assertions
*/
default Stream<Executable> checkRdfGraph(final Graph graph, final IRI identifier) {
return Stream.of(
() -> assertTrue(graph.contains(identifier, SKOS.prefLabel,
getInstance().createLiteral(BASIC_CONTAINER_LABEL, ENG)),
"Check for the presence of a skos:prefLabel triple"),
() -> assertTrue(graph.contains(identifier, DC.description, null),
"Check for the presence fo a dc:description triple"));
}
}
代码示例来源:origin: org.trellisldp/trellis-test
/**
* Check an RDF graph.
* @param graph the graph
* @param identifier the identifier
* @return a stream of testable assertions
*/
default Stream<Executable> checkRdfGraph(final Graph graph, final IRI identifier) {
return Stream.of(
() -> assertTrue(graph.contains(identifier, SKOS.prefLabel,
getInstance().createLiteral(BASIC_CONTAINER_LABEL, ENG)),
"Check for the presence of a skos:prefLabel triple"),
() -> assertTrue(graph.contains(identifier, DC.description, null),
"Check for the presence fo a dc:description triple"));
}
}
代码示例来源:origin: org.trellisldp/trellis-constraint-rules
private static Predicate<Graph> checkCardinality(final IRI model) {
return graph -> {
if (LDP.IndirectContainer.equals(model)) {
if (!graph.contains(null, LDP.insertedContentRelation, null) || !hasMembershipProps(graph)) {
return true;
}
} else if (LDP.DirectContainer.equals(model) && !hasMembershipProps(graph)) {
return true;
}
return propertiesWithUriRange.stream().anyMatch(p -> graph.stream(null, p, null).count() > 1);
};
}
代码示例来源:origin: trellis-ldp/trellis
private static Predicate<Graph> checkCardinality(final IRI model) {
return graph -> {
if (LDP.IndirectContainer.equals(model)) {
if (!graph.contains(null, LDP.insertedContentRelation, null) || !hasMembershipProps(graph)) {
return true;
}
} else if (LDP.DirectContainer.equals(model) && !hasMembershipProps(graph)) {
return true;
}
return propertiesWithUriRange.stream().anyMatch(p -> graph.stream(null, p, null).count() > 1);
};
}
代码示例来源:origin: org.trellisldp/trellis-test
/**
* Test with ldp:PreferMinimalContainer Prefer header.
*/
@Test
@DisplayName("Test with ldp:PreferMinimalContainer Prefer header")
default void testGetEmptyMember() {
final RDF rdf = getInstance();
try (final Response res = target(getMemberLocation()).request().header(PREFER,
"return=representation; include=\"" + LDP.PreferMinimalContainer.getIRIString() + "\"").get()) {
assertAll("Check the LDP-RS with Prefer", checkRdfResponse(res, LDP.RDFSource, TEXT_TURTLE_TYPE));
final Graph g = readEntityAsGraph(res.getEntity(), getBaseURL(), TURTLE);
final IRI identifier = rdf.createIRI(getMemberLocation());
assertTrue(g.contains(identifier, SKOS.prefLabel, null), "Check for a skos:prefLabel triple");
assertFalse(g.contains(identifier, LDP.member, null), "Check for no ldp:member triples");
assertFalse(g.contains(identifier, DC.relation, null), "Check for no dc:relation triples");
}
}
代码示例来源: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));
}
}
代码示例来源: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-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: trellis-ldp/trellis
/**
* Test that the binary appears in the parent container.
*/
@Test
@DisplayName("Test that the binary appears in the parent container")
default void testBinaryIsInContainer() {
final RDF rdf = getInstance();
// Test the root container, verifying that the containment triple exists
try (final Response res = target().request().get()) {
assertAll("Check binary in container", checkRdfResponse(res, LDP.BasicContainer, null));
final Graph g = readEntityAsGraph(res.getEntity(), getBaseURL(), TURTLE);
assertTrue(g.contains(rdf.createIRI(getBaseURL()), LDP.contains,
rdf.createIRI(getResourceLocation())), "Check for an ldp:contains triple");
}
}
代码示例来源:origin: org.trellisldp/trellis-test
/**
* Verify that the correct containment triples exist.
*/
@Test
@DisplayName("Verify that the correct containment triples exist")
default void testRdfContainment() {
final RDF rdf = getInstance();
// Test the root container, verifying that the containment triple exists
try (final Response res = target().request().get()) {
assertAll("Check a container resource", checkRdfResponse(res, LDP.BasicContainer, TEXT_TURTLE_TYPE));
final Graph g = readEntityAsGraph(res.getEntity(), getBaseURL(), TURTLE);
assertTrue(g.contains(rdf.createIRI(getBaseURL()), LDP.contains,
rdf.createIRI(getResourceLocation())), "Check for an ldp:contains property");
}
}
代码示例来源:origin: org.trellisldp/trellis-test
/**
* Test that the binary appears in the parent container.
*/
@Test
@DisplayName("Test that the binary appears in the parent container")
default void testBinaryIsInContainer() {
final RDF rdf = getInstance();
// Test the root container, verifying that the containment triple exists
try (final Response res = target().request().get()) {
assertAll("Check binary in container", checkRdfResponse(res, LDP.BasicContainer, null));
final Graph g = readEntityAsGraph(res.getEntity(), getBaseURL(), TURTLE);
assertTrue(g.contains(rdf.createIRI(getBaseURL()), LDP.contains,
rdf.createIRI(getResourceLocation())), "Check for an ldp:contains triple");
}
}
代码示例来源: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 contains() throws Exception {
assertTrue(graph.contains(new DummyTriple()));
}
代码示例来源:origin: org.apache.commons/commons-rdf-api
@Test
public void containsSPO() throws Exception {
assertTrue(graph.contains(null, null, null));
assertTrue(graph.contains(new DummyIRI(1), new DummyIRI(2), new DummyIRI(3)));
assertFalse(graph.contains(new DummyIRI(0), new DummyIRI(0), new DummyIRI(0)));
}
代码示例来源:origin: commons-rdf/commons-rdf
@Test
public void getTriples() throws Exception {
long tripleCount = graph.getTriples().count();
assertTrue(tripleCount > 0);
assertTrue(graph.getTriples().allMatch(t -> graph.contains(t)));
// Check exact count
Assume.assumeNotNull(org1, org2, aliceName, bobName, secretClubName,
companyName, bobNameTriple);
assertEquals(8, tripleCount);
}
代码示例来源:origin: org.apache.commons/commons-rdf-api
@Test
public void getTriples() throws Exception {
long tripleCount;
try (Stream<? extends Triple> stream = graph.stream()) {
tripleCount = stream.count();
}
assertTrue(tripleCount > 0);
try (Stream<? extends Triple> stream = graph.stream()) {
assertTrue(stream.allMatch(t -> graph.contains(t)));
}
// Check exact count
Assume.assumeNotNull(bnode1, bnode2, aliceName, bobName, secretClubName, companyName, bobNameTriple);
assertEquals(8, tripleCount);
}
代码示例来源: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());
}
内容来源于网络,如有侵权,请联系作者删除!