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
c12a0dae
Commit
c12a0dae
authored
Sep 12, 2017
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'unstable' into testing
parents
bfcabfad
ef842d62
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
52 additions
and
42 deletions
+52
-42
HAL.py
gargantext/util/crawlers/HAL.py
+17
-15
HAL.py
gargantext/util/parsers/HAL.py
+29
-26
gargantext_notebook.py
install/notebook/gargantext_notebook.py
+5
-1
overview.html
templates/pages/projects/overview.html
+1
-0
No files found.
gargantext/util/crawlers/HAL.py
View file @
c12a0dae
...
...
@@ -14,12 +14,12 @@ from gargantext.util.files import save
class
HalCrawler
(
Crawler
):
''' HAL API CLIENT'''
def
__init__
(
self
):
# Main EndPoints
self
.
BASE_URL
=
"https://api.archives-ouvertes.fr"
self
.
API_URL
=
"search"
# Final EndPoints
# TODO : Change endpoint according type of database
self
.
URL
=
self
.
BASE_URL
+
"/"
+
self
.
API_URL
...
...
@@ -38,7 +38,9 @@ class HalCrawler(Crawler):
def
_get
(
self
,
query
,
fromPage
=
1
,
count
=
10
,
lang
=
None
):
# Parameters
fl
=
""" en_title_s
fl
=
""" docid
, title_s
, abstract_s
, en_title_s
, en_abstract_s
, submittedDate_s
...
...
@@ -59,7 +61,7 @@ class HalCrawler(Crawler):
"""
#, authUrl_s
#, type_s
wt
=
"json"
querystring
=
{
"q"
:
query
...
...
@@ -68,18 +70,18 @@ class HalCrawler(Crawler):
,
"fl"
:
fl
,
"wt"
:
wt
}
# Specify Headers
headers
=
{
"cache-control"
:
"no-cache"
}
# Do Request and get response
response
=
requests
.
request
(
"GET"
,
self
.
URL
,
headers
=
headers
,
params
=
querystring
)
#print(querystring)
# Validation : 200 if ok else raise Value
if
response
.
status_code
==
200
:
...
...
@@ -90,27 +92,27 @@ class HalCrawler(Crawler):
return
(
json
.
loads
(
response
.
content
.
decode
(
charset
)))
else
:
raise
ValueError
(
response
.
status_code
,
response
.
reason
)
def
scan_results
(
self
,
query
):
'''
scan_results : Returns the number of results
Query String -> Int
'''
self
.
results_nb
=
0
total
=
(
self
.
_get
(
query
)
.
get
(
"response"
,
{})
.
get
(
"numFound"
,
0
)
)
self
.
results_nb
=
total
return
self
.
results_nb
def
download
(
self
,
query
):
downloaded
=
False
self
.
status
.
append
(
"fetching results"
)
corpus
=
[]
...
...
@@ -124,7 +126,7 @@ class HalCrawler(Crawler):
)
print
(
"ERROR (scrap: HAL d/l ): "
,
msg
)
self
.
query_max
=
QUERY_SIZE_N_MAX
#for page in range(1, trunc(self.query_max / 100) + 2):
for
page
in
range
(
0
,
self
.
query_max
,
paging
):
print
(
"Downloading page
%
s to
%
s results"
%
(
page
,
paging
))
...
...
@@ -141,5 +143,5 @@ class HalCrawler(Crawler):
,
basedir
=
UPLOAD_DIRECTORY
)
downloaded
=
True
return
downloaded
gargantext/util/parsers/HAL.py
View file @
c12a0dae
...
...
@@ -12,12 +12,12 @@ import json
class
HalParser
(
Parser
):
def
_parse
(
self
,
json_docs
):
hyperdata_list
=
[]
hyperdata_path
=
{
"id"
:
"
isbn_s
"
,
"title"
:
"en_title_s"
,
"abstract"
:
"en_abstract_s"
hyperdata_path
=
{
"id"
:
"
docid
"
,
"title"
:
[
"en_title_s"
,
"title_s"
]
,
"abstract"
:
[
"en_abstract_s"
,
"abstract_s"
]
,
"source"
:
"journalTitle_s"
,
"url"
:
"uri_s"
,
"authors"
:
"authFullName_s"
...
...
@@ -29,8 +29,8 @@ class HalParser(Parser):
,
"instStructId_i"
:
"instStructId_i"
,
"deptStructId_i"
:
"deptStructId_i"
,
"labStructId_i"
:
"labStructId_i"
,
"rteamStructId_i"
:
"rteamStructId_i"
,
"docType_s"
:
"docType_s"
,
"rteamStructId_i"
:
"rteamStructId_i"
,
"docType_s"
:
"docType_s"
}
uris
=
set
()
...
...
@@ -38,29 +38,32 @@ class HalParser(Parser):
for
doc
in
json_docs
:
hyperdata
=
{}
for
key
,
path
in
hyperdata_path
.
items
():
field
=
doc
.
get
(
path
,
"NOT FOUND"
)
if
isinstance
(
field
,
list
):
hyperdata
[
key
]
=
", "
.
join
(
map
(
lambda
x
:
str
(
x
),
field
))
else
:
hyperdata
[
key
]
=
str
(
field
)
# A path can be a field name or a sequence of field names
if
isinstance
(
path
,
(
list
,
tuple
)):
# Get first non-empty value of fields in path sequence, or None
field
=
next
((
x
for
x
in
(
doc
.
get
(
p
)
for
p
in
path
)
if
x
),
None
)
else
:
# Get field value
field
=
doc
.
get
(
path
)
if
field
is
None
:
field
=
"NOT FOUND"
if
isinstance
(
field
,
list
):
hyperdata
[
key
]
=
", "
.
join
(
map
(
str
,
field
))
else
:
hyperdata
[
key
]
=
str
(
field
)
if
hyperdata
[
"url"
]
in
uris
:
print
(
"Document already parsed"
)
else
:
uris
.
add
(
hyperdata
[
"url"
])
# hyperdata["authors"] = ", ".join(
# [ p.get("person", {})
# .get("name" , "")
#
# for p in doc.get("hasauthor", [])
# ]
# )
#
maybeDate
=
doc
.
get
(
"submittedDate_s"
,
None
)
maybeDate
=
doc
.
get
(
"submittedDate_s"
,
None
)
if
maybeDate
is
not
None
:
date
=
datetime
.
strptime
(
maybeDate
,
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)
else
:
...
...
@@ -70,9 +73,9 @@ class HalParser(Parser):
hyperdata
[
"publication_year"
]
=
str
(
date
.
year
)
hyperdata
[
"publication_month"
]
=
str
(
date
.
month
)
hyperdata
[
"publication_day"
]
=
str
(
date
.
day
)
hyperdata_list
.
append
(
hyperdata
)
return
hyperdata_list
def
parse
(
self
,
filebuf
):
...
...
install/notebook/gargantext_notebook.py
View file @
c12a0dae
...
...
@@ -15,12 +15,16 @@ os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'gargantext.settings')
django
.
setup
()
from
gargantext.constants
import
QUERY_SIZE_N_MAX
,
get_resource
,
get_resource_by_name
from
gargantext.models
import
ProjectNode
,
DocumentNode
,
UserNode
,
User
from
gargantext.models
import
ProjectNode
,
DocumentNode
from
gargantext.util.db
import
session
,
get_engine
from
collections
import
Counter
import
importlib
from
django.http
import
Http404
# Import those to be available by notebook user
from
langdetect
import
detect
as
detect_lang
from
gargantext.models
import
UserNode
,
User
class
NotebookError
(
Exception
):
pass
...
...
templates/pages/projects/overview.html
View file @
c12a0dae
...
...
@@ -203,6 +203,7 @@
// do something…
resetStatusForm
(
"#createForm"
);
})
return
false
;
})
...
...
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