dbpedia extract JSON

烂漫一生 提交于 2019-12-05 01:47:30

问题


http://dbpedia.org/resource/Los_Angeles
You can request this data programmatically in many formats by using the appropriate header in your HTTP request.
For example "Accept: application/json" will get you the results in JSON.
1. How do I go about retrieving the JSON
2. Since I have to filter only
a class="uri" href="http://www.w3.org/2000/01/rdf-schema#label"
for around 100 links on my page. What is the best way around it


回答1:


You can retrieve the JSON without having to create special headers by simpy requesting

  • http://dbpedia.org/data/Los_Angeles.json

If you're only interested in the rdfs:labels of the entity, you might query the endpoint by using a template request URL:

http://dbpedia.org/sparql?default-graph-uri=http%3A%2F%2Fdbpedia.org&query=select*%7Bdbpedia%3ALos_Angeles+rdfs%3Alabel+%3Flabel%7D&format=json

which corresponds to the query

select*{dbpedia:Los_Angeles rdfs:label ?label}

SPARQL results

which generates the JSON:

{ "head": { "link": [], "vars": ["label"] },
  "results": { "distinct": false, "ordered": true, "bindings": [
    { "label": { "type": "literal", "xml:lang": "uk", "value": "\u041B\u043E\u0441-\u0410\u043D\u0434\u0436\u0435\u043B\u0435\u0441" }},
    { "label": { "type": "literal", "xml:lang": "vi", "value": "Los Angeles" }},
    { "label": { "type": "literal", "xml:lang": "zh", "value": "\u6D1B\u6749\u77F6" }},
    { "label": { "type": "literal", "xml:lang": "ca", "value": "Los Angeles" }},
    { "label": { "type": "literal", "xml:lang": "cs", "value": "Los Angeles" }},
    { "label": { "type": "literal", "xml:lang": "de", "value": "Los Angeles" }},
    { "label": { "type": "literal", "xml:lang": "en", "value": "Los Angeles" }} ] } }


来源:https://stackoverflow.com/questions/17755229/dbpedia-extract-json

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!