本文整理了Java中org.apache.commons.rdf.api.Dataset.stream()
方法的一些代码示例,展示了Dataset.stream()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Dataset.stream()
方法的具体详情如下:
包路径:org.apache.commons.rdf.api.Dataset
类名称:Dataset
方法名:stream
[英]Get all quads contained by the dataset.
The iteration does not contain any duplicate quads, as determined by the Quad#equals(Object) method for each Quad.
The behaviour of the Stream is not specified if #add(Quad), #remove(Quad) or #clear() are called on the Dataset before it terminates.
Implementations may throw ConcurrentModificationException from Stream methods if they detect a conflict while the Stream is active.
[中]获取数据集包含的所有四边形。
迭代不包含任何重复的四边形,这是由每个四边形的Quad#equals(Object)方法确定的。
如果在数据集终止之前对数据集调用了#add(Quad)、#remove(Quad)或#clear(),则不会指定流的行为。
如果流方法在流处于活动状态时检测到冲突,则实现可能会从流方法中抛出ConcurrentModificationException。
代码示例来源:origin: trellis-ldp/trellis
@Override
public Stream<Quad> stream() {
return dataset.stream().map(Quad.class::cast);
}
代码示例来源:origin: org.trellisldp/trellis-api
@Override
public Stream<Quad> stream() {
return dataset.stream().map(Quad.class::cast);
}
代码示例来源:origin: org.trellisldp/trellis-rosid-common
/**
* Stream out the added quads
* @return the added quads
*/
public Stream<Quad> getAdded() {
return dataset.stream().filter(q -> !existing.contains(q)).map(q -> (Quad) q);
}
代码示例来源:origin: org.apache.commons/commons-rdf-simple
@Override
public Stream<? extends Triple> stream(final BlankNodeOrIRI subject, final IRI predicate, final RDFTerm object) {
final Stream<Triple> stream = dataset.stream(unionOrNamedGraph(), subject, predicate, object).map(Quad::asTriple);
if (unionGraph) {
// remove duplicates
return stream.distinct();
}
return stream;
}
代码示例来源:origin: org.trellisldp/trellis-rosid-common
/**
* Serialize a dataset
* @param dataset the dataset
* @return a string
*/
public static String serialize(final Dataset dataset) {
if (nonNull(dataset)) {
return serialize(dataset.stream().collect(toList()));
}
return "";
}
代码示例来源:origin: org.trellisldp/trellis-rosid-common
@Override
public Collection<IRI> getTargetTypes() {
return data.stream().filter(quad -> quad.getGraphName().filter(graphsForTypes::contains).isPresent())
.filter(quad -> quad.getPredicate().equals(type)).map(Quad::getObject)
.filter(term -> term instanceof IRI).map(term -> (IRI) term).distinct().collect(toList());
}
代码示例来源:origin: org.trellisldp/trellis-rosid-common
/**
* Get the PROV.endedAtTime quad, wrapped in a Stream
* @param identifier the identifier
* @param dataset the dataset
* @param time the time
* @return the quad
*/
public static Stream<Quad> endedAtQuad(final IRI identifier, final Dataset dataset, final Instant time) {
return dataset.stream(of(PreferAudit), identifier, wasGeneratedBy, null)
.map(Quad::getObject).filter(term -> term instanceof BlankNodeOrIRI)
.map(term -> (BlankNodeOrIRI) term)
.map(term -> (Quad) rdf.createQuad(PreferAudit, term, endedAtTime,
rdf.createLiteral(time.toString(), dateTime))).limit(1);
}
代码示例来源:origin: trellis-ldp/trellis
public TestResource(final IRI id, final Dataset quads) {
this.id = id;
quads.stream().forEach(dataset::add);
}
代码示例来源:origin: trellis-ldp/trellis
@Override
public Stream<Quad> stream() {
return dataset.stream().map(Quad.class::cast);
}
代码示例来源:origin: org.trellisldp/trellis-triplestore
/**
* TODO Replace when COMMONSRDF-74 is released.
*
* @param dataset a Commons RDF {@link Dataset}
* @return a Jena {@link org.apache.jena.query.Dataset}
*/
public static org.apache.jena.query.Dataset asJenaDataset(final Dataset dataset) {
final DatasetGraph dsg;
if (dataset instanceof JenaDataset) {
dsg = ((JenaDataset) dataset).asJenaDatasetGraph();
} else {
dsg = DatasetGraphFactory.createGeneral();
dataset.stream().map(rdf::asJenaQuad).forEach(dsg::add);
}
return wrap(dsg);
}
代码示例来源:origin: trellis-ldp/trellis
/**
* TODO Replace when COMMONSRDF-74 is released.
*
* @param dataset a Commons RDF {@link Dataset}
* @return a Jena {@link org.apache.jena.query.Dataset}
*/
public static org.apache.jena.query.Dataset asJenaDataset(final Dataset dataset) {
final DatasetGraph dsg;
if (dataset instanceof JenaDataset) {
dsg = ((JenaDataset) dataset).asJenaDatasetGraph();
} else {
dsg = DatasetGraphFactory.createGeneral();
dataset.stream().map(rdf::asJenaQuad).forEach(dsg::add);
}
return wrap(dsg);
}
代码示例来源:origin: org.trellisldp/trellis-rosid-common
private ProducerRecord<String, String> buildContainmentMessage(final String topic, final IRI resource,
final Resource parent, final Dataset dataset) throws Exception {
try (final Dataset data = dataset.stream(of(PreferAudit), null, null, null).map(auditTypeMapper)
.collect(toDataset())) {
data.add(PreferContainment, parent.getIdentifier(), contains, resource);
return new ProducerRecord<>(topic, parent.getIdentifier().getIRIString(), serialize(data));
}
}
代码示例来源:origin: trellis-ldp/trellis
@Override
public String toString() {
return asDataset().stream()
.map(q -> format("%1$s %2$s %3$s %4$s .",
q.getSubject().ntriplesString(),
q.getPredicate().ntriplesString(),
q.getObject().ntriplesString(),
q.getGraphName().map(BlankNodeOrIRI::ntriplesString).orElse("")))
.collect(joining("\n"));
}
}
代码示例来源:origin: org.apache.commons/commons-rdf-api
@Test
public void stream() throws Exception {
assertEquals(new DummyQuad(), dataset.stream().findAny().get());
}
代码示例来源:origin: org.apache.commons/commons-rdf-api
@Test
public void streamDefaultGraphNameByPattern() throws Exception {
// Explicitly select in only the default graph Optional.empty()
final Optional<? extends Quad> aliceTopic = dataset.stream(Optional.empty(), null, null, null).findAny();
assertTrue(aliceTopic.isPresent());
// COMMONSRDF-55: should not be <urn:x-arq:defaultgraph> or similar
assertNull(aliceTopic.get().getGraphName().orElse(null));
assertFalse(aliceTopic.get().getGraphName().isPresent());
}
代码示例来源:origin: org.apache.commons/commons-rdf-api
@Test
public void streamDefaultGraphNameAlice() throws Exception {
// null below would match in ANY graph (including default graph)
final Optional<? extends Quad> aliceTopic = dataset.stream(null, alice, isPrimaryTopicOf, null).findAny();
assertTrue(aliceTopic.isPresent());
// COMMONSRDF-55: should not be <urn:x-arq:defaultgraph> or similar
assertNull(aliceTopic.get().getGraphName().orElse(null));
assertFalse(aliceTopic.get().getGraphName().isPresent());
}
代码示例来源:origin: org.apache.commons/commons-rdf-api
@Test
public void streamFiltered() throws Exception {
assertEquals(new DummyQuad(), dataset.stream(null, null, null, null).findAny().get());
assertEquals(new DummyQuad(),
dataset.stream(null, new DummyIRI(1), new DummyIRI(2), new DummyIRI(3)).findAny().get());
assertFalse(dataset.stream(null, new DummyIRI(0), new DummyIRI(0), new DummyIRI(0)).findAny().isPresent());
}
代码示例来源: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: 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
@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));
}
}
内容来源于网络,如有侵权,请联系作者删除!