Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
humanities
gargantext
Commits
95f90782
Commit
95f90782
authored
Oct 19, 2014
by
Mathieu Rodic
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Slighlty improved the generic class for ngrams extraction.
parent
0d98962c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
15 deletions
+7
-15
NgramsExtractor.py
mat-parsing/NgramsExtractors/NgramsExtractor.py
+7
-15
No files found.
mat-parsing/NgramsExtractors/NgramsExtractor.py
View file @
95f90782
...
...
@@ -9,9 +9,10 @@ class NgramsExtractor:
"""Class instanciation.
This method can be overriden.
"""
def
__init__
(
self
,
rule
=
"
NP:
{<JJ.*>*<NN.*|>+<JJ.*>*}"
):
def
__init__
(
self
,
rule
=
"{<JJ.*>*<NN.*|>+<JJ.*>*}"
):
self
.
start
()
self
.
_rule
=
rule
self
.
_label
=
"NP"
self
.
_rule
=
self
.
_label
+
": "
+
rule
def
__del__
(
self
):
self
.
stop
()
...
...
@@ -33,20 +34,11 @@ class NgramsExtractor:
result
=
[]
try
:
grammar_parsed
=
grammar
.
parse
(
tagged_ngrams
)
grammar_parsed_iterator
=
grammar_parsed
.
subtrees
()
while
True
:
try
:
subtree
=
next
(
grammar_parsed_iterator
)
if
subtree
.
label
()
==
'NP'
:
#print(subtree.label())
result
.
append
(
subtree
.
leaves
())
except
Exception
as
e
:
break
for
subtree
in
grammar_parsed
.
subtrees
():
if
subtree
.
label
()
==
self
.
_label
:
result
.
append
(
subtree
.
leaves
())
except
Exception
as
e
:
print
(
e
)
print
(
"Problem while parsing rule '
%
s'"
%
(
self
.
_rule
,
)
)
pass
return
iter
(
result
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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