From 1072dfbbdec508cadb435e3417e4786b657f9db3 Mon Sep 17 00:00:00 2001 From: Maxime Lecoq Date: Thu, 12 Jan 2023 22:25:18 +0100 Subject: [PATCH] Initial commit --- .gitignore | 1 + CHANGELOG.md | 19 +++ Gemfile | 4 + LICENSE | 21 +++ README.md | 67 ++++++++ connector.gemspec | 12 ++ lib/datafoodconsortium/connector.rb | 34 ++++ lib/datafoodconsortium/connector/address.rb | 51 ++++++ lib/datafoodconsortium/connector/agent.rb | 62 +++++++ .../connector/allergen_characteristic.rb | 49 ++++++ .../connector/allergen_dimension.rb | 34 ++++ .../connector/catalog_item.rb | 62 +++++++ .../connector/certification.rb | 34 ++++ .../connector/characteristic.rb | 47 ++++++ .../connector/characteristic_dimension.rb | 34 ++++ lib/datafoodconsortium/connector/connector.rb | 73 ++++++++ .../connector/customer_category.rb | 45 +++++ .../connector/defined_product.rb | 157 ++++++++++++++++++ .../connector/enterprise.rb | 86 ++++++++++ .../connector/geographical_origin.rb | 34 ++++ .../connector/json_ld_serializer.rb | 39 +++++ .../connector/nature_origin.rb | 34 ++++ .../connector/nutrient_characteristic.rb | 49 ++++++ lib/datafoodconsortium/connector/offer.rb | 56 +++++++ lib/datafoodconsortium/connector/order.rb | 33 ++++ .../connector/order_line.rb | 33 ++++ .../connector/part_origin.rb | 34 ++++ lib/datafoodconsortium/connector/person.rb | 57 +++++++ .../connector/physical_characteristic.rb | 49 ++++++ .../connector/product_type.rb | 34 ++++ .../connector/quantitative_value.rb | 45 +++++ .../connector/repository.rb | 33 ++++ .../connector/skos_concept.rb | 85 ++++++++++ .../connector/skos_parser.rb | 133 +++++++++++++++ .../connector/skos_parser_element.rb | 78 +++++++++ .../connector/supplied_product.rb | 41 +++++ lib/datafoodconsortium/connector/unit.rb | 34 ++++ 37 files changed, 1793 insertions(+) create mode 100644 .gitignore create mode 100644 CHANGELOG.md create mode 100644 Gemfile create mode 100644 LICENSE create mode 100644 README.md create mode 100644 connector.gemspec create mode 100644 lib/datafoodconsortium/connector.rb create mode 100644 lib/datafoodconsortium/connector/address.rb create mode 100644 lib/datafoodconsortium/connector/agent.rb create mode 100644 lib/datafoodconsortium/connector/allergen_characteristic.rb create mode 100644 lib/datafoodconsortium/connector/allergen_dimension.rb create mode 100644 lib/datafoodconsortium/connector/catalog_item.rb create mode 100644 lib/datafoodconsortium/connector/certification.rb create mode 100644 lib/datafoodconsortium/connector/characteristic.rb create mode 100644 lib/datafoodconsortium/connector/characteristic_dimension.rb create mode 100644 lib/datafoodconsortium/connector/connector.rb create mode 100644 lib/datafoodconsortium/connector/customer_category.rb create mode 100644 lib/datafoodconsortium/connector/defined_product.rb create mode 100644 lib/datafoodconsortium/connector/enterprise.rb create mode 100644 lib/datafoodconsortium/connector/geographical_origin.rb create mode 100644 lib/datafoodconsortium/connector/json_ld_serializer.rb create mode 100644 lib/datafoodconsortium/connector/nature_origin.rb create mode 100644 lib/datafoodconsortium/connector/nutrient_characteristic.rb create mode 100644 lib/datafoodconsortium/connector/offer.rb create mode 100644 lib/datafoodconsortium/connector/order.rb create mode 100644 lib/datafoodconsortium/connector/order_line.rb create mode 100644 lib/datafoodconsortium/connector/part_origin.rb create mode 100644 lib/datafoodconsortium/connector/person.rb create mode 100644 lib/datafoodconsortium/connector/physical_characteristic.rb create mode 100644 lib/datafoodconsortium/connector/product_type.rb create mode 100644 lib/datafoodconsortium/connector/quantitative_value.rb create mode 100644 lib/datafoodconsortium/connector/repository.rb create mode 100644 lib/datafoodconsortium/connector/skos_concept.rb create mode 100644 lib/datafoodconsortium/connector/skos_parser.rb create mode 100644 lib/datafoodconsortium/connector/skos_parser_element.rb create mode 100644 lib/datafoodconsortium/connector/supplied_product.rb create mode 100644 lib/datafoodconsortium/connector/unit.rb diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..86339a0 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.gem \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..44550bc --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,19 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [Unreleased] + +None. + +## [1.0.0-alpha] - 2023-01-12 + +### Added + +- Initial version of this library. + +[unreleased]: https://github.com/datafoodconsortium/connector-ruby/compare/v1.0.0...HEAD +[1.0.0-alpha]: https://github.com/datafoodconsortium/connector-ruby/releases/tag/v1.0.0-alpha diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..95e927c --- /dev/null +++ b/Gemfile @@ -0,0 +1,4 @@ +source 'https://rubygems.org' + +gem 'virtual_assembly-semantizer', '~> 1.0' +gem 'json-ld', '~> 3.2', '>= 3.2.3' \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..a218aa6 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 Data Food Consortium + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..4103a3f --- /dev/null +++ b/README.md @@ -0,0 +1,67 @@ +The Data Food Connector is a tool to help you to integrate the DFC standard within you application. Each concept of the DFC ontology can be manipulated with the help of the corresponding class supplied by the connector. + +This connector will also help you to generate the JSON-LD required by the other DFC compliant platforms to exchange data. + +The [Data Food Consortium](https://datafoodconsortium.org) project (DFC) which aims to provide interoperability between food supply chain platforms. We use the semantizer library inside our connector library to help developers to exchange JSON-LD data expressed with the DFC ontology. + +# Get started + +You can install the connector with the following command: `gem install datafoodconsortium-connector`. + +Then in you Ruby file, import the newly installed connector: +``` +require 'datafoodconsortium/connector' +``` + +The connector is a singleton. To get it, access the instance member of the class: +``` +connector = DataFoodConsortium::Connector::Connector.instance +``` + +You can then load our different SKOS vocabularies providing the corresponding JSON-LD files: +``` +connector.loadMeasures(JSON.parse(File.read("/path/to/measures.json"))) +connector.loadFacets(JSON.parse(File.read("/path/to/facets.json"))) +connector.loadProductTypes(JSON.parse(File.read("/path/to/productTypes.json"))) +``` + +Then you can create product like: +``` +tomato = DataFoodConsortium::Connector::SuppliedProduct.new("Tomato", "Awesome tomato") +``` + +Don't forget to set its semantic id (URI) so the object will not being considered as a blank node: +``` +tomato.semanticId = "https://myplatform.com/tomato" +``` + +You can set the different properties of the object, like adding a certification. The connector provide helpers to get the certification from the previously loaded vocabularies: +``` +tomato.addCertification(connector.FACETS.CERTIFICATION.BIODYNAMICLABEL.DEMETER) +``` + +To finish you can export the DFC object to JSON-LD with: +``` +puts connector.export(tomato) +``` + +This will output DFC compliant valid JSON-LD: +``` +{ + "@context": { + "dfc-b": "http://static.datafoodconsortium.org/ontologies/DFC_BusinessOntology.owl#" + }, + "@type": "dfc-b:SuppliedProduct", + "dfc-b:name": "Tomato", + "dfc-b:description": "Awesome tomato", + "dfc-b:hasClaim": [], + "dfc-b:hasAllergenCharacteristic": [], + "dfc-b:hasNutrientCharacteristic": [], + "dfc-b:hasPhysicalCharacteristic": [], + "dfc-b:referencedBy": [], + "dfc-b:hasCertification": "dfc-f:Demeter", + "dfc-b:hasNatureOrigin": [], + "dfc-b:hasPartOrigin": [], + "@id": "https://myplatform.com/tomato" +} +``` \ No newline at end of file diff --git a/connector.gemspec b/connector.gemspec new file mode 100644 index 0000000..92c171e --- /dev/null +++ b/connector.gemspec @@ -0,0 +1,12 @@ +Gem::Specification.new do |s| + s.name = "datafoodconsortium-connector" + s.version = "1.0.0-alpha" + s.summary = "Data Food Consortium connector" + s.description = "A library to easily integrate the DFC standard within your application." + s.authors = ["Maxime Lecoq"] + s.email = "maxime@lecoqlibre.fr" + s.files = Dir["lib/**/*.rb"] + s.homepage = + "https://github.com/datafoodconsortium/connector-ruby/" + s.license = "MIT" +end \ No newline at end of file diff --git a/lib/datafoodconsortium/connector.rb b/lib/datafoodconsortium/connector.rb new file mode 100644 index 0000000..31c0807 --- /dev/null +++ b/lib/datafoodconsortium/connector.rb @@ -0,0 +1,34 @@ +module DataFoodConsortium + module Connector + require 'datafoodconsortium/connector/connector' + require 'datafoodconsortium/connector/json_ld_serializer' + require 'datafoodconsortium/connector/skos_parser_element' + require 'datafoodconsortium/connector/skos_parser' + require 'datafoodconsortium/connector/agent.rb' + require 'datafoodconsortium/connector/enterprise.rb' + require 'datafoodconsortium/connector/customer_category.rb' + require 'datafoodconsortium/connector/person.rb' + require 'datafoodconsortium/connector/repository.rb' + require 'datafoodconsortium/connector/catalog_item.rb' + require 'datafoodconsortium/connector/order.rb' + require 'datafoodconsortium/connector/offer.rb' + require 'datafoodconsortium/connector/order_line.rb' + require 'datafoodconsortium/connector/address.rb' + require 'datafoodconsortium/connector/geographical_origin.rb' + require 'datafoodconsortium/connector/physical_characteristic.rb' + require 'datafoodconsortium/connector/allergen_dimension.rb' + require 'datafoodconsortium/connector/allergen_characteristic.rb' + require 'datafoodconsortium/connector/nutrient_characteristic.rb' + require 'datafoodconsortium/connector/characteristic.rb' + require 'datafoodconsortium/connector/product_type.rb' + require 'datafoodconsortium/connector/part_origin.rb' + require 'datafoodconsortium/connector/quantitative_value.rb' + require 'datafoodconsortium/connector/unit.rb' + require 'datafoodconsortium/connector/certification.rb' + require 'datafoodconsortium/connector/characteristic_dimension.rb' + require 'datafoodconsortium/connector/nature_origin.rb' + require 'datafoodconsortium/connector/defined_product.rb' + require 'datafoodconsortium/connector/supplied_product.rb' + require 'datafoodconsortium/connector/skos_concept.rb' + end +end diff --git a/lib/datafoodconsortium/connector/address.rb b/lib/datafoodconsortium/connector/address.rb new file mode 100644 index 0000000..b999896 --- /dev/null +++ b/lib/datafoodconsortium/connector/address.rb @@ -0,0 +1,51 @@ +# MIT License +# +# Copyright (c) 2023 Maxime Lecoq +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + + +require "virtual_assembly/semantizer" + +class DataFoodConsortium::Connector::Address + + include VirtualAssembly::Semantizer::SemanticObject + + attr_accessor :street + attr_accessor :postalCode + attr_accessor :city + attr_accessor :country + + def initialize(street, postalCode, city, country) + super() + self.semanticType = "http://static.datafoodconsortium.org/ontologies/DFC_BusinessOntology.owl#Address" + self.street = street + self.postalCode = postalCode + self.city = city + self.country = country + + registerSemanticProperty("http://static.datafoodconsortium.org/ontologies/DFC_BusinessOntology.owl#hasStreet") { self.street } + registerSemanticProperty("http://static.datafoodconsortium.org/ontologies/DFC_BusinessOntology.owl#hasPostalCode") { self.postalCode } + registerSemanticProperty("http://static.datafoodconsortium.org/ontologies/DFC_BusinessOntology.owl#hasCity") { self.city } + registerSemanticProperty("http://static.datafoodconsortium.org/ontologies/DFC_BusinessOntology.owl#hasCountry") { self.country } + end + + + +end diff --git a/lib/datafoodconsortium/connector/agent.rb b/lib/datafoodconsortium/connector/agent.rb new file mode 100644 index 0000000..54f69e6 --- /dev/null +++ b/lib/datafoodconsortium/connector/agent.rb @@ -0,0 +1,62 @@ +# MIT License +# +# Copyright (c) 2023 Maxime Lecoq +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + + + + +require "virtual_assembly/semantizer" + +class DataFoodConsortium::Connector::Agent + + include VirtualAssembly::Semantizer::SemanticObject + + attr_accessor :contacts + attr_accessor :localizations + + def initialize() + super() + self.semanticType = "http://static.datafoodconsortium.org/ontologies/DFC_BusinessOntology.owl#Agent" + + self.contacts = [] + self.localizations = [] + registerSemanticProperty("http://static.datafoodconsortium.org/ontologies/DFC_BusinessOntology.owl#hasAddress") { self.localizations } + end + + + def addContact(contact) + self.contacts.push(contact) + end + + def addLocalization(localization) + self.localizations.push(localization) + end + + def removeContact(contact) + raise "Not implemented" + end + + def removeLocalization(localization) + raise "Not implemented" + end + + +end diff --git a/lib/datafoodconsortium/connector/allergen_characteristic.rb b/lib/datafoodconsortium/connector/allergen_characteristic.rb new file mode 100644 index 0000000..938db42 --- /dev/null +++ b/lib/datafoodconsortium/connector/allergen_characteristic.rb @@ -0,0 +1,49 @@ +# MIT License +# +# Copyright (c) 2023 Maxime Lecoq +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + + + + +require "datafoodconsortium/connector/characteristic" +require "virtual_assembly/semantizer" + +class DataFoodConsortium::Connector::AllergenCharacteristic < DataFoodConsortium::Connector::Characteristic + + + + attr_accessor :allergenDimension + + def initialize(quantityUnit, quantityValue, allergenDimension) + super(quantityUnit, quantityValue) + self.semanticType = "http://static.datafoodconsortium.org/ontologies/DFC_BusinessOntology.owl#AllergenCharacteristic" + self.allergenDimension = allergenDimension + + registerSemanticProperty("http://static.datafoodconsortium.org/ontologies/DFC_BusinessOntology.owl#hasAllergenDimension") { self.allergenDimension } + end + + + + + + + +end diff --git a/lib/datafoodconsortium/connector/allergen_dimension.rb b/lib/datafoodconsortium/connector/allergen_dimension.rb new file mode 100644 index 0000000..a502aa7 --- /dev/null +++ b/lib/datafoodconsortium/connector/allergen_dimension.rb @@ -0,0 +1,34 @@ +# MIT License +# +# Copyright (c) 2023 Maxime Lecoq +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + + +require "datafoodconsortium/connector/characteristic_dimension" +require "virtual_assembly/semantizer" + +class DataFoodConsortium::Connector::AllergenDimension < DataFoodConsortium::Connector::CharacteristicDimension + + + + + + +end diff --git a/lib/datafoodconsortium/connector/catalog_item.rb b/lib/datafoodconsortium/connector/catalog_item.rb new file mode 100644 index 0000000..3a1916e --- /dev/null +++ b/lib/datafoodconsortium/connector/catalog_item.rb @@ -0,0 +1,62 @@ +# MIT License +# +# Copyright (c) 2023 Maxime Lecoq +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + + + + +require "virtual_assembly/semantizer" + +class DataFoodConsortium::Connector::CatalogItem + + include VirtualAssembly::Semantizer::SemanticObject + + attr_accessor :product + attr_accessor :sku + attr_accessor :stockLimitation + attr_accessor :offers + + def initialize(product) + super() + self.semanticType = "http://static.datafoodconsortium.org/ontologies/DFC_BusinessOntology.owl#CatalogItem" + self.product = product + self.sku = nil + self.stockLimitation = nil + self.offers = [] + registerSemanticProperty("http://static.datafoodconsortium.org/ontologies/DFC_BusinessOntology.owl#references") { self.product } + registerSemanticProperty("http://static.datafoodconsortium.org/ontologies/DFC_BusinessOntology.owl#sku") { self.sku } + registerSemanticProperty("http://static.datafoodconsortium.org/ontologies/DFC_BusinessOntology.owl#stockLimitation") { self.stockLimitation } + registerSemanticProperty("http://static.datafoodconsortium.org/ontologies/DFC_BusinessOntology.owl#offeredThrough") { self.offers } + end + + + + + def addOffer(offer) + self.offers.push(offer) + end + + def addOffer(offer) + self.offers.push(offer) + end + + +end diff --git a/lib/datafoodconsortium/connector/certification.rb b/lib/datafoodconsortium/connector/certification.rb new file mode 100644 index 0000000..8ece5d2 --- /dev/null +++ b/lib/datafoodconsortium/connector/certification.rb @@ -0,0 +1,34 @@ +# MIT License +# +# Copyright (c) 2023 Maxime Lecoq +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + + +require "datafoodconsortium/connector/skos_concept" +require "virtual_assembly/semantizer" + +class DataFoodConsortium::Connector::Certification < DataFoodConsortium::Connector::SKOSConcept + + + + + + +end diff --git a/lib/datafoodconsortium/connector/characteristic.rb b/lib/datafoodconsortium/connector/characteristic.rb new file mode 100644 index 0000000..b84d6fe --- /dev/null +++ b/lib/datafoodconsortium/connector/characteristic.rb @@ -0,0 +1,47 @@ +# MIT License +# +# Copyright (c) 2023 Maxime Lecoq +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + + + +require "datafoodconsortium/connector/quantitative_value" +require "virtual_assembly/semantizer" + +class DataFoodConsortium::Connector::Characteristic < DataFoodConsortium::Connector::QuantitativeValue + + + + + def initialize(quantityUnit, quantityValue) + super(quantityUnit, quantityValue) + + + + + end + + + + + + + +end diff --git a/lib/datafoodconsortium/connector/characteristic_dimension.rb b/lib/datafoodconsortium/connector/characteristic_dimension.rb new file mode 100644 index 0000000..98231ab --- /dev/null +++ b/lib/datafoodconsortium/connector/characteristic_dimension.rb @@ -0,0 +1,34 @@ +# MIT License +# +# Copyright (c) 2023 Maxime Lecoq +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +require "datafoodconsortium/connector/skos_concept" + +require "virtual_assembly/semantizer" + +class DataFoodConsortium::Connector::CharacteristicDimension < DataFoodConsortium::Connector::SKOSConcept + + + + + + +end diff --git a/lib/datafoodconsortium/connector/connector.rb b/lib/datafoodconsortium/connector/connector.rb new file mode 100644 index 0000000..b9fe145 --- /dev/null +++ b/lib/datafoodconsortium/connector/connector.rb @@ -0,0 +1,73 @@ +# MIT License +# +# Copyright (c) 2023 Maxime Lecoq +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +require 'singleton' +require 'datafoodconsortium/connector/json_ld_serializer' + +class DataFoodConsortium::Connector::Connector + + include Singleton + + attr_reader :FACETS + attr_reader :MEASURES + attr_reader :PRODUCT_TYPES + + def export(subject) + return @exporter.process(subject); + end + + def loadFacets(data) + @FACETS = loadThesaurus(data); + end + + def loadMeasures(data) + @MEASURES = loadThesaurus(data); + end + + def loadProductTypes(data) + @PRODUCT_TYPES = loadThesaurus(data); + end + + private + + def initialize() + super() + + @context = JSON.parse(%({ + "@context": { + "dfc-b": "http://static.datafoodconsortium.org/ontologies/DFC_BusinessOntology.owl#" + } + }))['@context'] + + @exporter = DataFoodConsortium::Connector::JsonLdSerializer.new(@context) + @parser = DataFoodConsortium::Connector::SKOSParser.new + + @FACETS = [] + @MEASURES = [] + @PRODUCT_TYPES = [] + end + + def loadThesaurus(data) + return @parser.parse(data[0]["@graph"]) + end + +end diff --git a/lib/datafoodconsortium/connector/customer_category.rb b/lib/datafoodconsortium/connector/customer_category.rb new file mode 100644 index 0000000..8537c4a --- /dev/null +++ b/lib/datafoodconsortium/connector/customer_category.rb @@ -0,0 +1,45 @@ +# MIT License +# +# Copyright (c) 2023 Maxime Lecoq +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + + +require "virtual_assembly/semantizer" + +class DataFoodConsortium::Connector::CustomerCategory + + include VirtualAssembly::Semantizer::SemanticObject + + attr_accessor :name + attr_accessor :description + + def initialize(name, description) + super() + self.semanticType = "http://static.datafoodconsortium.org/ontologies/DFC_BusinessOntology.owl#CustomerCategory" + self.name = name + self.description = description + + registerSemanticProperty("http://static.datafoodconsortium.org/ontologies/DFC_BusinessOntology.owl#name") { self.name } + registerSemanticProperty("http://static.datafoodconsortium.org/ontologies/DFC_BusinessOntology.owl#description") { self.description } + end + + + +end diff --git a/lib/datafoodconsortium/connector/defined_product.rb b/lib/datafoodconsortium/connector/defined_product.rb new file mode 100644 index 0000000..9e7de32 --- /dev/null +++ b/lib/datafoodconsortium/connector/defined_product.rb @@ -0,0 +1,157 @@ +# MIT License +# +# Copyright (c) 2023 Maxime Lecoq +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + + + + + + + + + + + + + +require "virtual_assembly/semantizer" + +class DataFoodConsortium::Connector::DefinedProduct + + include VirtualAssembly::Semantizer::SemanticObject + + attr_accessor :name + attr_accessor :description + attr_accessor :productType + attr_accessor :quantity + attr_accessor :alcoholPercentage + attr_accessor :lifetime + attr_accessor :claims + attr_accessor :usageOrStorageConditions + attr_accessor :allergenCharacteristics + attr_accessor :nutrientCharacteristics + attr_accessor :physicalCharacteristics + attr_accessor :geographicalOrigin + attr_accessor :catalogItems + attr_accessor :certifications + attr_accessor :natureOrigin + attr_accessor :partOrigin + + def initialize(name, description) + super() + self.semanticType = "http://static.datafoodconsortium.org/ontologies/DFC_BusinessOntology.owl#DefinedProduct" + self.name = name + self.description = description + self.productType = nil + self.quantity = nil + self.alcoholPercentage = nil + self.lifetime = nil + self.claims = [] + self.usageOrStorageConditions = nil + self.allergenCharacteristics = [] + self.nutrientCharacteristics = [] + self.physicalCharacteristics = [] + self.geographicalOrigin = nil + self.catalogItems = [] + self.certifications = [] + self.natureOrigin = [] + self.partOrigin = [] + registerSemanticProperty("http://static.datafoodconsortium.org/ontologies/DFC_BusinessOntology.owl#name") { self.name } + registerSemanticProperty("http://static.datafoodconsortium.org/ontologies/DFC_BusinessOntology.owl#description") { self.description } + registerSemanticProperty("http://static.datafoodconsortium.org/ontologies/DFC_BusinessOntology.owl#hasType") { self.productType } + registerSemanticProperty("http://static.datafoodconsortium.org/ontologies/DFC_BusinessOntology.owl#hasQuantity") { self.quantity } + registerSemanticProperty("http://static.datafoodconsortium.org/ontologies/DFC_BusinessOntology.owl#alcoholPercentage") { self.alcoholPercentage } + registerSemanticProperty("http://static.datafoodconsortium.org/ontologies/DFC_BusinessOntology.owl#lifetime") { self.lifetime } + registerSemanticProperty("http://static.datafoodconsortium.org/ontologies/DFC_BusinessOntology.owl#hasClaim") { self.claims } + registerSemanticProperty("http://static.datafoodconsortium.org/ontologies/DFC_BusinessOntology.owl#usageOrStorageCondition") { self.usageOrStorageConditions } + registerSemanticProperty("http://static.datafoodconsortium.org/ontologies/DFC_BusinessOntology.owl#hasAllergenCharacteristic") { self.allergenCharacteristics } + registerSemanticProperty("http://static.datafoodconsortium.org/ontologies/DFC_BusinessOntology.owl#hasNutrientCharacteristic") { self.nutrientCharacteristics } + registerSemanticProperty("http://static.datafoodconsortium.org/ontologies/DFC_BusinessOntology.owl#hasPhysicalCharacteristic") { self.physicalCharacteristics } + registerSemanticProperty("http://static.datafoodconsortium.org/ontologies/DFC_BusinessOntology.owl#hasGeographicalOrigin") { self.geographicalOrigin } + registerSemanticProperty("http://static.datafoodconsortium.org/ontologies/DFC_BusinessOntology.owl#referencedBy") { self.catalogItems } + registerSemanticProperty("http://static.datafoodconsortium.org/ontologies/DFC_BusinessOntology.owl#hasCertification") { self.certifications } + registerSemanticProperty("http://static.datafoodconsortium.org/ontologies/DFC_BusinessOntology.owl#hasNatureOrigin") { self.natureOrigin } + registerSemanticProperty("http://static.datafoodconsortium.org/ontologies/DFC_BusinessOntology.owl#hasPartOrigin") { self.partOrigin } + end + + + def addClaim(claim) + self.claims.push(claim) + end + + def removeClaim(claim) + raise "Not implemented" + end + + def addAllergenCharacteristic(allergenCharacteristic) + self.allergenCharacteristics.push(allergenCharacteristic) + end + + def addNutrientCharacteristic(nutrientCharacteristic) + self.nutrientCharacteristics.push(nutrientCharacteristic) + end + + def addPhysicalCharacteristic(physicalCharacteristic) + self.physicalCharacteristics.push(physicalCharacteristic) + end + + def addNatureOrigin(natureOrigin) + self.natureOrigin.push(natureOrigin) + end + + def addPartOrigin(partOrigin) + self.partOrigin.push(partOrigin) + end + + def removeAllergenCharacteristic(allergenCharacteristic) + raise "Not implemented" + end + + def removeNutrientCharacteristic(nutrientCharacteristic) + raise "Not implemented" + end + + def removePhysicalCharacteristic(physicalCharacteristic) + raise "Not implemented" + end + + def removeNatureOrigin(natureOrigin) + raise "Not implemented" + end + + def removePartOrigin(partOrigin) + raise "Not implemented" + end + + def addCatalogItem(catalogItem) + self.catalogItems.push(catalogItem) + end + + def addCertification(certification) + self.certifications.push(certification) + end + + def removeCertification(certification) + raise "Not implemented" + end + + +end diff --git a/lib/datafoodconsortium/connector/enterprise.rb b/lib/datafoodconsortium/connector/enterprise.rb new file mode 100644 index 0000000..5dab7a4 --- /dev/null +++ b/lib/datafoodconsortium/connector/enterprise.rb @@ -0,0 +1,86 @@ +# MIT License +# +# Copyright (c) 2023 Maxime Lecoq +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + + + + +require "datafoodconsortium/connector/supplied_product" + +require "datafoodconsortium/connector/agent" + +require "virtual_assembly/semantizer" + +class DataFoodConsortium::Connector::Enterprise < DataFoodConsortium::Connector::Agent + + + + attr_accessor :name + attr_accessor :description + attr_accessor :vatNumber + attr_accessor :customerCategories + attr_accessor :suppliedProducts + attr_accessor :catalogItems + + def initialize(name) + super() + self.semanticType = "http://static.datafoodconsortium.org/ontologies/DFC_BusinessOntology.owl#Enterprise" + self.name = name + self.description = nil + self.vatNumber = nil + self.customerCategories = [] + self.suppliedProducts = [] + self.catalogItems = [] + registerSemanticProperty("http://static.datafoodconsortium.org/ontologies/DFC_BusinessOntology.owl#hasName") { self.name } + registerSemanticProperty("http://static.datafoodconsortium.org/ontologies/DFC_BusinessOntology.owl#hasDescription") { self.description } + registerSemanticProperty("http://static.datafoodconsortium.org/ontologies/DFC_BusinessOntology.owl#VATnumber") { self.vatNumber } + registerSemanticProperty("http://static.datafoodconsortium.org/ontologies/DFC_BusinessOntology.owl#defines") { self.customerCategories } + registerSemanticProperty("http://static.datafoodconsortium.org/ontologies/DFC_BusinessOntology.owl#supplies") { self.suppliedProducts } + registerSemanticProperty("http://static.datafoodconsortium.org/ontologies/DFC_BusinessOntology.owl#manages") { self.catalogItems } + end + + + def addCustomerCategory(customerCategory) + self.customerCategories.push(customerCategory) + end + + def addSupplyProduct(suppliedProduct) + self.suppliedProducts.push(suppliedProduct) + end + + def addCatalogItem(catalogItem) + self.catalogItems.push(catalogItem) + end + + def addSupplyProduct(suppliedProduct) + self.suppliedProducts.push(suppliedProduct) + end + + def addCatalogItem(catalogItem) + self.catalogItems.push(catalogItem) + end + + def addCustomerCategory(customerCategory) + self.customerCategories.push(customerCategory) + end + + +end diff --git a/lib/datafoodconsortium/connector/geographical_origin.rb b/lib/datafoodconsortium/connector/geographical_origin.rb new file mode 100644 index 0000000..562b23e --- /dev/null +++ b/lib/datafoodconsortium/connector/geographical_origin.rb @@ -0,0 +1,34 @@ +# MIT License +# +# Copyright (c) 2023 Maxime Lecoq +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + + +require "datafoodconsortium/connector/skos_concept" +require "virtual_assembly/semantizer" + +class DataFoodConsortium::Connector::GeographicalOrigin < DataFoodConsortium::Connector::SKOSConcept + + + + + + +end diff --git a/lib/datafoodconsortium/connector/json_ld_serializer.rb b/lib/datafoodconsortium/connector/json_ld_serializer.rb new file mode 100644 index 0000000..6d51c25 --- /dev/null +++ b/lib/datafoodconsortium/connector/json_ld_serializer.rb @@ -0,0 +1,39 @@ +# MIT License +# +# Copyright (c) 2023 Maxime Lecoq +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +require 'virtual_assembly/semantizer' +require 'json/ld' + +class DataFoodConsortium::Connector::JsonLdSerializer + + def initialize(context) + @context = context + @hashSerializer = VirtualAssembly::Semantizer::HashSerializer.new + end + + def process(subject) + input = subject.serialize(@hashSerializer) + jsonLd = JSON::LD::API.compact(input, @context) + return JSON.generate(jsonLd) + end + +end \ No newline at end of file diff --git a/lib/datafoodconsortium/connector/nature_origin.rb b/lib/datafoodconsortium/connector/nature_origin.rb new file mode 100644 index 0000000..4294c12 --- /dev/null +++ b/lib/datafoodconsortium/connector/nature_origin.rb @@ -0,0 +1,34 @@ +# MIT License +# +# Copyright (c) 2023 Maxime Lecoq +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +require "datafoodconsortium/connector/skos_concept" + +require "virtual_assembly/semantizer" + +class DataFoodConsortium::Connector::NatureOrigin < DataFoodConsortium::Connector::SKOSConcept + + + + + + +end diff --git a/lib/datafoodconsortium/connector/nutrient_characteristic.rb b/lib/datafoodconsortium/connector/nutrient_characteristic.rb new file mode 100644 index 0000000..a7162b0 --- /dev/null +++ b/lib/datafoodconsortium/connector/nutrient_characteristic.rb @@ -0,0 +1,49 @@ +# MIT License +# +# Copyright (c) 2023 Maxime Lecoq +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + + + + +require "datafoodconsortium/connector/characteristic" +require "virtual_assembly/semantizer" + +class DataFoodConsortium::Connector::NutrientCharacteristic < DataFoodConsortium::Connector::Characteristic + + + + attr_accessor :nutrientDimension + + def initialize(quantityUnit, quantityValue, nutrientDimension) + super(quantityUnit, quantityValue) + self.semanticType = "http://static.datafoodconsortium.org/ontologies/DFC_BusinessOntology.owl#NutrientCharacteristic" + self.nutrientDimension = nutrientDimension + + registerSemanticProperty("http://static.datafoodconsortium.org/ontologies/DFC_BusinessOntology.owl#hasNutrientDimension") { self.nutrientDimension } + end + + + + + + + +end diff --git a/lib/datafoodconsortium/connector/offer.rb b/lib/datafoodconsortium/connector/offer.rb new file mode 100644 index 0000000..44628e1 --- /dev/null +++ b/lib/datafoodconsortium/connector/offer.rb @@ -0,0 +1,56 @@ +# MIT License +# +# Copyright (c) 2023 Maxime Lecoq +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + + + + +require "virtual_assembly/semantizer" + +class DataFoodConsortium::Connector::Offer + + include VirtualAssembly::Semantizer::SemanticObject + + attr_accessor :price + attr_accessor :stockLimitation + attr_accessor :offeredItem + attr_accessor :offeredTo + + def initialize(offeredItem, offeredTo) + super() + self.semanticType = "http://static.datafoodconsortium.org/ontologies/DFC_BusinessOntology.owl#Offer" + self.offeredItem = offeredItem + self.offeredTo = offeredTo + self.price = nil + self.stockLimitation = nil + registerSemanticProperty("http://static.datafoodconsortium.org/ontologies/DFC_BusinessOntology.owl#price") { self.price } + registerSemanticProperty("http://static.datafoodconsortium.org/ontologies/DFC_BusinessOntology.owl#stockLimitation") { self.stockLimitation } + registerSemanticProperty("http://static.datafoodconsortium.org/ontologies/DFC_BusinessOntology.owl#offeredItem") { self.offeredItem } + registerSemanticProperty("http://static.datafoodconsortium.org/ontologies/DFC_BusinessOntology.owl#offeredTo") { self.offeredTo } + end + + + def addOffer(offer) + self..push(offer) + end + + +end diff --git a/lib/datafoodconsortium/connector/order.rb b/lib/datafoodconsortium/connector/order.rb new file mode 100644 index 0000000..7aa589b --- /dev/null +++ b/lib/datafoodconsortium/connector/order.rb @@ -0,0 +1,33 @@ +# MIT License +# +# Copyright (c) 2023 Maxime Lecoq +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + + +require "virtual_assembly/semantizer" + +class DataFoodConsortium::Connector::Order + + + + + + +end diff --git a/lib/datafoodconsortium/connector/order_line.rb b/lib/datafoodconsortium/connector/order_line.rb new file mode 100644 index 0000000..f07c786 --- /dev/null +++ b/lib/datafoodconsortium/connector/order_line.rb @@ -0,0 +1,33 @@ +# MIT License +# +# Copyright (c) 2023 Maxime Lecoq +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + + +require "virtual_assembly/semantizer" + +class DataFoodConsortium::Connector::OrderLine + + + + + + +end diff --git a/lib/datafoodconsortium/connector/part_origin.rb b/lib/datafoodconsortium/connector/part_origin.rb new file mode 100644 index 0000000..8d949d9 --- /dev/null +++ b/lib/datafoodconsortium/connector/part_origin.rb @@ -0,0 +1,34 @@ +# MIT License +# +# Copyright (c) 2023 Maxime Lecoq +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + + +require "datafoodconsortium/connector/skos_concept" +require "virtual_assembly/semantizer" + +class DataFoodConsortium::Connector::PartOrigin < DataFoodConsortium::Connector::SKOSConcept + + + + + + +end diff --git a/lib/datafoodconsortium/connector/person.rb b/lib/datafoodconsortium/connector/person.rb new file mode 100644 index 0000000..904a9f2 --- /dev/null +++ b/lib/datafoodconsortium/connector/person.rb @@ -0,0 +1,57 @@ +# MIT License +# +# Copyright (c) 2023 Maxime Lecoq +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + + + +require "datafoodconsortium/connector/agent" +require "virtual_assembly/semantizer" + +class DataFoodConsortium::Connector::Person < DataFoodConsortium::Connector::Agent + + + + attr_accessor :firstName + attr_accessor :lastName + attr_accessor :affiliatedOrganizations + + def initialize(firstName, lastName) + super() + self.semanticType = "http://static.datafoodconsortium.org/ontologies/DFC_BusinessOntology.owl#Person" + self.firstName = firstName + self.lastName = lastName + self.affiliatedOrganizations = [] + registerSemanticProperty("http://static.datafoodconsortium.org/ontologies/DFC_BusinessOntology.owl#firstName") { self.firstName } + registerSemanticProperty("http://static.datafoodconsortium.org/ontologies/DFC_BusinessOntology.owl#familyName") { self.lastName } + registerSemanticProperty("http://static.datafoodconsortium.org/ontologies/DFC_BusinessOntology.owl#affiliates") { self.affiliatedOrganizations } + end + + + def affiliateTo(organization) + self.affiliatedOrganizations.push(organization) + end + + def leaveAffiliatedOrganization(organization) + raise "Not implemented" + end + + +end diff --git a/lib/datafoodconsortium/connector/physical_characteristic.rb b/lib/datafoodconsortium/connector/physical_characteristic.rb new file mode 100644 index 0000000..0e0799f --- /dev/null +++ b/lib/datafoodconsortium/connector/physical_characteristic.rb @@ -0,0 +1,49 @@ +# MIT License +# +# Copyright (c) 2023 Maxime Lecoq +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + + + +require "datafoodconsortium/connector/characteristic" + +require "virtual_assembly/semantizer" + +class DataFoodConsortium::Connector::PhysicalCharacteristic < DataFoodConsortium::Connector::Characteristic + + + + attr_accessor :physicalDimension + + def initialize(quantityUnit, quantityValue, physicalDimension) + super(quantityUnit, quantityValue) + self.semanticType = "http://static.datafoodconsortium.org/ontologies/DFC_BusinessOntology.owl#PhysicalCharacteristic" + self.physicalDimension = physicalDimension + + registerSemanticProperty("http://static.datafoodconsortium.org/ontologies/DFC_BusinessOntology.owl#hasPhysicalDimension") { self.physicalDimension } + end + + + + + + + +end diff --git a/lib/datafoodconsortium/connector/product_type.rb b/lib/datafoodconsortium/connector/product_type.rb new file mode 100644 index 0000000..2581300 --- /dev/null +++ b/lib/datafoodconsortium/connector/product_type.rb @@ -0,0 +1,34 @@ +# MIT License +# +# Copyright (c) 2023 Maxime Lecoq +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + + +require "datafoodconsortium/connector/skos_concept" +require "virtual_assembly/semantizer" + +class DataFoodConsortium::Connector::ProductType < DataFoodConsortium::Connector::SKOSConcept + + + + + + +end diff --git a/lib/datafoodconsortium/connector/quantitative_value.rb b/lib/datafoodconsortium/connector/quantitative_value.rb new file mode 100644 index 0000000..5b326d4 --- /dev/null +++ b/lib/datafoodconsortium/connector/quantitative_value.rb @@ -0,0 +1,45 @@ +# MIT License +# +# Copyright (c) 2023 Maxime Lecoq +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + + +require "virtual_assembly/semantizer" + +class DataFoodConsortium::Connector::QuantitativeValue + + include VirtualAssembly::Semantizer::SemanticObject + + attr_accessor :quantityUnit + attr_accessor :quantityValue + + def initialize(quantityUnit, quantityValue) + super() + self.semanticType = "http://static.datafoodconsortium.org/ontologies/DFC_BusinessOntology.owl#QuantitativeValue" + self.quantityUnit = quantityUnit + self.quantityValue = quantityValue + + registerSemanticProperty("http://static.datafoodconsortium.org/ontologies/DFC_BusinessOntology.owl#hasUnit") { self.quantityUnit } + registerSemanticProperty("http://static.datafoodconsortium.org/ontologies/DFC_BusinessOntology.owl#value") { self.quantityValue } + end + + + +end diff --git a/lib/datafoodconsortium/connector/repository.rb b/lib/datafoodconsortium/connector/repository.rb new file mode 100644 index 0000000..f7a1380 --- /dev/null +++ b/lib/datafoodconsortium/connector/repository.rb @@ -0,0 +1,33 @@ +# MIT License +# +# Copyright (c) 2023 Maxime Lecoq +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + + +require "virtual_assembly/semantizer" + +class DataFoodConsortium::Connector::Repository + + + + + + +end diff --git a/lib/datafoodconsortium/connector/skos_concept.rb b/lib/datafoodconsortium/connector/skos_concept.rb new file mode 100644 index 0000000..476653c --- /dev/null +++ b/lib/datafoodconsortium/connector/skos_concept.rb @@ -0,0 +1,85 @@ +# MIT License +# +# Copyright (c) 2023 Maxime Lecoq +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + + + + +require "virtual_assembly/semantizer" + +class DataFoodConsortium::Connector::SKOSConcept + + include VirtualAssembly::Semantizer::SemanticObject + + attr_accessor :broaders + attr_accessor :schemes + attr_accessor :narrowers + attr_accessor :prefLabels + + def initialize() + super() + self.semanticType = "http://www.w3.org/2004/02/skos/core#Concept" + + self.broaders = [] + self.schemes = [] + self.narrowers = [] + self.prefLabels = [] + registerSemanticProperty("http://www.w3.org/2004/02/skos/core#broader") { self.broaders } + registerSemanticProperty("http://www.w3.org/2004/02/skos/core#inScheme") { self.schemes } + registerSemanticProperty("http://www.w3.org/2004/02/skos/core#narrower") { self.narrowers } + registerSemanticProperty("http://www.w3.org/2004/02/skos/core#prefLabel") { self.prefLabels } + end + + + def addBroader(broader) + self.broaders.push(broader) + end + + def addScheme(scheme) + self.schemes.push(scheme) + end + + def addNarrower(narrower) + self.narrowers.push(narrower) + end + + def addPrefLabel(prefLabel) + self.prefLabels.push(prefLabel) + end + + def removeBroader(broader) + raise "Not implemented" + end + + def removeScheme(scheme) + raise "Not implemented" + end + + def removeNarrower(narrower) + raise "Not implemented" + end + + def removePrefLabel(prefLabel) + raise "Not implemented" + end + + +end diff --git a/lib/datafoodconsortium/connector/skos_parser.rb b/lib/datafoodconsortium/connector/skos_parser.rb new file mode 100644 index 0000000..cd964b2 --- /dev/null +++ b/lib/datafoodconsortium/connector/skos_parser.rb @@ -0,0 +1,133 @@ +# MIT License +# +# Copyright (c) 2023 Maxime Lecoq +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +require 'datafoodconsortium/connector/skos_concept' +require 'datafoodconsortium/connector/skos_parser_element' + +class DataFoodConsortium::Connector::SKOSInstance + + def addAttribute(name, value) + instance_variable_set("@#{name}", value) + self.class.send(:attr_reader, name) + end + + def hasAttribute(name) + return self.methods.include?(:"#{name}") + end + +end + +class DataFoodConsortium::Connector::SKOSParser + + def initialize() + @results = DataFoodConsortium::Connector::SKOSInstance.new + @skosConcepts = {} + @rootElements = [] + @broaders = {} + end + + def parse(data) + init() + + data.each do |element| + current = DataFoodConsortium::Connector::SKOSParserElement.new(element) + + if (current.isConcept?() || current.isCollection?()) + if (!@skosConcepts.has_key?(current.id)) + concept = createSKOSConcept(current) + @skosConcepts[current.id] = concept + end + + if (current.hasBroader()) + current.broader.each do |broaderId| + if (!@broaders.has_key?(broaderId)) + @broaders[broaderId] = [] + end + + @broaders[broaderId].push(current.id) + end + + # No broader, save the concept to the root + else + @rootElements.push(current.id) + end + end + end + + @rootElements.each do |rootElementId| + setResults(@results, rootElementId) + end + + return @results + end + + protected + + def createSKOSConcept(element) + skosConcept = DataFoodConsortium::Connector::SKOSConcept.new + skosConcept.semanticId = element.id + skosConcept.semanticType = element.type + return skosConcept + end + + def getValueWithoutPrefix(property) + name = 'undefined' + + if (!property.include?('http') && property.include?(':')) + name = property.split(':')[1] + elsif (property.include?('#')) + name = property.split('#')[1] + end + + return name.gsub('-', '_').upcase + end + + private + + def init() + @results = DataFoodConsortium::Connector::SKOSInstance.new + @skosConcepts = {} + @rootElements = [] + @broaders = {} + end + + def setResults(parent, id) + name = getValueWithoutPrefix(id) + + if (!parent.hasAttribute(name)) + parent.addAttribute(name, DataFoodConsortium::Connector::SKOSInstance.new) + end + + # Leaf concepts, stop the process + if (!@broaders.has_key?(id)) + parent.instance_variable_set("@#{name}", @skosConcepts[id]) + return + end + + @broaders[id].each do |narrower| + childName = getValueWithoutPrefix(narrower) + parentSkosInstance = parent.instance_variable_get("@#{name}") + setResults(parentSkosInstance, narrower) # recursive call + end + end + +end \ No newline at end of file diff --git a/lib/datafoodconsortium/connector/skos_parser_element.rb b/lib/datafoodconsortium/connector/skos_parser_element.rb new file mode 100644 index 0000000..67fc4c0 --- /dev/null +++ b/lib/datafoodconsortium/connector/skos_parser_element.rb @@ -0,0 +1,78 @@ +# MIT License +# +# Copyright (c) 2023 Maxime Lecoq +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +class DataFoodConsortium::Connector::SKOSParserElement + + attr_reader :id + attr_reader :type + attr_reader :broader + + def initialize(element) + @broader = [] + + if (element) + @id = element["@id"] + + if (element["http://www.w3.org/1999/02/22-rdf-syntax-ns#type"]) + @type = extractId(element["http://www.w3.org/1999/02/22-rdf-syntax-ns#type"]) + elsif (element["@type"]) + @type = extractId(element["@type"]) + else + @type = "undefined" + end + + if (element["http://www.w3.org/2004/02/skos/core#broader"]) + element["http://www.w3.org/2004/02/skos/core#broader"].each do |broader| + @broader.push(broader["@id"]) + end + end + else + @id = "" + @type = "" + end + end + + def hasBroader() + return @broader.count > 0 + end + + def isConcept?() + return @type == "http://www.w3.org/2004/02/skos/core#Concept" || @type == "skos:Concept" + end + + def isCollection?() + return @type == "http://www.w3.org/2004/02/skos/core#Collection" || @type == "skos:Collection" + end + + private + + def extractId(data) + id = data[0] + + if (id["@id"]) + return id["@id"] + end + + return id + end + +end \ No newline at end of file diff --git a/lib/datafoodconsortium/connector/supplied_product.rb b/lib/datafoodconsortium/connector/supplied_product.rb new file mode 100644 index 0000000..6c73c56 --- /dev/null +++ b/lib/datafoodconsortium/connector/supplied_product.rb @@ -0,0 +1,41 @@ +# MIT License +# +# Copyright (c) 2023 Maxime Lecoq +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +require "datafoodconsortium/connector/defined_product" +require "virtual_assembly/semantizer" + +class DataFoodConsortium::Connector::SuppliedProduct < DataFoodConsortium::Connector::DefinedProduct + + + + + def initialize(name, description) + super(name, description) + self.semanticType = "http://static.datafoodconsortium.org/ontologies/DFC_BusinessOntology.owl#SuppliedProduct" + + + + end + + + +end diff --git a/lib/datafoodconsortium/connector/unit.rb b/lib/datafoodconsortium/connector/unit.rb new file mode 100644 index 0000000..9cdab3e --- /dev/null +++ b/lib/datafoodconsortium/connector/unit.rb @@ -0,0 +1,34 @@ +# MIT License +# +# Copyright (c) 2023 Maxime Lecoq +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +require "datafoodconsortium/connector/skos_concept" + +require "virtual_assembly/semantizer" + +class DataFoodConsortium::Connector::Unit < DataFoodConsortium::Connector::SKOSConcept + + + + + + +end