Skip to content

Instantly share code, notes, and snippets.

@tomayac
Created September 9, 2011 06:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomayac/1205635 to your computer and use it in GitHub Desktop.
Save tomayac/1205635 to your computer and use it in GitHub Desktop.
POST to DBpedia Spotlight
# This is what I try:
curl -i -X POST -d "text=dbpedia+spotlight+is+neat.&confidence=0.2&support=10" -H "Accept:application/json" -H "Content-Type:application/x-www-form-urlencoded" http://spotlight.dbpedia.org/rest/annotate
# This is what I get:
HTTP/1.1 415 Unsupported Media Type
Date: Fri, 09 Sep 2011 06:46:25 GMT
Transfer-Encoding: chunked
Content-Type: text/plain
# What is the correct "Content-Type" header if not "application/x-www-form-urlencoded"?
@pablomendes
Copy link

HTTP/1.1 200 OK
Date: Mon, 12 Sep 2011 09:45:03 GMT
Content-type: application/json
Access-control-allow-origin: *
Transfer-Encoding: chunked

{
"@text": "dbpedia spotlight is neat.",
"@confidence": "0.2",
"@support": "10",
"@types": "",
"@sparql": "",
"@Policy": "whitelist",
"Resources": [
{
"@uri": "http://dbpedia.org/resource/DBpedia",
"@support": "19",
"@types": "Work,Software",
"@surfaceForm": "dbpedia",
"@offset": "0",
"@similarityScore": "0.35254979133605957",
"@percentageOfSecondRank": "-1.0"
},
{
"@uri": "http://dbpedia.org/resource/Neat_%28TV_series%29",
"@support": "14",
"@types": "Work,TelevisionShow",
"@surfaceForm": "neat",
"@offset": "21",
"@similarityScore": "0.43913504481315613",
"@percentageOfSecondRank": "0.7044740024840299"
}
]
}

@pablomendes
Copy link

pablomendes commented Jun 23, 2021

Updated example:

Set -d for POST and form encoding (-d uses the application/x-www-form-urlencoded mime-type). More here: https://curl.se/docs/manual.html

curl -v -d "text=we love http post" -H "Accept:application/json" https://api.dbpedia-spotlight.org/en/annotate

Inspect the output in stderr to check that it's indeed using POST and setting the right Content-type and Accept headers.

(...)
> POST /en/annotate HTTP/1.1
> Host: api.dbpedia-spotlight.org
> User-Agent: curl/7.54.0
> Accept:application/json
> Content-Length: 31
> Content-Type: application/x-www-form-urlencoded
(...)

Check that you got a response from the API:

{
  "@text": "we love http post",
  "@confidence": "0.5",
  "@support": "0",
  "@types": "",
  "@sparql": "",
  "@policy": "whitelist",
  "Resources": [
    {
      "@URI": "http://dbpedia.org/resource/POST_(HTTP)",
      "@support": "133",
      "@types": "",
      "@surfaceForm": "http post",
      "@offset": "8",
      "@similarityScore": "0.9999984281214784",
      "@percentageOfSecondRank": "0.0"
    }
  ]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment