从SPARQL中选择食物卡路里

时间:2017-06-22 15:10:09

标签: sparql wikipedia-api wikidata

我开始研究SPARQL,我承认我发现它非常模糊和困难。

我需要输出所有食物的卡路里。

我真的不明白wd:wdt:p:和ps:

之间的区别

同样,我不清楚何时使用P000或Q000?

到目前为止我得到的最好的是:

SELECT ?food ?calories ?foodLabel ?caloriesLabel WHERE {
  ?food wdt:P31 wd:Q2095.
  ?food wdt:P31 ?calories.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}

给出:enter image description here

欢迎提出任何建议

1 个答案:

答案 0 :(得分:3)

如果您愿意下载1 GB的RDF文件并在自己的三元店中发布,这看起来很有希望:

https://datahub.io/dataset/open-food-facts

具体而言,http://en.openfoodfacts.org/data/en.openfoodfacts.org.products.rdf(如果英语是您首选的语言。)

我说下载和发布,因为谷歌搜索表明这些数据尚未在任何公共端点公开。

与WikiData相比,您可能不得不使用不同的类和谓词。

嘿,这很漂亮!

SELECT  *
WHERE
  { GRAPH <http://openfoodfacts.org>
      { ?s  a                     <http://data.lirmm.fr/ontologies/food#FoodProduct> ;
            <http://data.lirmm.fr/ontologies/food#name>  ?fn ;
            <http://data.lirmm.fr/ontologies/food#energyPer100g>  ?energy
      }
  }
LIMIT   9

给出

+------------------------------------------------------------------------------------------------------+---------------------------------------------+--------+
|                                                  s                                                   |                     fn                      | energy |
+------------------------------------------------------------------------------------------------------+---------------------------------------------+--------+
| http://world-en.openfoodfacts.org/product/9400547030446/heinz-big-n-chunky-chicken-corn              | "Heinz Big'n Chunky Chicken & Corn"         | "245"  |
| http://world-en.openfoodfacts.org/product/9400550004847/sour-patch-kids-pascall                      | "Sour Patch Kids"                           | "1440" |
| http://world-en.openfoodfacts.org/product/9400550602487/brunch-mixed-berry-bar-cadbury               | "Brunch Mixed Berry Bar"                    | "1810" |
| http://world-en.openfoodfacts.org/product/9400550646276/pascall-family-pack-sweets-fruit-bursts      | "Pascall Family Pack Sweets Fruit Bursts"   | "1427" |
| http://world-en.openfoodfacts.org/product/9400553011477/choc-thins-griffin-s                         | "Choc Thins"                                | "2010" |
| http://world-en.openfoodfacts.org/product/9400553438786/gingernuts-griffin-s                         | "Gingernuts"                                | "1810" |
| http://world-en.openfoodfacts.org/product/9400563448614/nice-natural-rosted-nut-bar-chocolate        | "Nice & Natural Rosted Nut Bar - Chocolate" | "2060" |
| http://world-en.openfoodfacts.org/product/9400563740589/nut-bar-caramel-cashew-flavour-nice-natural  | "Nut Bar - Caramel Cashew Flavour"          | "1960" |
| http://world-en.openfoodfacts.org/product/9400563741784/superfruits-cranberry-blueberry-nice-natural | "Superfruits - Cranberry & Blueberry"       | "1520" |
+------------------------------------------------------------------------------------------------------+---------------------------------------------+--------+