Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
python-common
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
nomad-lab
python-common
Commits
abb31fc5
Commit
abb31fc5
authored
9 years ago
by
Henning Glawe
Browse files
Options
Downloads
Patches
Plain Diff
move gathering of match telementry to match_info
parent
957445fc
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
common/python/nomadcore/annotator.py
+71
-41
71 additions, 41 deletions
common/python/nomadcore/annotator.py
with
71 additions
and
41 deletions
common/python/nomadcore/annotator.py
+
71
−
41
View file @
abb31fc5
...
...
@@ -41,31 +41,64 @@ class Annotator(object):
self
.
_formatNameWidth
=
formatNameWidth
self
.
_update_annotate_format
()
def
annotate
(
self
,
match
,
line
,
matcher
,
targetStartEnd
):
# classify match
full
=
match
and
match
.
start
()
==
0
and
match
.
end
()
==
len
(
line
)
local_ignore
=
False
global_ignore
=
False
matcher_does_nothing
=
False
def
match_info
(
self
,
match
,
line
,
matcher
,
targetStartEnd
):
result
=
{
# raw line
'
line
'
:
line
,
# information about SimpleMatcher
'
name
'
:
matcher
.
name
if
matcher
.
name
else
'
UNNAMED
'
,
'
defFile
'
:
matcher
.
defFile
,
'
defLine
'
:
matcher
.
defLine
,
'
matcher_does_nothing
'
:
matcher
.
does_nothing
,
# matcher without effect
'
which_re
'
:
'
end
'
if
targetStartEnd
else
'
start
'
,
# classification of match
'
match
'
:
0
,
# 0 - no, 1 - partial, 2 - full
'
coverageIgnore
'
:
0
,
# 0 - no, 1 - local, 2 - global
# overall span of match
'
span
'
:
[],
# capture groups
'
group
'
:
[],
}
if
match
:
if
matcher
.
coverageIgnore
:
local_ignore
=
True
elif
matcher
.
does_nothing
:
matcher_does_nothing
=
True
result
[
'
span
'
]
=
[
match
.
start
(),
match
.
end
()]
if
match
.
start
()
==
0
and
match
.
end
()
==
len
(
line
):
result
[
'
match
'
]
=
2
# full match
else
:
result
[
'
match
'
]
=
1
# partial match
if
matcher
.
coverageIgnore
:
# matcher is local coverageIgnore
result
[
'
coverageIgnore
'
]
=
1
# capture groups
# todo: move this to SimpleMatcher/CompiledMatcher
groupname
=
[
'
all
'
]
+
[
str
(
num
+
1
)
for
num
in
range
(
match
.
re
.
groups
)]
for
name
,
num
in
match
.
re
.
groupindex
.
items
():
groupname
[
num
]
=
name
# extract capture group info
for
groupi
in
range
(
1
,
match
.
re
.
groups
+
1
):
# Forward compatibility with 'regex' or 're2', which support
# multiple captures per named group:
# span: list of start/end indices
# capture: list of matched strings
result
[
'
group
'
].
append
({
'
name
'
:
groupname
[
groupi
],
'
span
'
:
[],
'
capture
'
:
[]})
if
match
.
group
(
groupi
)
is
not
None
:
result
[
'
group
'
][
-
1
][
'
capture
'
].
append
(
match
.
group
(
groupi
))
result
[
'
group
'
][
-
1
][
'
span
'
].
append
(
match
.
span
(
groupi
))
else
:
m2
=
self
.
coverageIgnore
.
match
(
line
)
if
m2
:
global_ignore
=
True
match
=
m2
m_ci
=
self
.
coverageIgnore
.
match
(
line
)
if
m_ci
:
result
[
'
coverageIgnore
'
]
=
2
# global coverageIgnore matched
result
[
'
span
'
]
=
[
m_ci
.
start
(),
m_ci
.
end
()]
return
result
def
annotate
(
self
,
match
,
line
,
matcher
,
targetStartEnd
):
minfo
=
self
.
match_info
(
match
,
line
,
matcher
,
targetStartEnd
)
# update counters
self
.
counter
[
'
total
'
]
+=
1
if
local_ignore
or
global_i
gnore
:
if
minfo
[
'
coverageI
gnore
'
]
:
self
.
counter
[
'
ignore
'
]
+=
1
elif
match
:
if
full
:
elif
minfo
[
'
match
'
]
>
1
:
self
.
counter
[
'
match
'
]
+=
1
else
:
elif
minfo
[
'
match
'
]
:
self
.
counter
[
'
partial
'
]
+=
1
else
:
self
.
counter
[
'
unmatched
'
]
+=
1
...
...
@@ -76,36 +109,33 @@ class Annotator(object):
# setup match label
matchlabel
=
''
if
local_ignore
:
if
minfo
[
'
coverageIgnore
'
]
==
1
:
matchlabel
=
'
l_ign
'
elif
global_i
gnore
:
elif
minfo
[
'
coverageI
gnore
'
]
:
matchlabel
=
'
g_ign
'
elif
match
:
if
matcher_does_nothing
:
elif
minfo
[
'
match
'
]
:
if
minfo
[
'
matcher_does_nothing
'
]
:
matchlabel
=
'
n_
'
if
not
full
:
if
minfo
[
'
match
'
]
<
2
:
matchlabel
+=
'
p_
'
matchlabel
+=
'
end
'
if
targetStartEnd
else
'
start
'
matchlabel
+=
minfo
[
'
which_re
'
]
else
:
matchlabel
=
'
no
'
# highlight line
if
local_ignore
or
global_i
gnore
:
highlighted
=
self
.
matchHighlighter
.
highlight
(
m
atch
,
line
,
linecolor
=
ANSI
.
FG_BLUE
)
elif
matcher_does_nothing
:
highlighted
=
self
.
matchHighlighter
.
highlight
(
m
atch
,
line
,
linecolor
=
ANSI
.
FG_MAGENTA
)
elif
match
:
highlighted
=
self
.
matchHighlighter
.
highlight
(
match
,
line
)
if
minfo
[
'
coverageI
gnore
'
]
:
highlighted
=
self
.
matchHighlighter
.
highlight
_minfo
(
m
info
,
linecolor
=
ANSI
.
FG_BLUE
)
elif
minfo
[
'
matcher_does_nothing
'
]
:
highlighted
=
self
.
matchHighlighter
.
highlight
_minfo
(
m
info
,
linecolor
=
ANSI
.
FG_MAGENTA
)
elif
minfo
[
'
match
'
]
:
highlighted
=
self
.
matchHighlighter
.
highlight
_minfo
(
minfo
)
else
:
highlighted
=
line
# set matcher name
if
matcher
.
name
:
name
=
matcher
.
name
[
-
self
.
_formatNameWidth
:]
else
:
name
=
'
UNNAMED
'
defFile
=
matcher
.
defFile
[
-
self
.
_formatSourceWidth
:]
# shorted matcher- and source file names
name
=
minfo
[
'
name
'
][
-
self
.
_formatNameWidth
:]
defFile
=
minfo
[
'
defFile
'
][
-
self
.
_formatSourceWidth
:]
self
.
annotateFile
.
write
(
self
.
_annotate_format
%
(
defFile
,
m
atcher
.
defLine
,
name
,
defFile
,
m
info
[
'
defLine
'
]
,
name
,
matchlabel
,
highlighted
,
))
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