Extract Chemical Data from DBpedia via SPARQL

浪子不回头ぞ 提交于 2019-12-11 09:47:39

问题


I'd like to know how to submit a SPARQL query to DDBpedia and be given back a table that includes the information found in the Wikipedia "chembox" info box template, such as molecular weight or formula.

So, the first step was just to make a query whose results should be a list of chemical substances that had the formula and molecularWeight properties included. But the following returns no results:

SELECT * WHERE {
  ?y rdf:type dbpedia-owl:ChemicalSubstance.
  ?y rdfs:label ?Name .
  ?y dbpedia:molecularWeight ?molecularWeight .
  ?y dbpedia:formula ?formula .
  OPTIONAL {?y dbpedia-owl:iupacName ?iupacname} .
  FILTER (langMatches(lang(?Name),"en"))
}
LIMIT 50

SPARQL Explorer at dbpedia.org

And so I'm stuck. Is something wrong with this query or does DBPedia really not collect that information from the Wikipedia chemboxes?


回答1:


You caught the wrong namespace for both dbpedia:molecularWeight and dbpedia:formula. The correct namespace here would be dbpedia2.

Furthermore, there seem rarely any entries having a dbpedia-owl:iupacName, dbpedia2:molecularWeight and dbpedia2:formula.

SELECT * WHERE {
  ?y rdf:type dbpedia-owl:ChemicalSubstance.
  ?y rdfs:label ?Name .
  OPTIONAL {?y dbpedia2:formula ?formula }.
  OPTIONAL {?y dbpedia2:molecularWeight ?molecularWeight}.
  OPTIONAL {?y dbpedia-owl:iupacName ?iupacname} .
  FILTER (langMatches(lang(?Name),"en"))
}
LIMIT 50

SPARQL Explorer @dbpedia.org


To get the correct namespaces, you could either look at one example like this or get a list of all used properties for type dbpedia-owl:ChemicalSubstance using

SELECT DISTINCT ?rel WHERE {
  ?y rdf:type dbpedia-owl:ChemicalSubstance.
  ?y ?rel ?x
}

SPARQL Explorer @dbpedia.org



来源:https://stackoverflow.com/questions/25950938/extract-chemical-data-from-dbpedia-via-sparql

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