Submit SPARQL via curl

72 views
Skip to first unread message

E Lynette Rayle

unread,
Jul 21, 2017, 11:15:06 AM7/21/17
to Getty Vocabularies as Linked Open Data
I would like to submit SPARQL using curl.  Based on what I could piece together from multiple sources, this is what I've tried.

To keep things simple, I am just trying to get the Top-level Subjects based on the query documented at...
* http://vocab.getty.edu/queries#Top-level_Subjects
* Query: select * {?f a gvp:Facet; skos:inScheme aat: ; gvp:prefLabelGVP/xl:literalForm ?l}
* UI Results:
{
  "head" :
  {
    "vars" : [ "f", "l" ]
  },
  "results" :
  {
    "bindings" :
      [
        {
          "f" :
          {
            "type" : "uri",
            "value" : "http://vocab.getty.edu/aat/300264086"
          },
          "l" :
          {
            "xml:lang" : "en",
            "type" : "literal",
            "value" : "Associated Concepts Facet"
          }
        },
        {
          "f" :
          {
            "type" : "uri",
            "value" : "http://vocab.getty.edu/aat/300264088"
          },
          "l" :
          {
            "xml:lang" : "en",
            "type" : "literal",
            "value" : "Styles and Periods Facet"
          }
        }
        ...
      ]
  }
}

Then I try this via curl...
curl -L -D - -H "Accept: application/json" "http://vocab.getty.edu/sparql?query=select * {?f a gvp:Facet; skos:inScheme aat: ; gvp:prefLabelGVP/xl:literalForm ?l}"

Which returns...
HTTP/1.1 505 HTTP Version Not Supported
Server: Apache-Coyote/1.1
Date: Fri, 21 Jul 2017 15:03:34 GMT
Connection: close
Set-Cookie: BIGipServerForest=587573440.45165.0000; path=/; Httponly

Ultimately, I want to pass a query that searches for a string match on prefLabel and returns triples (or other linked data serialization) of matches.  I wanted to start simple and see that I am getting connected and getting results.  Then I can tweak the sparql to return what I really want.

Any suggestions about how to get a connection via curl would be appreciated.

Vladimir Alexiev

unread,
Jul 21, 2017, 6:46:04 PM7/21/17
to Getty Vocabularies as Linked Open Data
You need to URL-encode the query:
 
curl -L -D - -H "Accept: application/sparql-results+json" "http://vocab.getty.edu/sparql?query="select%20*%20%7B?f%20a%20gvp:Facet;%20skos:inScheme%20aat:%20;%20gvp:prefLabelGVP/xl:literalForm%20?l%7D"


Vladimir Alexiev

unread,
May 10, 2018, 10:12:21 AM5/10/18
to Getty Vocabularies as Linked Open Data
To keep the query more readable, you can also remove optional spaces, encode the rest as "+", and use the special sparql.json endpoint instead of supplying an Accept header:

curl -g "http://vocab.getty.edu/sparql.json?query=select*{?f+a+gvp:Facet;skos:inScheme+aat:;gvp:prefLabelGVP/xl:literalForm?l}"

(option -g deals with curl globbing)
Reply all
Reply to author
Forward
0 new messages