Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RL-Parsing
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
Franck Dary
RL-Parsing
Commits
2e8416db
Commit
2e8416db
authored
3 years ago
by
Franck Dary
Browse files
Options
Downloads
Patches
Plain Diff
class block
parent
873f6c87
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
readTrace.py
+52
-20
52 additions, 20 deletions
readTrace.py
with
52 additions
and
20 deletions
readTrace.py
+
52
−
20
View file @
2e8416db
...
...
@@ -58,6 +58,49 @@ class Step() :
#-------------------------------------------------------------------------------
################################################################################
################################################################################
class
Block
()
:
#-------------------------------------------------------------------------------
def
__init__
(
self
,
state
)
:
self
.
versions
=
[[]]
# List of list of steps
self
.
state
=
state
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
def
addStep
(
self
,
step
)
:
self
.
versions
[
-
1
].
append
(
step
)
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
def
newVersion
(
self
)
:
self
.
versions
.
append
([])
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
def
nbVersions
(
self
)
:
return
len
(
self
.
versions
)
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
def
getAsLines
(
self
,
maxNbVersions
)
:
output
=
[]
versions
=
[]
for
version
in
self
.
versions
:
versions
.
append
([])
lineStr
=
englobStr
(
"
State %d
"
%
self
.
state
,
"
-
"
,
lenLine
())
versions
[
-
1
].
append
(
lineStr
+
(
lenLine
()
-
len
(
lineStr
))
*
"
"
)
for
step
in
version
:
versions
[
-
1
].
append
(
str
(
step
)
+
(
lenLine
()
-
len
(
str
(
step
)))
*
"
"
)
maxIndex
=
max
([
len
(
version
)
for
version
in
versions
])
for
i
in
range
(
maxIndex
)
:
output
.
append
(
""
)
for
j
in
range
(
maxNbVersions
)
:
output
[
-
1
]
+=
(
"
\t
"
if
j
>
0
else
""
)
+
(
versions
[
j
][
i
]
if
j
in
range
(
len
(
versions
))
and
i
in
range
(
len
(
versions
[
j
]))
else
lenLine
()
*
"
"
)
return
output
#-------------------------------------------------------------------------------
################################################################################
################################################################################
class
History
()
:
#-------------------------------------------------------------------------------
...
...
@@ -67,7 +110,7 @@ class History() :
#-------------------------------------------------------------------------------
def
segmentInBlocks
(
self
)
:
#structure : sentence = [annotations,list of blocks]
= list of versions = list of steps
#structure : sentence = [annotations,list of blocks]
sentences
=
[]
for
sentenceAnnot
in
self
.
sentences
:
annot
=
sentenceAnnot
[
0
]
...
...
@@ -78,21 +121,21 @@ class History() :
for
step
in
sentence
:
if
lastState
is
not
None
and
lastState
!=
step
.
state
:
blockIndex
+=
1
while
blockIndex
>=
len
(
sentences
[
-
1
][
1
])
:
sentences
[
-
1
][
1
].
append
(
[[]]
)
block
=
sentences
[
-
1
][
1
][
blockIndex
]
[
-
1
]
block
.
a
ppend
(
step
)
if
blockIndex
>=
len
(
sentences
[
-
1
][
1
])
:
sentences
[
-
1
][
1
].
append
(
Block
(
step
.
state
)
)
block
=
sentences
[
-
1
][
1
][
blockIndex
]
block
.
a
ddStep
(
step
)
lastState
=
step
.
state
if
"
BACK
"
in
step
.
action
and
"
NOBACK
"
not
in
step
.
action
:
backSize
=
int
(
step
.
action
.
split
()[
-
1
])
backState
=
step
.
state
while
backSize
>
0
:
blockIndex
-=
1
state
=
sentences
[
-
1
][
1
][
blockIndex
]
[
-
1
][
0
]
.
state
state
=
sentences
[
-
1
][
1
][
blockIndex
].
state
if
state
==
backState
:
backSize
-=
1
for
block
in
sentences
[
-
1
][
1
][
blockIndex
:]
:
block
.
append
([])
block
.
newVersion
()
self
.
sentences
=
sentences
#-------------------------------------------------------------------------------
...
...
@@ -110,22 +153,11 @@ class History() :
for
sentIndex
in
range
(
len
(
self
.
sentences
))
:
sentence
=
self
.
sentences
[
sentIndex
][
1
]
annotations
=
alignAsTab
([
self
.
sentences
[
sentIndex
][
0
][
wid
]
for
wid
in
sorted
(
list
(
self
.
sentences
[
sentIndex
][
0
].
keys
()))])
maxNbVersions
=
max
([
len
(
block
)
for
block
in
sentence
])
maxNbVersions
=
max
([
block
.
nbVersions
(
)
for
block
in
sentence
])
print
(
englobStr
(
"
Sentence %d
"
%
sentIndex
,
"
-
"
,
(
1
+
maxNbVersions
)
*
(
1
+
lenLine
())),
file
=
out
)
totalOutput
=
[]
for
block
in
sentence
:
versions
=
[]
for
version
in
block
:
versions
.
append
([])
lineStr
=
englobStr
(
"
State %d
"
%
block
[
0
][
0
].
state
,
"
-
"
,
lenLine
())
versions
[
-
1
].
append
(
lineStr
+
(
lenLine
()
-
len
(
lineStr
))
*
"
"
)
for
step
in
version
:
versions
[
-
1
].
append
(
str
(
step
)
+
(
lenLine
()
-
len
(
str
(
step
)))
*
"
"
)
maxIndex
=
max
([
len
(
version
)
for
version
in
versions
])
for
i
in
range
(
maxIndex
)
:
totalOutput
.
append
(
""
)
for
j
in
range
(
maxNbVersions
)
:
totalOutput
[
-
1
]
+=
(
"
\t
"
if
j
>
0
else
""
)
+
(
versions
[
j
][
i
]
if
j
in
range
(
len
(
versions
))
and
i
in
range
(
len
(
versions
[
j
]))
else
lenLine
()
*
"
"
)
totalOutput
+=
block
.
getAsLines
(
maxNbVersions
)
for
i
in
range
(
len
(
totalOutput
))
:
print
(
totalOutput
[
i
]
+
(
"
\t
"
+
annotations
[
i
]
if
i
in
range
(
len
(
annotations
))
else
""
),
file
=
out
)
print
(
""
,
file
=
out
)
...
...
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