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
4454aa47
Commit
4454aa47
authored
May 12, 2016
by
c24b
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
encours: parsers
parent
9a0747ad
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
64 additions
and
24 deletions
+64
-24
Cern.py
gargantext/util/parsers/Cern.py
+64
-24
No files found.
gargantext/util/parsers/Cern.py
View file @
4454aa47
...
...
@@ -7,42 +7,68 @@ import json
from
lxml
import
etree
class
CernParser
(
Parser
):
#mapping MARC21 ==> hyperdata
MARC21
=
{
"100"
:{
"a"
:
"author_name"
,
"v"
:
"author_affiliation"
,
"w"
:
"author_country"
,
"m"
:
"author_mail"
,
},
"700"
:
{
"a"
:
"coauthor_name"
,
"v"
:
"coauthor_affiliation"
,
"w"
:
"coauthor_country"
,
#here main author
"100"
:{
"a"
:
"author_name"
,
"v"
:
"author_affiliation"
,
"w"
:
"author_country"
,
"m"
:
"author_mail"
,
},
"773"
:{
"c"
:
"pages"
,
#here cooauthor
"700"
:
{
"a"
:
"authors_name"
,
"v"
:
"authors_affiliation"
,
"w"
:
"authors_country"
,
},
"773"
:{
"c"
:
"pages"
,
"n"
:
"issue"
,
"p"
:
"journal"
,
"v"
:
"volume"
,
"y"
:
"year"
},
"024"
:
{
"a"
:
"
DOI
"
},
"037"
:
{
"a"
:
"
ArX
iv"
},
"022"
:
{
"a"
:
"
ISSN
"
},
"245"
:
{
"a"
:
"
T
itle"
},
"520"
:
{
"a"
:
"
A
bstract"
},
"260"
:
{
"b"
:
"
Publisher"
,
"c"
:
"P
ubdate"
},
"024"
:
{
"t"
:
"D
ate"
},
"540"
:
{
"a"
:
"L
icence"
},
"653"
:
{
"a"
:
"keywords"
},
"856"
:
{
"u"
:
"pdf_source"
},
"024"
:
{
"a"
:
"
doi
"
},
"037"
:
{
"a"
:
"
arx
iv"
},
"022"
:
{
"a"
:
"
isbn
"
},
"245"
:
{
"a"
:
"
t
itle"
},
"520"
:
{
"a"
:
"
a
bstract"
},
"260"
:
{
"b"
:
"
publisher"
,
"c"
:
"p
ubdate"
},
#"024": {"t":"d
ate"},
#"540": {"a":"l
icence"},
#
"653": {"a":"keywords"},
#
"856": {"u":"pdf_source"},
}
#~ hyperdata_item = {
#~ "journal" : '',
#~ "title" : '',
#~ "abstract" : '',
#~ "title" : '',
#~ "language_iso2" : 'en',
#~ "doi" : '',
#~ "realdate_full_" : '',
#~ "realdate_year_" : '',
#~ "realdate_month_" : '',
#~ "realdate_day_" : '',
#~ "publication_year" : '',
#~ "publication_month" : '',
#~ "publication_day" : '',
#~ "authors" : '',
#~ "authors_countries" : '',
#~ "authors_affiliations": '',
#~ "publisher": '',
#~ }
def
parse
(
self
,
filebuf
):
doc
=
etree
.
parse
(
filebuf
)
def
parse
(
self
,
file
):
if
isinstance
(
file
,
str
):
file
=
open
(
file
,
'rb'
)
doc
=
etree
.
parse
(
file
.
read
())
tree
=
etree
.
tostring
(
doc
)
#parser = etree.XMLParser()
hyperdata_list
=
[]
soup
=
BeautifulSoup
(
tree
,
"lxml"
)
for
record
in
soup
.
find_all
(
"record"
):
r
=
{
v
:[]
for
v
in
self
.
MARC21
[
"700"
]
.
values
()}
r
[
"uid"
]
=
soup
.
find
(
"controlfield"
)
.
text
for
data
in
soup
.
find_all
(
"datafield"
):
...
...
@@ -53,8 +79,22 @@ class CernParser(Parser):
if
code
in
self
.
MARC21
[
tag
]
.
keys
():
if
tag
==
"700"
:
r
[
self
.
MARC21
[
tag
][
code
]]
.
append
(
sub
.
text
)
if
tag
==
"100"
:
r
[
self
.
MARC21
[
"700"
][
code
]]
.
insert
(
0
,
sub
.
text
)
else
:
r
[
self
.
MARC21
[
tag
][
code
]]
=
sub
.
text
records
.
append
(
r
.
decode
(
'utf-8'
))
print
(
r
)
#hyperdata_list.append(r["uid.decode('utf-8'))
break
return
hyperdata_list
if
__name__
==
"__main__"
:
pass
#~ e = CernParser()
#~ hyperdata = e.parse(str(sys.argv[1]))
#~ for h in hyperdata:
#~ try:
#~ print(h['journal'], ":", h['publication_date'])
#~ except:
#~ pass
#~ break
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