Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
fja
eval
Commits
df1a78ab
Verified
Commit
df1a78ab
authored
Apr 04, 2020
by
Vladimír Štill
Browse files
CFL: A simple big speed optimization for random generation
parent
473edc7b
Changes
1
Hide whitespace changes
Inline
Side-by-side
cfl.py
View file @
df1a78ab
...
...
@@ -826,9 +826,13 @@ class CFGRandom:
weights
:
List
[
int
]
=
[]
for
prod
in
self
.
cfg
.
rules
[
sym
]:
cand
=
sentence
[:
i
]
+
prod
+
sentence
[
i
+
1
:]
w
=
self
.
_materialize_prod
(
cand
,
length
)
suff
=
prod
+
sentence
[
i
+
1
:]
# note: no nonterminals before i ~> the weight of the whole
# candidate is the same as the weight of its suffix starting at
# position i
w
=
self
.
_materialize_prod
(
suff
,
length
-
i
)
if
w
>
0
:
cand
=
sentence
[:
i
]
+
suff
candidates
.
append
(
cand
)
weights
.
append
(
w
)
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment