From 3e7f61c4d11553534754a76debc97ac6b586fb56 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Thu, 5 Sep 2024 16:26:10 +1000 Subject: [PATCH] Add new DFC vocabulary So that we can use order states programmatically. --- .../dfc_provider/app/services/dfc_loader.rb | 15 +- .../script/update-dfc-vocabularies | 1 + .../spec/services/dfc_loader_spec.rb | 6 + engines/dfc_provider/vendor/vocabulary.json | 351 ++++++++++++++++++ 4 files changed, 370 insertions(+), 3 deletions(-) create mode 100644 engines/dfc_provider/vendor/vocabulary.json diff --git a/engines/dfc_provider/app/services/dfc_loader.rb b/engines/dfc_provider/app/services/dfc_loader.rb index 1fae62f9f4..471f19b94b 100644 --- a/engines/dfc_provider/app/services/dfc_loader.rb +++ b/engines/dfc_provider/app/services/dfc_loader.rb @@ -2,15 +2,24 @@ class DfcLoader def self.connector - @connector ||= load_vocabularies + unless @connector + @connector = DataFoodConsortium::Connector::Connector.instance + load_vocabularies + end + + @connector + end + + def self.vocabulary(name) + @vocabs ||= {} + @vocabs[name] ||= connector.__send__(:loadThesaurus, read_file(name)) end def self.load_vocabularies - connector = DataFoodConsortium::Connector::Connector.instance connector.loadMeasures(read_file("measures")) connector.loadFacets(read_file("facets")) connector.loadProductTypes(read_file("productTypes")) - connector + vocabulary("vocabulary") # order states etc end def self.read_file(name) diff --git a/engines/dfc_provider/script/update-dfc-vocabularies b/engines/dfc_provider/script/update-dfc-vocabularies index 1097b06044..81f5d48107 100755 --- a/engines/dfc_provider/script/update-dfc-vocabularies +++ b/engines/dfc_provider/script/update-dfc-vocabularies @@ -9,3 +9,4 @@ mkdir -p "$dst" curl --location "$src/facets.json" > "$dst/facets.json" curl --location "$src/measures.json" > "$dst/measures.json" curl --location "$src/productTypes.json" > "$dst/productTypes.json" +curl --location "$src/vocabulary.json" > "$dst/vocabulary.json" diff --git a/engines/dfc_provider/spec/services/dfc_loader_spec.rb b/engines/dfc_provider/spec/services/dfc_loader_spec.rb index 93ae98de9d..7e7d383ac6 100644 --- a/engines/dfc_provider/spec/services/dfc_loader_spec.rb +++ b/engines/dfc_provider/spec/services/dfc_loader_spec.rb @@ -21,4 +21,10 @@ RSpec.describe DfcLoader do ) expect(result["dfc-b:name"]).to eq "Tomato" end + + it "loads vocabularies" do + terms = DfcLoader.vocabulary("vocabulary") + expect(terms.STATES.ORDERSTATE.HELD.semanticId) + .to eq "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#Held" + end end diff --git a/engines/dfc_provider/vendor/vocabulary.json b/engines/dfc_provider/vendor/vocabulary.json new file mode 100644 index 0000000000..4dd405056e --- /dev/null +++ b/engines/dfc_provider/vendor/vocabulary.json @@ -0,0 +1,351 @@ +[ { + "@graph" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#", + "@type" : [ "http://www.w3.org/2002/07/owl#Ontology" ] + }, { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#Cancelled", + "@type" : [ "http://www.w3.org/2004/02/skos/core#Concept" ], + "http://www.w3.org/2004/02/skos/core#broader" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#OrderState" + }, { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#PaymentState" + }, { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#FulfilmentState" + } ], + "http://www.w3.org/2004/02/skos/core#inScheme" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#DFC_Vocabulary" + } ], + "http://www.w3.org/2004/02/skos/core#prefLabel" : [ { + "@language" : "en", + "@value" : "Cancelled" + } ] + }, { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#Complete", + "@type" : [ "http://www.w3.org/2004/02/skos/core#Concept" ], + "http://www.w3.org/2004/02/skos/core#broader" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#OrderState" + } ], + "http://www.w3.org/2004/02/skos/core#inScheme" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#DFC_Vocabulary" + } ], + "http://www.w3.org/2004/02/skos/core#prefLabel" : [ { + "@language" : "en", + "@value" : "Complete" + } ] + }, { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#DFC_Vocabulary", + "@type" : [ "http://www.w3.org/2004/02/skos/core#ConceptScheme" ], + "http://www.w3.org/2004/02/skos/core#prefLabel" : [ { + "@language" : "en", + "@value" : "DFC_Vocabulary" + } ] + }, { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#Draft", + "@type" : [ "http://www.w3.org/2004/02/skos/core#Concept" ], + "http://www.w3.org/2004/02/skos/core#broader" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#OrderState" + } ], + "http://www.w3.org/2004/02/skos/core#inScheme" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#DFC_Vocabulary" + } ], + "http://www.w3.org/2004/02/skos/core#prefLabel" : [ { + "@language" : "en", + "@value" : "Draft" + } ] + }, { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#Fulfilled", + "@type" : [ "http://www.w3.org/2004/02/skos/core#Concept" ], + "http://www.w3.org/2004/02/skos/core#broader" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#FulfilmentState" + } ], + "http://www.w3.org/2004/02/skos/core#inScheme" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#DFC_Vocabulary" + } ], + "http://www.w3.org/2004/02/skos/core#prefLabel" : [ { + "@language" : "en", + "@value" : "Fulfilled" + } ] + }, { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#FulfilmentState", + "@type" : [ "http://www.w3.org/2004/02/skos/core#Concept" ], + "http://www.w3.org/2004/02/skos/core#broader" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#States" + } ], + "http://www.w3.org/2004/02/skos/core#inScheme" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#DFC_Vocabulary" + } ], + "http://www.w3.org/2004/02/skos/core#prefLabel" : [ { + "@language" : "en", + "@value" : "Fulfilment state" + } ] + }, { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#Held", + "@type" : [ "http://www.w3.org/2004/02/skos/core#Concept" ], + "http://www.w3.org/2004/02/skos/core#broader" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#OrderState" + }, { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#FulfilmentState" + } ], + "http://www.w3.org/2004/02/skos/core#inScheme" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#DFC_Vocabulary" + } ], + "http://www.w3.org/2004/02/skos/core#prefLabel" : [ { + "@language" : "en", + "@value" : "Held" + } ] + }, { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#OrderState", + "@type" : [ "http://www.w3.org/2004/02/skos/core#Concept" ], + "http://www.w3.org/2004/02/skos/core#broader" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#States" + } ], + "http://www.w3.org/2004/02/skos/core#inScheme" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#DFC_Vocabulary" + } ], + "http://www.w3.org/2004/02/skos/core#prefLabel" : [ { + "@language" : "en", + "@value" : "Order state" + } ] + }, { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#Paid", + "@type" : [ "http://www.w3.org/2004/02/skos/core#Concept" ], + "http://www.w3.org/2004/02/skos/core#broader" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#PaymentState" + } ], + "http://www.w3.org/2004/02/skos/core#inScheme" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#DFC_Vocabulary" + } ], + "http://www.w3.org/2004/02/skos/core#prefLabel" : [ { + "@language" : "en", + "@value" : "Paid" + } ] + }, { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#PaymentState", + "@type" : [ "http://www.w3.org/2004/02/skos/core#Concept" ], + "http://www.w3.org/2004/02/skos/core#broader" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#States" + } ], + "http://www.w3.org/2004/02/skos/core#inScheme" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#DFC_Vocabulary" + } ], + "http://www.w3.org/2004/02/skos/core#prefLabel" : [ { + "@language" : "en", + "@value" : "Payment state" + } ] + }, { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#States", + "@type" : [ "http://www.w3.org/2004/02/skos/core#Concept" ], + "http://www.w3.org/2004/02/skos/core#inScheme" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#DFC_Vocabulary" + } ], + "http://www.w3.org/2004/02/skos/core#prefLabel" : [ { + "@language" : "en", + "@value" : "States" + } ], + "http://www.w3.org/2004/02/skos/core#topConceptOf" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#DFC_Vocabulary" + } ] + }, { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#Unfulfilled", + "@type" : [ "http://www.w3.org/2004/02/skos/core#Concept" ], + "http://www.w3.org/2004/02/skos/core#broader" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#FulfilmentState" + } ], + "http://www.w3.org/2004/02/skos/core#inScheme" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#DFC_Vocabulary" + } ], + "http://www.w3.org/2004/02/skos/core#prefLabel" : [ { + "@language" : "en", + "@value" : "Unfulfilled" + } ] + }, { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#Unpaid", + "@type" : [ "http://www.w3.org/2004/02/skos/core#Concept" ], + "http://www.w3.org/2004/02/skos/core#broader" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#PaymentState" + } ], + "http://www.w3.org/2004/02/skos/core#inScheme" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#DFC_Vocabulary" + } ], + "http://www.w3.org/2004/02/skos/core#prefLabel" : [ { + "@language" : "en", + "@value" : "Unpaid" + } ] + }, { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#accept", + "@type" : [ "http://www.w3.org/2004/02/skos/core#Concept" ], + "http://www.w3.org/2004/02/skos/core#broader" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#transformationType" + } ], + "http://www.w3.org/2004/02/skos/core#inScheme" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#DFC_Vocabulary" + } ], + "http://www.w3.org/2004/02/skos/core#prefLabel" : [ { + "@language" : "en", + "@value" : "accept" + } ] + }, { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#c_734fc709", + "http://www.w3.org/2004/02/skos/core#prefLabel" : [ { + "@language" : "en", + "@value" : "FulfilmentState" + } ] + }, { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#combine", + "@type" : [ "http://www.w3.org/2004/02/skos/core#Concept" ], + "http://www.w3.org/2004/02/skos/core#broader" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#transformationType" + } ], + "http://www.w3.org/2004/02/skos/core#inScheme" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#DFC_Vocabulary" + } ], + "http://www.w3.org/2004/02/skos/core#prefLabel" : [ { + "@language" : "en", + "@value" : "combine" + } ] + }, { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#consume", + "@type" : [ "http://www.w3.org/2004/02/skos/core#Concept" ], + "http://www.w3.org/2004/02/skos/core#broader" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#transformationType" + } ], + "http://www.w3.org/2004/02/skos/core#inScheme" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#DFC_Vocabulary" + } ], + "http://www.w3.org/2004/02/skos/core#prefLabel" : [ { + "@language" : "en", + "@value" : "consume" + } ] + }, { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#dropoff", + "@type" : [ "http://www.w3.org/2004/02/skos/core#Concept" ], + "http://www.w3.org/2004/02/skos/core#broader" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#transformationType" + } ], + "http://www.w3.org/2004/02/skos/core#inScheme" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#DFC_Vocabulary" + } ], + "http://www.w3.org/2004/02/skos/core#prefLabel" : [ { + "@language" : "en", + "@value" : "dropoff" + } ] + }, { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#lower", + "@type" : [ "http://www.w3.org/2004/02/skos/core#Concept" ], + "http://www.w3.org/2004/02/skos/core#broader" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#transformationType" + } ], + "http://www.w3.org/2004/02/skos/core#inScheme" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#DFC_Vocabulary" + } ], + "http://www.w3.org/2004/02/skos/core#prefLabel" : [ { + "@language" : "en", + "@value" : "lower" + } ] + }, { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#modify", + "@type" : [ "http://www.w3.org/2004/02/skos/core#Concept" ], + "http://www.w3.org/2004/02/skos/core#broader" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#transformationType" + } ], + "http://www.w3.org/2004/02/skos/core#inScheme" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#DFC_Vocabulary" + } ], + "http://www.w3.org/2004/02/skos/core#prefLabel" : [ { + "@language" : "en", + "@value" : "modify" + } ] + }, { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#move", + "@type" : [ "http://www.w3.org/2004/02/skos/core#Concept" ], + "http://www.w3.org/2004/02/skos/core#broader" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#transformationType" + } ], + "http://www.w3.org/2004/02/skos/core#inScheme" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#DFC_Vocabulary" + } ], + "http://www.w3.org/2004/02/skos/core#prefLabel" : [ { + "@language" : "en", + "@value" : "move" + } ] + }, { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#pickup", + "@type" : [ "http://www.w3.org/2004/02/skos/core#Concept" ], + "http://www.w3.org/2004/02/skos/core#broader" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#transformationType" + } ], + "http://www.w3.org/2004/02/skos/core#inScheme" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#DFC_Vocabulary" + } ], + "http://www.w3.org/2004/02/skos/core#prefLabel" : [ { + "@language" : "en", + "@value" : "pickup" + } ] + }, { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#produce", + "@type" : [ "http://www.w3.org/2004/02/skos/core#Concept" ], + "http://www.w3.org/2004/02/skos/core#broader" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#transformationType" + } ], + "http://www.w3.org/2004/02/skos/core#inScheme" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#DFC_Vocabulary" + } ], + "http://www.w3.org/2004/02/skos/core#prefLabel" : [ { + "@language" : "en", + "@value" : "produce" + } ] + }, { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#raise", + "@type" : [ "http://www.w3.org/2004/02/skos/core#Concept" ], + "http://www.w3.org/2004/02/skos/core#broader" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#transformationType" + } ], + "http://www.w3.org/2004/02/skos/core#inScheme" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#DFC_Vocabulary" + } ], + "http://www.w3.org/2004/02/skos/core#prefLabel" : [ { + "@language" : "en", + "@value" : "raise" + } ] + }, { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#separate", + "@type" : [ "http://www.w3.org/2004/02/skos/core#Concept" ], + "http://www.w3.org/2004/02/skos/core#broader" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#transformationType" + } ], + "http://www.w3.org/2004/02/skos/core#inScheme" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#DFC_Vocabulary" + } ], + "http://www.w3.org/2004/02/skos/core#prefLabel" : [ { + "@language" : "en", + "@value" : "separate" + } ] + }, { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#transformationType", + "@type" : [ "http://www.w3.org/2004/02/skos/core#Concept" ], + "http://www.w3.org/2004/02/skos/core#inScheme" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#DFC_Vocabulary" + } ], + "http://www.w3.org/2004/02/skos/core#prefLabel" : [ { + "@language" : "en", + "@value" : "Transformation type" + } ], + "http://www.w3.org/2004/02/skos/core#topConceptOf" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#DFC_Vocabulary" + } ] + }, { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#use", + "@type" : [ "http://www.w3.org/2004/02/skos/core#Concept" ], + "http://www.w3.org/2004/02/skos/core#broader" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#transformationType" + } ], + "http://www.w3.org/2004/02/skos/core#inScheme" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#DFC_Vocabulary" + } ], + "http://www.w3.org/2004/02/skos/core#prefLabel" : [ { + "@language" : "en", + "@value" : "use" + } ] + } ], + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#" +} ] \ No newline at end of file