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
94e16652
Commit
94e16652
authored
Dec 11, 2015
by
Romain Loth
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
suppression des tags XML avant le parsing POS
parent
27b02533
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
3 deletions
+22
-3
NgramsExtractor.py
parsing/NgramsExtractors/NgramsExtractor.py
+22
-3
No files found.
parsing/NgramsExtractors/NgramsExtractor.py
View file @
94e16652
from
..Taggers
import
TurboTagger
#NltkTagger #,
from
..Taggers
import
NltkTagger
import
nltk
from
re
import
sub
"""Base class for all ngrams extractors.
...
...
@@ -8,6 +9,12 @@ class NgramsExtractor:
"""Class instanciation.
This method can be overriden.
-*-*-*-*-
contenus :
[...'__dict__', '_grammar', '_label', '_rule', 'extract_ngrams', 'start', 'stop', 'tagger']
"""
def
__init__
(
self
,
rule
=
"{<JJ.*>*<NN.*|>+<JJ.*>*}"
):
# TODO add this regex
...
...
@@ -21,7 +28,7 @@ class NgramsExtractor:
self
.
stop
()
def
start
(
self
):
self
.
tagger
=
Turbo
Tagger
()
self
.
tagger
=
Nltk
Tagger
()
def
stop
(
self
):
pass
...
...
@@ -31,9 +38,21 @@ class NgramsExtractor:
Returns a list of the ngrams found in the given text.
"""
def
extract_ngrams
(
self
,
contents
):
tagged_tokens
=
list
(
self
.
tagger
.
tag_text
(
contents
))
clean_contents
=
self
.
_prepare_text
(
contents
)
# ici tagging
tagged_tokens
=
list
(
self
.
tagger
.
tag_text
(
clean_contents
))
if
len
(
tagged_tokens
):
grammar_parsed
=
self
.
_grammar
.
parse
(
tagged_tokens
)
for
subtree
in
grammar_parsed
.
subtrees
():
if
subtree
.
label
()
==
self
.
_label
:
yield
subtree
.
leaves
()
@
staticmethod
def
_prepare_text
(
text_contents
):
"""
Clean the text for better POS tagging
"""
# strip xml tags
return
sub
(
r"<[^>]{0,45}>"
,
""
,
text_contents
)
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