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 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:
    • subjectsOfType

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