本文整理汇总了Java中org.openrdf.repository.RepositoryResult类的典型用法代码示例。如果您正苦于以下问题:Java RepositoryResult类的具体用法?Java RepositoryResult怎么用?Java RepositoryResult使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RepositoryResult类属于org.openrdf.repository包,在下文中一共展示了RepositoryResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: tuplePattern
import org.openrdf.repository.RepositoryResult; //导入依赖的package包/类
/**
* Tuple pattern query - find all statements with the pattern, where null is
* a wild card
*
* @param s
* subject (null for wildcard)
* @param p
* predicate (null for wildcard)
* @param o
* object (null for wildcard)
* @return serialized graph of results
*/
public List tuplePattern(URI s, URI p, Value o) {
try {
RepositoryConnection con = therepository.getConnection();
try {
RepositoryResult repres = con.getStatements(s, p, o, true, new Resource[0]);
ArrayList reslist = new ArrayList();
while (repres.hasNext()) {
reslist.add(repres.next());
}
return reslist;
} finally {
con.close();
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
示例2: extractAllStatements
import org.openrdf.repository.RepositoryResult; //导入依赖的package包/类
@Override
public LinkedList<Statement> extractAllStatements(Repository repo, int nrTriples) {
RepositoryConnection con = repo.getConnection();
RepositoryResult<Statement> triples = con.getStatements(null, null,
null, false);
LinkedList<Statement> statements = new LinkedList<Statement>();
try {
System.out.println("triples to extract: "+nrTriples);
if(nrTriples == -1)
Iterations.addAll(triples, statements);
else {
int count = 0;
while(triples.hasNext() && count < nrTriples){
statements.add(triples.next());
count++;
}
}
} finally {
triples.close();
con.close();
}
return statements;
}
示例3: testBefore
import org.openrdf.repository.RepositoryResult; //导入依赖的package包/类
public void testBefore() throws Exception {
GregorianCalendar cal;
XMLGregorianCalendar yesterday;
int n = DatatypeConstants.FIELD_UNDEFINED;
DatatypeFactory f = DatatypeFactory.newInstance();
cal = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
yesterday = f.newXMLGregorianCalendar(cal);
yesterday.setTime(n, n, n, n);
yesterday.add(f.newDurationDayTime("-P1D"));
con.add(vf.createURI(PURL1), lastResolved, vf.createLiteral(yesterday));
domain.setPurlMaxUnresolvedDays(1);
domain.validatePURLs(xgc, 1, 1, xgc);
assertTrue(con.getObject(PURL1) instanceof Unresolvable);
RepositoryResult<Statement> stmts = con.getStatements(vf.createURI(PURL1), lastResolved, null);
assertTrue(stmts.hasNext());
Literal lit = (Literal) stmts.next().getObject();
assertEquals(xgc, lit.calendarValue());
}
示例4: testMMRTS152
import org.openrdf.repository.RepositoryResult; //导入依赖的package包/类
public void testMMRTS152() throws Exception {
RepositoryConnection conn = repository.getConnection();
URI loadPerc = vf.createURI(litdupsNS, "testPred");
URI uri1 = vf.createURI(litdupsNS, "uri1");
conn.add(cpu, loadPerc, uri1);
conn.commit();
RepositoryResult<Statement> result = conn.getStatements(cpu, loadPerc, null, false, new Resource[0]);
// RdfCloudTripleStoreCollectionStatementsIterator iterator = new RdfCloudTripleStoreCollectionStatementsIterator(
// cpu, loadPerc, null, store.connector,
// vf, new Configuration(), null);
while (result.hasNext()) {
assertTrue(result.hasNext());
assertNotNull(result.next());
}
conn.close();
}
示例5: testDuplicateLiterals
import org.openrdf.repository.RepositoryResult; //导入依赖的package包/类
public void testDuplicateLiterals() throws Exception {
RepositoryConnection conn = repository.getConnection();
URI loadPerc = vf.createURI(litdupsNS, "loadPerc");
Literal lit1 = vf.createLiteral(0.0);
Literal lit2 = vf.createLiteral(0.0);
Literal lit3 = vf.createLiteral(0.0);
conn.add(cpu, loadPerc, lit1);
conn.add(cpu, loadPerc, lit2);
conn.add(cpu, loadPerc, lit3);
conn.commit();
RepositoryResult<Statement> result = conn.getStatements(cpu, loadPerc, null, true, new Resource[0]);
int count = 0;
while (result.hasNext()) {
count++;
result.next();
}
result.close();
assertEquals(1, count);
//clean up
conn.remove(cpu, loadPerc, lit1);
conn.close();
}
示例6: testNotDuplicateUris
import org.openrdf.repository.RepositoryResult; //导入依赖的package包/类
public void testNotDuplicateUris() throws Exception {
RepositoryConnection conn = repository.getConnection();
URI loadPerc = vf.createURI(litdupsNS, "loadPerc");
URI uri1 = vf.createURI(litdupsNS, "uri1");
URI uri2 = vf.createURI(litdupsNS, "uri1");
URI uri3 = vf.createURI(litdupsNS, "uri1");
conn.add(cpu, loadPerc, uri1);
conn.add(cpu, loadPerc, uri2);
conn.add(cpu, loadPerc, uri3);
conn.commit();
RepositoryResult<Statement> result = conn.getStatements(cpu, loadPerc, null, true, new Resource[0]);
int count = 0;
while (result.hasNext()) {
count++;
result.next();
}
result.close();
assertEquals(1, count);
//clean up
conn.remove(cpu, loadPerc, uri1);
conn.close();
}
示例7: testNamedGraphLoad2
import org.openrdf.repository.RepositoryResult; //导入依赖的package包/类
public void testNamedGraphLoad2() throws Exception {
InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream("namedgraphs.trig");
assertNotNull(stream);
RepositoryConnection conn = repository.getConnection();
conn.add(stream, "", RDFFormat.TRIG);
conn.commit();
RepositoryResult<Statement> statements = conn.getStatements(null, vf.createURI("http://www.example.org/vocabulary#name"), null, true, vf.createURI("http://www.example.org/exampleDocument#G1"));
int count = 0;
while (statements.hasNext()) {
statements.next();
count++;
}
statements.close();
assertEquals(1, count);
conn.close();
}
示例8: testGetNamespaces
import org.openrdf.repository.RepositoryResult; //导入依赖的package包/类
public void testGetNamespaces() throws Exception {
String namespace = "urn:testNamespace#";
String prefix = "pfx";
connection.setNamespace(prefix, namespace);
namespace = "urn:testNamespace2#";
prefix = "pfx2";
connection.setNamespace(prefix, namespace);
RepositoryResult<Namespace> result = connection.getNamespaces();
int count = 0;
while (result.hasNext()) {
result.next();
count++;
}
assertEquals(2, count);
}
示例9: testGetStatement1
import org.openrdf.repository.RepositoryResult; //导入依赖的package包/类
@Test
public void testGetStatement1()
throws Exception {
Resource context1 = conn.getValueFactory().createURI("http://marklogic.com/test/context1");
Resource context2 = conn.getValueFactory().createURI("http://marklogic.com/test/context2");
File inputFile1 = new File("src/test/resources/testdata/default-graph-1.ttl");
conn.add(inputFile1, "http://example.org/example1/", RDFFormat.TURTLE, (Resource) null);
File inputFile2 = new File("src/test/resources/testdata/default-graph-2.ttl");
conn.add(inputFile2, "http://example.org/example1/", RDFFormat.TURTLE, context1);
File inputFile3 = new File("src/test/resources/testdata/default-graph-2.ttl");
conn.add(inputFile3, "http://example.org/example1/", RDFFormat.TURTLE, context2);
conn.clear(null, context1);
RepositoryResult<Statement> statements = conn.getStatements(null, null, null, true);
Model model = Iterations.addAll(statements, new LinkedHashModel());
Assert.assertEquals(4, model.size());
conn.clear();
}
示例10: testGetStatementIsEqualToSize
import org.openrdf.repository.RepositoryResult; //导入依赖的package包/类
@Test
public void testGetStatementIsEqualToSize() throws Exception{
Resource context5 = conn.getValueFactory().createURI("http://marklogic.com/test/context5");
ValueFactory f= conn.getValueFactory();
URI alice = f.createURI("http://example.org/people/alice");
URI bob = f.createURI("http://example.org/people/bob");
URI name = f.createURI("http://example.org/ontology/name");
URI person = f.createURI("http://example.org/ontology/Person");
Literal bobsName = f.createLiteral("Bob");
Literal alicesName = f.createLiteral("Alice");
conn.add(alice, RDF.TYPE, person, null, context5);
conn.add(alice, name, alicesName, null, context5);
conn.add(bob, RDF.TYPE, person, context5);
conn.add(bob, name, bobsName, context5);
RepositoryResult<Statement> statements = conn.getStatements(null, null, null, true, null,context5);
Model aboutPeople = Iterations.addAll(statements, new LinkedHashModel());
Assert.assertEquals(conn.size(null,context5),aboutPeople.size());
conn.clear(null,context5);
}
示例11: testGetStatementsMalformedTypedLiteral
import org.openrdf.repository.RepositoryResult; //导入依赖的package包/类
@Test
public void testGetStatementsMalformedTypedLiteral()
throws Exception
{
testAdminCon.getParserConfig().addNonFatalError(BasicParserSettings.VERIFY_DATATYPE_VALUES);
Literal invalidIntegerLiteral = vf.createLiteral("four", XMLSchema.INTEGER);
try {
testAdminCon.add(micah, homeTel, invalidIntegerLiteral, dirgraph);
RepositoryResult<Statement> statements = testAdminCon.getStatements(micah, homeTel, null, true);
assertNotNull(statements);
assertTrue(statements.hasNext());
Statement st = statements.next();
assertTrue(st.getObject() instanceof Literal);
assertTrue(st.getObject().equals(invalidIntegerLiteral));
}
catch (RepositoryException e) {
// shouldn't happen
fail(e.getMessage());
}
}
示例12: getStoredModelIds
import org.openrdf.repository.RepositoryResult; //导入依赖的package包/类
/**
* Retrieve a collection of all file/stored model ids found in the repo.<br>
* Note: Models may not be loaded at this point.
*
* @return set of modelids.
* @throws IOException
*/
public Set<IRI> getStoredModelIds() throws IOException {
try {
BigdataSailRepositoryConnection connection = repo.getReadOnlyConnection();
try {
RepositoryResult<Resource> graphs = connection.getContextIDs();
Set<IRI> modelIds = new HashSet<>();
while (graphs.hasNext()) {
modelIds.add(IRI.create(graphs.next().stringValue()));
}
graphs.close();
return Collections.unmodifiableSet(modelIds);
} finally {
connection.close();
}
} catch (RepositoryException e) {
throw new IOException(e);
}
}
示例13: loadModelABox
import org.openrdf.repository.RepositoryResult; //导入依赖的package包/类
@Override
protected OWLOntology loadModelABox(IRI modelId) throws OWLOntologyCreationException {
LOG.info("Load model abox: " + modelId + " from database");
try {
BigdataSailRepositoryConnection connection = repo.getReadOnlyConnection();
try {
//TODO repeated code with loadModel
RepositoryResult<Resource> graphs = connection.getContextIDs();
if (!Iterations.asSet(graphs).contains(new URIImpl(modelId.toString()))) {
throw new OWLOntologyCreationException("No such model in datastore: " + modelId);
}
graphs.close();
RepositoryResult<Statement> statements =
connection.getStatements(null, null, null, false, new URIImpl(modelId.toString()));
OWLOntology abox = loadOntologyDocumentSource(new RioMemoryTripleSource(statements), true);
statements.close();
abox = postLoadFileFilter(abox);
return abox;
} finally {
connection.close();
}
} catch (RepositoryException e) {
throw new OWLOntologyCreationException(e);
}
}
示例14: deletePlainAnnotation
import org.openrdf.repository.RepositoryResult; //导入依赖的package包/类
@Test
public void deletePlainAnnotation() throws RepositoryException, IllegalAccessException, InstantiationException, QueryEvaluationException, ParseException, MalformedQueryException {
// Create test annotation
Annotation annotation = anno4j.createObject(Annotation.class);
annotation.setCreated("2015-01-28T12:00:00Z");
annotation.setGenerated("2015-01-28T12:00:00Z");
// query persisted object
Annotation result = (Annotation) anno4j.createQueryService().execute().get(0);
assertEquals(annotation.getResource().toString(), result.getResource().toString());
// delete the annotation
result.delete();
// checking if there are no statements left
RepositoryResult<Statement> statements = anno4j.getObjectRepository().getConnection().getStatements(null, null, null);
assertEquals(false, statements.hasNext());
// confirming the empty result set with the QueryService
List<Annotation> emptyList = anno4j.createQueryService().execute();
assertEquals(0, emptyList.size());
}
示例15: getTypes
import org.openrdf.repository.RepositoryResult; //导入依赖的package包/类
public Set<URI> getTypes(Resource res) throws RepositoryException {
if (!readTypes)
return Collections.emptySet();
RepositoryResult<Statement> match = conn.getStatements(res, RDF.TYPE, null);
try {
if (!match.hasNext())
return Collections.emptySet();
Value obj = match.next().getObject();
if (obj instanceof URI && !match.hasNext())
return Collections.singleton((URI) obj);
Set<URI> types = new HashSet<URI>(4);
if (obj instanceof URI) {
types.add((URI) obj);
}
while (match.hasNext()) {
obj = match.next().getObject();
if (obj instanceof URI) {
types.add((URI) obj);
}
}
return types;
} finally {
match.close();
}
}