Package com.stardog.stark

# Class Graphs

java.lang.Object
com.stardog.stark.Graphs

public final class Graphs extends Object

Utilities for working with collections of RDF `statements`.

Since:
  1.0
Version:
  1.0
Author:
  Michael Grove

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `Graphs()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static Set<Statement>`
  `applyContext(Collection<Statement> theStatements, Resource theContext)`
  Create a copy of the statements, modifying them, to apply the given context to each.
  `static List<Value>`
  `asList(Collection<Statement> theGraph, Resource theRes)`
  Return the contents of the given list by following the `rdf:first`/`rdf:rest` structure of the list
  `static Set<Resource>`
  `contexts(Collection<Statement> theStatements)`
  `static boolean`
  `isList(Collection<Statement> theGraph, Resource theRes)`
  Returns whether or not the given resource is a `rdf:List`
  `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 Stream<Statement>`
  `matching(Iterable<Statement> theStmts, StatementPattern thePattern)`
  Return all the `statements` that `match the pattern`.
  `static Set<Statement>`
  `named(Iterable<Statement> theStatements, Resource theContext)`
  Apply the given context to all of the statements, including Statement values in the subject position.
  `static Optional<Value>`
  `object(Iterable<Statement> theStatements, Resource theSubj, IRI thePred)`
  Return the object for the given SP.
  `static Set<Value>`
  `objects(Collection<Statement> theStatements)`
  `static Set<IRI>`
  `predicates(Collection<Statement> theStatements)`
  `static Set<Resource>`
  `subjects(Collection<Statement> theStatements)`
  `static Stream<Resource>`
  `subjectsOfType(Iterable<Statement> theStatements, IRI theClass)`
  `static Set<Statement>`
  `toList(List<Resource> theResources)`
  Return the contents of the list serialized as an RDF list

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

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

- ## Constructor Details

  - ### Graphs

    public Graphs()

- ## Method Details

  - ### subjects

    @Nonnull public static Set<Resource> subjects(@Nonnull Collection<Statement> theStatements)

  - ### predicates

    @Nonnull public static Set<IRI> predicates(@Nonnull Collection<Statement> theStatements)

  - ### objects

    @Nonnull public static Set<Value> objects(@Nonnull Collection<Statement> theStatements)

  - ### contexts

    @Nonnull public static Set<Resource> contexts(@Nonnull Collection<Statement> theStatements)

  - ### applyContext

    @Nonnull public static Set<Statement> applyContext(@Nonnull Collection<Statement> theStatements, @Nonnull Resource theContext)
    Create a copy of the statements, modifying them, to apply the given context to each.
    Parameters:
      `theStatements` - the statements
      `theContext` - the new context
    Returns:
      the new statements

  - ### matching

    @Nonnull public static Stream<Statement> matching(@Nonnull Iterable<Statement> theStmts, @Nonnull StatementPattern thePattern)
    Return all the `statements` that `match the pattern`.
    Parameters:
      `theStmts` - the statements
      `thePattern` - the pattern to match
    Returns:
      the matching statements

  - ### object

    @Nonnull public static Optional<Value> object(@Nonnull Iterable<Statement> theStatements, @Nonnull Resource theSubj, @Nonnull IRI thePred)
    Return the object for the given SP. If the SP combination has more than one object associated with it, only the first one will be returned.
    Parameters:
      `theStatements` - the statements
      `theSubj` - the subject
      `thePred` - the predicate
    Returns:
      the object for the given SP

  - ### named

    @Nonnull public static Set<Statement> named(@Nonnull Iterable<Statement> theStatements, @Nonnull Resource theContext)
    Apply the given context to all of the statements, including Statement values in the subject position.
    Parameters:
      `theStatements` - the graph of statements
      `theContext` - the context to apply
    Returns:
      A *new* set of statements all of which are in the given context

  - ### isList

    public static boolean isList(@Nonnull Collection<Statement> theGraph, @Nonnull Resource theRes)
    Returns whether or not the given resource is a `rdf:List`
    Parameters:
      `theGraph` - the graph
      `theRes` - the resource to check
    Returns:
      `true` if its a list, `false` otherwise

  - ### asList

    @Nonnull public static List<Value> asList(@Nonnull Collection<Statement> theGraph, @Nonnull Resource theRes)
    Return the contents of the given list by following the `rdf:first`/`rdf:rest` structure of the list
    Parameters:
      `theGraph` - the graph
      `theRes` - the resource which is the head of the list
    Returns:
      the contents of the list.

  - ### toList

    @Nonnull public static Set<Statement> toList(@Nonnull List<Resource> theResources)
    Return the contents of the list serialized as an RDF list
    Parameters:
      `theResources` - the list
    Returns:
      the list as RDF

  - ### isomorphic

    public static boolean isomorphic(@Nonnull Iterable<? extends Statement> model1, @Nonnull 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)

  - ### subjectsOfType

    public static Stream<Resource> subjectsOfType(Iterable<Statement> theStatements, IRI theClass)