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
eb15d263
Commit
eb15d263
authored
May 03, 2016
by
delanoe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[NGRAMS EXTRACTOR] rules in constant, back to a simple rule for debugging.
parent
3b281cbc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
4 deletions
+10
-4
constants.py
gargantext/constants.py
+8
-0
ngramsextractors.py
gargantext/util/ngramsextractors.py
+2
-4
No files found.
gargantext/constants.py
View file @
eb15d263
...
...
@@ -215,3 +215,11 @@ BATCH_NGRAMSEXTRACTION_SIZE = 1024
# Scrapers config
QUERY_SIZE_N_MAX
=
1000
QUERY_SIZE_N_DEFAULT
=
1000
# Grammar rules for chunking
RULE_JJNN
=
"{<JJ.*>*<NN.*|>+<JJ.*>*}"
RULE_JJDTNN
=
"{<JJ.*>*<NN.*>+((<P|IN> <DT>? <JJ.*>* <NN.*>+ <JJ.*>*)|(<JJ.*>))*}"
RULE_TINA
=
"^((VBD,|VBG,|VBN,|CD.?,|JJ.?,|
\
?,){0,2}?(N.?.?,|
\
?,)+?(CD.,)??)
\
+?((PREP.?|DET.?,|IN.?,|CC.?,|
\
?,)((VBD,|VBG,|VBN,|CD.?,|JJ.?,|
\
?
\
,){0,2}?(N.?.?,|
\
?,)+?)+?)*?$"
gargantext/util/ngramsextractors.py
View file @
eb15d263
from
gargantext.util.languages
import
languages
from
gargantext.constants
import
LANGUAGES
,
DEFAULT_MAX_NGRAM_LEN
from
gargantext.constants
import
LANGUAGES
,
DEFAULT_MAX_NGRAM_LEN
,
RULE_JJNN
,
RULE_JJDTNN
import
nltk
import
re
class
NgramsExtractor
:
def
__init__
(
self
,
tagger
):
...
...
@@ -17,7 +15,7 @@ class NgramsExtractor:
"""
return
re
.
sub
(
r'<[^>]{0,45}>'
,
''
,
text
)
def
extract
(
self
,
text
,
rule
=
'{<JJ.*>*<NN.*>+((<P|IN> <DT>? <JJ.*>* <NN.*>+ <JJ.*>*)|(<JJ.*>))*}'
,
label
=
'NP'
,
max_n_words
=
DEFAULT_MAX_NGRAM_LEN
):
def
extract
(
self
,
text
,
rule
=
RULE_JJNN
,
label
=
'NP'
,
max_n_words
=
DEFAULT_MAX_NGRAM_LEN
):
text
=
self
.
clean_text
(
text
)
grammar
=
nltk
.
RegexpParser
(
label
+
': '
+
rule
)
tagged_tokens
=
list
(
self
.
_tagger
.
tag_text
(
text
))
...
...
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