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
97f70d54
Commit
97f70d54
authored
Aug 25, 2016
by
c24b
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
EUROPRESSE
parent
cc674dea
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
52 additions
and
62 deletions
+52
-62
constants.py
gargantext/constants.py
+3
-3
EUROPRESSE.py
gargantext/util/parsers/EUROPRESSE.py
+1
-11
ngrams_extraction.py
gargantext/util/toolchain/ngrams_extraction.py
+48
-47
parsing.py
gargantext/util/toolchain/parsing.py
+0
-1
No files found.
gargantext/constants.py
View file @
97f70d54
...
...
@@ -145,9 +145,9 @@ def get_tagger(lang):
RESOURCETYPES
=
[
{
"type"
:
1
,
'name'
:
'Europress'
,
'format'
:
'Europress'
,
'parser'
:
"EuropressParser"
,
'name'
:
'Europress
e
'
,
'format'
:
'Europress
e
'
,
'parser'
:
"Europress
e
Parser"
,
'file_formats'
:[
"zip"
],
'crawler'
:
None
,
'default_languages'
:
[
'en'
,
'fr'
],
...
...
gargantext/util/parsers/EUROPRESS.py
→
gargantext/util/parsers/EUROPRESS
E
.py
View file @
97f70d54
...
...
@@ -29,7 +29,7 @@ import sys
from
._Parser
import
Parser
class
EuropressParser
(
Parser
):
class
Europress
e
Parser
(
Parser
):
def
parse
(
self
,
file
):
#print("europr_parser file", file)
...
...
@@ -266,13 +266,3 @@ class EuropressParser(Parser):
except
:
print
(
'Something bad happened.'
)
if
__name__
==
"__main__"
:
e
=
EuropressFileParser
()
hyperdata
=
e
.
parse
(
str
(
sys
.
argv
[
1
]))
for
h
in
hyperdata
:
try
:
print
(
h
[
'journal'
],
":"
,
h
[
'publication_date'
])
except
:
pass
gargantext/util/toolchain/ngrams_extraction.py
View file @
97f70d54
...
...
@@ -48,7 +48,7 @@ def extract_ngrams(corpus, keys=DEFAULT_INDEX_FIELDS, do_subngrams = DEFAULT_IND
documents_count
=
0
source
=
get_resource
(
resource
[
"type"
])
#load only the docs that have passed the parsing without error
docs
=
[
doc
for
doc
in
corpus
.
children
(
'DOCUMENT'
)
if
doc
.
id
not
in
corpus
.
hyperdata
[
"skipped_docs"
]]
#load available taggers for default langage of plateform
#print(LANGUAGES.keys())
tagger_bots
=
{
lang
:
load_tagger
(
lang
)
for
lang
in
corpus
.
hyperdata
[
"languages"
]
\
...
...
@@ -56,53 +56,54 @@ def extract_ngrams(corpus, keys=DEFAULT_INDEX_FIELDS, do_subngrams = DEFAULT_IND
supported_taggers_lang
=
tagger_bots
.
keys
()
#sort docs by lang?
# for lang, tagger in tagger_bots.items():
for
documents_count
,
document
in
enumerate
(
docs
):
language_iso2
=
document
.
hyperdata
.
get
(
'language_iso2'
)
if
language_iso2
not
in
supported_taggers_lang
:
#print("ERROR NO language_iso2")
document
.
status
(
"NGRAMS"
,
error
=
"Error: unsupported language for tagging"
)
session
.
add
(
document
)
session
.
commit
()
corpus
.
hyperdata
[
"skipped_docs"
]
.
append
(
document
.
id
)
corpus
.
save_hyperdata
()
continue
else
:
tagger
=
tagger_bots
[
language_iso2
]
#print(language_iso2)
#>>> romain-stable-patch
#to do verify if document has no KEYS to index
for
key
in
keys
:
try
:
value
=
document
.
hyperdata
[
str
(
key
)]
if
not
isinstance
(
value
,
str
):
#print("DBG wrong content in doc for key", key)
for
documents_count
,
document
in
enumerate
(
corpus
.
children
(
'DOCUMENT'
)):
if
doc
.
id
not
in
corpus
.
hyperdata
[
"skipped_docs"
]:
language_iso2
=
document
.
hyperdata
.
get
(
'language_iso2'
)
if
language_iso2
not
in
supported_taggers_lang
:
#print("ERROR NO language_iso2")
document
.
status
(
"NGRAMS"
,
error
=
"Error: unsupported language for tagging"
)
session
.
add
(
document
)
session
.
commit
()
corpus
.
hyperdata
[
"skipped_docs"
]
.
append
(
document
.
id
)
corpus
.
save_hyperdata
()
continue
else
:
tagger
=
tagger_bots
[
language_iso2
]
#print(language_iso2)
#>>> romain-stable-patch
#to do verify if document has no KEYS to index
for
key
in
keys
:
try
:
value
=
document
.
hyperdata
[
str
(
key
)]
if
not
isinstance
(
value
,
str
):
#print("DBG wrong content in doc for key", key)
continue
# get ngrams
for
ngram
in
tagger
.
extract
(
value
):
tokens
=
tuple
(
normalize_forms
(
token
[
0
])
for
token
in
ngram
)
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
=
' '
.
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
),
))
except
:
#value not in doc
continue
# get ngrams
for
ngram
in
tagger
.
extract
(
value
):
tokens
=
tuple
(
normalize_forms
(
token
[
0
])
for
token
in
ngram
)
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
=
' '
.
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
),
))
except
:
#value not in doc
continue
# integrate ngrams and nodes-ngrams
if
len
(
nodes_ngrams_count
)
>=
BATCH_NGRAMSEXTRACTION_SIZE
:
...
...
gargantext/util/toolchain/parsing.py
View file @
97f70d54
...
...
@@ -164,7 +164,6 @@ def parse(corpus):
except
Exception
as
error
:
corpus
.
status
(
'Docs'
,
error
=
error
)
corpus
.
save_hyperdata
()
session
.
commit
()
raise
error
...
...
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