mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Import DFC measures
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative "skos_parser"
|
||||
|
||||
module DataFoodConsortium
|
||||
module Connector
|
||||
class Importer
|
||||
@@ -88,7 +90,16 @@ module DataFoodConsortium
|
||||
end
|
||||
|
||||
def resolve_object(object)
|
||||
@subjects[object] || object.object
|
||||
@subjects[object] || skos_concept(object) || object.object
|
||||
end
|
||||
|
||||
def skos_concept(object)
|
||||
return unless object.uri?
|
||||
|
||||
id = object.value.sub(
|
||||
"http://static.datafoodconsortium.org/data/measures.rdf#", "dfc-m:"
|
||||
)
|
||||
SKOSParser.concepts[id]
|
||||
end
|
||||
|
||||
def guess_setter_name(predicate)
|
||||
|
||||
24
lib/data_food_consortium/connector/skos_parser.rb
Normal file
24
lib/data_food_consortium/connector/skos_parser.rb
Normal file
@@ -0,0 +1,24 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# Overriding the current implementation to store all parsed concepts for
|
||||
# lookup later. Otherwise the importer can't associate these.
|
||||
# This is just a workaround and needs to be solved upstream.
|
||||
module DataFoodConsortium
|
||||
module Connector
|
||||
class SKOSParser
|
||||
def self.concepts
|
||||
@concepts ||= {}
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def createSKOSConcept(element) # rubocop:disable Naming/MethodName
|
||||
concept = DataFoodConsortium::Connector::SKOSConcept.new
|
||||
concept.semanticId = element.id
|
||||
concept.semanticType = element.type
|
||||
self.class.concepts[element.id] = concept
|
||||
concept
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -79,10 +79,7 @@ describe DataFoodConsortium::Connector::Importer, vcr: true do
|
||||
expect(tomato.name).to eq "Tomato"
|
||||
expect(tomato.quantity).to eq items
|
||||
expect(items.value).to eq 5
|
||||
expect(items.unit[:fragment]).to eq "Piece"
|
||||
|
||||
# Pending matching concepts:
|
||||
#expect(items.unit).to eq piece
|
||||
expect(items.unit).to eq piece
|
||||
end
|
||||
|
||||
it "imports properties with lists" do
|
||||
|
||||
Reference in New Issue
Block a user