Class RowProcessor.Builder<T extends Output<T>>
- Type Parameters:
T
- The output type.
- Enclosing class:
- RowProcessor<T extends Output<T>>
RowProcessor
.-
Constructor Summary
ConstructorDescriptionBuilder()
Builder forRowProcessor
, see RowProcessor constructors for argument details. -
Method Summary
Modifier and TypeMethodDescriptionaddFeatureProcessor
(FeatureProcessor featureProcessor) Add a single feature processor to the builder.addFieldProcessor
(FieldProcessor fieldProcessor) Add a single field processor to the builder.addMetadataExtractor
(FieldExtractor<?> metadataExtractor) Add a single metadata extractor to the builder.addRegexMappingProcessor
(String regex, FieldProcessor fieldProcessor) Add a single regex FieldProcessor mapping to the builder.build
(ResponseProcessor<T> responseProcessor) Construct theRowProcessor
represented by this builder's state.getFieldProcessor
(String fieldName) Retrieves, if present, the fieldProcessor with the given namegetRegexFieldProcessor
(String regexName) Retrieves, if present, the regexFieldProcessor with the given regexsetFeatureProcessors
(Set<FeatureProcessor> featureProcessors) TheFeatureProcessor
s to apply to each extracted feature list.setFieldProcessors
(Iterable<FieldProcessor> fieldProcessors) theFieldProcessor
s to apply to each row.setMetadataExtractors
(List<FieldExtractor<?>> metadataExtractors) If set, the suppliedFieldExtractor
s will be run for each example, populatingExample.getMetadata()
.setRegexMappingProcessors
(Map<String, FieldProcessor> regexMappingProcessors) A map from strings (interpreted as regular expressions byPattern.compile(String)
) toFieldProcessor
s such that if a field name matches a regular expression, the corresponding FieldProcessor is used to process it.setReplaceNewLinesWithSpaces
(boolean replaceNewLinesWithSpaces) If true, replaces newlines in fields with spaces before passing them toFieldProcessor
s.setWeightExtractor
(FieldExtractor<Float> weightExtractor) If set, the constructedRowProcessor
will add the extracted floats into theExample.setWeight(float)
s.
-
Constructor Details
-
Builder
public Builder()Builder forRowProcessor
, see RowProcessor constructors for argument details.
-
-
Method Details
-
setReplaceNewLinesWithSpaces
If true, replaces newlines in fields with spaces before passing them toFieldProcessor
s.Defaults to true, some FieldProcessors may behave unexpectedly if this is false.
- Parameters:
replaceNewLinesWithSpaces
- Should newlines be replaced with spaces when parsing fields?- Returns:
- This builder with updated state
-
setWeightExtractor
If set, the constructedRowProcessor
will add the extracted floats into theExample.setWeight(float)
s. Otherwise, all examples will be equally weighted.- Parameters:
weightExtractor
- FieldExtractor to generate example-wise weights- Returns:
- This builder with updated state
-
setMetadataExtractors
If set, the suppliedFieldExtractor
s will be run for each example, populatingExample.getMetadata()
. If two FieldExtractors in this list share the sameFieldExtractor.getMetadataName()
,build(ResponseProcessor)
will throw aPropertyException
.N.B. this method overrides all existing values for metadata extractors, to non-destructively add use
addMetadataExtractor(FieldExtractor)
.- Parameters:
metadataExtractors
- List of metadata extractors to use- Returns:
- This builder with updated state
-
addMetadataExtractor
Add a single metadata extractor to the builder. SeesetMetadataExtractors(List)
for more detail.- Parameters:
metadataExtractor
- The extractor to add.- Returns:
- This builder with updated state
-
setFeatureProcessors
TheFeatureProcessor
s to apply to each extracted feature list.N.B. this method overrides all existing values for feature processors, to non-destructively add use
addFeatureProcessor(FeatureProcessor)
.- Parameters:
featureProcessors
- the processors to add.- Returns:
- This builder with updated state
-
addFeatureProcessor
Add a single feature processor to the builder. SeesetFeatureProcessors(Set)
for more detail.- Parameters:
featureProcessor
- the processor to add.- Returns:
- This builder with updated state
-
addFieldProcessor
Add a single field processor to the builder. If there is already a field processor with the sameFieldProcessor.getFieldName()
, warns and overwrites.- Parameters:
fieldProcessor
- The field processor to add- Returns:
- This builder with updated state
-
setFieldProcessors
theFieldProcessor
s to apply to each row. ThrowsIllegalArgumentException
if fieldProcessors have duplicateFieldProcessor.getFieldName()
values.N.B. this method overrides all existing values for field processors, to non-descructively add use
addFieldProcessor(FieldProcessor)
.- Parameters:
fieldProcessors
- an Iterable of field processors- Returns:
- This builder with updated state
-
getFieldProcessor
Retrieves, if present, the fieldProcessor with the given name- Parameters:
fieldName
- The field name.- Returns:
- The field processor or an empty optional.
-
setRegexMappingProcessors
public RowProcessor.Builder<T> setRegexMappingProcessors(Map<String, FieldProcessor> regexMappingProcessors) A map from strings (interpreted as regular expressions byPattern.compile(String)
) toFieldProcessor
s such that if a field name matches a regular expression, the corresponding FieldProcessor is used to process it.N.B. This method overrides all existing values for regex mapping, to non-destructively add use
addRegexMappingProcessor(String, FieldProcessor)
. If none of the keys in the regex mapping processor match fields in your data, and there are only regex mapped fields, theRowProcessor
's behavior is undefined.- Parameters:
regexMappingProcessors
- The map from regex strings to FieldProcessors.- Returns:
- This builder with updated state
-
getRegexFieldProcessor
Retrieves, if present, the regexFieldProcessor with the given regex- Parameters:
regexName
- The regex.- Returns:
- The regexFieldProcessor or an empty optional.
-
addRegexMappingProcessor
public RowProcessor.Builder<T> addRegexMappingProcessor(String regex, FieldProcessor fieldProcessor) Add a single regex FieldProcessor mapping to the builder. If there is already a field processor with the same regex, warns and overwrites.N.B. If none of the keys in the regex mapping processor match fields in your data, and there are only regex mapped fields, the
RowProcessor
's behavior is undefined.- Parameters:
regex
- The regex to use.fieldProcessor
- The field processor to apply when the regex matches.- Returns:
- This builder with updated state
-
build
Construct theRowProcessor
represented by this builder's state. ThrowsPropertyException
if the state is invalid. ThrowsIllegalArgumentException
if there is not at least oneFieldProcessor
set via eitheraddFieldProcessor(FieldProcessor)
,setFieldProcessors(Iterable)
,addRegexMappingProcessor(String, FieldProcessor)
orsetRegexMappingProcessors(Map)
.N.B. If none of the keys in the regex mapping processor match fields in your data, and there are only regex mapped fields, the
RowProcessor
's behavior is undefined.- Parameters:
responseProcessor
- The response processor to use.- Returns:
- The RowProcessor represented by the builder's state
-