/** * Retrieves a subject {@link IRI} from the statements in the given model. If * more than one possible IRI value exists, any one IRI value is picked and * returned. * * @param m * the model from which to retrieve a subject IRI value. * @return an {@link Optional} subject IRI value from the given model, which * will be {@link Optional#empty() empty} if no such value exists. */ public static Optional<IRI> subjectIRI(Model m) { return m.stream().map(st -> st.getSubject()).filter(s -> s instanceof IRI).map(s -> (IRI)s).findAny(); }
/** * Retrieves a predicate from the statements in the given model. If more than * one possible predicate value exists, any one value is picked and returned. * * @param m * the model from which to retrieve a predicate value. * @return an {@link Optional} predicate value from the given model, which * will be {@link Optional#empty() empty} if no such value exists. * @since 4.0 */ public static Optional<IRI> predicate(Model m) { return m.stream().map(st -> st.getPredicate()).findAny(); }
/** * Retrieves a subject {@link Resource} from the statements in the given * model. If more than one possible resource value exists, any one resource * value is picked and returned. * * @param m * the model from which to retrieve a subject Resource. * @return an {@link Optional} subject resource from the given model, which * will be {@link Optional#empty() empty} if no such value exists. * @since 4.0 */ public static Optional<Resource> subject(Model m) { return m.stream().map(st -> st.getSubject()).findAny(); }
/** * Retrieves an object {@link Literal} value from the statements in the given * model. If more than one possible Literal value exists, any one Literal * value is picked and returned. * * @param m * the model from which to retrieve an object Literal value. * @return an object Literal value from the given model, or * {@link Optional#empty()} if no such value exists. * @since 4.0 */ public static Optional<Literal> objectLiteral(Model m) { return m.stream().map(st -> st.getObject()).filter(o -> o instanceof Literal).map( l -> (Literal)l).findAny(); }
/** * Retrieves an object {@link IRI} value from the statements in the given * model. If more than one possible IRI value exists, any one value is picked * and returned. * * @param m * the model from which to retrieve an object IRI value. * @return an {@link Optional} object IRI value from the given model, which * will be {@link Optional#empty() empty} if no such value exists. * @since 4.0 */ public static Optional<IRI> objectIRI(Model m) { return m.stream().map(st -> st.getObject()).filter(o -> o instanceof IRI).map(r -> (IRI)r).findAny(); }
/** * Retrieves an object {@link Value} from the statements in the given model. * If more than one possible object value exists, any one value is picked and * returned. * * @param m * the model from which to retrieve an object value. * @return an object value from the given model, or {@link Optional#empty()} * if no such value exists. * @since 4.0 */ public static Optional<Value> object(Model m) { return m.stream().map(st -> st.getObject()).findAny(); }
/** * Retrieves a subject {@link BNode} from the statements in the given model. * If more than one possible blank node value exists, any one blank node * value is picked and returned. * * @param m * the model from which to retrieve a subject BNode value. * @return an {@link Optional} subject BNode value from the given model, * which will be {@link Optional#empty() empty} if no such value * exists. * @since 4.0 */ public static Optional<BNode> subjectBNode(Model m) { return m.stream().map(st -> st.getSubject()).filter(s -> s instanceof BNode).map( s -> (BNode)s).findAny(); }
/** * Retrieves an object {@link Resource} value from the statements in the * given model. If more than one possible Resource value exists, any one * Resource value is picked and returned. * * @param m * the model from which to retrieve an object Resource value. * @return an {@link Optional} object Resource value from the given model, * which will be {@link Optional#empty() empty} if no such value * exists. * @since 4.0 */ public static Optional<Resource> objectResource(Model m) { return m.stream().map(st -> st.getObject()).filter(o -> o instanceof Resource).map( r -> (Resource)r).findAny(); }
/** * Returns a {@link Set} view of the contexts contained in this model. The * set is backed by the model, so changes to the model are reflected in the * set, and vice-versa. If the model is modified while an iteration over the * set is in progress (except through the iterator's own {@code remove} * operation), the results of the iteration are undefined. The set supports * element removal, which removes all statements from the model for which * that element is a context value, via the {@code Iterator.remove}, * {@code Set.remove}, {@code removeAll}, {@code retainAll}, and * {@code clear} operations. It does not support the {@code add} or * {@code addAll} operations if the parameters {@code subj} , {@code pred} or * {@code obj} are null. * * @return a set view of the contexts contained in this model */ public default Set<Resource> contexts() { Set<Resource> subjects = stream().map(st -> st.getContext()).collect(Collectors.toSet()); return subjects; };
/** * Retrieves an object value as a String from the statements in the given * model. If more than one possible object value exists, any one value is * picked and returned. * * @param m * the model from which to retrieve an object String value. * @return an {@link Optional} object String value from the given model, * which will be {@link Optional#empty() empty} if no such value * exists. * @since 4.0 */ public static Optional<String> objectString(Model m) { return m.stream().map(st -> st.getObject().stringValue()).findAny(); }
throws ModelException Set<Resource> result = stream().map(st -> st.getSubject()).distinct().limit(2).collect( Collectors.toSet()); if (result.isEmpty()) {
/** * Gets the object of the statement(s). If the model contains one or more * statements, all these statements should have the same object. A * {@link ModelException} is thrown if this is not the case. * * @return The object of the matched statement(s), or * {@link Optional#empty()} if no matching statements were found. * @throws ModelException * If the statements matched by the specified parameters have more * than one unique object. * @deprecated since 4.0. Instead, use {@link Models#object(Model)} to * retrieve an object value, and/or use the size of the set * returned by {@link #objects()} to verify if the object is * unique. */ @Deprecated public default Optional<Value> objectValue() throws ModelException { Set<Value> result = stream().map(st -> st.getObject()).distinct().limit(2).collect(Collectors.toSet()); if (result.isEmpty()) { return Optional.empty(); } else if (result.size() > 1) { throw new ModelException("Did not find a unique object value"); } else { return Optional.of(result.iterator().next()); } };
c) -> ((Model)sourceModel).filter(s, p, o, c).stream().findAny(); extract(statementSupplier, head, consumer, Models::modelException, contexts);
Objects.requireNonNull(m, "input model may not be null"); GetStatementOptional statementSupplier = (s, p, o, c) -> m.filter(s, p, o, c).stream().findAny(); Function<String, Supplier<ModelException>> exceptionSupplier = Models::modelException;