本文整理了Java中org.apache.commons.rdf.api.Graph.stream()
方法的一些代码示例,展示了Graph.stream()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Graph.stream()
方法的具体详情如下:
包路径:org.apache.commons.rdf.api.Graph
类名称:Graph
方法名:stream
[英]Gets all triples contained by the graph.
The iteration does not contain any duplicate triples, as determined by the Triple#equals(Object) method for each Triple.
The behaviour of the Stream is not specified if #add(Triple), #remove(Triple) or #clear() are called on the Graph before it terminates.
Implementations may throw ConcurrentModificationException from Stream methods if they detect a conflict while the Stream is active.
[中]获取图形包含的所有三元组。
迭代不包含任何重复的三元组,由每个三元组的Triple#equals(Object)方法确定。
如果在图形终止之前对其调用#add(Triple)、#remove(Triple)或#clear(),则不会指定流的行为。
如果流方法在流处于活动状态时检测到冲突,则实现可能会从流方法中抛出ConcurrentModificationException。
代码示例来源:origin: trellis-ldp/trellis
/**
* Stream triples from the graph.
*
* @return a stream of triples
*/
public Stream<Triple> stream() {
return graph.stream().map(Triple.class::cast);
}
代码示例来源:origin: org.apache.commons/commons-rdf-api
/**
* This method is deprecated, use the equivalent method {@link #stream()}
* instead.
*
* @return A {@link Stream} over all triples.
*/
@Deprecated
default Stream<? extends Triple> getTriples() {
return stream();
}
代码示例来源: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: eu.optique-project/r2rml-api-core
/**
* This method processes the given Resource node as subject by finding the
* object node with the given resourceType URI as predicate. Finds and
* returns the first object.
*
* @param node
* The Resource node as subject
* @param resourceType
* The URI as predicate
* @return the extracted first object as String
*/
private Collection<RDFTerm> readObjectsInMappingGraph(BlankNodeOrIRI node, IRI resourceType) {
// look for resourceType declaration
return graph.stream(node, resourceType, null)
.map(Triple::getObject)
.collect(toSet());
}
代码示例来源:origin: org.trellisldp/trellis-rosid-common
@Override
public Collection<IRI> getAgents() {
return data.getGraph(Trellis.PreferAudit)
.map(graph -> graph.stream(null, PROV.wasAssociatedWith, null).map(Triple::getObject)
.filter(term -> term instanceof IRI).map(term -> (IRI) term).collect(toList()))
.orElseGet(Collections::emptyList);
}
代码示例来源:origin: org.trellisldp/trellis-rosid-common
@Override
public Collection<IRI> getTypes() {
return data.getGraph(Trellis.PreferAudit)
.map(graph -> graph.stream(null, type, null).map(Triple::getObject)
.filter(term -> term instanceof IRI).map(term -> (IRI) term).collect(toList()))
.orElseGet(Collections::emptyList);
}
代码示例来源:origin: org.trellisldp/trellis-rosid-common
@Override
public Optional<IRI> getInbox() {
return data.getGraph(Trellis.PreferUserManaged)
.flatMap(graph -> graph.stream(null, LDP.inbox, null).map(Triple::getObject)
.filter(term -> term instanceof IRI).map(term -> (IRI) term).findFirst());
}
}
代码示例来源:origin: trellis-ldp/trellis
@Override
public Stream<ConstraintViolation> constrainedBy(final IRI model, final Graph graph, final String domain) {
return concat(graph.stream().flatMap(checkModelConstraints(model, domain)),
Stream.of(graph).filter(checkCardinality(model))
.map(g -> new ConstraintViolation(Trellis.InvalidCardinality, g.stream().collect(toList()))));
}
}
代码示例来源:origin: org.trellisldp/trellis-constraint-rules
@Override
public Stream<ConstraintViolation> constrainedBy(final IRI model, final Graph graph, final String domain) {
return concat(graph.stream().flatMap(checkModelConstraints(model, domain)),
Stream.of(graph).filter(checkCardinality(model))
.map(g -> new ConstraintViolation(Trellis.InvalidCardinality, g.stream().collect(toList()))));
}
}
代码示例来源:origin: trellis-ldp/trellis
protected Metadata.Builder metadataBuilder(final IRI identifier, final IRI ixnModel, final TrellisDataset mutable) {
final Metadata.Builder builder = Metadata.builder(identifier).interactionModel(ixnModel);
mutable.asDataset().getGraph(Trellis.PreferUserManaged).ifPresent(graph -> {
graph.stream(identifier, LDP.membershipResource, null).findFirst().map(Triple::getObject)
.filter(IRI.class::isInstance).map(IRI.class::cast).ifPresent(builder::membershipResource);
graph.stream(identifier, LDP.hasMemberRelation, null).findFirst().map(Triple::getObject)
.filter(IRI.class::isInstance).map(IRI.class::cast).ifPresent(builder::memberRelation);
graph.stream(identifier, LDP.isMemberOfRelation, null).findFirst().map(Triple::getObject)
.filter(IRI.class::isInstance).map(IRI.class::cast).ifPresent(builder::memberOfRelation);
graph.stream(identifier, LDP.insertedContentRelation, null).findFirst().map(Triple::getObject)
.filter(IRI.class::isInstance).map(IRI.class::cast).ifPresent(builder::insertedContentRelation);
});
return builder;
}
代码示例来源:origin: trellis-ldp/trellis
private List<Authorization> getAuthorizationFromGraph(final Graph graph) {
return graph.stream().map(Triple::getSubject).distinct().map(subject -> {
try (final WrappedGraph subGraph = wrap(graph.stream(subject, null, null).collect(toGraph()))) {
return Authorization.from(subject, subGraph.getGraph());
}
}).collect(toList());
}
代码示例来源: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.apache.commons/commons-rdf-jena
/**
* Convert a CommonsRDF Graph to a Jena Graph. If the Graph was from Jena
* originally, return that original object else create a copy using Jena
* objects.
*
* @param graph
* Commons RDF {@link Graph} to convert
* @return Converted Jena {@link org.apache.jena.graph.Graph}
*/
public org.apache.jena.graph.Graph asJenaGraph(final Graph graph) {
if (graph instanceof JenaGraph) {
return ((JenaGraph) graph).asJenaGraph();
}
final org.apache.jena.graph.Graph g = GraphFactory.createGraphMem();
graph.stream().forEach(t -> g.add(asJenaTriple(t)));
return g;
}
代码示例来源:origin: org.apache.commons/commons-rdf-api
@Test
public void stream() throws Exception {
assertEquals(new DummyTriple(), graph.stream().findAny().get());
}
代码示例来源:origin: org.trellisldp/trellis-triplestore
@Override
public CompletionStage<Void> add(final IRI id, final Dataset dataset) {
return runAsync(() -> {
final IRI graphName = rdf.createIRI(id.getIRIString() + "?ext=audit");
try (final Dataset data = rdf.createDataset()) {
dataset.getGraph(PreferAudit).ifPresent(g ->
g.stream().forEach(t -> data.add(graphName, t.getSubject(), t.getPredicate(), t.getObject())));
executeWrite(rdfConnection, () -> rdfConnection.loadDataset(asJenaDataset(data)));
} catch (final Exception ex) {
throw new RuntimeTrellisException("Error storing audit dataset for " + id, ex);
}
});
}
代码示例来源:origin: trellis-ldp/trellis
@Override
public CompletionStage<Void> add(final IRI id, final Dataset dataset) {
return runAsync(() -> {
final IRI graphName = rdf.createIRI(id.getIRIString() + "?ext=audit");
try (final Dataset data = rdf.createDataset()) {
dataset.getGraph(PreferAudit).ifPresent(g ->
g.stream().forEach(t -> data.add(graphName, t.getSubject(), t.getPredicate(), t.getObject())));
executeWrite(rdfConnection, () -> rdfConnection.loadDataset(asJenaDataset(data)));
} catch (final Exception ex) {
throw new RuntimeTrellisException("Error storing audit dataset for " + id, ex);
}
});
}
代码示例来源:origin: org.apache.commons/commons-rdf-api
@Test
public void streamFiltered() throws Exception {
assertEquals(new DummyTriple(), graph.stream(null, null, null).findAny().get());
assertEquals(new DummyTriple(),
graph.stream(new DummyIRI(1), new DummyIRI(2), new DummyIRI(3)).findAny().get());
assertFalse(graph.stream(new DummyIRI(0), new DummyIRI(0), new DummyIRI(0)).findAny().isPresent());
}
代码示例来源: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);
}
内容来源于网络,如有侵权,请联系作者删除!