本文整理汇总了Java中org.apache.jena.sparql.core.DatasetGraph.find方法的典型用法代码示例。如果您正苦于以下问题:Java DatasetGraph.find方法的具体用法?Java DatasetGraph.find怎么用?Java DatasetGraph.find使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.jena.sparql.core.DatasetGraph
的用法示例。
在下文中一共展示了DatasetGraph.find方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: assertIdentical
import org.apache.jena.sparql.core.DatasetGraph; //导入方法依赖的package包/类
private void assertIdentical(final String uri, final String originalRdf) throws IOException {
try (CloseableDataset roundtripped = getDataset(new HttpGet(uri))) {
try (CloseableDataset original = parseTriples(new ByteArrayInputStream(originalRdf.getBytes()))) {
final DatasetGraph originalGraph = original.asDatasetGraph();
final DatasetGraph roundtrippedGraph = roundtripped.asDatasetGraph();
final Iterator<Quad> originalQuadIt = originalGraph.find();
while (originalQuadIt.hasNext()) {
final Quad q = originalQuadIt.next();
assertTrue(q + " should be preserved through a roundtrip! \nOriginal RDF: " + originalRdf
+ "\nRoundtripped Graph:\n" + roundtrippedGraph, roundtrippedGraph.contains(q));
roundtrippedGraph.delete(q);
}
assertTrue("Roundtripped graph had extra quads! " + roundtrippedGraph, roundtrippedGraph.isEmpty());
}
}
}
示例2: testGetObjectVersionProfile
import org.apache.jena.sparql.core.DatasetGraph; //导入方法依赖的package包/类
@Test
public void testGetObjectVersionProfile() throws IOException {
final String id = getRandomUniqueId();
final String label = "v0.0.1";
createObjectAndClose(id);
enableVersioning(id);
postObjectVersion(id, label);
logger.debug("Retrieved version profile:");
try (final CloseableDataset dataset = getDataset(new HttpGet(serverAddress + id + "/fcr:versions"))) {
final DatasetGraph graph = dataset.asDatasetGraph();
assertEquals("Expected exactly 3 triples!", 3, countTriples(graph));
final Resource subject = createResource(serverAddress + id);
final Iterator<Quad> hasVersionTriple = graph.find(ANY, subject.asNode(), HAS_VERSION.asNode(), ANY);
assertTrue("Didn't find a version triple!", hasVersionTriple.hasNext());
final Node versionURI = hasVersionTriple.next().getObject();
assertFalse("Found extra version triple!", hasVersionTriple.hasNext());
assertTrue("Version label wasn't presented!",
graph.contains(ANY, versionURI, HAS_VERSION_LABEL.asNode(), createLiteral(label)));
assertTrue("Version creation date wasn't present!",
graph.contains(ANY, versionURI, CREATED_DATE.asNode(), ANY));
}
}
示例3: testVersioningANodeWithAVersionableChild
import org.apache.jena.sparql.core.DatasetGraph; //导入方法依赖的package包/类
@Test
public void testVersioningANodeWithAVersionableChild() throws IOException {
final String id = getRandomUniqueId();
createObjectAndClose(id);
enableVersioning(id);
logger.debug("Adding a child");
createDatastream(id, "ds", "This DS will not be versioned");
logger.debug("Posting version");
postObjectVersion(id, "label");
logger.debug("Retrieved version profile:");
try (final CloseableDataset dataset = getDataset(new HttpGet(serverAddress + id + "/fcr:versions"))) {
final DatasetGraph results = dataset.asDatasetGraph();
final Node subject = createURI(serverAddress + id);
assertTrue("Didn't find a version triple!", results.contains(ANY, subject, HAS_VERSION.asNode(), ANY));
final Iterator<Quad> versionIt = results.find(ANY, subject, HAS_VERSION.asNode(), ANY);
while (versionIt.hasNext()) {
final String url = versionIt.next().getObject().getURI();
assertEquals("Version " + url + " isn't accessible!", OK.getStatusCode(), getStatus(new HttpGet(url)));
}
}
}
示例4: testBinaryVersionFixity
import org.apache.jena.sparql.core.DatasetGraph; //导入方法依赖的package包/类
@Test
public void testBinaryVersionFixity() throws IOException {
final String id = getRandomUniqueId();
createObjectAndClose(id);
createDatastream(id, "dsid", "foo");
logger.debug("Creating binary content version v0 ...");
postVersion(id + "/dsid", "v0");
try (final CloseableDataset dataset =
getDataset(new HttpGet(serverAddress + id + "/dsid/fcr%3aversions/v0/fcr:fixity"))) {
final DatasetGraph graphStore = dataset.asDatasetGraph();
logger.debug("Got binary content versioned fixity triples {}", graphStore);
final Iterator<Quad> stmtIt = graphStore.find(ANY, ANY, HAS_FIXITY_RESULT.asNode(), ANY);
assertTrue(stmtIt.hasNext());
assertTrue(graphStore.contains(ANY, ANY, HAS_FIXITY_STATE.asNode(), createLiteral("SUCCESS")));
assertTrue(graphStore.contains(ANY, ANY, HAS_MESSAGE_DIGEST.asNode(), ANY));
assertTrue(graphStore.contains(ANY, ANY, HAS_SIZE.asNode(), createLiteral("3", IntegerType)));
}
}
示例5: testCreateGraphWithBlanknodes
import org.apache.jena.sparql.core.DatasetGraph; //导入方法依赖的package包/类
@Test
public void testCreateGraphWithBlanknodes() throws IOException {
final String subjectURI = serverAddress + getRandomUniqueId();
final HttpPut createMethod = new HttpPut(subjectURI);
createMethod.addHeader(CONTENT_TYPE, "text/n3");
createMethod.setEntity(new StringEntity("<" + subjectURI + "> <info:some-predicate> _:a ." +
"_:a <info:test#label> \"asdfg\""));
assertEquals(CREATED.getStatusCode(), getStatus(createMethod));
final HttpGet getObjMethod = new HttpGet(subjectURI);
getObjMethod.addHeader(ACCEPT, "application/rdf+xml");
try (final CloseableDataset dataset = getDataset(getObjMethod)) {
final DatasetGraph graph = dataset.asDatasetGraph();
final Iterator<Quad> quads =
graph.find(ANY, createURI(subjectURI), createURI("info:some-predicate"), ANY);
assertTrue("Didn't find skolemized blank node assertion", quads.hasNext());
final Node skolemizedNode = quads.next().getObject();
assertTrue("Didn't find a triple we tried to create!", graph.contains(ANY,
skolemizedNode, createURI("info:test#label"), createLiteral("asdfg")));
}
}
示例6: testGetObjectGraphWithChildren
import org.apache.jena.sparql.core.DatasetGraph; //导入方法依赖的package包/类
@Test
public void testGetObjectGraphWithChildren() throws IOException {
final String id = getRandomUniqueId();
final String location = getLocation(createObject(id));
// Create some children
final int CHILDREN_TOTAL = 20;
for (int x = 0; x < CHILDREN_TOTAL; ++x) {
createObjectAndClose(id + "/child-" + x);
}
final int CHILDREN_LIMIT = 12;
final HttpGet httpGet = getObjMethod(id);
httpGet.setHeader("Limit", Integer.toString(CHILDREN_LIMIT));
try (final CloseableHttpResponse response = execute(httpGet)) {
try (final CloseableDataset dataset = getDataset(response)) {
final DatasetGraph graph = dataset.asDatasetGraph();
final Iterator<Quad> contains = graph.find(ANY, createURI(location), CONTAINS.asNode(), ANY);
assertTrue("Should find contained child!", contains.hasNext());
assertEquals(CHILDREN_LIMIT, Iterators.size(contains));
}
}
}
示例7: stringToQuad
import org.apache.jena.sparql.core.DatasetGraph; //导入方法依赖的package包/类
/**
* Parse a string into a Quad
* @param rdf the RDF object
* @param line the line of text
* @return the Quad
*/
public static Optional<Quad> stringToQuad(final RDF rdf, final String line) {
final DatasetGraph dataset = create();
try {
fromString(line).lang(NQUADS).parse(dataset);
} catch (final RiotException ex) {
LOGGER.warn("Skipping invalid data value: {}", line);
return empty();
}
final Iterator<org.apache.jena.sparql.core.Quad> i = dataset.find();
if (i.hasNext()) {
return of(i.next()).map(x -> asQuad(rdf, x));
}
return empty();
}
示例8: testFindByLiteralWithLanguage
import org.apache.jena.sparql.core.DatasetGraph; //导入方法依赖的package包/类
@Test
public void testFindByLiteralWithLanguage() {
Node g = NodeFactory.createURI("http://example.org/g");
Node s = NodeFactory.createURI("s");
Node p = NodeFactory.createURI("p");
Node o = NodeFactory.createLiteral("abc", "en");
DatasetGraph markLogicDatasetGraph = getMarkLogicDatasetGraph();
markLogicDatasetGraph.add(g, s, p, o);
Iterator<Quad> iter = markLogicDatasetGraph.find(g, null, null, o);
Quad quad = iter.next();
assertEquals("abc", quad.getObject().getLiteralLexicalForm());
assertEquals("en", quad.getObject().getLiteralLanguage());
}
示例9: testConcurrentPuts
import org.apache.jena.sparql.core.DatasetGraph; //导入方法依赖的package包/类
@Test
public void testConcurrentPuts() throws InterruptedException, IOException {
final String parent = getRandomUniqueId();
executeAndClose(putObjMethod(parent));
final String newResource = parent + "/test";
final Runnable updateRunnable = () -> { executeAndClose(putObjMethod(newResource)); };
final Thread t1 = new Thread(updateRunnable);
final Thread t2 = new Thread(updateRunnable);
final Thread t3 = new Thread(updateRunnable);
final Thread t4 = new Thread(updateRunnable);
t1.start();
t2.start();
t3.start();
t4.start();
t1.join();
t2.join();
t3.join();
t4.join();
try (final CloseableDataset dataset = getDataset(getObjMethod(parent))) {
final DatasetGraph graphStore = dataset.asDatasetGraph();
final Iterator<Quad> children = graphStore.find(ANY, ANY, CONTAINS.asNode(), ANY);
assertTrue("One of the PUTs should have resulted in a child.", children.hasNext());
children.next();
if (children.hasNext()) {
fail("Only one of the PUTs should have resulted in a child (unexpected child "
+ children.next().getObject().getURI() + ")!");
}
}
}
示例10: getChildrenTriples
import org.apache.jena.sparql.core.DatasetGraph; //导入方法依赖的package包/类
private Stream<Triple> getChildrenTriples(final DatasetGraph graph, final String subject) {
final Iterator<Quad> quads =
graph.find(ANY, createURI(subject), createProperty(LDP + "contains").asNode(), ANY);
return iteratorToStream(quads).map(Quad::asTriple);
}
示例11: testConcurrentPutsWithPairtrees
import org.apache.jena.sparql.core.DatasetGraph; //导入方法依赖的package包/类
@Test
public void testConcurrentPutsWithPairtrees() throws InterruptedException, IOException {
final String parent = getRandomUniqueId();
executeAndClose(putObjMethod(parent));
final String first = parent + "/00/1";
final String second = parent + "/00/2";
final String third = parent + "/00/3";
final String fourth = parent + "/00/4";
final Thread t1 = new Thread(() -> { executeAndClose(putObjMethod(first));});
final Thread t2 = new Thread(() -> { executeAndClose(putObjMethod(second)); });
final Thread t3 = new Thread(() -> { executeAndClose(putObjMethod(third)); });
final Thread t4 = new Thread(() -> { executeAndClose(putObjMethod(fourth)); });
t1.start();
t2.start();
t3.start();
t4.start();
t1.join();
t2.join();
t3.join();
t4.join();
try (final CloseableDataset dataset = getDataset(getObjMethod(parent))) {
final DatasetGraph graphStore = dataset.asDatasetGraph();
final List<String> childPaths = new ArrayList<String>();
final Iterator<Quad> children = graphStore.find(ANY, ANY, CONTAINS.asNode(), ANY);
assertTrue("Four children should have been created (none found).", children.hasNext());
childPaths.add(children.next().getObject().getURI());
LOGGER.info("Found child: {}", childPaths.get(0));
assertTrue("Four children should have been created (only one found).", children.hasNext());
childPaths.add(children.next().getObject().getURI());
LOGGER.info("Found child: {}", childPaths.get(1));
assertTrue("Four children should have been created (only two found).", children.hasNext());
childPaths.add(children.next().getObject().getURI());
LOGGER.info("Found child: {}", childPaths.get(2));
assertTrue("Four children should have been created. (only three found)", children.hasNext());
childPaths.add(children.next().getObject().getURI());
LOGGER.info("Found child: {}", childPaths.get(3));
assertFalse("Only four children should have been created.", children.hasNext());
assertTrue(childPaths.contains(serverAddress + first));
assertTrue(childPaths.contains(serverAddress + second));
assertTrue(childPaths.contains(serverAddress + third));
assertTrue(childPaths.contains(serverAddress + fourth));
}
}
示例12: testConcurrentPatches
import org.apache.jena.sparql.core.DatasetGraph; //导入方法依赖的package包/类
@Test
public void testConcurrentPatches() throws IOException, InterruptedException {
// create a resource
final String path = getRandomUniqueId();
executeAndClose(putObjMethod(path));
final int[] responseCodes = new int[4];
final Thread t1 = new Thread(() -> { responseCodes[0] = patchWithSparql(path,
"PREFIX dc: <http://purl.org/dc/elements/1.1/>\nINSERT DATA { <> dc:identifier 'one' . }");});
final Thread t2 = new Thread(() -> { responseCodes[1] = patchWithSparql(path,
"PREFIX dc: <http://purl.org/dc/elements/1.1/>\nINSERT DATA { <> dc:identifier 'two' . }");});
final Thread t3 = new Thread(() -> { responseCodes[2] = patchWithSparql(path,
"PREFIX dc: <http://purl.org/dc/elements/1.1/>\nINSERT DATA { <> dc:identifier 'three' . }");});
final Thread t4 = new Thread(() -> { responseCodes[3] = patchWithSparql(path,
"PREFIX dc: <http://purl.org/dc/elements/1.1/>\nINSERT DATA { <> dc:identifier 'four' . }");});
t1.start();
t2.start();
t3.start();
t4.start();
t1.join();
t2.join();
t3.join();
t4.join();
assertEquals("Patch should have succeeded!", 204, responseCodes[0]);
assertEquals("Patch should have succeeded!", 204, responseCodes[1]);
assertEquals("Patch should have succeeded!", 204, responseCodes[2]);
assertEquals("Patch should have succeeded!", 204, responseCodes[3]);
try (final CloseableDataset dataset = getDataset(getObjMethod(path))) {
final DatasetGraph graphStore = dataset.asDatasetGraph();
final List<String> missingDcIdentifiers
= new ArrayList<>(Arrays.asList(new String[] { "one", "two", "three", "four" }));
final Iterator<Quad> dcIdentifierIt = graphStore.find(ANY, createURI(serverAddress + path),
createProperty("http://purl.org/dc/elements/1.1/identifier").asNode(), ANY);
while (dcIdentifierIt.hasNext()) {
final String value = dcIdentifierIt.next().getObject().getLiteralValue().toString();
assertTrue("Unexpected dc:identifier found: " + value, missingDcIdentifiers.remove(value));
}
assertTrue("All of the dc:identifiers should have been applied! (missing "
+ Arrays.toString(missingDcIdentifiers.toArray()) + ")", missingDcIdentifiers.isEmpty());
assertTrue("Added property must exist!", graphStore.contains(ANY, createURI(serverAddress + path),
createProperty("http://purl.org/dc/elements/1.1/identifier").asNode(), createLiteral("one")));
assertTrue("Added property must exist!", graphStore.contains(ANY, createURI(serverAddress + path),
createProperty("http://purl.org/dc/elements/1.1/identifier").asNode(), createLiteral("two")));
assertTrue("Added property must exist!", graphStore.contains(ANY, createURI(serverAddress + path),
createProperty("http://purl.org/dc/elements/1.1/identifier").asNode(), createLiteral("three")));
assertTrue("Added property must exist!", graphStore.contains(ANY, createURI(serverAddress + path),
createProperty("http://purl.org/dc/elements/1.1/identifier").asNode(), createLiteral("four")));
}
}