本文整理了Java中org.apache.commons.rdf.api.Dataset.getGraph()
方法的一些代码示例,展示了Dataset.getGraph()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Dataset.getGraph()
方法的具体详情如下:
包路径:org.apache.commons.rdf.api.Dataset
类名称:Dataset
方法名:getGraph
[英]Get the default graph of this dataset.
The Triples of the default graph are equivalent to the Quads in this Dataset which has the Quad#getGraphName()set to Optional#empty().
It is unspecified if modifications to the returned Graph are reflected in this Dataset.
The returned graph MAY be empty.
[中]获取此数据集的默认图形。
默认图形的三元组等效于此数据集中的四元组,其中四元组#getGraphName()设置为可选的#empty()。
如果对返回图形的修改反映在此数据集中,则未指定。
返回的图形可能为空。
代码示例来源:origin: trellis-ldp/trellis
/**
* Get a graph from the dataset.
*
* @param graphName the graph name
* @return the graph
*/
public Optional<Graph> getGraph(final IRI graphName) {
return dataset.getGraph(graphName);
}
代码示例来源:origin: org.trellisldp.ext/trellis-db
private static void updateAcl(final Handle handle, final int resourceId, final Dataset dataset,
final int batchSize) {
dataset.getGraph(PreferAccessControl).ifPresent(graph ->
batchUpdateTriples(handle, resourceId, "acl", graph, batchSize));
}
代码示例来源: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 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.ext/trellis-db
private static void updateDescription(final Handle handle, final int resourceId, final Dataset dataset,
final int batchSize) {
dataset.getGraph(PreferUserManaged).ifPresent(graph ->
batchUpdateTriples(handle, resourceId, "description", graph, batchSize));
}
代码示例来源: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
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: org.apache.commons/commons-rdf-api
@Test
public void getGraphNull() throws Exception {
assertTrue(dataset.getGraph(null).get() instanceof DummyGraph);
}
代码示例来源:origin: org.trellisldp.ext/trellis-db
private static void updateExtra(final Handle handle, final int resourceId, final IRI identifier,
final Dataset dataset) {
dataset.getGraph(PreferUserManaged).ifPresent(graph -> {
final String query = "INSERT INTO extra (resource_id, predicate, object) VALUES (?, ?, ?)";
try (final PreparedBatch batch = handle.prepareBatch(query)) {
graph.stream(identifier, LDP.inbox, null).map(Triple::getObject).filter(t -> t instanceof IRI)
.map(t -> ((IRI) t).getIRIString()).findFirst().ifPresent(iri ->
batch.bind(0, resourceId)
.bind(1, LDP.inbox.getIRIString())
.bind(2, iri)
.add());
graph.stream(identifier, OA.annotationService, null).map(Triple::getObject)
.filter(t -> t instanceof IRI).map(t -> ((IRI) t).getIRIString()).findFirst().ifPresent(iri ->
batch.bind(0, resourceId)
.bind(1, OA.annotationService.getIRIString())
.bind(2, iri).add());
if (batch.size() > 0) {
batch.execute();
}
}
});
}
代码示例来源:origin: org.apache.commons/commons-rdf-api
@Test
public void getGraph() throws Exception {
assertTrue(dataset.getGraph() instanceof DummyGraph);
}
代码示例来源: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 getGraphNamed() throws Exception {
assertFalse(dataset.getGraph(new DummyIRI(0)).isPresent());
}
代码示例来源: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 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: 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-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));
}
}
内容来源于网络,如有侵权,请联系作者删除!