Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
nifi-processors
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
gn4-3-wp8-t3.1 SOC
nifi-processors
Commits
da9e7a2d
Commit
da9e7a2d
authored
4 years ago
by
Václav Bartoš
Browse files
Options
Downloads
Patches
Plain Diff
FreqProcessor: Added support for nested fields.
plus data type check added
parent
913e1634
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
scripts/freq/freqProcessor.py
+27
-9
27 additions, 9 deletions
scripts/freq/freqProcessor.py
with
27 additions
and
9 deletions
scripts/freq/freqProcessor.py
+
27
−
9
View file @
da9e7a2d
...
...
@@ -208,16 +208,34 @@ class FreqProcessor(AbstractProcessor):
Get domain form record, compute probability using the FreqCounter,
and store the resulting probabilities to the record.
"""
text
=
record
.
getValue
(
self
.
input_field_name
)
if
text
is
None
:
# FlowFile attribute tells we should take the domain from the field
# names as $input_field_name, but such a field i not present in the
# record.
# Don't set the result fields
self
.
logger
.
warn
(
"
The
'
Input field
'
attribute points to
'
{}
'
field which is not present in the record.
"
.
format
(
self
.
input_field_name
))
return
# Get value of given field.
# The field name may look like 'xx/yy/zz'. There can be a field with
# exactly this key (incl. slashes), or there can be tree of nested
# keys/sub-objects.
# First, try to get the field by its full name.
value
=
record
.
getValue
(
self
.
input_field_name
)
if
value
is
None
:
# The field named exactly as $input_field_name is not present in
# the record. Maybe it's a nested key ...
if
"
/
"
in
self
.
input_field_name
:
path_parts
=
self
.
input_field_name
.
split
(
'
/
'
)
# Get first sub-key/sub-object (returns another MapRecord or None)
value
=
record
.
getValue
(
path_parts
.
pop
(
0
))
# iterate any possible sub-objects to final sub-key
while
value
and
path_parts
:
value
=
value
.
getValue
(
path_parts
.
pop
(
0
))
# If value is still None, the field is not there
# -> don't set the result fields
if
value
is
None
:
self
.
logger
.
warn
(
"
The
'
Input field
'
attribute points to
'
{}
'
field which is not present in the record, record skipped.
"
.
format
(
self
.
input_field_name
))
return
prob1
,
prob2
=
self
.
fc
.
probability
(
text
)
if
not
isinstance
(
value
,
(
str
,
unicode
)):
self
.
logger
.
warn
(
"
Value of the
'
{}
'
field is not a string, record skipped.
"
.
format
(
self
.
input_field_name
))
return
prob1
,
prob2
=
self
.
fc
.
probability
(
value
)
record
.
setValue
(
self
.
result1_field_name
,
prob1
)
record
.
setValue
(
self
.
result2_field_name
,
prob2
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment