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
4b5e0672
Commit
4b5e0672
authored
May 16, 2017
by
delanoe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[FEAT] ISIDORE backend almost done needs to connect Gargantext worflow.
parent
747c0a60
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
782 additions
and
18 deletions
+782
-18
bool2sparql.py
moissonneurs/bool2sparql.py
+58
-18
sparql.py
moissonneurs/sparql.py
+724
-0
No files found.
moissonneurs/bool2sparql.py
View file @
4b5e0672
import
subprocess
import
sparql
as
s
import
subprocess
def
bool2sparql
(
query
,
count
=
False
,
limit
=
None
):
"""
bool2sparql :: String -> Bool -> Int -> String
Translate a boolean query into a Sparql request
You need to build bool2sparql binaries before
See: https://github.com/delanoe/bool2sparql
"""
bashCommand
=
[
"./bool2sparql-exe"
,
"-q"
,
query
]
if
count
is
True
:
bashCommand
.
append
(
"-c"
)
else
:
for
command
in
[
"-l"
,
str
(
limit
)]
:
bashCommand
.
append
(
command
)
process
=
subprocess
.
Popen
(
bashCommand
,
stdout
=
subprocess
.
PIPE
)
output
,
error
=
process
.
communicate
()
if
error
is
not
None
:
raise
(
error
)
else
:
return
(
output
.
decode
(
"utf-8"
))
def
isidore
(
query
,
count
=
False
,
limit
=
None
):
"""
isidore :: String -> Bool -> Int -> Either (Dict String) Int
use sparql-client either to search or to scan
"""
query
=
bool2sparql
(
query
,
count
,
limit
)
print
(
query
)
go
=
s
.
Service
(
"https://www.rechercheisidore.fr/sparql/"
,
"utf-8"
,
"GET"
)
results
=
go
.
query
(
query
)
query
=
"bourdieu OR habitus"
if
count
is
False
:
for
r
in
results
:
doc
=
dict
()
doc_values
=
dict
()
doc
[
"url"
],
doc
[
"id"
],
doc
[
"title"
],
doc
[
"date"
],
doc
[
"abstract"
],
doc
[
"journal"
]
=
r
#def bool2sparql(query, count=False, limit=None):
for
k
in
doc
.
keys
():
doc_values
[
k
]
=
doc
[
k
]
.
value
countCommand
=
[
"./bool2sparql-exe"
,
"-q"
,
query
,
"-c"
]
getCommand
=
[
"./bool2sparql-exe"
,
"-q"
,
query
,
"-l"
,
"100"
]
yield
(
doc_values
)
process
=
subprocess
.
Popen
(
countCommand
,
stdout
=
subprocess
.
PIPE
)
output
,
error
=
process
.
communicate
()
sparqlQuery
=
output
.
decode
(
"utf-8"
)
else
:
count
=
[]
for
r
in
results
:
n
,
=
r
count
.
append
(
int
(
n
.
value
))
yield
count
[
0
]
print
(
sparqlQuery
)
def
test
():
query
=
"ricoeur"
limit
=
2
c
=
s
.
Service
(
"https://www.rechercheisidore.fr/sparql/"
,
"utf-8"
,
"GET"
)
for
d
in
isidore
(
query
,
limit
=
limit
):
print
(
d
[
"abstract"
])
print
([
n
for
n
in
isidore
(
query
,
count
=
True
)])
test
()
# count:
count
=
[]
for
r
in
result
:
(
n
,)
=
r
count
.
append
(
n
.
value
)
#print(n.split('\"')[1])
#print(r)
print
(
count
[
0
])
moissonneurs/sparql.py
0 → 100755
View file @
4b5e0672
This diff is collapsed.
Click to expand it.
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