Class Statements

java.lang.Object
org.eclipse.rdf4j.model.util.Statements

public class Statements extends Object
Utility methods for working with Statement objects, including conversion to/from RDF 1.2 triple objects.
Author:
Jeen Broekstra
  • Field Details

  • Constructor Details

    • Statements

      public Statements()
  • Method Details

    • consume

      public static void consume(ValueFactory vf, Resource subject, IRI predicate, Value object, Consumer<Statement> consumer, Resource... contexts)
      Creates one or more Statement objects with the given subject, predicate and object, one for each given context, and sends each created statement to the supplied Consumer. If no context is supplied, only a single statement (without any assigned context) is created.
      Parameters:
      vf - the ValueFactory to use for creating statements.
      subject - the subject of each statement. May not be null.
      predicate - the predicate of each statement. May not be null.
      object - the object of each statement. May not be null.
      consumer - the Consumer function for the produced statements.
      contexts - the context(s) for which to produce statements. This argument is an optional vararg: leave it out completely to produce a single statement without context.
    • create

      public static <C extends Collection<Statement>> C create(ValueFactory vf, Resource subject, IRI predicate, Value object, C collection, Resource... contexts)
      Creates one or more Statement objects with the given subject, predicate and object, one for each given context. If no context is supplied, only a single statement (without any assigned context) is created.
      Parameters:
      vf - the ValueFactory to use for creating statements.
      subject - the subject of each statement. May not be null.
      predicate - the predicate of each statement. May not be null.
      object - the object of each statement. May not be null.
      collection - the collection of Statements to which the newly created Statements will be added. May not be null.
      contexts - the context(s) for which to produce statements. This argument is an optional vararg: leave it out completely to produce a single statement without context.
      Returns:
      the input collection of Statements, with the newly created Statements added.
    • stripContext

      public static Statement stripContext(Statement statement)
      Strips the context (if any) from the supplied statement and returns a statement with the same subject, predicate and object, but with no assigned context.
      Parameters:
      statement - the statement to strip the context from
      Returns:
      a statement without context
      Since:
      3.1.0
    • stripContext

      public static Statement stripContext(ValueFactory vf, Statement statement)
      Strips the context (if any) from the supplied statement and returns a statement with the same subject, predicate and object, but with no assigned context.
      Parameters:
      vf - the ValueFactory to use for creating a new Statement.
      statement - the statement to strip the context from.
      Returns:
      a statement without context
      Since:
      3.1.0
    • toTriple

      @Deprecated(since="3.5.0") public static TripleTerm toTriple(Statement statement)
      Deprecated.
      Create an RDF 1.2 triple from the supplied Statement
      Parameters:
      statement - a statement to convert to an RDF 1.2 triple
      Returns:
      an RDF 1.2 triple with the same subject, predicate and object as the input statement.
      Since:
      3.4.0
    • toTriple

      @Deprecated(since="3.5.0") public static TripleTerm toTriple(ValueFactory vf, Statement statement)
      Create an RDF 1.2 triple from the supplied Statement
      Parameters:
      vf - the ValueFactory to use for creating the TripleTerm object.
      statement - a statement to convert to an RDF 1.2 triple
      Returns:
      an RDF 1.2 triple with the same subject, predicate and object as the input statement.
      Since:
      3.4.0
    • toStatement

      public static Statement toStatement(TripleTerm tripleTerm)
      Deprecated.
      Create a Statement from the supplied RDF 1.2 tripleTerm
      Parameters:
      tripleTerm - an RDF 1.2 tripleTerm to convert to a Statement.
      Returns:
      an Statement with the same subject, predicate and object as the input tripleTerm, and no context.
      Since:
      3.4.0
    • statement

      public static Statement statement(TripleTerm tripleTerm)
      Create a Statement from the supplied RDF 1.2 tripleTerm
      Parameters:
      tripleTerm - an RDF 1.2 tripleTerm to convert to a Statement.
      Returns:
      an Statement with the same subject, predicate and object as the input tripleTerm, and no context.
      Since:
      3.4.0
    • statement

      public static Statement statement(TripleTerm tripleTerm, Resource context)
      Create a Statement from the supplied RDF 1.2 tripleTerm and context.
      Parameters:
      tripleTerm - an RDF 1.2 tripleTerm to convert to a Statement.
      context - the context to assign to the Statement.
      Returns:
      an Statement with the same subject, predicate and object as the input tripleTerm, and having the supplied context.
      Since:
      3.7.0
    • toStatement

      public static Statement toStatement(TripleTerm tripleTerm, Resource context)
      Deprecated.
      since 3.7.0 - use statement(TripleTerm, Resource) instead
      Create a Statement from the supplied RDF 1.2 tripleTerm and context.
      Parameters:
      tripleTerm - an RDF 1.2 tripleTerm to convert to a Statement.
      context - the context to assign to the Statement.
      Returns:
      an Statement with the same subject, predicate and object as the input tripleTerm, and having the supplied context.
      Since:
      3.4.0
    • toStatement

      public static Statement toStatement(ValueFactory vf, TripleTerm tripleTerm, Resource context)
      Create a Statement from the supplied RDF 1.2 tripleTerm and context.
      Parameters:
      vf - the ValueFactory to use for creating the Statement object.
      tripleTerm - an RDF 1.2 tripleTerm to convert to a Statement.
      context - the context to assign to the Statement. May be null to indicate no context.
      Returns:
      an Statement with the same subject, predicate and object as the input tripleTerm, and having the supplied context.
      Since:
      3.4.0
    • statement

      public static Statement statement(ValueFactory vf, TripleTerm tripleTerm, Resource context)
      Create a Statement from the supplied RDF 1.2 tripleTerm and context.
      Parameters:
      vf - the ValueFactory to use for creating the Statement object.
      tripleTerm - an RDF 1.2 tripleTerm to convert to a Statement.
      context - the context to assign to the Statement. May be null to indicate no context.
      Returns:
      an Statement with the same subject, predicate and object as the input tripleTerm, and having the supplied context.
      Since:
      3.7.0
    • statement

      public static Statement statement(Resource subject, IRI predicate, Value object, Resource context)
      Create a Statement from the supplied subject, predicate, object and context.
      Parameters:
      subject - the statement subject
      predicate - the statement predicate
      object - the statement object
      context - the context to assign to the Statement. May be null to indicate no context.
      Returns:
      an Statement with the same subject, predicate and object as the input triple, and having the supplied context.
      Throws:
      NullPointerException - if any of subject, predicate, or object are null.
      Since:
      3.5.0
    • statement

      public static Statement statement(ValueFactory vf, Resource subject, IRI predicate, Value object, Resource context)
      Create a Statement from the supplied subject, predicate, object and context.
      Parameters:
      vf - the ValueFactory to use for creating the Statement object.
      subject - the statement subject
      predicate - the statement predicate
      object - the statement object
      context - the context to assign to the Statement. May be null to indicate no context.
      Returns:
      an Statement with the same subject, predicate and object as the input triple, and having the supplied context.
      Throws:
      NullPointerException - if any of vf, subject, predicate, or object are null.
      Since:
      3.5.0
    • isSameTriple

      public static boolean isSameTriple(Statement st1, Statement st2)
      Checks if the two statements represent the same triple (that is, they have equal subject, predicate, and object). Context information is disregarded.
      Parameters:
      st1 - the first statement to compare. May not be null.
      st2 - the second statement to compare. May not be null.
      Returns:
      true iff the subject, predicate and object of st1 and st2 are equal, false otherwise.
      Since:
      2.0
      See Also:
    • convertRDF12ReificationToRDF11

      @Experimental public static void convertRDF12ReificationToRDF11(Statement st, Consumer<Statement> consumer)
      Converts the supplied RDF 1.2 statement to RDF reification statements, and sends the resultant statements to the supplied consumer. If the supplied statement is not RDF 1.2 it will be sent to the consumer as is.

      The statements needed to represent reification will use blank nodes.

      Parameters:
      st - the Statement to convert.
      consumer - the Consumer function for the produced statements.
    • convertRDF12ReificationToRDF11

      @Experimental public static void convertRDF12ReificationToRDF11(ValueFactory vf, Statement st, Consumer<Statement> consumer)
      Converts the supplied RDF 1.2 statement to RDF 1.1 reification statements, and sends the resultant statements to the supplied consumer. If the supplied statement does not contain a triple term it will be sent to the consumer as is.

      The supplied value factory is used to create all new statements.

      Parameters:
      vf - the ValueFactory to use for creating statements.
      st - the Statement to convert,
      consumer - the Consumer function for the produced statements.