1

I am trying to save data in the following url as triples into triples store for future query. Here are my code:

import requests
from bs4 import BeautifulSoup
import pandas as pd
import numpy as np
import re

url='http://gnafld.net/address/?per_page=10&page=7'
page = requests.get(url)
response = requests.get(url)
response.raise_for_status()
results = re.findall('\"Address ID: (GAACT[0-9]+)\"', response.text)
address1=results[0]
a = "http://gnafld.net/address/"
new_url = a + address1
r  = requests.get(new_url).content
print(r)

After I run the code above, I got the answer like: enter image description here

My question is how to insert the RDF data to a Fuseki Server SPARQL endpoint? I try the code like this:

import rdflib
from rdflib.plugins.stores import sparqlstore
#the following sparql endpoint is provided by the GNAF website
endpoint = 'http://gnafld.net/sparql' 

store = sparqlstore.SPARQLUpdateStore(endpoint)
gs=rdflib.ConjunctiveGraph(store)
gs.open((endpoint,endpoint))
for stmt in r:
    gs.add(stmt)

But it seems that it does not work. How can I fix this problem? Thanks for your help!

SpongeBob
  • 41
  • 5

1 Answers1

3

The answer you show in the image is in RDF triple format, it is just not pretty printed.

To store the RDF data in an RDF store you can use RDFlib. Here is an example of how to do that.

If you use Jena Fuseki server you should be able to access it from python just as you access any other SPARQL endpoint from python.

You may want to see my answer to a related SO question as well.

Henriette Harmse
  • 4,167
  • 1
  • 13
  • 22
  • Thanks for your help. I am new to semantic web and linked data so I am not very clear about the relationship between rdflib, jena fuseki and SPARQL endpoint. Like for SQL in relational database, we need the database first, and do query by using SQL to get the results we want. But in this case, do I need to create a triplestore to store data shown in RDF and then use SPARQL to query the RDF data? Or I can directly store the RDF data using SPARQL update? – SpongeBob May 07 '18 at 04:42
  • Like SQL for RDBMS you can use an insert SQL statement to create the data in the database first. Same with SPARQL. You use the RDFLib update which does a SPARQL insert into your Fuseki endpoint. Hence, you first need to setup Fuseki. – Henriette Harmse May 07 '18 at 06:09