org.eclipse.rdf4j.model.util

## Class Models

- java.lang.Object
- - org.eclipse.rdf4j.model.util.Models

- Direct Known Subclasses:
    ModelUtil

      public class Models
      extends Object

  Utility functions for working with `Model`s and other `Statement` collections.
  Author:
    Jeen Broekstra, Arjohn Kampman
  See Also:
    `Model`, `ModelBuilder`

- - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `Models()`

  - ### Method Summary

    All Methods Static Methods Concrete Methods Deprecated Methods
    Modifier and Type | Method and Description
    --- | ---
    `static Value` | `anyObject(Model m)` Deprecated. since 2.0. Use `object(Model)` instead.
    `static Literal` | `anyObjectLiteral(Model m)` Deprecated. since 2.0. Use `objectLiteral(Model)` instead.
    `static Resource` | `anyObjectResource(Model m)` Deprecated. since 2.0. Use `objectResource(Model)` instead.
    `static URI` | `anyObjectURI(Model m)` Deprecated. since 2.0. Use `objectIRI(Model)` instead.
    `static URI` | `anyPredicate(Model m)` Deprecated. since 2.0. Use `predicate(Model)` instead.
    `static Resource` | `anySubject(Model m)` Deprecated. since 2.0. Use `subject(Model)` instead.
    `static BNode` | `anySubjectBNode(Model m)` Deprecated. since 2.0. Use `subjectBNode(Model)` instead.
    `static URI` | `anySubjectURI(Model m)` Deprecated. since 2.0. Use `subjectIRI(Model)` instead.
    `static boolean` | `equals(Iterable<? extends Statement> model1, Iterable<? extends Statement> model2)` Deprecated. since 2.0. Use `isomorphic(Iterable, Iterable)` instead.
    `static Set<Value>` | `getProperties(Model m, Resource subject, IRI property, Resource... contexts)` Retrieve all property values for the supplied subject and property from the given model.
    `static Optional<Value>` | `getProperty(Model m, Resource subject, IRI property, Resource... contexts)` Retrieve a property value for the supplied subject from the given model.
    `static Optional<IRI>` | `getPropertyIRI(Model m, Resource subject, IRI property, Resource... contexts)` Retrieve a property value as an IRI for the supplied subject from the given model.
    `static Set<IRI>` | `getPropertyIRIs(Model m, Resource subject, IRI property, Resource... contexts)` Retrieve all property IRI values for the supplied subject and property from the given model.
    `static Optional<Literal>` | `getPropertyLiteral(Model m, Resource subject, IRI property, Resource... contexts)` Retrieve a property value as a `Literal` for the supplied subject from the given model.
    `static Set<Literal>` | `getPropertyLiterals(Model m, Resource subject, IRI property, Resource... contexts)` Retrieve all property Literal values for the supplied subject and property from the given model.
    `static Optional<Resource>` | `getPropertyResource(Model m, Resource subject, IRI property, Resource... contexts)` Retrieve a property value as an IRI for the supplied subject from the given model.
    `static Set<Resource>` | `getPropertyResources(Model m, Resource subject, IRI property, Resource... contexts)` Retrieve all property Resource values for the supplied subject and property from the given model.
    `static Optional<String>` | `getPropertyString(Model m, Resource subject, IRI property, Resource... contexts)` Retrieve a property value as a String for the supplied subject from the given model.
    `static Set<String>` | `getPropertyStrings(Model m, Resource subject, IRI property, Resource... contexts)` Retrieve all property values as Strings for the supplied subject and property from the given model.
    `static boolean` | `isomorphic(Iterable<? extends Statement> model1, Iterable<? extends Statement> model2)` Compares two RDF models, and returns `true` if they consist of isomorphic graphs and the isomorphic graph identifiers map 1:1 to each other.
    `static boolean` | `isSubset(Iterable<? extends Statement> model1, Iterable<? extends Statement> model2)` Compares two RDF models, and returns `true` if the first model is a subset of the second model, using graph isomorphism to map statements between models.
    `static boolean` | `isSubset(Set<? extends Statement> model1, Set<? extends Statement> model2)` Compares two RDF models, and returns `true` if the first model is a subset of the second model, using graph isomorphism to map statements between models.
    `static java.util.function.Supplier<ModelException>` | `modelException(String message)` Creates a `Supplier` of `ModelException` objects that be passed to `Optional.orElseThrow(Supplier)` to generate exceptions as necessary.
    `static Optional<Value>` | `object(Model m)` Retrieves an object `Value` from the statements in the given model.
    `static Optional<IRI>` | `objectIRI(Model m)` Retrieves an object `IRI` value from the statements in the given model.
    `static Set<IRI>` | `objectIRIs(Model m)` Retrieves all object `IRI` values from the statements in the given model.
    `static Optional<Literal>` | `objectLiteral(Model m)` Retrieves an object `Literal` value from the statements in the given model.
    `static Set<Literal>` | `objectLiterals(Model m)` Retrieves all object `Literal` values from the statements in the given model.
    `static Optional<Resource>` | `objectResource(Model m)` Retrieves an object `Resource` value from the statements in the given model.
    `static Set<Resource>` | `objectResources(Model m)` Retrieves all object `Resource` values from the statements in the given model.
    `static Optional<String>` | `objectString(Model m)` Retrieves an object value as a String from the statements in the given model.
    `static Set<String>` | `objectStrings(Model m)` Retrieves all object String values from the statements in the given model.
    `static Optional<IRI>` | `predicate(Model m)` Retrieves a predicate from the statements in the given model.
    `static Model` | `setProperty(Model m, Resource subject, IRI property, Value value, Resource... contexts)` Sets the property value for the given subject to the given object value, replacing any existing value(s) for the subject's property.
    `static Optional<Resource>` | `subject(Model m)` Retrieves a subject `Resource` from the statements in the given model.
    `static Optional<BNode>` | `subjectBNode(Model m)` Retrieves a subject `BNode` from the statements in the given model.
    `static Set<BNode>` | `subjectBNodes(Model m)` Retrieves all subject `BNode`s from the statements in the given model.
    `static Optional<IRI>` | `subjectIRI(Model m)` Retrieves a subject `IRI` from the statements in the given model.
    `static Set<IRI>` | `subjectIRIs(Model m)` Retrieves all subject `IRI`s from the statements in the given model.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### Models

          protected Models()

  - ### Method Detail

    - #### object

          public static Optional<Value> object(Model m)

      Retrieves an object `Value` from the statements in the given model. If more than one possible object value exists, any one value is picked and returned.
      Parameters:
        `m` - the model from which to retrieve an object value.
      Returns:
        an object value from the given model, or `Optional.empty()` if no such value exists.

    - #### anyObject

          @Deprecated
          public static Value anyObject(Model m)

      Deprecated. since 2.0. Use `object(Model)` instead.

    - #### objectLiteral

          public static Optional<Literal> objectLiteral(Model m)

      Retrieves an object `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.
      Parameters:
        `m` - the model from which to retrieve an object Literal value.
      Returns:
        an object Literal value from the given model, or `Optional.empty()` if no such value exists.

    - #### objectLiterals

          public static Set<Literal> objectLiterals(Model m)

      Retrieves all object `Literal` values from the statements in the given model.
      Parameters:
        `m` - the model from which to retrieve all object `Literal` values.
      Returns:
        a `Set` containing object `Literal` values from the given model, which will be empty if no such value exists.
      See Also:
        `Model.objects()`

    - #### anyObjectLiteral

          @Deprecated
          public static Literal anyObjectLiteral(Model m)

      Deprecated. since 2.0. Use `objectLiteral(Model)` instead.

    - #### objectResource

          public static Optional<Resource> objectResource(Model m)

      Retrieves an object `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.
      Parameters:
        `m` - the model from which to retrieve an object Resource value.
      Returns:
        an `Optional` object Resource value from the given model, which will be `empty` if no such value exists.

    - #### objectResources

          public static Set<Resource> objectResources(Model m)

      Retrieves all object `Resource` values from the statements in the given model.
      Parameters:
        `m` - the model from which to retrieve all object `Resource` values.
      Returns:
        a `Set` containing object `Resource` values from the given model, which will be empty if no such value exists.
      See Also:
        `Model.objects()`

    - #### anyObjectResource

          @Deprecated
          public static Resource anyObjectResource(Model m)

      Deprecated. since 2.0. Use `objectResource(Model)` instead.

    - #### objectIRI

          public static Optional<IRI> objectIRI(Model m)

      Retrieves an object `IRI` value from the statements in the given model. If more than one possible IRI value exists, any one value is picked and returned.
      Parameters:
        `m` - the model from which to retrieve an object IRI value.
      Returns:
        an `Optional` object IRI value from the given model, which will be `empty` if no such value exists.

    - #### objectIRIs

          public static Set<IRI> objectIRIs(Model m)

      Retrieves all object `IRI` values from the statements in the given model.
      Parameters:
        `m` - the model from which to retrieve all object IRI values.
      Returns:
        a `Set` containing object IRI values from the given model, which will be empty if no such value exists.
      See Also:
        `Model.objects()`

    - #### objectString

          public static Optional<String> objectString(Model m)

      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.
      Parameters:
        `m` - the model from which to retrieve an object String value.
      Returns:
        an `Optional` object String value from the given model, which will be `empty` if no such value exists.

    - #### objectStrings

          public static Set<String> objectStrings(Model m)

      Retrieves all object String values from the statements in the given model.
      Parameters:
        `m` - the model from which to retrieve all object String values.
      Returns:
        a `Set` containing object String values from the given model, which will be empty if no such value exists.
      See Also:
        `Model.objects()`

    - #### anyObjectURI

          @Deprecated
          public static URI anyObjectURI(Model m)

      Deprecated. since 2.0. Use `objectIRI(Model)` instead.

    - #### subject

          public static Optional<Resource> subject(Model m)

      Retrieves a subject `Resource` from the statements in the given model. If more than one possible resource value exists, any one resource value is picked and returned.
      Parameters:
        `m` - the model from which to retrieve a subject Resource.
      Returns:
        an `Optional` subject resource from the given model, which will be `empty` if no such value exists.

    - #### anySubject

          @Deprecated
          public static Resource anySubject(Model m)

      Deprecated. since 2.0. Use `subject(Model)` instead.

    - #### subjectIRI

          public static Optional<IRI> subjectIRI(Model m)

      Retrieves a subject `IRI` from the statements in the given model. If more than one possible IRI value exists, any one IRI value is picked and returned.
      Parameters:
        `m` - the model from which to retrieve a subject IRI value.
      Returns:
        an `Optional` subject IRI value from the given model, which will be `empty` if no such value exists.

    - #### subjectIRIs

          public static Set<IRI> subjectIRIs(Model m)

      Retrieves all subject `IRI`s from the statements in the given model.
      Parameters:
        `m` - the model from which to retrieve a subject IRI value.
      Returns:
        a `Set` of subject IRI values from the given model. The returned Set may be empty.

    - #### anySubjectURI

          @Deprecated
          public static URI anySubjectURI(Model m)

      Deprecated. since 2.0. Use `subjectIRI(Model)` instead.

    - #### subjectBNode

          public static Optional<BNode> subjectBNode(Model m)

      Retrieves a subject `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.
      Parameters:
        `m` - the model from which to retrieve a subject BNode value.
      Returns:
        an `Optional` subject BNode value from the given model, which will be `empty` if no such value exists.

    - #### subjectBNodes

          public static Set<BNode> subjectBNodes(Model m)

      Retrieves all subject `BNode`s from the statements in the given model.
      Parameters:
        `m` - the model from which to retrieve a subject IRI value.
      Returns:
        a `Set` of subject `BNode` values from the given model. The returned Set may be empty.

    - #### anySubjectBNode

          @Deprecated
          public static BNode anySubjectBNode(Model m)

      Deprecated. since 2.0. Use `subjectBNode(Model)` instead.

    - #### predicate

          public static Optional<IRI> predicate(Model m)

      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.
      Parameters:
        `m` - the model from which to retrieve a predicate value.
      Returns:
        an `Optional` predicate value from the given model, which will be `empty` if no such value exists.

    - #### anyPredicate

          @Deprecated
          public static URI anyPredicate(Model m)

      Deprecated. since 2.0. Use `predicate(Model)` instead.

    - #### setProperty

          public static Model setProperty(Model m,
                                          Resource subject,
                                          IRI property,
                                          Value value,
                                          Resource... contexts)

      Sets the property value for the given subject to the given object value, replacing any existing value(s) for the subject's property. This method updates the original input Model and then returns that same Model object.
      Parameters:
        `m` - the model in which to set the property value. May not be null.
        `subject` - the subject for which to set/replace the property value. May not be null.
        `property` - the property for which to set/replace the value. May not be null.
        `value` - the value to set for the given subject and property. May not be null.
        `contexts` - the context(s) in which to set/replace the property value. Optional vararg argument. If not specified the operations works on the entire Model.
      Returns:
        the Model object, containing the updated property value.

    - #### getProperty

          public static Optional<Value> getProperty(Model m,
                                                    Resource subject,
                                                    IRI property,
                                                    Resource... contexts)

      Retrieve a property value for the supplied subject from the given model. If more than one property value exists, any one value is picked and returned.
      Parameters:
        `m` - the model from which to retrieve an object value.
        `subject` - the subject resource for which to retrieve a property value.
        `property` - the property for which to retrieve a value.
        `contexts` - the contexts from which to retrieve the property value. Optional vararg argument. If not specified the operations works on the entire Model.
      Returns:
        a property value from the given model, or `Optional.empty()` if no such value exists.

    - #### getProperties

          public static Set<Value> getProperties(Model m,
                                                 Resource subject,
                                                 IRI property,
                                                 Resource... contexts)

      Retrieve all property values for the supplied subject and property from the given model.
      Parameters:
        `m` - the model from which to retrieve the property values.
        `subject` - the subject resource for which to retrieve all property values.
        `property` - the property for which to retrieve all values.
        `contexts` - the contexts from which to retrieve the property values. Optional vararg argument. If not specified the operations works on the entire Model.
      Returns:
        a Set of all property values for the supplied input. The resulting set may be empty.

    - #### getPropertyResource

          public static Optional<Resource> getPropertyResource(Model m,
                                                               Resource subject,
                                                               IRI property,
                                                               Resource... contexts)

      Retrieve a property value as an IRI for the supplied subject from the given model. If more than one property value exists, any one value is picked and returned.
      Parameters:
        `m` - the model from which to retrieve an object value.
        `subject` - the subject resource for which to retrieve a property value.
        `property` - the property for which to retrieve a value.
        `contexts` - the contexts from which to retrieve the property value. Optional vararg argument. If not specified the operations works on the entire Model.
      Returns:
        a property value Resource from the given model, or `Optional.empty()` if no such value exists.

    - #### getPropertyResources

          public static Set<Resource> getPropertyResources(Model m,
                                                           Resource subject,
                                                           IRI property,
                                                           Resource... contexts)

      Retrieve all property Resource values for the supplied subject and property from the given model.
      Parameters:
        `m` - the model from which to retrieve the property Resource values.
        `subject` - the subject resource for which to retrieve all property Resource values.
        `property` - the property for which to retrieve all Resource values.
        `contexts` - the contexts from which to retrieve the property values. Optional vararg argument. If not specified the operations works on the entire Model.
      Returns:
        a Set of all property Resource values for the supplied input. The resulting set may be empty.

    - #### getPropertyIRI

          public static Optional<IRI> getPropertyIRI(Model m,
                                                     Resource subject,
                                                     IRI property,
                                                     Resource... contexts)

      Retrieve a property value as an IRI for the supplied subject from the given model. If more than one property value exists, any one value is picked and returned.
      Parameters:
        `m` - the model from which to retrieve an object value.
        `subject` - the subject resource for which to retrieve a property value.
        `property` - the property for which to retrieve a value.
        `contexts` - the contexts from which to retrieve the property value. Optional vararg argument. If not specified the operations works on the entire Model.
      Returns:
        a property value IRI from the given model, or `Optional.empty()` if no such value exists.

    - #### getPropertyIRIs

          public static Set<IRI> getPropertyIRIs(Model m,
                                                 Resource subject,
                                                 IRI property,
                                                 Resource... contexts)

      Retrieve all property IRI values for the supplied subject and property from the given model.
      Parameters:
        `m` - the model from which to retrieve the property IRI values.
        `subject` - the subject resource for which to retrieve all property IRI values.
        `property` - the property for which to retrieve all IRI values.
        `contexts` - the contexts from which to retrieve the property values. Optional vararg argument. If not specified the operations works on the entire Model.
      Returns:
        a Set of all property IRI values for the supplied input. The resulting set may be empty.

    - #### getPropertyLiteral

          public static Optional<Literal> getPropertyLiteral(Model m,
                                                             Resource subject,
                                                             IRI property,
                                                             Resource... contexts)

      Retrieve a property value as a `Literal` for the supplied subject from the given model. If more than one property value exists, any one value is picked and returned.
      Parameters:
        `m` - the model from which to retrieve an object value.
        `subject` - the subject resource for which to retrieve a property literal value.
        `property` - the property for which to retrieve a value.
        `contexts` - the contexts from which to retrieve the property value. Optional vararg argument. If not specified the operations works on the entire Model.
      Returns:
        a property value Literal from the given model, or `Optional.empty()` if no such value exists.

    - #### getPropertyLiterals

          public static Set<Literal> getPropertyLiterals(Model m,
                                                         Resource subject,
                                                         IRI property,
                                                         Resource... contexts)

      Retrieve all property Literal values for the supplied subject and property from the given model.
      Parameters:
        `m` - the model from which to retrieve the property Literal values.
        `subject` - the subject resource for which to retrieve all property Literal values.
        `property` - the property for which to retrieve all Literal values.
        `contexts` - the contexts from which to retrieve the property values. Optional vararg argument. If not specified the operations works on the entire Model.
      Returns:
        a Set of all property IRI values for the supplied input. The resulting set may be empty.

    - #### getPropertyString

          public static Optional<String> getPropertyString(Model m,
                                                           Resource subject,
                                                           IRI property,
                                                           Resource... contexts)

      Retrieve a property value as a String for the supplied subject from the given model. If more than one property value exists, any one value is picked and returned.
      Parameters:
        `m` - the model from which to retrieve an object value.
        `subject` - the subject resource for which to retrieve a property literal value.
        `property` - the property for which to retrieve a value.
        `contexts` - the contexts from which to retrieve the property value. Optional vararg argument. If not specified the operations works on the entire Model.
      Returns:
        a property value String from the given model, or `Optional.empty()` if no such value exists.

    - #### getPropertyStrings

          public static Set<String> getPropertyStrings(Model m,
                                                       Resource subject,
                                                       IRI property,
                                                       Resource... contexts)

      Retrieve all property values as Strings for the supplied subject and property from the given model.
      Parameters:
        `m` - the model from which to retrieve the property values as Strings.
        `subject` - the subject resource for which to retrieve all property values as Strings.
        `property` - the property for which to retrieve all values as Strings.
        `contexts` - the contexts from which to retrieve the property values. Optional vararg argument. If not specified the operations works on the entire Model.
      Returns:
        a Set of all property values as Strings for the supplied input. The resulting set may be empty.

    - #### isomorphic

          public static boolean isomorphic(Iterable<? extends Statement> model1,
                                           Iterable<? extends Statement> model2)

      Compares two RDF models, and returns `true` if they consist of isomorphic graphs and the isomorphic graph identifiers map 1:1 to each other. RDF graphs are isomorphic graphs if statements from one graphs can be mapped 1:1 on to statements in the other graphs. In this mapping, blank nodes are not considered mapped when having an identical internal id, but are mapped from one graph to the other by looking at the statements in which the blank nodes occur. A Model can consist of more than one graph (denoted by context identifiers). Two models are considered isomorphic if for each of the graphs in one model, an isomorphic graph exists in the other model, and the context identifiers of these graphs are either identical or (in the case of blank nodes) map 1:1 on each other.
      See Also:
        RDF Concepts & Abstract Syntax, section 3.6 (Graph Comparison)

    - #### equals

          @Deprecated
          public static boolean equals(Iterable<? extends Statement> model1,
                                                   Iterable<? extends Statement> model2)

      Deprecated. since 2.0. Use `isomorphic(Iterable, Iterable)` instead.
      Compares two RDF models, defined by two statement collections, and returns `true` if they are equal. Models are equal if they contain the same set of statements. Blank node IDs are not relevant for model equality, they are mapped from one model to the other by using the attached properties.

    - #### isSubset

          public static boolean isSubset(Iterable<? extends Statement> model1,
                                         Iterable<? extends Statement> model2)

      Compares two RDF models, and returns `true` if the first model is a subset of the second model, using graph isomorphism to map statements between models.

    - #### isSubset

          public static boolean isSubset(Set<? extends Statement> model1,
                                         Set<? extends Statement> model2)

      Compares two RDF models, and returns `true` if the first model is a subset of the second model, using graph isomorphism to map statements between models.

    - #### modelException

          public static java.util.function.Supplier<ModelException> modelException(String message)

      Creates a `Supplier` of `ModelException` objects that be passed to `Optional.orElseThrow(Supplier)` to generate exceptions as necessary.
      Parameters:
        `message` - The message to be used for the exception
      Returns:
        A `Supplier` that will create `ModelException` objects with the given message.

Copyright © 2015-2020 Eclipse Foundation. All Rights Reserved.