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
5118824d
Commit
5118824d
authored
Sep 06, 2016
by
Romain Loth
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
risparser: fix handling of continuation lines
parent
a4a744d7
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
56 additions
and
38 deletions
+56
-38
RIS.py
gargantext/util/parsers/RIS.py
+56
-38
No files found.
gargantext/util/parsers/RIS.py
View file @
5118824d
...
...
@@ -47,11 +47,19 @@ class RISParser(Parser):
for
line
in
file
:
# bytes ~~> str
line
=
line
.
decode
(
"UTF-8"
)
.
rstrip
(
'
\r\n
'
)
# print("RIS line:", line)
if
len
(
line
)
>=
2
:
# extract the parameter key...
# print("(nonemptyline)")
# test if key line (otherwise: continuation line)
if
match
(
r'[A-Z][A-Z0-9]\s'
,
line
):
parameter_key
=
line
[:
2
]
# print("(matchparamline:"+parameter_key+")")
# ...and keep the rest for when we know what to do with it
# we can now be sure that the value is rest of the line
# (keep it for when we know what to do with it)
current_value
=
line
[
self
.
_begin
:]
# it's a new key => therefore the previous key is finished
...
...
@@ -68,6 +76,7 @@ class RISParser(Parser):
hyperdata
[
parameter
[
"key"
]]
=
final_value
else
:
hyperdata
=
PY_values_decompose_and_save
(
final_value
,
hyperdata
)
# print("{saved previous"+last_key+"}")
#... or even finish the record (rare here, most often after empty line)
elif
parameter
[
"type"
]
==
"delimiter"
:
...
...
@@ -76,6 +85,7 @@ class RISParser(Parser):
if
'language_iso2'
not
in
hyperdata
.
keys
():
hyperdata
[
'language_iso2'
]
=
'en'
yield
hyperdata
# print("{saved previous record}")
last_key
=
None
hyperdata
=
{}
...
...
@@ -83,13 +93,20 @@ class RISParser(Parser):
last_values
=
[]
last_key
=
parameter_key
# 3 - new key or old: in any case we pass contents to
# continuation line: values start from position 0
else
:
current_value
=
line
# print("(continuationline)")
# 3 - new key or old or no key: in any case we pass contents to
# the value array buffer (=> for the next loop only)
last_values
.
append
(
current_value
)
current_value
=
None
# empty line => we need to check if PREVIOUS LINE was record delimiter
else
:
# print("(emptyline)")
if
last_key
in
self
.
_parameters
:
if
parameter
[
"type"
]
==
"delimiter"
:
if
'language_fullname'
not
in
hyperdata
.
keys
():
...
...
@@ -97,6 +114,7 @@ class RISParser(Parser):
if
'language_iso2'
not
in
hyperdata
.
keys
():
hyperdata
[
'language_iso2'
]
=
'en'
yield
hyperdata
# print("{saved previous record}")
last_key
=
None
hyperdata
=
{}
# [end of loop per lines]
...
...
@@ -111,6 +129,7 @@ class RISParser(Parser):
hyperdata
[
parameter
[
"key"
]]
=
final_value
else
:
hyperdata
=
PY_values_decompose_and_save
(
final_value
,
hyperdata
)
# print("{saved previous"+last_key+"}")
# if a hyperdata object is left in memory, yield it as well
if
hyperdata
:
...
...
@@ -119,8 +138,7 @@ class RISParser(Parser):
if
'language_iso2'
not
in
hyperdata
.
keys
():
hyperdata
[
'language_iso2'
]
=
'en'
yield
hyperdata
# print("{saved previous record}")
...
...
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