本文整理汇总了Java中org.apache.commons.rdf.api.Graph类的典型用法代码示例。如果您正苦于以下问题:Java Graph类的具体用法?Java Graph怎么用?Java Graph使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Graph类属于org.apache.commons.rdf.api包,在下文中一共展示了Graph类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: testJsonLdNullCache
import org.apache.commons.rdf.api.Graph; //导入依赖的package包/类
@Test
public void testJsonLdNullCache() throws UnsupportedEncodingException {
final Map<String, String> properties = new HashMap<>();
properties.put("icon", "//www.trellisldp.org/assets/img/trellis.png");
properties.put("css", "//www.trellisldp.org/assets/css/trellis.css");
final ByteArrayOutputStream out = new ByteArrayOutputStream();
final IOService myservice = new JenaIOService(null, properties, emptySet(),
singleton("http://www.w3.org/ns/"), null);
myservice.write(getTriples(), out, JSONLD, rdf.createIRI("http://www.w3.org/ns/anno.jsonld"));
final String output = out.toString("UTF-8");
assertTrue(output.contains("\"http://purl.org/dc/terms/title\":[{\"@value\":\"A title\"}]"));
assertFalse(output.contains("\"@context\":"));
assertFalse(output.contains("\"@graph\":"));
final Graph graph = rdf.createGraph();
myservice.read(new ByteArrayInputStream(output.getBytes(UTF_8)), null, JSONLD).forEach(graph::add);
validateGraph(graph);
}
开发者ID:trellis-ldp,项目名称:trellis,代码行数:20,代码来源:IOServiceTest.java
示例2: testUpdate
import org.apache.commons.rdf.api.Graph; //导入依赖的package包/类
@Test
public void testUpdate() {
final Graph graph = rdf.createGraph();
getTriples().forEach(graph::add);
assertEquals(3L, graph.size());
service.update(graph, "DELETE WHERE { ?s <http://purl.org/dc/terms/title> ?o }", "test:info");
assertEquals(2L, graph.size());
service.update(graph, "INSERT { " +
"<> <http://purl.org/dc/terms/title> \"Other title\" } WHERE {}",
"trellis:repository/resource");
assertEquals(3L, graph.size());
service.update(graph, "DELETE WHERE { ?s ?p ?o };" +
"INSERT { <> <http://purl.org/dc/terms/title> \"Other title\" } WHERE {}",
"trellis:repository");
assertEquals(1L, graph.size());
assertEquals("<trellis:repository>", graph.stream().findFirst().map(Triple::getSubject)
.map(RDFTerm::ntriplesString).get());
}
开发者ID:trellis-ldp,项目名称:trellis,代码行数:19,代码来源:IOServiceTest.java
示例3: checkCardinality
import org.apache.commons.rdf.api.Graph; //导入依赖的package包/类
private static Predicate<Graph> checkCardinality(final IRI model) {
return graph -> {
final Map<IRI, Long> cardinality = graph.stream()
.filter(triple -> propertiesWithUriRange.contains(triple.getPredicate()))
.collect(groupingBy(Triple::getPredicate, counting()));
if (LDP.IndirectContainer.equals(model)) {
if (isNull(cardinality.get(LDP.insertedContentRelation)) || !hasMembershipProps(cardinality)) {
return true;
}
} else if (LDP.DirectContainer.equals(model) && !hasMembershipProps(cardinality)) {
return true;
}
return cardinality.entrySet().stream().map(Map.Entry::getValue).anyMatch(val -> val > 1);
};
}
开发者ID:trellis-ldp,项目名称:trellis,代码行数:18,代码来源:LdpConstraints.java
示例4: Authorization
import org.apache.commons.rdf.api.Graph; //导入依赖的package包/类
/**
* Create an Authorization object from an RDF graph.
*
* @param identifier the subject IRI
* @param graph the RDF graph
*/
public Authorization(final BlankNodeOrIRI identifier, final Graph graph) {
requireNonNull(identifier, "The Authorization identifier may not be null!");
requireNonNull(graph, "The input graph may not be null!");
this.identifier = identifier;
this.dataMap.put(ACL.agent, new HashSet<>());
this.dataMap.put(ACL.agentClass, new HashSet<>());
this.dataMap.put(ACL.agentGroup, new HashSet<>());
this.dataMap.put(ACL.mode, new HashSet<>());
this.dataMap.put(ACL.accessTo, new HashSet<>());
this.dataMap.put(ACL.default_, new HashSet<>());
graph.stream(identifier, null, null).filter(triple -> dataMap.containsKey(triple.getPredicate()))
.filter(triple -> triple.getObject() instanceof IRI)
.forEachOrdered(triple -> dataMap.get(triple.getPredicate()).add((IRI) triple.getObject()));
}
开发者ID:trellis-ldp,项目名称:trellis,代码行数:24,代码来源:Authorization.java
示例5: getAllAuthorizationsFor
import org.apache.commons.rdf.api.Graph; //导入依赖的package包/类
private Stream<Authorization> getAllAuthorizationsFor(final Resource resource, final Boolean top) {
LOGGER.debug("Checking ACL for: {}", resource.getIdentifier());
final Optional<IRI> parent = resourceService.getContainer(resource.getIdentifier());
if (resource.hasAcl()) {
try (final Graph graph = resource.stream(Trellis.PreferAccessControl).collect(toGraph())) {
final List<Authorization> authorizations = getAuthorizationFromGraph(graph);
if (!top && authorizations.stream().anyMatch(getInheritedAuth(resource.getIdentifier()))) {
return authorizations.stream().filter(getInheritedAuth(resource.getIdentifier()));
}
return authorizations.stream().filter(getAccessToAuth(resource.getIdentifier()));
} catch (final Exception ex) {
throw new RuntimeTrellisException(ex);
}
}
// Nothing here, check the parent
LOGGER.debug("No ACL for {}; looking up parent resource", resource.getIdentifier());
return parent.flatMap(resourceService::get).map(res -> getAllAuthorizationsFor(res, false))
.orElseGet(Stream::empty);
}
开发者ID:trellis-ldp,项目名称:trellis,代码行数:21,代码来源:WebACService.java
示例6: testEntity
import org.apache.commons.rdf.api.Graph; //导入依赖的package包/类
@Test
public void testEntity() {
final Triple triple = rdf.createTriple(identifier, RDFS.label, rdf.createLiteral("A label"));
when(mockResource.stream(eq(Trellis.PreferUserManaged))).thenAnswer(x -> of(triple));
when(mockLdpRequest.getPath()).thenReturn("resource");
final PatchHandler patchHandler = new PatchHandler(mockLdpRequest, insert,
mockResourceService, mockIoService, null);
final Response res = patchHandler.updateResource(mockResource).build();
assertEquals(NO_CONTENT, res.getStatusInfo());
verify(mockIoService).update(any(Graph.class), eq(insert), eq(identifier.getIRIString()));
verify(mockResourceService).put(eq(identifier), eq(LDP.RDFSource), any(Dataset.class));
}
开发者ID:trellis-ldp,项目名称:trellis,代码行数:18,代码来源:PatchHandlerTest.java
示例7: testJsonLdNullCache
import org.apache.commons.rdf.api.Graph; //导入依赖的package包/类
@Test
public void testJsonLdNullCache() throws UnsupportedEncodingException {
final Map<String, String> properties = new HashMap<>();
properties.put("icon",
"//s3.amazonaws.com/www.trellisldp.org/assets/img/trellis.png");
properties.put("css",
"//s3.amazonaws.com/www.trellisldp.org/assets/css/trellis.css");
final ByteArrayOutputStream out = new ByteArrayOutputStream();
final IOService myservice = new JenaIOService(null, properties, emptySet(),
singleton("http://www.w3.org/ns/"), null);
myservice.write(getTriples(), out, JSONLD, rdf.createIRI("http://www.w3.org/ns/anno.jsonld"));
final String output = out.toString("UTF-8");
assertTrue(output.contains("\"http://purl.org/dc/terms/title\":[{\"@value\":\"A title\"}]"));
assertFalse(output.contains("\"@context\":"));
assertFalse(output.contains("\"@graph\":"));
final Graph graph = rdf.createGraph();
myservice.read(new ByteArrayInputStream(output.getBytes(UTF_8)), null, JSONLD).forEach(graph::add);
validateGraph(graph);
}
开发者ID:trellis-ldp-archive,项目名称:trellis-io-jena,代码行数:22,代码来源:IOServiceTest.java
示例8: Authorization
import org.apache.commons.rdf.api.Graph; //导入依赖的package包/类
/**
* Create an Authorization object from an RDF graph
* @param identifier the subject IRI
* @param graph the RDF graph
*/
public Authorization(final BlankNodeOrIRI identifier, final Graph graph) {
requireNonNull(identifier, "The Authorization identifier may not be null!");
requireNonNull(graph, "The input graph may not be null!");
this.identifier = identifier;
this.dataMap.put(ACL.agent, new HashSet<>());
this.dataMap.put(ACL.agentClass, new HashSet<>());
this.dataMap.put(ACL.agentGroup, new HashSet<>());
this.dataMap.put(ACL.mode, new HashSet<>());
this.dataMap.put(ACL.accessTo, new HashSet<>());
this.dataMap.put(ACL.default_, new HashSet<>());
graph.stream(identifier, null, null).filter(triple -> dataMap.containsKey(triple.getPredicate()))
.filter(triple -> triple.getObject() instanceof IRI)
.forEachOrdered(triple -> dataMap.get(triple.getPredicate()).add((IRI) triple.getObject()));
}
开发者ID:trellis-ldp-archive,项目名称:trellis-webac,代码行数:23,代码来源:Authorization.java
示例9: getAllAuthorizationsFor
import org.apache.commons.rdf.api.Graph; //导入依赖的package包/类
private Stream<Authorization> getAllAuthorizationsFor(final Resource resource, final Boolean top) {
LOGGER.debug("Checking ACL for: {}", resource.getIdentifier());
final Optional<IRI> parent = resourceService.getContainer(resource.getIdentifier());
if (resource.hasAcl()) {
try (final Graph graph = resource.stream(Trellis.PreferAccessControl).collect(toGraph())) {
final List<Authorization> authorizations = getAuthorizationFromGraph(graph);
if (!top && authorizations.stream().anyMatch(getInheritedAuth(resource.getIdentifier()))) {
return authorizations.stream().filter(getInheritedAuth(resource.getIdentifier()));
}
return authorizations.stream().filter(getAccessToAuth(resource.getIdentifier()));
} catch (final Exception ex) {
throw new RuntimeRepositoryException(ex);
}
}
// Nothing here, check the parent
LOGGER.debug("No ACL for {}; looking up parent resource", resource.getIdentifier());
return parent.flatMap(resourceService::get).map(res -> getAllAuthorizationsFor(res, false))
.orElseGet(Stream::empty);
}
开发者ID:trellis-ldp-archive,项目名称:trellis-webac,代码行数:21,代码来源:WebACService.java
示例10: checkGraph
import org.apache.commons.rdf.api.Graph; //导入依赖的package包/类
private void checkGraph(final Graph g) throws Exception {
assertTrue(g.size() > 0);
final IRI greeting = factory.createIRI("http://example.com/greeting");
// Should only have parsed once!
assertEquals(1, g.stream(null, greeting, null).count());
final Triple triple = g.stream(null, greeting, null).findAny().get();
assertTrue(triple.getSubject() instanceof IRI);
final IRI parsing = (IRI) triple.getSubject();
assertTrue(parsing.getIRIString().startsWith("urn:uuid:"));
assertEquals("http://example.com/greeting", triple.getPredicate().getIRIString());
assertTrue(triple.getObject() instanceof Literal);
final Literal literal = (Literal) triple.getObject();
assertEquals("Hello world", literal.getLexicalForm());
assertFalse(literal.getLanguageTag().isPresent());
assertEquals(Types.XSD_STRING, literal.getDatatype());
// Check uniqueness of properties that are always present
assertEquals(1, g.stream(null, factory.createIRI("http://example.com/source"), null).count());
// Check optional properties that are unique
assertTrue(2 > g.stream(null, factory.createIRI("http://example.com/base"), null).count());
assertTrue(2 > g.stream(null, factory.createIRI("http://example.com/contentType"), null).count());
assertTrue(2 > g.stream(null, factory.createIRI("http://example.com/contentTypeSyntax"), null).count());
}
开发者ID:apache,项目名称:commons-rdf,代码行数:27,代码来源:AbstractRDFParserTest.java
示例11: parseFile
import org.apache.commons.rdf.api.Graph; //导入依赖的package包/类
@Test
public void parseFile() throws Exception {
try (final Graph g = factory.createGraph()) {
final RDFParser parser = dummyParser.source(testNt).target(g);
parser.parse().get(5, TimeUnit.SECONDS);
checkGraph(g);
// FIXME: this could potentially break if the equivalent of /tmp
// includes
// international characters
assertEquals("<" + testNt.toUri().toString() + ">", firstPredicate(g, "source"));
// Should be set to the file path - after following symlinks
assertEquals("<" + testNt.toRealPath().toUri().toString() + ">", firstPredicate(g, "base"));
// Should NOT have guessed the content type
assertNull(firstPredicate(g, "contentType"));
assertNull(firstPredicate(g, "contentTypeSyntax"));
}
}
开发者ID:apache,项目名称:commons-rdf,代码行数:19,代码来源:AbstractRDFParserTest.java
示例12: parseFileContentType
import org.apache.commons.rdf.api.Graph; //导入依赖的package包/类
@Test
public void parseFileContentType() throws Exception {
try (final Graph g = factory.createGraph()) {
final RDFParser parser = dummyParser.source(testNt).contentType(RDFSyntax.NTRIPLES).target(g);
parser.parse().get(5, TimeUnit.SECONDS);
checkGraph(g);
// FIXME: this could potentially break if the equivalent of /tmp
// includes
// international characters
assertEquals("<" + testNt.toUri().toString() + ">", firstPredicate(g, "source"));
// Should be set to the file path - after following symlinks
assertEquals("<" + testNt.toRealPath().toUri().toString() + ">", firstPredicate(g, "base"));
assertEquals("\"" + RDFSyntax.NTRIPLES.name() + "\"", firstPredicate(g, "contentTypeSyntax"));
assertEquals("\"application/n-triples\"", firstPredicate(g, "contentType"));
}
}
开发者ID:apache,项目名称:commons-rdf,代码行数:17,代码来源:AbstractRDFParserTest.java
示例13: parseInputStreamWithBase
import org.apache.commons.rdf.api.Graph; //导入依赖的package包/类
@Test
public void parseInputStreamWithBase() throws Exception {
final InputStream inputStream = new ByteArrayInputStream(new byte[0]);
final IRI base = dummyParser.createRDFTermFactory().createIRI("http://www.example.org/test.rdf");
try (final Graph g = factory.createGraph()) {
final RDFParser parser = dummyParser.source(inputStream).base(base).target(g);
parser.parse().get(5, TimeUnit.SECONDS);
checkGraph(g);
assertEquals("<http://www.example.org/test.rdf>", firstPredicate(g, "base"));
// in our particular debug output,
// bnode source indicates InputStream
assertTrue(firstPredicate(g, "source").startsWith("_:"));
assertNull(firstPredicate(g, "contentType"));
assertNull(firstPredicate(g, "contentTypeSyntax"));
}
}
开发者ID:apache,项目名称:commons-rdf,代码行数:17,代码来源:AbstractRDFParserTest.java
示例14: parseIRI
import org.apache.commons.rdf.api.Graph; //导入依赖的package包/类
@Test
public void parseIRI() throws Exception {
final IRI iri = dummyParser.createRDFTermFactory().createIRI("http://www.example.net/test.ttl");
try (final Graph g = factory.createGraph()) {
final RDFParser parser = dummyParser.source(iri).target(g);
parser.parse().get(5, TimeUnit.SECONDS);
checkGraph(g);
assertEquals("<http://www.example.net/test.ttl>", firstPredicate(g, "source"));
// No base - assuming the above IRI is always
// the base would break server-supplied base from
// any HTTP Location redirects and Content-Location header
assertNull(firstPredicate(g, "base"));
// ".ttl" in IRI string does not imply any content type
assertNull(firstPredicate(g, "contentType"));
assertNull(firstPredicate(g, "contentTypeSyntax"));
}
}
开发者ID:apache,项目名称:commons-rdf,代码行数:18,代码来源:AbstractRDFParserTest.java
示例15: checkGraph
import org.apache.commons.rdf.api.Graph; //导入依赖的package包/类
private void checkGraph(final Graph g) {
assertTrue(g.contains(test, type, Type));
// Should not include statements from the named graph
assertEquals(1, g.stream(test, pred1, null).count());
assertEquals(1, g.stream(test, pred2, null).count());
assertEquals("Hello", ((Literal) g.stream(test, pred1, null).findFirst().get().getObject()).getLexicalForm());
assertTrue(g.contains(test, pred2, other));
assertEquals("1337", ((Literal) g.stream(test, pred3, null).findFirst().get().getObject()).getLexicalForm());
assertEquals(Types.XSD_INTEGER,
((Literal) g.stream(test, pred3, null).findFirst().get().getObject()).getDatatype());
// While the named graph 'graph' is not included, the relationship
// to that @id is included.
assertTrue(g.contains(test, pred4, graph));
}
开发者ID:apache,项目名称:commons-rdf,代码行数:19,代码来源:JsonLdParserBuilderTest.java
示例16: write
import org.apache.commons.rdf.api.Graph; //导入依赖的package包/类
@Override
public void write(final Stream<? extends Triple> triples, final OutputStream output, final RDFSyntax syntax,
final IRI... profiles) {
requireNonNull(triples, "The triples stream may not be null!");
requireNonNull(output, "The output stream may not be null!");
requireNonNull(syntax, "The RDF syntax value may not be null!");
try {
if (RDFA.equals(syntax)) {
htmlSerializer.write(output, triples, profiles.length > 0 ? profiles[0] : null);
} else {
final Lang lang = rdf.asJenaLang(syntax).orElseThrow(() ->
new RuntimeTrellisException("Invalid content type: " + syntax.mediaType()));
final RDFFormat format = defaultSerialization(lang);
if (nonNull(format)) {
LOGGER.debug("Writing stream-based RDF: {}", format);
final StreamRDF stream = getWriterStream(output, format);
stream.start();
ofNullable(nsService).ifPresent(svc -> svc.getNamespaces().forEach(stream::prefix));
triples.map(rdf::asJenaTriple).forEachOrdered(stream::triple);
stream.finish();
} else {
LOGGER.debug("Writing buffered RDF: {}", lang);
final org.apache.jena.graph.Graph graph = createDefaultGraph();
ofNullable(nsService).map(NamespaceService::getNamespaces)
.ifPresent(graph.getPrefixMapping()::setNsPrefixes);
triples.map(rdf::asJenaTriple).forEachOrdered(graph::add);
if (JSONLD.equals(lang)) {
writeJsonLd(output, DatasetGraphFactory.create(graph), profiles);
} else {
RDFDataMgr.write(output, graph, lang);
}
}
}
} catch (final AtlasException ex) {
throw new RuntimeTrellisException(ex);
}
}
开发者ID:trellis-ldp,项目名称:trellis,代码行数:41,代码来源:JenaIOService.java
示例17: read
import org.apache.commons.rdf.api.Graph; //导入依赖的package包/类
@Override
public Stream<? extends Triple> read(final InputStream input, final String base, final RDFSyntax syntax) {
requireNonNull(input, "The input stream may not be null!");
requireNonNull(syntax, "The syntax value may not be null!");
try {
final org.apache.jena.graph.Graph graph = createDefaultGraph();
final Lang lang = rdf.asJenaLang(syntax).orElseThrow(() ->
new RuntimeTrellisException("Unsupported RDF Syntax: " + syntax.mediaType()));
RDFParser.source(input).lang(lang).base(base).parse(graph);
// Check the graph for any new namespace definitions
if (nonNull(nsService)) {
final Set<String> namespaces = nsService.getNamespaces().entrySet().stream().map(Map.Entry::getValue)
.collect(toSet());
graph.getPrefixMapping().getNsPrefixMap().forEach((prefix, namespace) -> {
if (!namespaces.contains(namespace)) {
LOGGER.debug("Setting prefix ({}) for namespace {}", prefix, namespace);
nsService.setPrefix(prefix, namespace);
}
});
}
return rdf.asGraph(graph).stream();
} catch (final RiotException | AtlasException ex) {
throw new RuntimeTrellisException(ex);
}
}
开发者ID:trellis-ldp,项目名称:trellis,代码行数:29,代码来源:JenaIOService.java
示例18: testJsonLdDefaultSerializer
import org.apache.commons.rdf.api.Graph; //导入依赖的package包/类
@Test
public void testJsonLdDefaultSerializer() throws UnsupportedEncodingException {
final ByteArrayOutputStream out = new ByteArrayOutputStream();
service3.write(getTriples(), out, JSONLD);
final String output = out.toString("UTF-8");
assertTrue(output.contains("\"http://purl.org/dc/terms/title\":[{\"@value\":\"A title\"}]"));
assertFalse(output.contains("\"@context\":"));
assertFalse(output.contains("\"@graph\":"));
final Graph graph = rdf.createGraph();
service3.read(new ByteArrayInputStream(output.getBytes(UTF_8)), null, JSONLD).forEach(graph::add);
validateGraph(graph);
}
开发者ID:trellis-ldp,项目名称:trellis,代码行数:14,代码来源:IOServiceTest.java
示例19: testJsonLdExpandedSerializer
import org.apache.commons.rdf.api.Graph; //导入依赖的package包/类
@Test
public void testJsonLdExpandedSerializer() throws UnsupportedEncodingException {
final ByteArrayOutputStream out = new ByteArrayOutputStream();
service.write(getTriples(), out, JSONLD, expanded);
final String output = out.toString("UTF-8");
assertTrue(output.contains("\"http://purl.org/dc/terms/title\":[{\"@value\":\"A title\"}]"));
assertFalse(output.contains("\"@context\":"));
assertFalse(output.contains("\"@graph\":"));
final Graph graph = rdf.createGraph();
service.read(new ByteArrayInputStream(output.getBytes(UTF_8)), null, JSONLD).forEach(graph::add);
validateGraph(graph);
}
开发者ID:trellis-ldp,项目名称:trellis,代码行数:14,代码来源:IOServiceTest.java
示例20: testJsonLdCustomSerializer
import org.apache.commons.rdf.api.Graph; //导入依赖的package包/类
@Test
public void testJsonLdCustomSerializer() throws UnsupportedEncodingException {
final ByteArrayOutputStream out = new ByteArrayOutputStream();
service.write(getTriples(), out, JSONLD, rdf.createIRI("http://www.w3.org/ns/anno.jsonld"));
final String output = out.toString("UTF-8");
assertTrue(output.contains("\"dcterms:title\":\"A title\""));
assertTrue(output.contains("\"type\":\"Text\""));
assertTrue(output.contains("\"@context\":"));
assertTrue(output.contains("\"@context\":\"http://www.w3.org/ns/anno.jsonld\""));
assertFalse(output.contains("\"@graph\":"));
final Graph graph = rdf.createGraph();
service.read(new ByteArrayInputStream(output.getBytes(UTF_8)), null, JSONLD).forEach(graph::add);
validateGraph(graph);
}
开发者ID:trellis-ldp,项目名称:trellis,代码行数:16,代码来源:IOServiceTest.java
注:本文中的org.apache.commons.rdf.api.Graph类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论