/** Find any existing reified statement that reifies a givem statement. If there isn't one, create one. @param s a Statement for which to find [or create] a reification @return a reification for s, re-using an existing one if possible */ public Resource getAnyReifiedStatement( Statement s ) { RSIterator it = listReifiedStatements( s ); if (it.hasNext()) try { return it.nextRS(); } finally { it.close(); } else return createReifiedStatement( s ); }
try { RSIterator rsIter = resultModel.listReifiedStatements(); if (!rsIter.hasNext()) { executeAllMappings = true; rsIter.close(); } catch (Exception e) { log.error(e.toString()); resultModel.listReifiedStatements(); RSIterator rsExistingIter = resultModel.listReifiedStatements(); while (rsExistingIter.hasNext()) { ReifiedStatement rstmt = rsExistingIter.next(); Statement st = rstmt.getProperty(DC.source); String source = st.getObject().toString(); rsExistingIter.close(); while (rsIter.hasNext()) { ReifiedStatement rstmt = rsIter.next(); if (verbose && addedStatements % 10000 == 0) log.info("At " + addedStatements); rsIter.close();
@Override public void clear() { Model graph = null; GraphConnection graphConnection = null; try { graphConnection = openGraph(); graph = graphConnection.getGraph(); graph.enterCriticalSection(Lock.READ); graph.removeAll(); // XXX AT: remove reification quadlets explicitly RSIterator it = graph.listReifiedStatements(); List<ReifiedStatement> rss = new ArrayList<ReifiedStatement>(); while (it.hasNext()) { rss.add(it.nextRS()); } for (ReifiedStatement rs : rss) { graph.removeReification(rs); } } finally { if (graph != null) { graph.leaveCriticalSection(); } if (graphConnection != null) { graphConnection.close(); } } }
/** * @param type * The type of reified statements to retrieve, i.e. anonymous or named ones. * @return Every reified statements of the model, having a type as <code>type</code>. */ private List<ReifiedStatement> listReifStats(final ResourceTypes type) { final RSIterator rsi = this.model.listReifiedStatements(); final List<ReifiedStatement> rss = new ArrayList<ReifiedStatement>(); if (type.equals(ResourceTypes.ANON)) { while (rsi.hasNext()) { final ReifiedStatement rs = rsi.nextRS(); if (rs.isAnon()) { rss.add(rs); } } } else if (type.equals(ResourceTypes.NAMED)) { while (rsi.hasNext()) { final ReifiedStatement rs = rsi.nextRS(); if (rs.isURIResource()) { rss.add(rs); } } } else { LogFactory.getLog(this.getClass()).warn("Error in listReifiedStatement " + "ResourceType was neither an " + "anon nor a named resource..."); } rsi.close(); return rss; }
/** * @param subj * The subject of the statement that might be reified. * @param pred * The predicate of the statement that might be reified. * @param obj * The object of the statement that might be reified. * @return A list that might be empty of reified statement representing the statement (<code>subj</code>, <code>pred</code>, <code>obj</code> ). */ protected List<ReifiedStatement> getReifStats(final Resource subj, final Property pred, final RDFNode obj) { final List<ReifiedStatement> reifs = new ArrayList<ReifiedStatement>(); if (this.containsStatement(subj, pred, obj)) { final Statement s = this.createStatement(subj, pred, obj, false); if (s.isReified()) { final RSIterator rsit = s.listReifiedStatements(); while (rsit.hasNext()) { reifs.add(rsit.nextRS()); } rsit.close(); } } return reifs; }
/** * @return A list containing every statements including the one that are subject of reifications but not the reification implementation ones (subject, * object...). */ protected List<Statement> listStatements() { final List<Statement> stats = new ArrayList<Statement>(); final StmtIterator sit = this.model.listStatements(); while (sit.hasNext()) { final Statement stat = sit.nextStatement(); // Filtering reified statement if (!stat.getPredicate().equals(RDF.subject) && !stat.getPredicate().equals(RDF.predicate) && !stat.getPredicate().equals(RDF.object)) { if (stat.getPredicate().equals(RDF.type) && stat.getObject().isResource()) { if (!((Resource) stat.getObject()).equals(RDF.Statement)) { stats.add(stat); } } else { stats.add(stat); } } } sit.close(); final RSIterator rsit = this.model.listReifiedStatements(); while (rsit.hasNext()) { stats.add(rsit.nextRS().getStatement()); } rsit.close(); return stats; }