/** * Gets the subject of the statements with the specified predicate, object * and (optionally) contexts from the supplied graph. Calling this method is * equivalent to calling <tt>graph.match(null, pred, obj, contexts)</tt> and * extracting the subjects of the matching statements from the returned * iterator. See {@link Graph#match(Resource, URI, Value, Resource[])} for a * description of the parameter values. */ public static Iterator<Resource> getSubjectIterator(Graph graph, URI pred, Value obj, Resource... contexts) { Iterator<Statement> iter = graph.match(null, pred, obj, contexts); return new ConvertingIterator<Statement, Resource>(iter) { @Override protected Resource convert(Statement st) throws RuntimeException { return st.getSubject(); } }; }
/** * Gets the objects of the statements with the specified subject, predicate * and (optionally) contexts from the supplied graph. Calling this method is * equivalent to calling <tt>graph.match(subj, pred, null, contexts)</tt> and * extracting the objects of the matching statements from the returned * iterator. See {@link Graph#match(Resource, URI, Value, Resource[])} for a * description of the parameter values. */ public static Iterator<Value> getObjectIterator(Graph graph, Resource subj, URI pred, Resource... contexts) { Iterator<Statement> iter = graph.match(subj, pred, null, contexts); return new ConvertingIterator<Statement, Value>(iter) { @Override protected Value convert(Statement st) throws RuntimeException { return st.getObject(); } }; }
/** * Count matches of the triple pattern. */ static protected int countMatches(final Graph g, final Resource s, final URI p, final Value o) { int n = 0; final Iterator<Statement> itr = g.match(s, p, o); while (itr.hasNext()) { itr.next(); n++; } return n; }
/** * Gets the objects of the statements with the specified subject, predicate * and (optionally) contexts from the supplied graph. Calling this method is * equivalent to calling <tt>graph.match(subj, pred, null, contexts)</tt> and * extracting the objects of the matching statements from the returned * iterator. See {@link Graph#match(Resource, IRI, Value, Resource[])} for a * description of the parameter values. * * @deprecated since 2.8.0. Use * {@link Model#filter(Resource, IRI, Value, Resource...)} and * {@link Model#objects()} instead. */ @Deprecated public static Iterator<Value> getObjectIterator(Graph graph, Resource subj, IRI pred, Resource... contexts) { Iterator<Statement> iter = graph.match(subj, pred, null, contexts); return new ConvertingIterator<Statement, Value>(iter) { @Override protected Value convert(Statement st) throws RuntimeException { return st.getObject(); } }; }
/** * Return the statements matching the triple pattern. */ static protected Statement[] getMatches(final Graph g, final Resource s, final URI p, final Value o) { final List<Statement> out = new LinkedList<Statement>(); final Iterator<Statement> itr = g.match(s, p, o); while (itr.hasNext()) { out.add(itr.next()); } return out.toArray(new Statement[out.size()]); }
/** * Gets the subject of the statements with the specified predicate, object * and (optionally) contexts from the supplied graph. Calling this method is * equivalent to calling <tt>graph.match(null, pred, obj, contexts)</tt> and * extracting the subjects of the matching statements from the returned * iterator. See {@link Graph#match(Resource, IRI, Value, Resource[])} for a * description of the parameter values. * * @deprecated since 2.8.0. Use * {@link Model#filter(Resource, IRI, Value, Resource...)} and * {@link Model#subjects()} instead. */ @Deprecated public static Iterator<Resource> getSubjectIterator(Graph graph, IRI pred, Value obj, Resource... contexts) { Iterator<Statement> iter = graph.match(null, pred, obj, contexts); return new ConvertingIterator<Statement, Resource>(iter) { @Override protected Resource convert(Statement st) throws RuntimeException { return st.getSubject(); } }; }
/** * Adds the specified statement and makes sure that no other statements are * present in the Graph with the same subject and predicate. When contexts * are specified, the (subj, pred) pair will occur exactly once in each * context, else the (subj, pred) pair will occur exactly once in the entire * Graph. */ public static void setUniqueObject(Graph graph, Resource subj, URI pred, Value obj, Resource... contexts) { Iterator<Statement> iter = graph.match(subj, pred, null, contexts); while (iter.hasNext()) { iter.next(); iter.remove(); } graph.add(subj, pred, obj, contexts); }
public void importGraph(Graph model, Resource... contexts) { Iterator<Statement> statements = model.match(null, null, null, contexts); while (statements.hasNext()) { handleStatement(statements.next()); } }
Iterator<Statement> statements = graph.match(subj, pred, obj, contexts); while (statements.hasNext()) { statements.next();
/** * Adds the specified statement and makes sure that no other statements are * present in the Graph with the same subject and predicate. When contexts * are specified, the (subj, pred) pair will occur exactly once in each * context, else the (subj, pred) pair will occur exactly once in the entire * Graph. * * @deprecated since 2.8.0. Use * {@link Models#setProperty(Model, Resource, IRI, Value, Resource...) } * instead. */ @Deprecated public static void setUniqueObject(Graph graph, Resource subj, IRI pred, Value obj, Resource... contexts) { Iterator<Statement> iter = graph.match(subj, pred, null, contexts); while (iter.hasNext()) { iter.next(); iter.remove(); } graph.add(subj, pred, obj, contexts); }
Iterator<Statement> statements = graph.match(subj, pred, obj, contexts); while (statements.hasNext()) { statements.next();
/** * Count matches of the triple pattern. */ static protected int countMatches(final Graph g, final Resource s, final URI p, final Value o) { int n = 0; final Iterator<Statement> itr = g.match(s, p, o); while (itr.hasNext()) { itr.next(); n++; } return n; }
Iterator<Statement> typeIter = graph.match(subject, rdfType, null);
/** * Return the statements matching the triple pattern. */ static protected Statement[] getMatches(final Graph g, final Resource s, final URI p, final Value o) { final List<Statement> out = new LinkedList<Statement>(); final Iterator<Statement> itr = g.match(s, p, o); while (itr.hasNext()) { out.add(itr.next()); } return out.toArray(new Statement[out.size()]); }
Iterator<Statement> subjectIter = graph.match(null, null, null);
Iterator<Statement> typeStatements = bufferedStatements.match(subject, RDF.TYPE, null, context); while (typeStatements.hasNext()) { Statement typeStatement = typeStatements.next(); Iterator<Statement> subjectStatements = bufferedStatements.match(subject, null, null, context); while (subjectStatements.hasNext()) { Statement subjectStatement = subjectStatements.next(); IRI predicate = subjectStatement.getPredicate(); if (!processedPredicates.contains(predicate)) { Iterator<Statement> toWrite = bufferedStatements.match(subject, predicate, null, context); while (toWrite.hasNext()) { Statement toWriteSt = toWrite.next();
Iterator<Statement> graphIter = graph.match(null, null, null);
Iterator<Statement> tripleIter = graph.match(null, null, null);
assertTrue(g2.match(s, p, o).hasNext());
assertTrue(g2.match(s, p, o).hasNext());