首页 > 解决方案 > 如何使用 SPARQL 将数据插入命名图?

问题描述

我正在使用 python 将数据插入到 blazegraph 中。我想指定插入数据的命名图,但我使用的代码触发了错误:

SPARQLWrapper.SPARQLExceptions.QueryBadFormed: QueryBadFormed: a bad request has been sent to the endpoint, probably the sparql query is bad formed. 

如何解决此错误并将数据插入给定的命名图中?

from SPARQLWrapper import SPARQLWrapper, JSON, TURTLE, RDFXML

query='''
PREFIX dcterms: <http://purl.org/dc/terms/>

INSERT DATA {
    GRAPH <http://example/shelf_A> {
        <http://example/author> dcterms:name "author" .

        <http://example/book> dcterms:title "book" ;
                              dcterms:author <http://example/author> .  
    } 
}
'''

sparql =SPARQLWrapper("http://localhost:9999/blazegraph/namespace/kb/sparql")

sparql.setQuery(query)
sparql.method = 'POST'
sparql.query()

我还尝试从 blazegraph 的更新选项卡运行此查询,并发生相同的错误。我究竟做错了什么?

标签: pythonsparqltriplestoresparqlwrappertriples

解决方案


推荐阅读