mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-01 21:47:16 +00:00
Merge pull request #11818 from mkllnk/dfc-vocabularies
This commit is contained in:
@@ -19,11 +19,11 @@ class QuantitativeValueBuilder < DfcBuilder
|
||||
def self.unit(variant)
|
||||
case variant.product.variant_unit
|
||||
when "volume"
|
||||
DfcLoader.connector.MEASURES.UNIT.QUANTITYUNIT.LITRE
|
||||
DfcLoader.connector.MEASURES.LITRE
|
||||
when "weight"
|
||||
DfcLoader.connector.MEASURES.UNIT.QUANTITYUNIT.GRAM
|
||||
DfcLoader.connector.MEASURES.GRAM
|
||||
else
|
||||
DfcLoader.connector.MEASURES.UNIT.QUANTITYUNIT.PIECE
|
||||
DfcLoader.connector.MEASURES.PIECE
|
||||
end
|
||||
end
|
||||
|
||||
@@ -67,7 +67,7 @@ class QuantitativeValueBuilder < DfcBuilder
|
||||
#
|
||||
# Until then, we can ignore Rubocop metrics, IMO.
|
||||
def self.map_unit(unit) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength
|
||||
quantity_unit = DfcLoader.connector.MEASURES.UNIT.QUANTITYUNIT
|
||||
quantity_unit = DfcLoader.connector.MEASURES
|
||||
|
||||
# The unit name is only set for items. The name is implied for weight and
|
||||
# volume and filled in by `WeightsAndMeasures`.
|
||||
@@ -110,7 +110,8 @@ class QuantitativeValueBuilder < DfcBuilder
|
||||
else
|
||||
# Labels may be provided one day:
|
||||
# https://github.com/datafoodconsortium/connector-ruby/issues/18
|
||||
label = unit.try(:semanticId)&.split("#")&.last || "items"
|
||||
unit_id = unit.try(:semanticId)&.split("#")&.last&.split(":")&.last
|
||||
label = unit_id || "items"
|
||||
["items", label, 1]
|
||||
end
|
||||
end
|
||||
|
||||
@@ -13,6 +13,14 @@ module DataFoodConsortium
|
||||
def import(json_string_or_io)
|
||||
Importer.new.import(json_string_or_io)
|
||||
end
|
||||
|
||||
# Monkey patch private method until fixed upstream:
|
||||
# https://github.com/datafoodconsortium/connector-ruby/issues/19
|
||||
def loadThesaurus(data) # rubocop:disable Naming/MethodName
|
||||
# The root element may be an array or the ontology.
|
||||
data = data[0] if data.is_a?(Array)
|
||||
@parser.parse(data["@graph"])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,9 +2,10 @@
|
||||
|
||||
set -e
|
||||
|
||||
src="https://github.com/datafoodconsortium/taxonomies/releases/latest/download"
|
||||
dst="`dirname $0`/../vendor"
|
||||
mkdir -p "$dst"
|
||||
|
||||
curl 'http://static.datafoodconsortium.org/data/facets.json' > "$dst/facets.json"
|
||||
curl 'http://static.datafoodconsortium.org/data/measures.json' > "$dst/measures.json"
|
||||
curl 'http://static.datafoodconsortium.org/data/productTypes.json' > "$dst/productTypes.json"
|
||||
curl --location "$src/facets.json" > "$dst/facets.json"
|
||||
curl --location "$src/measures.json" > "$dst/measures.json"
|
||||
curl --location "$src/productTypes.json" > "$dst/productTypes.json"
|
||||
|
||||
@@ -94,7 +94,7 @@ describe DataFoodConsortium::Connector::Importer do
|
||||
unless connector.MEASURES.respond_to?(:UNIT)
|
||||
connector.loadMeasures(read_file("measures"))
|
||||
end
|
||||
connector.MEASURES.UNIT.QUANTITYUNIT.PIECE
|
||||
connector.MEASURES.PIECE
|
||||
end
|
||||
|
||||
it "imports a single object with simple properties" do
|
||||
|
||||
@@ -45,7 +45,7 @@ describe QuantitativeValueBuilder do
|
||||
end
|
||||
|
||||
describe ".apply" do
|
||||
let(:quantity_unit) { DfcLoader.connector.MEASURES.UNIT.QUANTITYUNIT }
|
||||
let(:quantity_unit) { DfcLoader.connector.MEASURES }
|
||||
let(:product) { Spree::Product.new }
|
||||
|
||||
it "uses items for anything unknown" do
|
||||
|
||||
1248
engines/dfc_provider/vendor/facets.json
vendored
1248
engines/dfc_provider/vendor/facets.json
vendored
File diff suppressed because it is too large
Load Diff
1660
engines/dfc_provider/vendor/measures.json
vendored
1660
engines/dfc_provider/vendor/measures.json
vendored
File diff suppressed because it is too large
Load Diff
2110
engines/dfc_provider/vendor/productTypes.json
vendored
2110
engines/dfc_provider/vendor/productTypes.json
vendored
File diff suppressed because it is too large
Load Diff
@@ -110,7 +110,7 @@ paths:
|
||||
"@type": dfc-b:SuppliedProduct
|
||||
dfc-b:name: Apple
|
||||
dfc-b:description: Red
|
||||
dfc-b:hasType: http://static.datafoodconsortium.org/data/productTypes.rdf#non-local-vegetable
|
||||
dfc-b:hasType: dfc-pt:non-local-vegetable
|
||||
dfc-b:hasQuantity:
|
||||
"@type": dfc-b:QuantitativeValue
|
||||
dfc-b:hasUnit: dfc-m:Gram
|
||||
@@ -341,7 +341,7 @@ paths:
|
||||
"@type": dfc-b:SuppliedProduct
|
||||
dfc-b:name: Apple
|
||||
dfc-b:description: Round
|
||||
dfc-b:hasType: http://static.datafoodconsortium.org/data/productTypes.rdf#non-local-vegetable
|
||||
dfc-b:hasType: dfc-pt:non-local-vegetable
|
||||
dfc-b:hasQuantity:
|
||||
"@type": dfc-b:QuantitativeValue
|
||||
dfc-b:hasUnit: dfc-m:Gram
|
||||
@@ -446,7 +446,7 @@ paths:
|
||||
"@type": dfc-b:SuppliedProduct
|
||||
dfc-b:name: Apple
|
||||
dfc-b:description: A delicious heritage apple
|
||||
dfc-b:hasType: http://static.datafoodconsortium.org/data/productTypes.rdf#non-local-vegetable
|
||||
dfc-b:hasType: dfc-pt:non-local-vegetable
|
||||
dfc-b:hasQuantity:
|
||||
"@type": dfc-b:QuantitativeValue
|
||||
dfc-b:hasUnit: dfc-m:Gram
|
||||
@@ -510,7 +510,7 @@ paths:
|
||||
"@type": dfc-b:SuppliedProduct
|
||||
dfc-b:name: Pesto
|
||||
dfc-b:description: Basil Pesto
|
||||
dfc-b:hasType: http://static.datafoodconsortium.org/data/productTypes.rdf#non-local-vegetable
|
||||
dfc-b:hasType: dfc-pt:non-local-vegetable
|
||||
dfc-b:hasQuantity:
|
||||
"@type": dfc-b:QuantitativeValue
|
||||
dfc-b:hasUnit: dfc-m:Gram
|
||||
|
||||
Reference in New Issue
Block a user