本文整理了Java中org.apache.commons.rdf.api.RDF.createQuad
方法的一些代码示例,展示了RDF.createQuad
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。RDF.createQuad
方法的具体详情如下:
包路径:org.apache.commons.rdf.api.RDF
类名称:RDF
方法名:createQuad
[英]Create a quad.
The returned Quad SHOULD have a Quad#getGraphName() that is equal to the provided graphName, a Quad#getSubject() that is equal to the provided subject, a Quad#getPredicate() that is equal to the provided predicate, and a Quad#getObject() that is equal to the provided object.
[中]创建一个四边形。
返回的四元组应该有一个四元组#getGraphName()与提供的graphName相等,一个四元组#getSubject()与提供的主语相等,一个四元组#getPredicate()与提供的谓词相等,以及一个四元组#getObject()与提供的对象相等。
代码示例来源:origin: trellis-ldp/trellis
private List<Quad> auditData(final IRI subject, final Session session, final List<IRI> types) {
final List<Quad> data = new ArrayList<>();
final BlankNode bnode = rdf.createBlankNode();
data.add(rdf.createQuad(PreferAudit, subject, PROV.wasGeneratedBy, bnode));
types.forEach(t -> data.add(rdf.createQuad(PreferAudit, bnode, type, t)));
data.add(rdf.createQuad(PreferAudit, bnode, PROV.wasAssociatedWith, session.getAgent()));
data.add(rdf.createQuad(PreferAudit, bnode, PROV.atTime,
rdf.createLiteral(session.getCreated().toString(), XSD.dateTime)));
session.getDelegatedBy().ifPresent(delegate ->
data.add(rdf.createQuad(PreferAudit, bnode, PROV.actedOnBehalfOf, delegate)));
return data;
}
}
代码示例来源:origin: org.trellisldp/trellis-api
/**
* Get a mapping function to turn a triple into a quad.
*
* @param graphName the graph name
* @return the mapping function
*/
public static Function<Triple, Quad> toQuad(final IRI graphName) {
return triple -> rdf.createQuad(graphName, triple.getSubject(), triple.getPredicate(), triple.getObject());
}
代码示例来源:origin: org.trellisldp.ext/trellis-db
private Stream<Quad> fetchQuadsFromTable(final String tableName, final IRI graphName) {
final String query = "SELECT subject, predicate, object, lang, datatype "
+ "FROM " + tableName + " WHERE resource_id = ?";
return jdbi.withHandle(handle -> handle.select(query, data.getId())
.map((rs, ctx) -> rdf.createQuad(graphName, rdf.createIRI(rs.getString(SUBJECT)),
rdf.createIRI(rs.getString(PREDICATE)),
getObject(rs.getString(OBJECT), rs.getString(LANG), rs.getString(DATATYPE))))
.stream());
}
代码示例来源:origin: trellis-ldp/trellis
/**
* Get a mapping function to turn a triple into a quad.
*
* @param graphName the graph name
* @return the mapping function
*/
public static Function<Triple, Quad> toQuad(final IRI graphName) {
return triple -> rdf.createQuad(graphName, triple.getSubject(), triple.getPredicate(), triple.getObject());
}
代码示例来源:origin: org.trellisldp.ext/trellis-db
/**
* Fetch a stream of the audit-related quads.
*/
private Stream<Quad> fetchAuditQuads() {
final String query = "SELECT subject, predicate, object, lang, datatype FROM log WHERE id = ?";
return jdbi.withHandle(handle -> handle.select(query, getIdentifier().getIRIString())
.map((rs, ctx) -> rdf.createQuad(Trellis.PreferAudit, rdf.createIRI(rs.getString(SUBJECT)),
rdf.createIRI(rs.getString(PREDICATE)),
getObject(rs.getString(OBJECT), rs.getString(LANG), rs.getString(DATATYPE))))
.stream());
}
代码示例来源:origin: trellis-ldp/trellis
private static Quad createQuad(final BlankNodeOrIRI g, final BlankNodeOrIRI s, final IRI p, final RDFTerm o) {
return TrellisUtils.getInstance().createQuad(g, s, p, o);
}
代码示例来源:origin: trellis-ldp/trellis
private Stream<Quad> getLdfQuads() {
return Stream.of(
rdf.createQuad(PreferUserManaged, identifier, DC.creator, rdf.createLiteral("User")),
rdf.createQuad(PreferUserManaged, rdf.createIRI("ex:foo"), DC.title, rdf.createIRI("ex:title")),
rdf.createQuad(PreferUserManaged, identifier, DC.title, rdf.createLiteral("A title")),
rdf.createQuad(PreferUserManaged, identifier, DC.title, rdf.createLiteral("Other title")),
rdf.createQuad(PreferUserManaged, identifier, type, rdf.createIRI("ex:Type")),
rdf.createQuad(PreferUserManaged, rdf.createIRI("ex:foo"), type, rdf.createIRI("ex:Type")),
rdf.createQuad(PreferUserManaged, rdf.createIRI("ex:foo"), type, rdf.createIRI("ex:Other")),
rdf.createQuad(PreferServerManaged, identifier, DC.created,
rdf.createLiteral("2017-04-01T10:15:00Z", XSD.dateTime)),
rdf.createQuad(PreferAccessControl, identifier, type, ACL.Authorization),
rdf.createQuad(PreferAccessControl, identifier, ACL.mode, ACL.Control));
}
代码示例来源:origin: org.trellisldp.ext/trellis-db
/**
* Fetch a stream of containment quads for a resource.
*/
private Stream<Quad> fetchContainmentQuads() {
if (getInteractionModel().getIRIString().endsWith("Container")) {
final String query = "SELECT subject FROM resource WHERE is_part_of = ?";
return jdbi.withHandle(handle -> handle.select(query,
getIdentifier().getIRIString())
.map((rs, ctx) -> rdf.createQuad(LDP.PreferContainment, getIdentifier(),
LDP.contains, rdf.createIRI(rs.getString(SUBJECT))))
.stream());
}
return empty();
}
代码示例来源:origin: trellis-ldp/trellis
/**
* Convert quads from a skolemized form to an external form.
*
* @param svc the resource service
* @param baseUrl the base URL
* @return a mapping function
*/
public static Function<Quad, Quad> unskolemizeQuads(final ResourceService svc, final String baseUrl) {
return quad -> rdf.createQuad(quad.getGraphName().orElse(PreferUserManaged),
(BlankNodeOrIRI) svc.toExternal(svc.unskolemize(quad.getSubject()), baseUrl),
quad.getPredicate(), svc.toExternal(svc.unskolemize(quad.getObject()), baseUrl));
}
代码示例来源:origin: trellis-ldp/trellis
@Test
public void testResourceWithQuads() {
final IRI subject = rdf.createIRI("ex:subject");
when(mockResource.stream()).thenAnswer((x) -> of(
rdf.createQuad(prefer, subject, DC.title, rdf.createLiteral("A title")),
rdf.createQuad(PreferUserManaged, subject, DC.title, rdf.createLiteral("Other title"))));
assertEquals(1L, mockResource.stream(prefer).count(), "Resource stream has wrong number of triples!");
assertEquals(1L, mockResource.stream(singleton(prefer)).count(), "Resource has wrong number of triples!");
}
代码示例来源:origin: trellis-ldp/trellis
/**
* Convert quads from an external form to a skolemized form.
*
* @param svc the resource service
* @param baseUrl the base URL
* @return a mapping function
*/
public static Function<Quad, Quad> skolemizeQuads(final ResourceService svc, final String baseUrl) {
return quad -> rdf.createQuad(quad.getGraphName().orElse(PreferUserManaged),
(BlankNodeOrIRI) svc.toInternal(svc.skolemize(quad.getSubject()), baseUrl), quad.getPredicate(),
svc.toInternal(svc.skolemize(quad.getObject()), baseUrl));
}
代码示例来源:origin: trellis-ldp/trellis
@Test
public void testDatasetCombiner() {
final Set<Quad> quads1 = generate(() -> rdf.createQuad(getIRI(), getIRI(), getIRI(), getIRI()))
.parallel().limit(size).collect(toSet());
final Set<Quad> quads2 = generate(() -> rdf.createQuad(getIRI(), getIRI(), getIRI(), getIRI()))
.parallel().limit(size).collect(toSet());
final Collector<Quad, Set<Quad>, Dataset> collector = toDataset().concurrent();
assertEquals(quads1.size() + quads2.size(), collector.combiner().apply(quads1, quads2).size(),
"Dataset combiner produces the wrong number of quads!");
}
代码示例来源:origin: trellis-ldp/trellis
@Test
public void testDatasetCollectorFinisher() {
final Dataset dataset = generate(() -> rdf.createQuad(getIRI(), getIRI(), getIRI(), getIRI()))
.parallel().limit(size).collect(toDataset());
final TrellisUtils.DatasetCollector collector = toDataset();
assertEquals(dataset, collector.finisher().apply(dataset), "Dataset finisher returns the wrong object!");
}
代码示例来源:origin: trellis-ldp/trellis
@Test
public void testCollectDataset() {
final Dataset dataset = generate(() -> rdf.createQuad(getIRI(), getIRI(), getIRI(), getIRI()))
.parallel().limit(size).collect(toDataset());
assertTrue(size >= dataset.size(), "Generated dataset has too many triples!");
}
代码示例来源:origin: trellis-ldp/trellis
@Test
public void testToQuad() {
final IRI subject = rdf.createIRI("http://example.com/resource");
final Literal object = rdf.createLiteral("title");
final Triple triple = rdf.createTriple(subject, DC.title, object);
final Quad quad = rdf.createQuad(Trellis.PreferUserManaged, subject, DC.title, object);
assertEquals(quad, toQuad(Trellis.PreferUserManaged).apply(triple), "Incorrect quad from triple!");
}
代码示例来源:origin: trellis-ldp/trellis
@Test
public void testCollectDatasetConcurrent() {
final Dataset dataset = generate(() -> rdf.createQuad(getIRI(), getIRI(), getIRI(), getIRI()))
.parallel().limit(size).collect(toDataset().concurrent());
assertTrue(size >= dataset.size(), "Generated dataset has too many triples!");
}
代码示例来源:origin: trellis-ldp/trellis
@Test
public void testSerializeQuadDefaultGraph() {
final Quad quad = rdf.createQuad(null, rdf.createIRI("trellis:data/resource"),
DC.subject, rdf.createIRI("http://example.org"));
assertEquals("<trellis:data/resource> <http://purl.org/dc/terms/subject> <http://example.org> .",
FileUtils.serializeQuad(quad),
"Triple isn't serialized properly!");
}
代码示例来源:origin: trellis-ldp/trellis
@Test
public void testSerializeQuad() {
final Quad quad = rdf.createQuad(Trellis.PreferServerManaged, rdf.createIRI("trellis:data/resource"),
DC.subject, rdf.createIRI("http://example.org"));
assertEquals("<trellis:data/resource> <http://purl.org/dc/terms/subject> <http://example.org> "
+ "<http://www.trellisldp.org/ns/trellis#PreferServerManaged> .", FileUtils.serializeQuad(quad),
"Quad isn't serialized properly!");
}
代码示例来源:origin: trellis-ldp/trellis
@Test
public void testDatasetConversion() {
final Dataset dataset = simpleRdf.createDataset();
dataset.add(simpleRdf.createQuad(PreferUserManaged, subject, SKOS.prefLabel, literal));
dataset.add(simpleRdf.createQuad(PreferUserManaged, subject, type, SKOS.Concept));
dataset.add(simpleRdf.createQuad(PreferUserManaged, subject, DC.subject, AS.Activity));
assertEquals(3L, dataset.size(), "Confirm dataset size");
assertTrue(TriplestoreUtils.asJenaDataset(dataset).containsNamedModel(PreferUserManaged.getIRIString()),
"Confirm presence of trellis:PreferUserManaged named graph");
assertNotEquals(TriplestoreUtils.asJenaDataset(dataset).asDatasetGraph(),
TriplestoreUtils.asJenaDataset(dataset).asDatasetGraph(), "Confirm dataset has been converted");
}
代码示例来源:origin: trellis-ldp/trellis
@Test
public void testDatasetNoConversion() {
final Dataset dataset = jenaRdf.createDataset();
dataset.add(jenaRdf.createQuad(PreferUserManaged, subject, SKOS.prefLabel, literal));
dataset.add(jenaRdf.createQuad(PreferUserManaged, subject, type, SKOS.Concept));
dataset.add(jenaRdf.createQuad(PreferUserManaged, subject, DC.subject, AS.Activity));
assertEquals(3L, dataset.size(), "Confirm dataset size");
assertTrue(TriplestoreUtils.asJenaDataset(dataset).containsNamedModel(PreferUserManaged.getIRIString()),
"Confirm presence of trellis:PreferUserManaged named graph");
assertEquals(TriplestoreUtils.asJenaDataset(dataset).asDatasetGraph(),
TriplestoreUtils.asJenaDataset(dataset).asDatasetGraph(), "Confirm datasets are equal");
}
内容来源于网络,如有侵权,请联系作者删除!