Java Code Examples for org.openrdf.model.Statement#getObject()
The following examples show how to use
org.openrdf.model.Statement#getObject() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RMLMappingFactory.java From GeoTriples with Apache License 2.0 | 6 votes |
protected static Set<Value> extractValuesFromResource( CustomSesameDataset r2rmlMappingGraph, Resource termType) throws InvalidR2RMLStructureException { List<Statement> statements = r2rmlMappingGraph.tuplePattern(termType, null, null); if (statements.isEmpty()) { return null; } Set<Value> values = new HashSet<Value>(); for (Statement statement : statements) { Value value = statement.getObject(); values.add(value); } return values; }
Example 2
Source File: RangeQueriesTest.java From cumulusrdf with Apache License 2.0 | 6 votes |
@Test public void inverseValueOrderSubjTest() throws CumulusStoreException { Value[] query = new Value[2]; query[0] = buildResource(_subject); query[1] = buildResource(_predicate); Iterator<Statement> iter = _tripleStore.range(query, null, true, null, true, true, Integer.MAX_VALUE); assertTrue(iter != null && iter.hasNext()); double last = Double.MAX_VALUE; double current = Double.MAX_VALUE; while (iter.hasNext()) { last = current; final Statement res = iter.next(); Literal lit = (Literal) res.getObject(); current = Double.parseDouble(lit.getLabel()); assertTrue(last >= current); } }
Example 3
Source File: AbstractDataAndSPARQLTestCase.java From database with GNU General Public License v2.0 | 6 votes |
@Override public void handleStatement(final Statement stmt) throws RDFHandlerException { final Resource s = stmt.getSubject(); final URI p = stmt.getPredicate(); final Value o = stmt.getObject(); final Resource c = stmt.getContext() == null ? this.context : stmt.getContext(); // if (log.isDebugEnabled()) // log.debug("<" + s + "," + p + "," + o + "," + c + ">"); buffer.add(s, p, o, c, StatementEnum.Explicit); n++; }
Example 4
Source File: ForwardChainingRDFSInferencerConnection.java From semweb4j with BSD 2-Clause "Simplified" License | 6 votes |
private int applyRuleRdfs4b() throws SailException { int nofInferred = 0; Iterator<Statement> iter = this.newThisIteration.match(null, null, null); while (iter.hasNext()) { Statement st = iter.next(); Value uuu = st.getObject(); if (uuu instanceof Resource) { boolean added = addInferredStatement((Resource)uuu, RDF.TYPE, RDFS.RESOURCE); if (added) { nofInferred++; } } } return nofInferred; }
Example 5
Source File: LoadPdb.java From database with GNU General Public License v2.0 | 5 votes |
public static void readSomeData(Repository repo) throws Exception { RepositoryConnection cxn = repo.getConnection(); int counter = 0; try { RepositoryResult<Statement> stmts = cxn.getStatements(null, null, null, true /* * include * inferred */); while (stmts.hasNext()) { Statement stmt = stmts.next(); Resource s = stmt.getSubject(); URI p = stmt.getPredicate(); Value o = stmt.getObject(); // do something with the statement LOG.info(stmt); // cast to BigdataStatement to get at additional information BigdataStatement bdStmt = (BigdataStatement) stmt; if (bdStmt.isExplicit()) { // do one thing } else if (bdStmt.isInferred()) { // do another thing } else { // bdStmt.isAxiom() // do something else } LOG.info(bdStmt.getStatementType()); counter++; } } finally { // close the repository connection cxn.close(); LOG.info("Number of Triples: " + counter); } }
Example 6
Source File: Util.java From cumulusrdf with Apache License 2.0 | 5 votes |
/** * Converts a statement to an array of its RDF values. * * @param stmt - statement to be converted * @return array containing the RDF values comprised in the statement. */ public static Value[] toValueArray(Statement stmt) { Value[] out = new Value[stmt.getContext() == null ? 3 : 4]; out[0] = stmt.getSubject(); out[1] = stmt.getPredicate(); out[2] = stmt.getObject(); if (stmt.getContext() != null) { out[3] = stmt.getContext(); } return out; }
Example 7
Source File: ForwardChainingRDFSInferencerConnection.java From semweb4j with BSD 2-Clause "Simplified" License | 5 votes |
/** * xxx nrl:inverseProperty yyy * aaa xxx bbb * --> * bbb yyy aaa * @return * @throws SailException */ private int applyRuleN1a() throws SailException { int nofInferred = 0; Iterator<Statement> ntIter = this.newThisIteration.match(null, NRL_InverseProperty, null); while (ntIter.hasNext()) { Statement nt = ntIter.next(); Resource xxx = nt.getSubject(); Value yyy = nt.getObject(); if (xxx instanceof URI && yyy instanceof URI) { // apply to triples using the property CloseableIteration<? extends Statement, SailException> t1Iter; t1Iter = getWrappedConnection().getStatements(null, (URI)xxx, null, true); while (t1Iter.hasNext()) { Statement t1 = t1Iter.next(); Value aaa = t1.getSubject(); Value bbb = t1.getObject(); if (bbb instanceof Resource) { boolean added = addInferredStatement((Resource)bbb, (URI) yyy, aaa); if (added) { nofInferred++; } } } t1Iter.close(); } } return nofInferred; }
Example 8
Source File: ForwardChainingRDFSInferencerConnection.java From semweb4j with BSD 2-Clause "Simplified" License | 5 votes |
private int applyRuleRdfs11_1() throws SailException { int nofInferred = 0; Iterator<Statement> ntIter = this.newThisIteration.match(null, RDFS.SUBCLASSOF, null); while (ntIter.hasNext()) { Statement nt = ntIter.next(); Resource xxx = nt.getSubject(); Value yyy = nt.getObject(); if (yyy instanceof Resource) { CloseableIteration<? extends Statement, SailException> t1Iter; t1Iter = getWrappedConnection().getStatements((Resource)yyy, RDFS.SUBCLASSOF, null, true); while (t1Iter.hasNext()) { Statement t1 = t1Iter.next(); Value zzz = t1.getObject(); if (zzz instanceof Resource) { boolean added = addInferredStatement(xxx, RDFS.SUBCLASSOF, zzz); if (added) { nofInferred++; } } } t1Iter.close(); } } return nofInferred; }
Example 9
Source File: RepositoryConnectionTest.java From database with GNU General Public License v2.0 | 5 votes |
@Test public void testPreparedGraphQuery() throws Exception { testCon.add(alice, name, nameAlice, context2); testCon.add(alice, mbox, mboxAlice, context2); testCon.add(context2, publisher, nameAlice); testCon.add(bob, name, nameBob, context1); testCon.add(bob, mbox, mboxBob, context1); testCon.add(context1, publisher, nameBob); StringBuilder queryBuilder = new StringBuilder(128); queryBuilder.append(" prefix foaf: <" + FOAF_NS + ">"); queryBuilder.append(" construct "); queryBuilder.append(" where { ?s foaf:name ?name . ?s foaf:mbox ?mbox . }"); GraphQuery query = testCon.prepareGraphQuery(QueryLanguage.SPARQL, queryBuilder.toString()); query.setBinding(NAME, nameBob); GraphQueryResult result = query.evaluate(); try { assertThat(result, is(notNullValue())); assertThat(result.hasNext(), is(equalTo(true))); while (result.hasNext()) { Statement st = result.next(); URI predicate = st.getPredicate(); assertThat(predicate, anyOf(is(equalTo(name)), is(equalTo(mbox)))); Value object = st.getObject(); if (name.equals(predicate)) { assertEquals("unexpected value for name: " + object, nameBob, object); } else { assertThat(predicate, is(equalTo(mbox))); assertEquals("unexpected value for mbox: " + object, mboxBob, object); } } } finally { result.close(); } }
Example 10
Source File: ForwardChainingRDFSInferencerConnection.java From semweb4j with BSD 2-Clause "Simplified" License | 5 votes |
private int applyRuleRdfs9_2() throws SailException { int nofInferred = 0; Iterator<Statement> ntIter = this.newThisIteration.match(null, RDF.TYPE, null); while (ntIter.hasNext()) { Statement nt = ntIter.next(); Resource aaa = nt.getSubject(); Value xxx = nt.getObject(); if (xxx instanceof Resource) { CloseableIteration<? extends Statement, SailException> t1Iter; t1Iter = getWrappedConnection().getStatements((Resource)xxx, RDFS.SUBCLASSOF, null, true); while (t1Iter.hasNext()) { Statement t1 = t1Iter.next(); Value yyy = t1.getObject(); if (yyy instanceof Resource) { boolean added = addInferredStatement(aaa, RDF.TYPE, yyy); if (added) { nofInferred++; } } } t1Iter.close(); } } return nofInferred; }
Example 11
Source File: ForwardChainingRDFSInferencerConnection.java From semweb4j with BSD 2-Clause "Simplified" License | 5 votes |
private int applyRuleRdfs2_2() throws SailException { int nofInferred = 0; Iterator<Statement> ntIter = this.newThisIteration.match(null, RDFS.DOMAIN, null); while (ntIter.hasNext()) { Statement nt = ntIter.next(); Resource aaa = nt.getSubject(); Value zzz = nt.getObject(); if (aaa instanceof URI && zzz instanceof Resource) { CloseableIteration<? extends Statement, SailException> t1Iter; t1Iter = getWrappedConnection().getStatements(null, (URI)aaa, null, true); while (t1Iter.hasNext()) { Statement t1 = t1Iter.next(); Resource xxx = t1.getSubject(); boolean added = addInferredStatement(xxx, RDF.TYPE, zzz); if (added) { nofInferred++; } } t1Iter.close(); } } return nofInferred; }
Example 12
Source File: ForwardChainingRDFSInferencerConnection.java From semweb4j with BSD 2-Clause "Simplified" License | 5 votes |
/** * aaa xxx bbb * xxx nrl:inverseProperty yyy * --> * bbb yyy aaa * @return * @throws SailException */ private int applyRuleN1b() throws SailException { int nofInferred = 0; Iterator<Statement> ntIter = this.newThisIteration.match(null, null, null); while (ntIter.hasNext()) { Statement nt = ntIter.next(); Resource xxx = nt.getPredicate(); CloseableIteration<? extends Statement, SailException> t1Iter; t1Iter = getWrappedConnection().getStatements(xxx,NRL_InverseProperty, null, true); while (t1Iter.hasNext()) { Statement t1 = t1Iter.next(); Value yyy = t1.getObject(); if (yyy instanceof URI) { Resource aaa = nt.getSubject(); Value bbb = nt.getObject(); boolean added = addInferredStatement((Resource)bbb, (URI) yyy, aaa); if (added) { nofInferred++; } } } t1Iter.close(); } return nofInferred; }
Example 13
Source File: ForwardChainingRDFSInferencerConnection.java From semweb4j with BSD 2-Clause "Simplified" License | 5 votes |
/** * rrr rdfs:subPropertyOf ppp * rrr nrl:inverseProperty sss * ppp nrl:inverseProperty qqq * --> * sss rdfs:subPropertyOf qqq * @return * @throws SailException */ private int applyRuleN2b() throws SailException { int nofInferred = 0; Iterator<Statement> it1 = this.newThisIteration.match(null, RDFS.SUBPROPERTYOF, null); while (it1.hasNext()) { Statement stmt1 = it1.next(); Resource rrr = stmt1.getSubject(); Value ppp = stmt1.getObject(); if(ppp instanceof Resource) { CloseableIteration<? extends Statement, SailException> it2; it2 = getWrappedConnection().getStatements(rrr,NRL_InverseProperty, null, true); while (it2.hasNext()) { Statement stmt2 = it2.next(); Value sss = stmt2.getObject(); if(sss instanceof Resource) { CloseableIteration<? extends Statement, SailException> it3; it3 = getWrappedConnection().getStatements( (Resource) ppp,NRL_InverseProperty, null, true); while (it3.hasNext()) { Statement stmt3 = it3.next(); Value qqq = stmt3.getObject(); if( qqq instanceof Resource) { boolean added = addInferredStatement((Resource)sss, RDFS.SUBPROPERTYOF, qqq); if (added) { nofInferred++; } } } it3.close(); } } it2.close(); } } return nofInferred; }
Example 14
Source File: OwlNormalizer.java From anno4j with Apache License 2.0 | 5 votes |
private void setObjectType(URI pred, URI type) { for (Statement st : ds.match(null, pred, null)) { if (st.getObject() instanceof Resource) { Resource subj = (Resource) st.getObject(); ds.add(subj, RDF.TYPE, type); } else { logger.warn("Invalid statement {}", st); } } }
Example 15
Source File: ForwardChainingRDFSInferencerConnection.java From semweb4j with BSD 2-Clause "Simplified" License | 5 votes |
private int applyRuleRdfs9_1() throws SailException { int nofInferred = 0; Iterator<Statement> ntIter = this.newThisIteration.match(null, RDFS.SUBCLASSOF, null); while (ntIter.hasNext()) { Statement nt = ntIter.next(); Resource xxx = nt.getSubject(); Value yyy = nt.getObject(); if (yyy instanceof Resource) { CloseableIteration<? extends Statement, SailException> t1Iter; t1Iter = getWrappedConnection().getStatements(null, RDF.TYPE, xxx, true); while (t1Iter.hasNext()) { Statement t1 = t1Iter.next(); Resource aaa = t1.getSubject(); boolean added = addInferredStatement(aaa, RDF.TYPE, yyy); if (added) { nofInferred++; } } t1Iter.close(); } } return nofInferred; }
Example 16
Source File: GASState.java From database with GNU General Public License v2.0 | 4 votes |
@Override public boolean isEdge(final Statement e) { return e.getObject() instanceof Resource; }
Example 17
Source File: Schema.java From cumulusrdf with Apache License 2.0 | 4 votes |
public void index(final Store store, final ITopLevelDictionary dictionary) throws DataAccessLayerException { PersistentSet<byte[]> clazzes_cassandra = new PersistentSet<byte[]>(byte[].class, COL_CLAZZES); PersistentSet<byte[]> d_props_cassandra = new PersistentSet<byte[]>(byte[].class, COL_D_PROPS); PersistentSet<byte[]> o_props_cassandra = new PersistentSet<byte[]>(byte[].class, COL_O_PROPS); try { long counter = 0; LOG.info(MessageCatalog._00063_CREATING_NEW_SCHEMA); for (final Iterator<Statement> iterator = store.query(new Value[] {null, RDF.TYPE, null}); iterator.hasNext();) { // TODO it should be sufficient to just "getID" here clazzes_cassandra.add(dictionary.getID(iterator.next().getObject(), false)); if (++counter % 1000 == 0) { LOG.info(MessageCatalog._00064_HOW_MANY_TYPE_TRIPLES, counter); } } LOG.info(MessageCatalog._00065_HOW_MANY_CLASSES_FOUND, clazzes_cassandra.size()); counter = 0; /* * probe each class for instances ... */ for (byte[] clazz_id : clazzes_cassandra) { final Value clazz = dictionary.getValue(clazz_id, false); LOG.info(MessageCatalog._00066_SAMPLING_OVER, clazz); for (Iterator<Statement> clazz_iter = store.query(new Value[] {null, RDF.TYPE, clazz}); clazz_iter.hasNext();) { for (final Iterator<Statement> instance_iter = store.query( new Value[] {clazz_iter.next().getSubject(), null, null}, 100); instance_iter.hasNext();) { final Statement triple = instance_iter.next(); final Value object = triple.getObject(); final URI predicate = triple.getPredicate(); if (object instanceof Literal) { // TODO it should be sufficient to just "getID" here d_props_cassandra.add(dictionary.getID(predicate, true)); } else { // TODO it should be sufficient to just "getID" here o_props_cassandra.add(dictionary.getID(predicate, true)); } if (++counter % 1000 == 0) { LOG.info(MessageCatalog._00067_HOW_MANY_INSTANCE_TRIPLES, counter); } } } } LOG.info(MessageCatalog._00068_SAMPLING_COMPLETED, counter); } catch (final CumulusStoreException exception) { LOG.error(MessageCatalog._00025_CUMULUS_SYSTEM_INTERNAL_FAILURE, exception); } }
Example 18
Source File: RangeQueriesTest.java From cumulusrdf with Apache License 2.0 | 4 votes |
@Test public void rangeBoundsSubjTest() throws CumulusStoreException { Value[] query = new Value[2]; query[0] = buildResource(_subject); query[1] = buildResource(_predicate); double lowerBound = 3.18; double upperBound = 3.20; for (boolean upper_equals : new boolean[] { true, false }) { for (boolean lower_equals : new boolean[] { true, false }) { Iterator<Statement> iter = _tripleStore.range( query, buildLiteral(String.valueOf(lowerBound)), lower_equals, buildLiteral(String.valueOf(upperBound)), upper_equals, false, Integer.MAX_VALUE); final String message = new StringBuilder() .append("query = ").append(Arrays.toString(query)) .append("lower = ").append(lowerBound).append(", ") .append("lower_equals = ").append(lower_equals).append(", ") .append("upper = ").append(upperBound).append(", ") .append("upper_equals = ").append(upper_equals).append(", ") .toString(); assertTrue(message, iter != null && iter.hasNext()); int counter = 0; double current = -Double.MAX_VALUE, last; while (iter.hasNext()) { last = current; Statement res = iter.next(); Literal lit = (Literal) res.getObject(); current = Double.parseDouble(lit.getLabel()); if (upper_equals) { assertTrue(current <= upperBound); } else { assertTrue(current < upperBound); } if (lower_equals) { assertTrue(current >= lowerBound); } else { assertTrue(current > lowerBound); } assertTrue(last <= current); counter++; } assertTrue(counter == 1); } } }
Example 19
Source File: BigdataGASState.java From database with GNU General Public License v2.0 | 4 votes |
@Override @SuppressWarnings("rawtypes") public Value getOtherVertex(final Value u, final Statement e) { if (e.getSubject() instanceof SidIV) { final ISPO spo = ((SidIV) e.getSubject()).getInlineValue(); if (spo.s().equals(u)) return spo.o(); return spo.s(); } else { if (e.getSubject().equals(u)) return e.getObject(); return e.getSubject(); } }
Example 20
Source File: SAILGASEngine.java From database with GNU General Public License v2.0 | 2 votes |
@Override public VertexDistribution getDistribution(final Random r) { try { final VertexDistribution sample = new VertexDistribution(r); final CloseableIteration<? extends Statement, SailException> citr = cxn .getStatements(null/* s */, null/* p */, null /* o */, includeInferred, defaultContext); try { while (citr.hasNext()) { final Statement st = citr.next(); if (!(st.getObject() instanceof Resource)) { // This is a property value, not an edge. continue; } if (st.getSubject().equals(st.getObject())) { // ignore self-loops. continue; } sample.addOutEdgeSample(st.getSubject()); sample.addInEdgeSample((Resource) st.getObject()); } } finally { citr.close(); } return sample; } catch (SailException ex) { throw new RuntimeException(ex); } }