implement conversion:inverse_of
Closed this issue · 1 comments
timrdf commented
e.g. https://github.com/ewpatton/SemanticDiet/tree/develop/data/source/usgs-gov/nutrient-database/version
- NUT_DATA.csv has row:
01001, 204, 81.11
- The
01001
is a foreign key into NUTR_DEF.csv, which describes different nutritions (e.g. "saturated fat", "protein"). - The
204
is a foreign key into FOOD_DES.csv, which describes different foods (e.g. "Big Mac", "1 slice Toast"). - The
81.11
is the amount of "nutrition"204
(e.g. "saturated fat") that "food"01001
(e.g. "Big Mac") contains.
Be deliberate about the order that we convert the tables, so that the one with foreign keys is converted after those that it references.
cr-create-conversion-trigger.sh -w manual/NUTR_DEF.txt.csv manual/FOOD_DES.txt.csv manual/NUT_DATA.txt.csv
enhance NUTR_DEF's row e.g. 204, g, FAT, Total lipid (fat)
to:
<http://localhost/nutrient/Total_lipid_fat>
a nutrient-database_vocab:Nutrition ;
dcterms:title "Total lipid (fat)" ;
<http://localhost/vocab/nndsr> "204" ;
dcterms:identifier "204" ;
enhance FOOD_DES's row e.g. 01002, 0100, Butter, whipped, with salt
to:
<http://localhost/food/Butter_whipped_with_salt>
a nutrient-database_vocab:Food ;
<http://localhost/vocab/fda_food_id> "01002" ;
dcterms:identifier "01002" ;
dcterms:title "Butter, whipped, with salt" ;
enhance NUT_FOOD's row e.g. 01003, 312, 81.11
to say "100 grams of Butter oil anhydrous has .001 grams of Copper:
:nutritionalMeasure_222
a nutrient-database_vocab:NutritionalMeasure ;
e1:food
<http://localhost/source/usgs-gov/dataset/nutrient-database/nut-data.txt/value-of/food/01003> ,
<http://localhost/food/Butter_oil_anhydrous> ;
e1:nutrition
<http://localhost/source/usgs-gov/dataset/nutrient-database/nut-data.txt/value-of/nutrition/312> ,
<http://localhost/nutrient/Copper_Cu> ;
e1:amountin100g "0.001"^^xsd:decimal ;
but, for <http://localhost/food/Butter_oil_anhydrous>
, we want to point to the nutrition measure, so we add an inverse:
conversion:enhance [
ov:csvCol 1;
ov:csvHeader "01001";
conversion:label "Food";
conversion:comment "";
conversion:links_via <../automatic/FOOD_DES.txt.csv.e1.ttl>; # Depends on FOOD_DES being converted earlier.
a conversion:DirectSameAsEnhancement;
conversion:inverse_of foaf:knows; # Add the inverse (with a real property)
conversion:range rdfs:Resource;
];
to get:
:nutritionalMeasure_222
a nutrient-database_vocab:NutritionalMeasure ;
e1:food
<http://localhost/source/usgs-gov/dataset/nutrient-database/nut-data.txt/value-of/food/01003> ,
<http://localhost/food/Butter_oil_anhydrous> ;
e1:nutrition
<http://localhost/source/usgs-gov/dataset/nutrient-database/nut-data.txt/value-of/nutrition/312> ,
<http://localhost/nutrient/Copper_Cu> ;
e1:amountin100g "0.001"^^xsd:decimal ;
...
<http://localhost/food/Butter_oil_anhydrous> foaf:knows :nutritionalMeasure_222 .
# ^^ The food is now also pointing at the NutritionalMeasure.
Original:
:thing_1
nutrition:hasNutritionalContent
<http://localhost/source/usgs-gov/dataset/nutrient-database/version/release-25/1>;
.
<http://localhost/source/usgs-gov/dataset/nutrient-database/version/release-25/1>
nutrition:measuredNutrient
<http://localhost/source/usgs-gov/dataset/nutrient-database/nut-data.txt/typed/nutrient/203> ,
<http://localhost/nutrient/Protein> ;
nutrition:amountIn100g "0.85" ;
.