【发布时间】:2025-12-15 00:35:02
【问题描述】:
我正在尝试将以下 url 中的数据作为三元组保存到三元组存储中以供将来查询。这是我的代码:
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)
运行上面的代码后,我得到的答案如下: enter image description here
我的问题是如何将 RDF 数据插入到 Fuseki Server SPARQL 端点?我尝试这样的代码:
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)
但是好像不行。我该如何解决这个问题?感谢您的帮助!
【问题讨论】:
-
你想“转换”什么?它已经是 RDF ...
标签: python rdf jena rdflib triplestore