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
7795a72f
Commit
7795a72f
authored
Jun 01, 2016
by
Romain Loth
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add subsequences of long terms in the counts/indexation + remove debug log
parent
07086b67
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
57 additions
and
7 deletions
+57
-7
constants.py
gargantext/constants.py
+11
-0
ngrams_extraction.py
gargantext/util/toolchain/ngrams_extraction.py
+44
-5
NGrams_dyna_chart_and_table.js
static/lib/gargantext/NGrams_dyna_chart_and_table.js
+2
-2
No files found.
gargantext/constants.py
View file @
7795a72f
...
...
@@ -233,6 +233,17 @@ DEFAULT_ALL_LOWERCASE_FLAG = True # lowercase ngrams before recording
# good for variants like same term
# occurring at sentence beginning)
DEFAULT_INDEX_SUBGRAMS
=
False
# False <=> traditional
# True <=>
# when ngram is like:
# "very cool example"
# then also count:
# "very cool" and "cool example"
# (n-1 length ngrams, at initial
# indexing after extraction)
# ------------------------------------------------------------------------------
# other parameters
...
...
gargantext/util/toolchain/ngrams_extraction.py
View file @
7795a72f
...
...
@@ -33,7 +33,7 @@ def _integrate_associations(nodes_ngrams_count, ngrams_data, db, cursor):
db
.
commit
()
def
extract_ngrams
(
corpus
,
keys
=
(
'title'
,
'abstract'
,
)):
def
extract_ngrams
(
corpus
,
keys
=
(
'title'
,
'abstract'
,
)
,
do_subngrams
=
DEFAULT_INDEX_SUBGRAMS
):
"""Extract ngrams for every document below the given corpus.
Default language is given by the resource type.
The result is then inserted into database.
...
...
@@ -75,10 +75,25 @@ def extract_ngrams(corpus, keys=('title', 'abstract', )):
# get ngrams
for
ngram
in
ngramsextractor
.
extract
(
value
):
tokens
=
tuple
(
token
[
0
]
for
token
in
ngram
)
terms
=
normalize_terms
(
' '
.
join
(
tokens
))
if
len
(
terms
)
>
1
:
nodes_ngrams_count
[(
document
.
id
,
terms
)]
+=
1
ngrams_data
.
add
((
terms
[:
255
],
len
(
tokens
),
))
if
do_subngrams
:
# ex tokens = ["very", "cool", "exemple"]
# subterms = [['very', 'cool'],
# ['very', 'cool', 'exemple'],
# ['cool', 'exemple']]
subterms
=
subsequences
(
tokens
)
else
:
subterms
=
[
tokens
]
for
seqterm
in
subterms
:
ngram
=
normalize_term
(
' '
.
join
(
seqterm
))
if
len
(
ngram
)
>
1
:
# doc <=> ngram index
nodes_ngrams_count
[(
document
.
id
,
ngram
)]
+=
1
# add fields : terms n
ngrams_data
.
add
((
ngram
[:
255
],
len
(
seqterm
),
))
# integrate ngrams and nodes-ngrams
if
len
(
nodes_ngrams_count
)
>=
BATCH_NGRAMSEXTRACTION_SIZE
:
_integrate_associations
(
nodes_ngrams_count
,
ngrams_data
,
db
,
cursor
)
...
...
@@ -116,3 +131,27 @@ def normalize_terms(term_str, do_lowercase=DEFAULT_ALL_LOWERCASE_FLAG):
term_str
=
term_str
.
lower
()
return
term_str
def
subsequences
(
sequence
):
"""
For an array of length n, returns an array of subarrays
with the original and all its sub arrays of length n-1
Ex: subsequences(["Aaa","Bbb", "Ccc", "Ddd"])
[
['Aaa', 'Bbb', 'Ccc'],
['Aaa', 'Bbb', 'Ccc', 'Ddd'],
['Bbb', 'Ccc', 'Ddd']
]
"""
l
=
len
(
sequence
)
li
=
[]
lsave
=
li
.
append
for
i
in
range
(
l
):
for
j
in
range
(
i
+
(
l
-
1
),
l
+
1
):
if
i
!=
j
:
lsave
(
sequence
[
i
:
j
])
# debug
# print(" >", sequence[i:j])
return
li
static/lib/gargantext/NGrams_dyna_chart_and_table.js
View file @
7795a72f
...
...
@@ -1325,8 +1325,8 @@ function InferCRUDFlags(id, oldState, desiredState, registry) {
}
}
}
console
.
log
(
"registry"
)
console
.
log
(
registry
)
//
console.log("registry")
//
console.log(registry)
return
registry
}
...
...
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