R036 Value Extract Production
Outline
Filters all non-relevant samples and extract textual information from the relevant ones. This information will be converted into a given output signal type.
Platforms: |
|
|||
Requirements: |
|
|||
Known limitations: |
|
|||
Status: |
|
|||
Input signals: |
|
|||
Output signal: |
|
|||
Parameters: |
|
Input Signal Configuration
The production accepts signal of any type.
- Primary Source
- The primary source is the first source signal of the production.
Output Signal Configuration
Productions are executed on the fly, as soon as the signal data is required for further processing, and re-executed when settings or input signal have been changed. Before executing a production, the system needs to know the source signals, the type and the domain of the signal. All these informations need to be entered into the plot configuration dialog. If you leave the configuration fields empty, impulse tries to extract the information from the sources. The fields will display this information in light gray <e.g. Derived(Time)>.
- Signal type
- Select the output signal type of your script (Float, Text, Logic, Integer, ..).
- Signal descriptor
- The signal descriptor describes the signal type in more details (e.g the bit width of a logic vector (default<bits=16>)). See below for more details. But in most case, you will use the standard settings (default<>) - Press CTRL-Space to view content proposals.
- Domain Class/Base
- The domain base is just required if your output signal has a different domain than the source signals. If not, just don't touch these settings.
- Domain Range
- Use this field to set the domain range, so the minimum and maximum value of the domain (e.g. 0 .. 1000 Hz)
Production Configuration
- Filter Member: Select the filter member name or id/index in case of struct or array signals. If left empty, the filtering is performed on the total value.
- Filter: Enter the filter definition. If left empty, no filtering is performed.
- Extract Member: Select the extract member name or id/index in case of array or struct signals. If left empty, the extraction is performed on the total value.
- Extract: Enter the extraction (regular or text) definition.
In case of Struct signals, enter the member name or id of the member. In case of Array signals, enter the member name or index of the member.
The id defines the position of the member definition, whereas the index means the position of the value. Only in case of arrays, id and index are equal.
Example with members (id/member name):
- 0: A
- 1: B
- 2: C
Struct
- 0: data; 1: data
- 1: data; 3: data (data index and member id not identical)
- 0: data;
- 0: data; 1: data; 2:data
Array
- 0: data; 1: data; 2:data (data index and member id identical)
- 0: data; 1: data; 2:data
- 0: data; 1: data; 2:data
The filter definition can be either a text fragment, a regular expression or a numeric expression.
- Filter samples using a text fragment
- abc: Show sample if text contains 'abc'
- Filter samples using a regular expression - Indicate with any of: '[](){}|?*^$.'
- ab[0-9]n? : ... if text matches 'abc0n', ....
- Filter samples using a numeric expression
- 0.4 < 2.0: Show sample if value matches range - use float or integer numbers (e.g. 0.1; 12 ; 0x300)
- < 0x400: ... if value less than argument
- <=-4: ... if value less or equal than argument
- > 2.7: ... if value greater than argument
- >= 0.04: ... if value greater or equal than argument
- == 1000: ... if value equals argument
The extract definition may be either a text fragment or a regular expression.
If text fragment is chosen, the production will try to find the text in the value representation and extracts the following text fragment surrounded by white-spaces.
Example: Sample value = "nx=400 mx=500"; if extract is set to "nx=", the value 400 will be extracted.
If a regular expression is given, the production will try to find a match in the value representation and extracts the 1st group value.
Example: Sample value = "nx=400 mx=500"; if extract is set to "mx\=([0-9]+)", the value 500 will be extracted.
Signal Handling
- Keep tags: The output samples shall keep the tag information of each input sample.
- Ignore 'None': Ignore 'None' samples of the input signals.
- Hide identical: Check to hide sequence of identical samples (will only write to output signal in case of changed sample value/tag, may not have any effect in case of 'Continuous' process type).
The signal handling flags give the user more control over the output signal generation. If the "Keep tags" is checked, the output samples will get the tag information of each input samples. The "Ignore None" flag let the production ignore 'None' input samples. The "Hide identical" hides the production from generating sequences of identical samples.
Operation
Below you find the operation code for the production.
// iterate while (iter.hasNext() && isCanceled()) { // value Long current = iter.next(targetWriter); CompoundValue cvalue = input.compound(); if (cvalue == null) continue; // none sample boolean hasMember = member != null && cvalue.hasMember(member); boolean isNone = cvalue.isNone() || (member != null && !hasMember); if (ignoreNone && isNone) continue; // filter String fval = (isNone || filter == null) ? null : member == null ? cvalue.stringValue() : cvalue.stringValueOf(member); boolean hit = filter != null ? filter.matches(fval != null ? fval : "") : true; // hit if (hit) { // none sample hasMember = emember != null && cvalue.hasMember(emember); isNone = cvalue.isNone() || (emember != null && !hasMember); if (ignoreNone && isNone) continue; String value = null; // value extract if (!isNone) { String val = emember == null ? cvalue.stringValue() : cvalue.stringValueOf(emember); if (val == null) continue; if (extract instanceof String) { int pos = val.indexOf((String) extract); if (pos >= 0) { pos += ((String) extract).length(); while (pos < val.length() && Character.isWhitespace(val.charAt(pos))) pos++; int start = pos; while (pos < val.length() && !Character.isWhitespace(val.charAt(pos))) pos++; int end = pos; if (end > start) { value = val.substring(start, end); } } } else if (extract instanceof Pattern) { Matcher m = ((Pattern) extract).matcher(val); if (m.find() && m.groupCount() == 1) { value = m.group(1); } }else value = val; } if (!isNone && value == null) // could not extract continue; // tag boolean tag = keepTags && cvalue != null && cvalue.isTagged(); // check identical if (!hideIdentical || tag != previousTag || !Utils.equals(value, previousValue)) { // write if (isNone) targetWriter.writeNone(current, tag); else write(targetWriter, current, tag, value); // remember previousTag = tag; previousValue = value; } } }