-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 1072dfb
Showing
37 changed files
with
1,793 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.gem |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
source 'https://rubygems.org' | ||
|
||
gem 'virtual_assembly-semantizer', '~> 1.0' | ||
gem 'json-ld', '~> 3.2', '>= 3.2.3' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 = "[email protected]" | ||
s.files = Dir["lib/**/*.rb"] | ||
s.homepage = | ||
"https://github.com/datafoodconsortium/connector-ruby/" | ||
s.license = "MIT" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# MIT License | ||
# | ||
# Copyright (c) 2023 Maxime Lecoq <[email protected]> | ||
# | ||
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# MIT License | ||
# | ||
# Copyright (c) 2023 Maxime Lecoq <[email protected]> | ||
# | ||
# 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 |
49 changes: 49 additions & 0 deletions
49
lib/datafoodconsortium/connector/allergen_characteristic.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# MIT License | ||
# | ||
# Copyright (c) 2023 Maxime Lecoq <[email protected]> | ||
# | ||
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# MIT License | ||
# | ||
# Copyright (c) 2023 Maxime Lecoq <[email protected]> | ||
# | ||
# 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 |
Oops, something went wrong.