0

I am trying to insert triples into blazegraph using below sparql query.

for index, row in df_omim.iterrows():
    omim = row['mim_number']
    omim_label = row['preferred_title_symbol']
    rel = row['skos_rel']
    meddra = row['MDR_code']
    
    queryString = """ 
                    PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
                    PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
                    
                    INSERT DATA {
                    GRAPH <http://example.org/mapping> 
                    { %s skos:%s %s ;
                         rdfs:%s %s .}} 
                    
                  """ %(omim, rel, meddra, 'label', omim_label)
    
    sparql = SPARQLWrapper("http://blazegraph/namespace/HC2/sparql/update")
    sparql.setQuery(queryString)
    sparql.method = 'POST'
    sparql.query()
Sample triples are:
<https://www.omim.org/entry/202110> skos:exactMatch <https://identifiers.org/meddra:10000014> ;                         
                                    rdfs:label ADRENAL HYPERPLASIA, CONGENITAL, DUE TO 17-ALPHA-HYDROXYLASE DEFICIENCY .

The value of omim and meddra are https://www.omim.org/entry/202110, https://identifiers.org/meddra:10000014

I am getting below error while running above SPARQL query. QueryBadFormed: QueryBadFormed: A bad request has been sent to the endpoint: probably the SPARQL query is badly formed.

Any help is highly appreciated

rshar
  • 1,381
  • 10
  • 28
  • 2
    printing the formatted `queryString` would have shown you what the issue is. In SPARQL the URIs and literals have to be provided correctly. So, for full URIs it has to be put in angle brackets (look at your provided sample data). And for literals like it is obviously for `rdfs:label` values, it has to be put at least in double quotes, and optionally also extended by some language tag. For other literals you even miht have to add the datatype URI. By the way, in that case your example is misleading as the labels haven't been put in quotes. – UninformedUser Jul 14 '23 at 06:51
  • 2
    Untested as I do not not your input data: `INSERT DATA { GRAPH { <%s> skos:%s <%s> ; rdfs:%s \"%s\" .}}` - in any case, print the queryString for debugging, then think about how the SPARQL query would have been syntactically corret, then adapt your template string – UninformedUser Jul 14 '23 at 06:52
  • Your comments helped. Thank you! – rshar Jul 14 '23 at 11:52

0 Answers0