Java Code Examples for org.openrdf.model.Statement#getSubject()
The following examples show how to use
org.openrdf.model.Statement#getSubject() .
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: 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 2
Source File: ForwardChainingRDFSInferencerConnection.java From semweb4j with BSD 2-Clause "Simplified" License | 6 votes |
private int applyRuleRdfs13() throws SailException { int nofInferred = 0; Iterator<Statement> iter = this.newThisIteration.match(null, RDF.TYPE, RDFS.DATATYPE); while (iter.hasNext()) { Statement st = iter.next(); Resource xxx = st.getSubject(); boolean added = addInferredStatement(xxx, RDFS.SUBCLASSOF, RDFS.LITERAL); if (added) { nofInferred++; } } return nofInferred; }
Example 3
Source File: ForwardChainingRDFSInferencerConnection.java From semweb4j with BSD 2-Clause "Simplified" License | 6 votes |
private int applyRuleRdfs8() throws SailException { int nofInferred = 0; Iterator<Statement> iter = this.newThisIteration.match(null, RDF.TYPE, RDFS.CLASS); while (iter.hasNext()) { Statement st = iter.next(); Resource xxx = st.getSubject(); boolean added = addInferredStatement(xxx, RDFS.SUBCLASSOF, RDFS.RESOURCE); if (added) { nofInferred++; } } return nofInferred; }
Example 4
Source File: ModelUtil.java From database with GNU General Public License v2.0 | 6 votes |
private static boolean matchModels(Set<? extends Statement> model1, Set<? extends Statement> model2) { // Compare statements without blank nodes first, save the rest for later List<Statement> model1BNodes = new ArrayList<Statement>(model1.size()); for (Statement st : model1) { if (st.getSubject() instanceof BNode || st.getObject() instanceof BNode) { model1BNodes.add(st); } else { if (!model2.contains(st)) { return false; } } } return matchModels(model1BNodes, model2, new HashMap<BNode, BNode>(), 0); }
Example 5
Source File: RAMGASEngine.java From database with GNU General Public License v2.0 | 6 votes |
public boolean add(final Statement st) { final Resource s = st.getSubject(); final Value o = st.getObject(); boolean modified = false; if (o instanceof URI) { // Edge modified |= get(s, true/* create */).addOutEdge(st); modified |= get(o, true/* create */).addInEdge(st); } else { // Property value. modified |= get(s, true/* create */).addAttrib(st); } return modified; }
Example 6
Source File: AugurTest.java From anno4j with Apache License 2.0 | 6 votes |
public void test_naive() throws Exception { ValueFactory vf = con.getValueFactory(); final URI Bean = vf.createURI(NS, "Bean"); final URI name = vf.createURI(NS, "name"); final URI parent = vf.createURI(NS, "parent"); final URI friend = vf.createURI(NS, "friend"); long start = System.currentTimeMillis(); RepositoryResult<Statement> beans = con.getStatements(null, RDF.TYPE, Bean); while (beans.hasNext()) { Statement st = beans.next(); Resource bean = st.getSubject(); QueryResults.asList(con.getStatements(bean, name, null)); RepositoryResult<Statement> match; match = con.getStatements(bean, parent, null); while (match.hasNext()) { QueryResults.asList(con.getStatements((Resource)match.next().getObject(), name, null)); } match = con.getStatements(bean, friend, null); while (match.hasNext()) { QueryResults.asList(con.getStatements((Resource)match.next().getObject(), name, null)); } } long end = System.currentTimeMillis(); System.out.println((end - start) / 1000.0); }
Example 7
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 8
Source File: OwlNormalizer.java From anno4j with Apache License 2.0 | 5 votes |
private void hasValueFromList() { ValueFactory vf = getValueFactory(); for (Statement st : ds.match(null, OWL.HASVALUE, null)) { Resource res = st.getSubject(); Value obj = st.getObject(); if (obj instanceof Resource) { BNode node = vf.createBNode(); ds.add(res, OWL.ALLVALUESFROM, node); ds.add(node, RDF.TYPE, OWL.CLASS); BNode list = vf.createBNode(); ds.add(node, OWL.ONEOF, list); ds.add(list, RDF.TYPE, RDF.LIST); ds.add(list, RDF.FIRST, obj); ds.add(list, RDF.REST, RDF.NIL); for (Value type : ds.match(obj, RDF.TYPE, null).objects()) { ds.add(node, RDFS.SUBCLASSOF, type); } for (Value prop : ds.match(res, OWL.ONPROPERTY, null).objects()) { for (Value range : ds.match(prop, RDFS.RANGE, null).objects()) { ds.add(node, RDFS.SUBCLASSOF, range); } for (Resource cls : ds.match(null, RDFS.SUBCLASSOF, res).subjects()) { for (Value sup : findSuperClasses(cls)) { if (!sup.equals(res) && !ds.match(sup, OWL.ONPROPERTY, prop).isEmpty()) { for (Value from : ds.match(sup, OWL.ALLVALUESFROM, null).objects()) { ds.add(node, RDFS.SUBCLASSOF, from); } } } } } } } }
Example 9
Source File: ForwardChainingRDFSInferencerConnection.java From semweb4j with BSD 2-Clause "Simplified" License | 5 votes |
private int applyRuleRdfs7_2() throws SailException { int nofInferred = 0; Iterator<Statement> ntIter = this.newThisIteration.match(null, RDFS.SUBPROPERTYOF, null); while (ntIter.hasNext()) { Statement nt = ntIter.next(); Resource aaa = nt.getSubject(); Value bbb = nt.getObject(); if (aaa instanceof URI && bbb instanceof URI) { CloseableIteration<? extends Statement, SailException> t1Iter; t1Iter = getWrappedConnection().getStatements(null, (URI)aaa, null, true); while (t1Iter.hasNext()) { Statement t1 = t1Iter.next(); Resource xxx = t1.getSubject(); Value yyy = t1.getObject(); boolean added = addInferredStatement(xxx, (URI)bbb, yyy); if (added) { nofInferred++; } } t1Iter.close(); } } return nofInferred; }
Example 10
Source File: ForwardChainingRDFSInferencerConnection.java From semweb4j with BSD 2-Clause "Simplified" License | 5 votes |
private int applyRuleRdfs2_1() throws SailException { int nofInferred = 0; Iterator<Statement> ntIter = this.newThisIteration.match(null, null, null); while (ntIter.hasNext()) { Statement nt = ntIter.next(); Resource xxx = nt.getSubject(); URI aaa = nt.getPredicate(); CloseableIteration<? extends Statement, SailException> t1Iter; t1Iter = getWrappedConnection().getStatements(aaa, RDFS.DOMAIN, null, true); while (t1Iter.hasNext()) { Statement t1 = t1Iter.next(); Value zzz = t1.getObject(); if (zzz instanceof Resource) { boolean added = addInferredStatement(xxx, RDF.TYPE, zzz); if (added) { nofInferred++; } } } t1Iter.close(); } return nofInferred; }
Example 11
Source File: OwlNormalizer.java From anno4j with Apache License 2.0 | 5 votes |
private void propagateSubClassType(Resource classDef) { for (Resource c : findClasses(Collections.singleton(classDef))) { if (c.equals(RDFS.DATATYPE)) continue; for (Statement stmt : ds.match(null, RDF.TYPE, c)) { Resource subj = stmt.getSubject(); ds.add(subj, RDF.TYPE, classDef); } } }
Example 12
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 13
Source File: OwlNormalizer.java From anno4j with Apache License 2.0 | 5 votes |
private void checkPropertyRanges() { loop: for (Statement st : ds.match(null, RDF.TYPE, RDF.PROPERTY)) { Resource p = st.getSubject(); if (!ds.contains(p, RDFS.RANGE, null)) { for (Value sup : ds.match(p, RDFS.SUBPROPERTYOF, null).objects()) { for (Value obj : ds.match(sup, RDFS.RANGE, null).objects()) { ds.add(p, RDFS.RANGE, obj); continue loop; } } ds.add(p, RDFS.RANGE, RDFS.RESOURCE); } } }
Example 14
Source File: ForwardChainingRDFSInferencerConnection.java From semweb4j with BSD 2-Clause "Simplified" License | 5 votes |
private int applyRuleRdfs5_1() throws SailException { int nofInferred = 0; Iterator<Statement> ntIter = this.newThisIteration.match(null, RDFS.SUBPROPERTYOF, null); while (ntIter.hasNext()) { Statement nt = ntIter.next(); Resource aaa = nt.getSubject(); Value bbb = nt.getObject(); if (bbb instanceof Resource) { CloseableIteration<? extends Statement, SailException> t1Iter; t1Iter = getWrappedConnection().getStatements((Resource)bbb, RDFS.SUBPROPERTYOF, null, true); while (t1Iter.hasNext()) { Statement t1 = t1Iter.next(); Value ccc = t1.getObject(); if (ccc instanceof Resource) { boolean added = addInferredStatement(aaa, RDFS.SUBPROPERTYOF, ccc); if (added) { nofInferred++; } } } t1Iter.close(); } } return nofInferred; }
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: ForwardChainingRDFSInferencerConnection.java From semweb4j with BSD 2-Clause "Simplified" License | 5 votes |
/** * ppp nrl:inverseProperty qqq * --> * qqq nrl:inverseProperty ppp * ppp a rdf:Property * qqq a rdf:Property * * @return * @throws SailException */ private int applyRuleN3() throws SailException { int nofInferred = 0; Iterator<Statement> it1 = this.newThisIteration.match(null, NRL_InverseProperty, null); while (it1.hasNext()) { Statement stmt1 = it1.next(); Resource ppp = stmt1.getSubject(); if(ppp instanceof URI) { // infer: ppp is a property boolean addedPPP = addInferredStatement(ppp, RDF.TYPE, RDF.PROPERTY); if (addedPPP) { nofInferred++; } } Value qqq = stmt1.getObject(); if(qqq instanceof Resource) { if(qqq instanceof URI) { // infer: qqq is a property boolean addedQQQ = addInferredStatement((URI)qqq, RDF.TYPE, RDF.PROPERTY); if (addedQQQ) { nofInferred++; } } if(! qqq.equals(ppp)) { // infer: qqq inverse ppp boolean added = addInferredStatement((Resource)qqq, NRL_InverseProperty, ppp); if (added) { nofInferred++; } } } } return nofInferred; }
Example 17
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 18
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 19
Source File: SesameHTTPRepositoryTest.java From cumulusrdf with Apache License 2.0 | 5 votes |
/** * test statements related operations. * @throws Exception Exception the test would fails if exception occurs */ @Test public void testStatements() throws Exception { //test add Statements for (final String tripleAsString : _data) { final Statement triple = parseNX(tripleAsString).iterator().next(); final Value[] query = new Value[] { triple.getSubject(), triple.getPredicate(), triple.getObject() }; TRIPLE_STORE.removeData(query); //ensure the repository contains not statements to be added int howManyTriplesForPattern = numOfRes(TRIPLE_STORE.query(query)); assertEquals("This triple " + tripleAsString + " mustn't exist on store", 0, howManyTriplesForPattern); String uri = BASE_URI + Protocol.REPOSITORIES + "/" + REPO_ID + "/" + Protocol.STATEMENTS; final ServletInputStream stream = new ServletInputStream() { final InputStream _inputStream = new ByteArrayInputStream(tripleAsString.getBytes(Environment.CHARSET_UTF8)); @Override public int read() throws IOException { return _inputStream.read(); } }; final HttpServletRequest request = mockHttpRequest(uri, METHOD_PUT); when(request.getInputStream()).thenReturn(stream); when(request.getContentType()).thenReturn(MIMETYPE_TXT_N3); when(request.getCharacterEncoding()).thenReturn(UTF_8); File tmp = WebTestUtils.tmpFile(); final ServletOutputStream servletOutputStream = new StubServletOutputStream(tmp); final HttpServletResponse response = mock(HttpServletResponse.class); when(response.getOutputStream()).thenReturn(servletOutputStream); _classUnderTest.service(request, response); verify(response).setStatus(HttpServletResponse.SC_NO_CONTENT); int howManyTriplesOnTheStore = numOfRes(TRIPLE_STORE.query(query)); assertEquals(1, howManyTriplesOnTheStore); } }
Example 20
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; }