/** * Gets the subject of the statement(s) with the specified predicate and * object from the specified contexts in the supplied graph. If the * combination of predicate, object and contexts matches one or more * statements, all these statements should have the same subject. A * {@link GraphUtilException} is thrown if this is not the case. See * {@link Graph#match(Resource, URI, Value, Resource[])} for a description of * the parameter values. * * @return The subject of the matched statement(s), or <tt>null</tt> if no * matching statements were found. * @throws GraphUtilException * If the statements matched by the specified parameters have more * than one unique subject. */ public static Resource getOptionalSubject(Graph graph, URI pred, Value obj, Resource... contexts) throws GraphUtilException { Set<Resource> subjects = getSubjects(graph, pred, obj, contexts); if (subjects.isEmpty()) { return null; } else if (subjects.size() == 1) { return subjects.iterator().next(); } else { throw new GraphUtilException("Multiple " + pred + " properties found"); } }
throws GraphUtilException Set<Resource> subjects = getSubjects(graph, pred, obj, contexts);
throws GraphUtilException Set<Resource> subjects = getSubjects(graph, pred, obj, contexts);
/** * Gets the subject of the statement(s) with the specified predicate and * object from the specified contexts in the supplied graph. The combination * of predicate, object and contexts must match at least one statement. In * case more than one statement matches -- for example statements from * multiple contexts -- all these statements should have the same subject. A * {@link GraphUtilException} is thrown if these conditions are not met. See * {@link Graph#match(Resource, URI, Value, Resource[])} for a description of * the parameter values. * * @return The subject of the matched statement(s). * @throws GraphUtilException * If the statements matched by the specified parameters do not have * exactly one unique subject. */ public static Resource getUniqueSubject(Graph graph, URI pred, Value obj, Resource... contexts) throws GraphUtilException { Set<Resource> subjects = getSubjects(graph, pred, obj, contexts); if (subjects.size() == 1) { return subjects.iterator().next(); } else if (subjects.isEmpty()) { throw new GraphUtilException("Missing property: " + pred); } else { throw new GraphUtilException("Multiple " + pred + " properties found"); } }
Set<Resource> subjects = GraphUtil.getSubjects(bufferedStatements, null, null, context); for (Resource subject : subjects) { Set<IRI> processedPredicates = new HashSet<IRI>();