Skip to content

Instantly share code, notes, and snippets.

@dvsrepo
Last active April 22, 2021 08:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dvsrepo/9e5ea7880d891c702b5295f519b1ca77 to your computer and use it in GitHub Desktop.
Save dvsrepo/9e5ea7880d891c702b5295f519b1ca77 to your computer and use it in GitHub Desktop.
@base <https://www.food.com/recipe/> .
@prefix ind: <http://purl.org/heals/ingredient/> .
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
@prefix wtm: <http://purl.org/heals/food/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
ind:Almond a wtm:Ingredient ;
skos:definition "the nutlike kernel of the fruit of either of two trees, Prunus dulcis (sweet almond) or P. dulcis amara (bitter almond), which grow in warm temperate regions" ;
skos:prefLabel "almond" .
ind:BlackPeppercorn a wtm:Ingredient ;
skos:definition "a dried berry of the black pepper" ;
skos:prefLabel "black peppercorn" .
ind:Blueberry a wtm:Ingredient ;
skos:definition "the edible, usually bluish berry of various shrubs belonging to the genus Vaccinium, of the heath family" ;
skos:prefLabel "blueberry" .
ind:ChayoteSquash a wtm:Ingredient ;
skos:definition "pear-shaped fruit of a West Indian annual vine (Sechium edule) of the gourd family that is widely cultivated as a vegetable" ;
skos:prefLabel "chayote squash" .
ind:DriedCranberry a wtm:Ingredient ;
skos:definition "an ingredient made by partially dehydrating fresh cranberries" ;
skos:prefLabel "dried cranberry" .
ind:GlutenFreeFlour a wtm:Ingredient ;
skos:definition "flours that are made of non-gluten containing products" ;
skos:prefLabel "gluten free flour" .
ind:Kamut a wtm:Ingredient ;
skos:definition "khorasan wheat (kamut) is an ancient grain" ;
skos:prefLabel "kamut" .
ind:KamutFlour a wtm:Ingredient ;
skos:definition "flour made from an ancient grain also known as khorsan wheat" ;
skos:prefLabel "kamut flour" .
ind:Oat a wtm:Ingredient ;
skos:definition "a cereal grass, Avena sativa, cultivated for its edible seed" ;
skos:prefLabel "oat" .
ind:Peanut a wtm:Ingredient ;
skos:definition "the pod or the enclosed edible seed of the plant, Arachis hypogaea, of the legume family: the pod is forced underground in growing, where it ripens" ;
skos:prefLabel "peanut" .
ind:Pecan a wtm:Ingredient ;
skos:definition "a tall hickory tree, Carya illinoinensis, of the southern U.S. and Mexico, cultivated for its oval, smooth-shelled, edible nuts" ;
skos:prefLabel "pecan" .
ind:PumpkinSeed a wtm:Ingredient ;
skos:definition "the edible seed of a pumpkin" ;
skos:prefLabel "pumpkin seed" .
ind:Walnut a wtm:Ingredient ;
skos:definition "the furrowed nut of any of a genus (Juglans of the family Juglandaceae, the walnut family) of deciduous trees" ;
skos:prefLabel "walnut" .
<10000> a wtm:Recipe ;
wtm:hasCookTime "PT3H15M"^^xsd:duration ;
wtm:hasIngredient ind:Salt,
ind:Tomato ;
skos:definition "tomato paste" .
<100026> a wtm:Recipe ;
wtm:hasCookTime "PT1H5M"^^xsd:duration ;
wtm:hasIngredient ind:BakingPowder,
ind:BlackPepper,
ind:CowMilk,
ind:Onion,
ind:Salt,
ind:VegetableOil,
ind:bread,
ind:cream_of_mushroom_soup,
ind:ground_beef ;
skos:definition "baking powder meatballs" .
<100034> a wtm:Recipe ;
wtm:hasCookTime "PT35M"^^xsd:duration ;
wtm:hasIngredient ind:AllPurposeFlour,
ind:BakingPowder,
ind:Butter,
ind:ChickenEgg,
ind:CowMilk,
ind:cottage_cheese,
ind:cream_cheese,
ind:monterey_jack_cheese ;
skos:definition "working woman s cheese souffle" .
<100048> a wtm:Recipe ;
wtm:hasCookTime "PT27M"^^xsd:duration ;
wtm:hasIngredient ind:AllPurposeFlour,
ind:BakingPowder,
ind:BakingSoda,
ind:BrownSugar,
ind:Carrot,
ind:ChickenEgg,
ind:Salt,
ind:cinnamon,
ind:margarine ;
skos:definition "carrot spice cookies" .
<100051> a wtm:Recipe ;
wtm:hasCookTime "PT2M"^^xsd:duration ;
wtm:hasIngredient ind:AppleCiderVinegar,
ind:Salt,
ind:mustard_powder,
ind:sweetened_condensed_milk ;
skos:definition "2 minute mayonnaise" .
<100074> a wtm:Recipe ;
wtm:hasCookTime "PT10M"^^xsd:duration ;
wtm:hasIngredient ind:Cornstarch,
ind:Salt,
ind:WhiteSugar,
ind:cinnamon,
ind:cloves,
ind:orange_juice ;
skos:definition "sheila s orange sauce" .
<100117> a wtm:Recipe ;
wtm:hasCookTime "PT25M"^^xsd:duration ;
wtm:hasIngredient ind:Butter,
ind:LemonJuice,
ind:Salt,
ind:tabasco_sauce,
ind:worcestershire_sauce ;
skos:definition "lemon butter for shrimp" .
<107885> a wtm:Recipe ;
wtm:hasCookTime "PT40M"^^xsd:duration ;
wtm:hasIngredient ind:Carrot,
ind:Celery,
ind:Onion,
ind:Water,
ind:bay_leaf,
ind:dried_parsley,
ind:ham ;
skos:definition "ham stock" .
<1079> a wtm:Recipe ;
wtm:hasCookTime "P0D"^^xsd:duration ;
wtm:hasIngredient ind:AllPurposeFlour,
ind:Butter,
ind:ChickenEgg,
ind:CowMilk,
ind:Salt ;
skos:definition "salty milk biscuits" .
import kglab
import tqdm
NAMESPACES = {
"wtm": "http://purl.org/heals/food/",
"ind": "http://purl.org/heals/ingredient/",
"recipe": "https://www.food.com/recipe/",
}
kg = kglab.KnowledgeGraph(namespaces = NAMESPACES)
kg.load_rdf("example_0D_duration.ttl")
sg = kglab.SubgraphTensor(kg)
edge_list = []
for s, p, o in tqdm(sg.as_tuples()):
s_label = sg.n3fy(s)
s_id = sg.transform(s_label)
p_label = sg.n3fy(p)
p_id = sg.transform(p_label)
o_label = sg.n3fy(o)
o_id = sg.transform(o_label)
if o_id >= 0:
edge_list.append([s_id, o_id, 2 * p_id])
edge_list.append([o_id, s_id, 2 * p_id + 1])
else:
print(s_label)
# For ref. creation of graph as a torch.Tensor from the edge list
# import torch
#edge = torch.tensor(edge_list, dtype=torch.long).t().contiguous()
#edge_index, edge_type = edge[:2], edge[2]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment