datafoodconsortium-connector-v1 1.4.0.pre.beta2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. checksums.yaml +7 -0
  2. data/lib/datafoodconsortium/connector/address.rb +81 -0
  3. data/lib/datafoodconsortium/connector/agent.rb +76 -0
  4. data/lib/datafoodconsortium/connector/allergen_characteristic.rb +51 -0
  5. data/lib/datafoodconsortium/connector/catalog.rb +54 -0
  6. data/lib/datafoodconsortium/connector/catalog_item.rb +72 -0
  7. data/lib/datafoodconsortium/connector/characteristic.rb +46 -0
  8. data/lib/datafoodconsortium/connector/connector.rb +84 -0
  9. data/lib/datafoodconsortium/connector/context.rb +51 -0
  10. data/lib/datafoodconsortium/connector/context_1.16.0.json +492 -0
  11. data/lib/datafoodconsortium/connector/customer_category.rb +45 -0
  12. data/lib/datafoodconsortium/connector/defined_product.rb +159 -0
  13. data/lib/datafoodconsortium/connector/delivery_option.rb +67 -0
  14. data/lib/datafoodconsortium/connector/enterprise.rb +108 -0
  15. data/lib/datafoodconsortium/connector/flow.rb +46 -0
  16. data/lib/datafoodconsortium/connector/importer.rb +112 -0
  17. data/lib/datafoodconsortium/connector/json_ld_serializer.rb +47 -0
  18. data/lib/datafoodconsortium/connector/localized_product.rb +105 -0
  19. data/lib/datafoodconsortium/connector/nutrient_characteristic.rb +51 -0
  20. data/lib/datafoodconsortium/connector/offer.rb +66 -0
  21. data/lib/datafoodconsortium/connector/order.rb +96 -0
  22. data/lib/datafoodconsortium/connector/order_line.rb +72 -0
  23. data/lib/datafoodconsortium/connector/payment_method.rb +70 -0
  24. data/lib/datafoodconsortium/connector/person.rb +65 -0
  25. data/lib/datafoodconsortium/connector/phone_number.rb +51 -0
  26. data/lib/datafoodconsortium/connector/physical_characteristic.rb +51 -0
  27. data/lib/datafoodconsortium/connector/physical_place.rb +94 -0
  28. data/lib/datafoodconsortium/connector/physical_product.rb +104 -0
  29. data/lib/datafoodconsortium/connector/pickup_option.rb +55 -0
  30. data/lib/datafoodconsortium/connector/planned_consumption_flow.rb +56 -0
  31. data/lib/datafoodconsortium/connector/planned_local_consumption_flow.rb +56 -0
  32. data/lib/datafoodconsortium/connector/planned_local_production_flow.rb +56 -0
  33. data/lib/datafoodconsortium/connector/planned_local_transformation.rb +79 -0
  34. data/lib/datafoodconsortium/connector/planned_production_flow.rb +56 -0
  35. data/lib/datafoodconsortium/connector/planned_transformation.rb +60 -0
  36. data/lib/datafoodconsortium/connector/price.rb +57 -0
  37. data/lib/datafoodconsortium/connector/product_batch.rb +90 -0
  38. data/lib/datafoodconsortium/connector/quantitative_value.rb +51 -0
  39. data/lib/datafoodconsortium/connector/quantity.rb +51 -0
  40. data/lib/datafoodconsortium/connector/real_stock.rb +74 -0
  41. data/lib/datafoodconsortium/connector/realized_consumption_flow.rb +56 -0
  42. data/lib/datafoodconsortium/connector/realized_production_flow.rb +56 -0
  43. data/lib/datafoodconsortium/connector/realized_transformation.rb +73 -0
  44. data/lib/datafoodconsortium/connector/sale_session.rb +64 -0
  45. data/lib/datafoodconsortium/connector/shipping_option.rb +91 -0
  46. data/lib/datafoodconsortium/connector/skos_concept.rb +67 -0
  47. data/lib/datafoodconsortium/connector/skos_helper.rb +14 -0
  48. data/lib/datafoodconsortium/connector/skos_parser.rb +166 -0
  49. data/lib/datafoodconsortium/connector/skos_parser_element.rb +97 -0
  50. data/lib/datafoodconsortium/connector/social_media.rb +51 -0
  51. data/lib/datafoodconsortium/connector/supplied_product.rb +74 -0
  52. data/lib/datafoodconsortium/connector/technical_product.rb +62 -0
  53. data/lib/datafoodconsortium/connector/theoretical_stock.rb +67 -0
  54. data/lib/datafoodconsortium/connector/virtual_place.rb +64 -0
  55. data/lib/datafoodconsortium/connector.rb +59 -0
  56. metadata +116 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 28fd8d09adf6b2c2a9b3d9e8f865bb29499e56fa76a8bba2cc566b25b4df98ee
4
+ data.tar.gz: 6cb8596a4ec6b5034a21854e9b8f336b170d7975e9ea116247dd10103919342d
5
+ SHA512:
6
+ metadata.gz: cea6c4229915a9d6fdb09b8e70ae2854bff050d12029f4ba3eca72f07b7201ca17b064870d36d2e2513ed1b23ab67a89139bd6c858e5c354c05dda1aa1b3b6a9
7
+ data.tar.gz: bbddded1ea0201d0085f9870fa135036706dd13270ee35d476884fdee4f46bf1702bb07285e654202151633b8e8d92c8346ad56fd76ae415cf4931b9aeef338d
@@ -0,0 +1,81 @@
1
+ # MIT License
2
+ #
3
+ # Copyright (c) 2023 Maxime Lecoq <maxime@lecoqlibre.fr>
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in all
13
+ # copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ # SOFTWARE.
22
+
23
+
24
+ require "virtual_assembly/semantizer"
25
+
26
+ class DataFoodConsortium::Connector::Address
27
+ include VirtualAssembly::Semantizer::SemanticObject
28
+
29
+ SEMANTIC_TYPE = "dfc-b:Address".freeze
30
+
31
+ # @return [String]
32
+ attr_accessor :street
33
+
34
+ # @return [String]
35
+ attr_accessor :postalCode
36
+
37
+ # @return [String]
38
+ attr_accessor :city
39
+
40
+ # @return [String]
41
+ attr_accessor :country
42
+
43
+ # @return [Real]
44
+ attr_accessor :latitude
45
+
46
+ # @return [Real]
47
+ attr_accessor :longitude
48
+
49
+ # @return [String]
50
+ attr_accessor :region
51
+
52
+ # @param semanticId [String]
53
+ # @param street [String]
54
+ # @param postalCode [String]
55
+ # @param city [String]
56
+ # @param country [String]
57
+ # @param latitude [Real]
58
+ # @param longitude [Real]
59
+ # @param region [String]
60
+ def initialize(semanticId, street: nil, postalCode: nil, city: nil, country: nil, latitude: nil, longitude: nil, region: nil)
61
+ super(semanticId)
62
+ @street = street
63
+ @postalCode = postalCode
64
+ @city = city
65
+ @country = country
66
+ @latitude = latitude
67
+ @longitude = longitude
68
+ @region = region
69
+ self.semanticType = "dfc-b:Address"
70
+ registerSemanticProperty("dfc-b:hasStreet", &method("street")).valueSetter = method("street=")
71
+ registerSemanticProperty("dfc-b:hasPostalCode", &method("postalCode")).valueSetter = method("postalCode=")
72
+ registerSemanticProperty("dfc-b:hasCity", &method("city")).valueSetter = method("city=")
73
+ registerSemanticProperty("dfc-b:hasCountry", &method("country")).valueSetter = method("country=")
74
+ registerSemanticProperty("dfc-b:latitude", &method("latitude")).valueSetter = method("latitude=")
75
+ registerSemanticProperty("dfc-b:longitude", &method("longitude")).valueSetter = method("longitude=")
76
+ registerSemanticProperty("dfc-b:region", &method("region")).valueSetter = method("region=")
77
+ end
78
+
79
+
80
+
81
+ end
@@ -0,0 +1,76 @@
1
+ # MIT License
2
+ #
3
+ # Copyright (c) 2023 Maxime Lecoq <maxime@lecoqlibre.fr>
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in all
13
+ # copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ # SOFTWARE.
22
+
23
+
24
+
25
+ require "virtual_assembly/semantizer"
26
+
27
+ class DataFoodConsortium::Connector::Agent
28
+ include VirtualAssembly::Semantizer::SemanticObject
29
+
30
+ SEMANTIC_TYPE = "dfc-b:Agent".freeze
31
+
32
+ # @return [IAddress]
33
+ attr_accessor :localizations
34
+
35
+ # @return [IPhoneNumber]
36
+ attr_accessor :phoneNumbers
37
+
38
+ # @return [String]
39
+ attr_accessor :emails
40
+
41
+ # @return [String]
42
+ attr_accessor :websites
43
+
44
+ # @return [ISocialMedia]
45
+ attr_accessor :socialMedias
46
+
47
+ # @return [String]
48
+ attr_accessor :logo
49
+
50
+ # @param semanticId [String]
51
+ # @param localizations [IAddress]
52
+ # @param phoneNumbers [IPhoneNumber]
53
+ # @param emails [String]
54
+ # @param websites [String]
55
+ # @param socialMedias [ISocialMedia]
56
+ # @param logo [String]
57
+ def initialize(semanticId, localizations: [], phoneNumbers: [], emails: [], websites: [], socialMedias: [], logo: nil)
58
+ super(semanticId)
59
+ @localizations = localizations
60
+ @phoneNumbers = phoneNumbers
61
+ @emails = emails
62
+ @websites = websites
63
+ @socialMedias = socialMedias
64
+ @logo = logo
65
+ self.semanticType = "dfc-b:Agent"
66
+ registerSemanticProperty("dfc-b:hasAddress", &method("localizations")).valueSetter = method("localizations=")
67
+ registerSemanticProperty("dfc-b:hasPhoneNumber", &method("phoneNumbers")).valueSetter = method("phoneNumbers=")
68
+ registerSemanticProperty("dfc-b:email", &method("emails")).valueSetter = method("emails=")
69
+ registerSemanticProperty("dfc-b:websitePage", &method("websites")).valueSetter = method("websites=")
70
+ registerSemanticProperty("dfc-b:hasSocialMedia", &method("socialMedias")).valueSetter = method("socialMedias=")
71
+ registerSemanticProperty("dfc-b:logo", &method("logo")).valueSetter = method("logo=")
72
+ end
73
+
74
+
75
+
76
+ end
@@ -0,0 +1,51 @@
1
+ # MIT License
2
+ #
3
+ # Copyright (c) 2023 Maxime Lecoq <maxime@lecoqlibre.fr>
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in all
13
+ # copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ # SOFTWARE.
22
+
23
+ require "datafoodconsortium/connector/characteristic"
24
+
25
+
26
+ require "virtual_assembly/semantizer"
27
+
28
+ class DataFoodConsortium::Connector::AllergenCharacteristic < DataFoodConsortium::Connector::Characteristic
29
+
30
+ SEMANTIC_TYPE = "dfc-b:AllergenCharacteristic".freeze
31
+
32
+ # @return [ISKOSConcept]
33
+ attr_accessor :allergenDimension
34
+
35
+ # @param allergenDimension [ISKOSConcept]
36
+ # @param unit [ISKOSConcept]
37
+ # @param value [Real]
38
+ def initialize(allergenDimension: nil, unit: nil, value: nil)
39
+ super(unit: unit, value: value)
40
+ @allergenDimension = allergenDimension
41
+ self.semanticType = "dfc-b:AllergenCharacteristic"
42
+ registerSemanticProperty("dfc-b:hasAllergenDimension", &method("allergenDimension")).valueSetter = method("allergenDimension=")
43
+ end
44
+
45
+
46
+
47
+
48
+
49
+
50
+
51
+ end
@@ -0,0 +1,54 @@
1
+ # MIT License
2
+ #
3
+ # Copyright (c) 2023 Maxime Lecoq <maxime@lecoqlibre.fr>
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in all
13
+ # copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ # SOFTWARE.
22
+
23
+
24
+
25
+
26
+
27
+ require "virtual_assembly/semantizer"
28
+
29
+ class DataFoodConsortium::Connector::Catalog
30
+ include VirtualAssembly::Semantizer::SemanticObject
31
+
32
+ SEMANTIC_TYPE = "dfc-b:Catalog".freeze
33
+
34
+ # @return [ICatalogItem]
35
+ attr_accessor :items
36
+
37
+ # @return [IEnterprise]
38
+ attr_accessor :maintainers
39
+
40
+ # @param semanticId [String]
41
+ # @param items [ICatalogItem]
42
+ # @param maintainers [IEnterprise]
43
+ def initialize(semanticId, items: [], maintainers: [])
44
+ super(semanticId)
45
+ @items = items
46
+ @maintainers = maintainers
47
+ self.semanticType = "dfc-b:Catalog"
48
+ registerSemanticProperty("dfc-b:lists", &method("items")).valueSetter = method("items=")
49
+ registerSemanticProperty("dfc-b:maintainedBy", &method("maintainers")).valueSetter = method("maintainers=")
50
+ end
51
+
52
+
53
+
54
+ end
@@ -0,0 +1,72 @@
1
+ # MIT License
2
+ #
3
+ # Copyright (c) 2023 Maxime Lecoq <maxime@lecoqlibre.fr>
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in all
13
+ # copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ # SOFTWARE.
22
+
23
+
24
+
25
+
26
+
27
+ require "virtual_assembly/semantizer"
28
+
29
+ class DataFoodConsortium::Connector::CatalogItem
30
+ include VirtualAssembly::Semantizer::SemanticObject
31
+
32
+ SEMANTIC_TYPE = "dfc-b:CatalogItem".freeze
33
+
34
+ # @return [IDefinedProduct]
35
+ attr_accessor :product
36
+
37
+ # @return [String]
38
+ attr_accessor :sku
39
+
40
+ # @return [Real]
41
+ attr_accessor :stockLimitation
42
+
43
+ # @return [IOffer]
44
+ attr_accessor :offers
45
+
46
+ # @return [ICatalog]
47
+ attr_accessor :catalogs
48
+
49
+ # @param semanticId [String]
50
+ # @param product [IDefinedProduct]
51
+ # @param sku [String]
52
+ # @param stockLimitation [Real]
53
+ # @param offers [IOffer]
54
+ # @param catalogs [ICatalog]
55
+ def initialize(semanticId, product: nil, sku: nil, stockLimitation: nil, offers: [], catalogs: [])
56
+ super(semanticId)
57
+ @product = product
58
+ @sku = sku
59
+ @stockLimitation = stockLimitation
60
+ @offers = offers
61
+ @catalogs = catalogs
62
+ self.semanticType = "dfc-b:CatalogItem"
63
+ registerSemanticProperty("dfc-b:references", &method("product")).valueSetter = method("product=")
64
+ registerSemanticProperty("dfc-b:sku", &method("sku")).valueSetter = method("sku=")
65
+ registerSemanticProperty("dfc-b:stockLimitation", &method("stockLimitation")).valueSetter = method("stockLimitation=")
66
+ registerSemanticProperty("dfc-b:offeredThrough", &method("offers")).valueSetter = method("offers=")
67
+ registerSemanticProperty("dfc-b:listedIn", &method("catalogs")).valueSetter = method("catalogs=")
68
+ end
69
+
70
+
71
+
72
+ end
@@ -0,0 +1,46 @@
1
+ # MIT License
2
+ #
3
+ # Copyright (c) 2023 Maxime Lecoq <maxime@lecoqlibre.fr>
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in all
13
+ # copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ # SOFTWARE.
22
+
23
+
24
+
25
+ require "datafoodconsortium/connector/quantitative_value"
26
+ require "virtual_assembly/semantizer"
27
+
28
+ class DataFoodConsortium::Connector::Characteristic < DataFoodConsortium::Connector::QuantitativeValue
29
+
30
+
31
+ # @param unit [ISKOSConcept]
32
+ # @param value [Real]
33
+ def initialize(unit: nil, value: nil)
34
+ super(unit: unit, value: value)
35
+
36
+
37
+
38
+ end
39
+
40
+
41
+
42
+
43
+
44
+
45
+
46
+ end
@@ -0,0 +1,84 @@
1
+ # MIT License
2
+ #
3
+ # Copyright (c) 2023 Maxime Lecoq <maxime@lecoqlibre.fr>
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in all
13
+ # copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ # SOFTWARE.
22
+
23
+ require 'singleton'
24
+ require 'datafoodconsortium/connector/context'
25
+ require 'datafoodconsortium/connector/importer'
26
+ require 'datafoodconsortium/connector/json_ld_serializer'
27
+
28
+ module DataFoodConsortium::Connector
29
+ class Connector
30
+ include Singleton
31
+
32
+ attr_accessor :context
33
+
34
+ attr_reader :FACETS
35
+ attr_reader :MEASURES
36
+ attr_reader :PRODUCT_TYPES
37
+
38
+ def export(*subjects)
39
+ @exporter.process(*subjects)
40
+ end
41
+
42
+ def import(json_string_or_io)
43
+ Importer.new.import(json_string_or_io)
44
+ end
45
+
46
+ def loadFacets(data)
47
+ @FACETS = loadThesaurus(data)
48
+ end
49
+
50
+ def loadMeasures(data)
51
+ @MEASURES = loadThesaurus(data)
52
+ end
53
+
54
+ def loadProductTypes(data)
55
+ @PRODUCT_TYPES = loadThesaurus(data)
56
+ end
57
+
58
+ private
59
+
60
+ def initialize()
61
+ super()
62
+
63
+ # used to prefix properties
64
+ # so the DFC's context can be used.
65
+ # See https://github.com/datafoodconsortium/connector-ruby/issues/11.
66
+ inputContext = Context.inputContext
67
+
68
+ @context = Context::URL
69
+
70
+ @exporter = JsonLdSerializer.new(@context, inputContext)
71
+ @parser = SKOSParser.new
72
+
73
+ @FACETS = []
74
+ @MEASURES = []
75
+ @PRODUCT_TYPES = []
76
+ end
77
+
78
+ def loadThesaurus(data)
79
+ # The root element may be an array or the ontology.
80
+ data = data[0] if data.is_a?(Array)
81
+ @parser.parse(data["@graph"])
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json/ld'
4
+
5
+ module DataFoodConsortium
6
+ module Connector
7
+ # Preload the DFC context.
8
+ #
9
+ # Similar to: https://github.com/ruby-rdf/json-ld-preloaded/
10
+ class Context < JSON::LD::Context
11
+ URL = "https://w3id.org/dfc/ontology/context/context_1.16.0.json"
12
+ URL_NORMALISED = "http://w3id.org/dfc/ontology/context/context_1.16.0.json"
13
+
14
+ # All context URIs have to use http because https is normalised to http
15
+ # during the lookup of preloaded contexts.
16
+ # And if the URI doesn't have a path, it must end with `/`.
17
+ add_preloaded(URL_NORMALISED) { parse(json) }
18
+
19
+ # The default context always pointing to the latest version:
20
+ alias_preloaded("http://www.datafoodconsortium.org/", URL_NORMALISED)
21
+
22
+ # This is the current file the DFC website refers to in a link header.
23
+ alias_preloaded(
24
+ "http://www.datafoodconsortium.org/wp-content/plugins/wordpress-context-jsonld/context_1.16.0.jsonld",
25
+ URL_NORMALISED
26
+ )
27
+
28
+ # This was the file the DFC website refers to in a link header.
29
+ alias_preloaded(
30
+ "http://www.datafoodconsortium.org/wp-content/plugins/wordpress-context-jsonld/context.jsonld",
31
+ URL_NORMALISED
32
+ )
33
+
34
+ # This is the old URL that's not online anymore.
35
+ # Keep it for compatiblity with all versions before 1.8.
36
+ alias_preloaded(
37
+ "http://static.datafoodconsortium.org/ontologies/context.json",
38
+ URL_NORMALISED
39
+ )
40
+
41
+ # The hash serializer expects only string values in the context.
42
+ def self.inputContext
43
+ @inputContext = json.select { |key, value| value.is_a? String }
44
+ end
45
+
46
+ def self.json
47
+ @json ||= JSON.parse(File.read("#{__dir__}/context_1.16.0.json"))["@context"]
48
+ end
49
+ end
50
+ end
51
+ end