Merge pull request #11818 from mkllnk/dfc-vocabularies

This commit is contained in:
Maikel
2023-11-23 10:06:38 +11:00
committed by GitHub
9 changed files with 2585 additions and 2471 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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"

View File

@@ -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

View File

@@ -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

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -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