@FunctionalInterface public interface Transformer
Statement -> Statement [0..*] transformer.
A Transformer is a stateless function mapping an input Statement to zero or
more output Statements, via method transform(Statement, RDFHandler); for
efficiency reasons, output statements are not returned as a list but are instead forwarded to a
supplied RDFHandler (this avoids creation of intermediate array/lists objects, as well
as the efficient mapping of a statement to a large number of output statements). While somehow
similar to an RDFProcessor, a Transformer operates on a statement at a time,
whereas an RDFProcessor transforms streams of statements, i.e., it can perform
transformations that depends on combinations or sets of statements rather than on a single
input statement.
Implementations of this interface should be thread-safe, i.e., they should support multiple
threads calling concurrently method transform(); this can be however achieved by means
of synchronization.
A number of constants and static factory methods provide access to basic Transformer
implementations:
NIL is the null transformer, mapping every statement to an empty statement list;IDENTITY is the identity transformer, mapping every statement to itself;filter(Predicate) and filter(String, Predicate) create transformers that
apply a given Predicate to check the input statements or its components, emitting the
statement only if the check is successful;map(Function) and map(String, Function) create transformers that apply a
given Function to transform the input statement or its components, emitting the result
to the supplied RDFHandler;set(String, Value...) create transformers that replace selected components of the
input statement;sequence(Transformer...) chains multiple transformers so that the output of one is
used as the input of the next;parallel(Transformer...) calls multiple transformers in parallel, emitting the
concatenation of their results;rules(String) return a transformer that applies the filtering rules encoded in a
supplied string.| Modifier and Type | Field and Description |
|---|---|
static Transformer |
IDENTITY
The identity
Transformer, that maps every input statement to itself. |
static Transformer |
NIL
The null
Transformer, that maps each statement to an empty list of statements. |
| Modifier and Type | Method and Description |
|---|---|
static Transformer |
filter(Predicate<? super org.openrdf.model.Statement> predicate)
Returns a
Transformer that emits only statements matching the supplied
Predicate. |
static Transformer |
filter(String components,
Predicate<? super org.openrdf.model.Value> predicate)
Returns a
Transformer that emits only statements whose selected component matches
the specified Predicate. |
static Transformer |
map(Function<? super org.openrdf.model.Statement,? extends org.openrdf.model.Statement> function)
Returns a
Transformer that applies the supplied function to each input statement,
emitting its output if not null. |
static Transformer |
map(String components,
Function<? super org.openrdf.model.Value,? extends org.openrdf.model.Value> function)
Returns a
Transformer that replaces selected components of the input statement
using the supplied function. |
static Transformer |
parallel(Transformer... transformers)
Returns a
Transfomer that applies each supplied transformer in parallel, emitting
the concatenation of their results to the supplied RDFHandler. |
static Transformer |
parse(String expression)
Parses a
Transformer out of the supplied expression string. |
static Transformer |
rules(String rules)
Returns a
Transformer applying the filtering and assignent rules encoded by the
supplied string. |
static Transformer |
sequence(Transformer... transformers)
Returns a
Transformer chaining the specified Transformers. |
static Transformer |
set(String components,
org.openrdf.model.Value... values)
Returns a
Transformer that replaces selected components of the input statement with
the replacement values supplied. |
void |
transform(org.openrdf.model.Statement statement,
org.openrdf.rio.RDFHandler handler)
Applies the
Transformer to the specified statement, emitting its output (possibly
empty) to the supplied RDFHandler. |
static final Transformer NIL
Transformer, that maps each statement to an empty list of statements.static final Transformer IDENTITY
Transformer, that maps every input statement to itself.static Transformer filter(Predicate<? super org.openrdf.model.Statement> predicate)
Transformer that emits only statements matching the supplied
Predicate.predicate - the predicate, not nullTransformerstatic Transformer filter(String components, Predicate<? super org.openrdf.model.Value> predicate)
Transformer that emits only statements whose selected component matches
the specified Predicate. The predicate is evaluated on each s, p,
o , c component given by the components string. If any of these
tests fails, the input statement is dropped, otherwise it is emitted to the
RDFHandler.components - a string of symbols s , p, o, c specifying which
components to test, not nullpredicate - the predicate to apply to selected components, not nullTransformerstatic Transformer map(Function<? super org.openrdf.model.Statement,? extends org.openrdf.model.Statement> function)
Transformer that applies the supplied function to each input statement,
emitting its output if not null.function - the function to apply, not nullTransformerstatic Transformer map(String components, Function<? super org.openrdf.model.Value,? extends org.openrdf.model.Value> function)
Transformer that replaces selected components of the input statement
using the supplied function. The function is applied to each s, p,
o , c component given by the components string. The resulting
component values, if not null and compatible with expected component types, are used to
assemble an output statement that is emitted to the supplied RDFHandler.components - a string of symbols s , p, o, c specifying the
components to replace, not nullfunction - the function to apply to selected components, not nullTransformerstatic Transformer set(String components, org.openrdf.model.Value... values)
Transformer that replaces selected components of the input statement with
the replacement values supplied. Parameter components is a sequence of s,
p, o, c symbols that specify the components to replace. The i-th
symbol corresponds to a replacement i-th value in the array values (if the array is
shorter, its last element is used). An output statement is assembled by mixing unmodified
components with replaced ones. If a valid statement is obtained, it is emitted to the
supplied RDFHandler.components - a string of symbols s , p, o, c specifying the
components to replace, not nullvalues - the replacement values, with i-th value corresponding to the i-th symbol (if
fewer values are supplied, the last value is used for unmatched component
symbols).Transformerstatic Transformer sequence(Transformer... transformers)
Transformer chaining the specified Transformers. The first
supplied transformer is applied first, its output piped to the next transformer and so on,
with the final result sent to the supplied RDFHandler. If no transformer is
supplied, NIL is returned.transformers - the transformers to chainTransformerstatic Transformer parallel(Transformer... transformers)
Transfomer that applies each supplied transformer in parallel, emitting
the concatenation of their results to the supplied RDFHandler.transformers - the transformers to compose in parallelTransformerstatic Transformer rules(String rules)
Transformer applying the filtering and assignent rules encoded by the
supplied string. Given X a quad component (values: s, p, o,
c), the string contains three types of rules:
+X value list - quad is dropped if X does not belong to list;-X value list - quad is dropped if X belongs to list;=X value - quad component X is replaced with value (evaluated
after filters).<*> - any URI;_:* - any BNode;* - any literal;*@* - any literal with a language;*@xyz - any literal with language xyz;*^^* - any typed literal;*^^<uri> - any literal with datatype <uri>;*^^ns:uri - any literal with datatype ns:uri;*^^ns:* - any typed literal with datatype prefixed with ns:;ns:* - any URI prefixed with ns:;<ns*> - any URI with namespace URI ns.rules - the filtering rules, not nullTransformer@Nullable static Transformer parse(@Nullable String expression)
Transformer out of the supplied expression string. The expression can be a
language: expression script or a rules expression supported by
rules(String).expression - the expression to parsevoid transform(org.openrdf.model.Statement statement,
org.openrdf.rio.RDFHandler handler)
throws org.openrdf.rio.RDFHandlerException
Transformer to the specified statement, emitting its output (possibly
empty) to the supplied RDFHandler. Statement emission should be performed calling
method RDFHandler.handleStatement(Statement); other RDFHandler methods
should not be called. This method is meant to be called concurrently by multiple thread, so
a thread-safe implementation is required.statement - the input statement, not nullhandler - the RDFHandler where to emit output statementsorg.openrdf.rio.RDFHandlerException - in case of errorCopyright © 2015–2016 FBK-irst. All rights reserved.