I need to get a list of "tokens" that are semantically related to a certain query: the field "dcterms:subject" of a DBpedia page would be perfect (see for example http://dbpedia.org/page/Michelle_Obama). I can correctly get the dbpedia URL related to my query, using a CURL http post request. This query
"text=Michelle%20Obama.&confidence=0.2&support=20";
returns this object:
{ "@text": "Michelle Obama.", "@confidence": "0.2", "@support": "20", "@types": "", "@sparql": "", "@policy": "whitelist", "Resources": [ { "@URI": "http://dbpedia.org/resource/Michelle_Obama", "@support": "321", "@types": "DBpedia:OfficeHolder,DBpedia:Person,Schema:Person,Freebase:/award/ranked_item,Freebase:/award,Freebase:/organization/organization_member,Freebase:/organization,Freebase:/book/book_subject,Freebase:/book,Freebase:/celebrities/celebrity,Freebase:/celebrities,Freebase:/people/person,Freebase:/people,Freebase:/tv/tv_actor,Freebase:/tv,Freebase:/education/honorary_degree_recipient,Freebase:/education", "@surfaceForm": "Michelle Obama", "@offset": "0", "@similarityScore": "0.20646192133426666", "@percentageOfSecondRank": "-1.0" }] }
At the moment, I use this object only to get the URL and I use the URL to get the entire html content of the DBpedia page and then look for what I need (the "dcterms:subject" paragraph), but I think there's a more efficient way to do this, maybe directly from spotlight. How can I adjust my query to get that list (or something similar) with only one post to spotlight? I don't even need the links, just a list of tokens.
If you want the dcterms:subjects of a DBpedia resource, you can simply ask for it with a SPARQL query:
select ?subject { dbpedia:Michelle_Obama dcterms:subject ?subject }
You can run that query on the DBpedia SPARQL endpoint, and it's not too hard to figure out how you can construct the corresponding query URL. There are some different results formats, too, so you can experiment with what works best for you.
If by tokens you just mean the names of those categories, then you can ask for that directly, too. The following should work, but I can't test it at the moment; DBpedia seems to be down.
select ?subject {
dbpedia:Michelle_Obama dcterms:subject/rdfs:label ?subject
}