Skip to content

Nutritional Case Study

nipdep edited this page Apr 23, 2025 · 2 revisions

Nutritional Case Study

System Prompt You are a culinary assistant that recommends one personalized dish per request, complete with ingredients and step-by-step instructions. Focus on dietary needs, allergy safety, and easy, enjoyable cooking.

User prompt

Task2 Can you suggest a low-calorie, low-sugar breakfast dish with a complete ingredient list and step-by-step guide?

Information extraction instructions FoodKG

Extract all main ingredients from the text, without considering variation like color. Return them in lowercase, using spaces for multi-word ingredients. [Ex. from "chicken breast" extract out "chicken", likewise in "red bell papper" get "bell papper"]

DBpedia Extract all the main ingredients without any subsidiary; return in singular noun form and First letter capital. Extract mean and dairy product in its' base form. (e.g., from 'egg white' extract 'Egg')

SPARQL Query

FoodKG

Endpoint URL https://inciteprojects.idea.rpi.edu/foodkg/sparql

Query template

PREFIX food: <http://purl.org/heals/food/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT DISTINCT ?ingredientName ?GI ?typeLabel 
WHERE {
?ingredient rdfs:label ?ingredientName .
FILTER(?ingredientName = '%s') .
OPTIONAL { ?ingredient food:hasGlycemicIndex ?GI } .

    ?ingredient rdf:type ?type .
    FILTER(STRSTARTS(STR(?type), 'http://purl.obolibrary.org/obo'))
    OPTIONAL { ?type rdfs:label ?typeLabel }
}

DBpedia

Endpoint URL https://dbpedia.org/sparql

Query template

PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbp: <http://dbpedia.org/property/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX dbt: <http://dbpedia.org/resource/Template:>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>

SELECT (STR(?ingredientLabel) AS ?ingredientName) 
       (STR(?sugar) AS ?sugarG) 
       (STR(?subjectLabel) AS ?ingredientCat) 
WHERE {
  ?ingredient rdfs:label ?ingredientLabel .
  FILTER (?ingredientLabel = "%s"@en) .

  OPTIONAL { ?ingredient dbp:sugars ?sugar . }

  ?ingredient dcterms:subject ?subject .
  OPTIONAL { ?subject rdfs:label ?subjectLabel . }

  ?subject dbp:wikiPageUsesTemplate ?template0 .
  FILTER (?template0 IN (dbt:CatAutoTOC, dbt:Cookbook))
  ?subject skos:broader ?broader .

  OPTIONAL {
    ?broader dbp:wikiPageUsesTemplate ?template .
    BIND(IF(?template = dbt:CatAutoTOC, 1, 0) AS ?autoCount)
    BIND(IF(?template = dbt:Cookbook, 1, 0) AS ?cookCount)
  }
}
GROUP BY ?ingredient ?ingredientLabel ?sugar ?subjectLabel
ORDER BY DESC(?BroaderCount)
LIMIT 1

Post processing instructions FoodKG If there are duplicate ingredients then select row with most information on GI and typeLabel columns. Fill all the missing values with '-'. DBpedia If there are duplicate ingredients then select row with most information on sugarG and ingredientCat columns. Fill all the missing values with '0' in sugarG column and with '-' in 'ingredientCat` column.

Post formatting instructions concat all the rows into single row at each column by '|' concatenation marker.