public class TransformerUtils extends Object
Transformers usually follow one of the following two patterns:
For example a logging transfomer might want to log all of the values for the 'title' field or a lower case transformer might want to convert all of the text in a given field to lowercase. The following methods can be used for this purpose:
TransformerUtils#modifyFieldValues(ProcessingResult, IngestDocument, Iterable, AdvancedFieldValueModifier)
TransformerUtils#modifyFieldValues(ProcessingResult, IngestDocument, Iterable, FieldValueModifier)
For example a pattern based extractor might want to scan the text in one field an output pattern matches to another output field. The following methods can be used for this purpose:
TransformerUtils#mapFieldValues(ProcessingResult, IngestDocument, Map, AdvancedFieldValueMapper)
TransformerUtils#mapFieldValues(ProcessingResult, IngestDocument, Map, FieldValueMapper)
TransformerUtils#mapFieldValues(ProcessingResult, IngestDocument, Map, AdvancedFieldValueMapper, NewFieldCreator)
TransformerUtils#mapFieldValues(ProcessingResult, IngestDocument, Map, FieldValueMapper, NewFieldCreator)
// The actual modifier/mapper interface implemented should be chosen based on your transformer's needs. public class MyTransformer extends AbstractSingleDocumentTransformer implements FieldValueMapper { // provide getters/setters for this private MapfieldMapping = null; &Override public ProcessingResult processDocument(IngestDocument doc) throws AttivioException { return TransformerUtils.mapFieldValues(okResult(), doc, fieldMapping, this); } &Override public Object createMappedValue(ProcessingResult result, String fieldName, IngestFieldValue fv) { // this logic should be replaced with your own return String.valueof(fv.getValue()).toLowerCase(); } }
Constructor and Description |
---|
TransformerUtils() |
Modifier and Type | Method and Description |
---|---|
static Collection<String> |
getAllOrSpecificFieldList(IngestDocument doc,
Collection<String> input)
Returns a specific list of input field names or all fields in the document if the input list is null or empty.
|
static <T> boolean |
mapFieldValues(IngestDocument doc,
FieldValueCreatingTransformer<T> trans)
Applies a FieldValueCreatingTransformer to the given IngestDocument.
|
static void |
mapFieldValues(IngestDocument doc,
Map<String,String> fieldMapping,
AdvancedFieldValueMapper mapper)
Map each document based on the fieldMapping using the supplied
AdvancedFieldValueMapper . |
static void |
mapFieldValues(IngestDocument doc,
Map<String,String> fieldMapping,
AdvancedFieldValueMapper mapper,
NewFieldCreator newFieldCreator)
Map each document based on the fieldMapping using the supplied
FieldValueMapper . |
static void |
mapFieldValues(IngestDocument doc,
Map<String,String> fieldMapping,
FieldValueMapper mapper)
Map each document based on the fieldMapping using the supplied
FieldValueMapper . |
static void |
mapFieldValues(IngestDocument doc,
Map<String,String> fieldMapping,
FieldValueMapper mapper,
NewFieldCreator newFieldCreator)
Map each document based on the fieldMapping using the supplied
FieldValueMapper . |
static void |
modifyFieldValues(IngestDocument doc,
Iterable<String> input,
AdvancedFieldValueModifier handler)
Iterates over all fields in
input , passing the field values for each to the modifier . |
static void |
modifyFieldValues(IngestDocument doc,
Iterable<String> input,
FieldValueModifier modifier)
Iterates over all fields in
input , passing the field values for each to the modifier . |
static <T> boolean |
processDocument(IngestDocument doc,
FieldValueCreatingTransformer<T> transformer)
A processDocument utility method for FieldValueCreatingTransformer, because that class doesn't have one.
|
public static void modifyFieldValues(IngestDocument doc, Iterable<String> input, FieldValueModifier modifier)
input
, passing the field values for each to the modifier
.doc
- the document to processinput
- the input fields to work onmodifier
- the modifier call for each field valuepublic static void modifyFieldValues(IngestDocument doc, Iterable<String> input, AdvancedFieldValueModifier handler)
input
, passing the field values for each to the modifier
.
The AdvancedFieldValueModifier
and this method provide access to more data during each call than the
FieldValueModifier
and the TransformerUtils#modifyFieldValues(ProcessingResult, IngestDocument, Iterable, FieldValueModifier)
method does.doc
- the document to processinput
- the input fields to work onhandler
- the modifier call for each field valuepublic static <T> boolean processDocument(IngestDocument doc, FieldValueCreatingTransformer<T> transformer) throws AttivioException
transformer
- AttivioException
public static void mapFieldValues(IngestDocument doc, Map<String,String> fieldMapping, FieldValueMapper mapper)
FieldValueMapper
.doc
- the document to processfieldMapping
- the field mapping to use. The keys represent the input field names, the values represent the output field
names.mapper
- the mapper to use when processing data.public static void mapFieldValues(IngestDocument doc, Map<String,String> fieldMapping, AdvancedFieldValueMapper mapper)
AdvancedFieldValueMapper
. This method and the
AdvancedFieldValueMapper
provide access to more information in each call than the FieldValueMapper
and the
TransformerUtils#mapFieldValues(ProcessingResult, IngestDocument, Map, FieldValueMapper)
method does.doc
- the document to processfieldMapping
- the field mapping to use. The keys represent the input field names, the values represent the output field
names.mapper
- the mapper to use when processing data.public static void mapFieldValues(IngestDocument doc, Map<String,String> fieldMapping, FieldValueMapper mapper, NewFieldCreator newFieldCreator)
FieldValueMapper
.doc
- the document to processfieldMapping
- the field mapping to use. The keys represent the input field names, the values represent the output field
names.newFieldCreator
- any new fields specified in the fieldMapping will be created using this factorymapper
- the mapper to use when processing data.public static void mapFieldValues(IngestDocument doc, Map<String,String> fieldMapping, AdvancedFieldValueMapper mapper, NewFieldCreator newFieldCreator)
FieldValueMapper
. This method and the
AdvancedFieldValueMapper
provide access to more information in each call than the FieldValueMapper
and the
TransformerUtils#mapFieldValues(ProcessingResult, IngestDocument, Map, FieldValueMapper)
method does.doc
- the document to processfieldMapping
- the field mapping to use. The keys represent the input field names, the values represent the output field
names.newFieldCreator
- any new fields specified in teh fieldMapping will be created using this factorymapper
- the mapper to use when processing data.public static <T> boolean mapFieldValues(IngestDocument doc, FieldValueCreatingTransformer<T> trans) throws AttivioException
doc
- trans
- AttivioException
public static Collection<String> getAllOrSpecificFieldList(IngestDocument doc, Collection<String> input)
Copyright © 2018 Attivio, Inc. All Rights Reserved.
PATENT NOTICE: Attivio, Inc. Software Related Patents. With respect to the Attivio software product(s) being used, the following patents apply: Querying Joined Data Within A Search Engine Index: United States Patent No.(s): 8,073,840. Ordered Processing of Groups of Messages: U.S. Patent No.(s) 8,495,656. Signal processing approach to sentiment analysis for entities in documents: U.S. Patent No.(s) 8,725,494. Other U.S. and International Patents Pending.