datafoodconsortium-connector 1.0.0.pre.alpha.9 → 1.0.0.pre.alpha.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/datafoodconsortium/connector/address.rb +6 -5
- data/lib/datafoodconsortium/connector/agent.rb +7 -6
- data/lib/datafoodconsortium/connector/allergen_characteristic.rb +3 -3
- data/lib/datafoodconsortium/connector/catalog.rb +4 -3
- data/lib/datafoodconsortium/connector/catalog_item.rb +7 -6
- data/lib/datafoodconsortium/connector/characteristic.rb +1 -3
- data/lib/datafoodconsortium/connector/connector.rb +10 -9
- data/lib/datafoodconsortium/connector/context.rb +72 -0
- data/lib/datafoodconsortium/connector/customer_category.rb +3 -2
- data/lib/datafoodconsortium/connector/defined_product.rb +18 -17
- data/lib/datafoodconsortium/connector/enterprise.rb +11 -11
- data/lib/datafoodconsortium/connector/importer.rb +112 -0
- data/lib/datafoodconsortium/connector/json_ld_serializer.rb +7 -14
- data/lib/datafoodconsortium/connector/nutrient_characteristic.rb +2 -2
- data/lib/datafoodconsortium/connector/offer.rb +6 -5
- data/lib/datafoodconsortium/connector/order.rb +7 -6
- data/lib/datafoodconsortium/connector/order_line.rb +7 -6
- data/lib/datafoodconsortium/connector/person.rb +5 -5
- data/lib/datafoodconsortium/connector/phone_number.rb +4 -3
- data/lib/datafoodconsortium/connector/physical_characteristic.rb +3 -3
- data/lib/datafoodconsortium/connector/price.rb +5 -4
- data/lib/datafoodconsortium/connector/quantitative_value.rb +4 -3
- data/lib/datafoodconsortium/connector/quantity.rb +4 -3
- data/lib/datafoodconsortium/connector/sale_session.rb +6 -5
- data/lib/datafoodconsortium/connector/skos_concept.rb +10 -7
- data/lib/datafoodconsortium/connector/skos_helper.rb +14 -0
- data/lib/datafoodconsortium/connector/skos_parser.rb +122 -99
- data/lib/datafoodconsortium/connector/skos_parser_element.rb +72 -53
- data/lib/datafoodconsortium/connector/social_media.rb +4 -3
- data/lib/datafoodconsortium/connector/supplied_product.rb +2 -2
- data/lib/datafoodconsortium/connector/technical_product.rb +2 -2
- data/lib/datafoodconsortium/connector.rb +19 -13
- metadata +6 -40
- data/lib/datafoodconsortium/connector/allergen_dimension.rb +0 -34
- data/lib/datafoodconsortium/connector/certification.rb +0 -34
- data/lib/datafoodconsortium/connector/characteristic_dimension.rb +0 -34
- data/lib/datafoodconsortium/connector/geographical_origin.rb +0 -34
- data/lib/datafoodconsortium/connector/nature_origin.rb +0 -34
- data/lib/datafoodconsortium/connector/part_origin.rb +0 -34
- data/lib/datafoodconsortium/connector/product_type.rb +0 -34
- data/lib/datafoodconsortium/connector/repository.rb +0 -33
- data/lib/datafoodconsortium/connector/unit.rb +0 -34
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b7948a960df0e1c5980954d67ab8b386029789fe867d06bcef4b1ff8944bacec
|
4
|
+
data.tar.gz: 8ad3b6dd4c57b621e4a712424b8fcfa7a8b1c0efec75cde535554617ad72e6d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 45c695953704de93af40ed04d87e73abc0084d93cce29c28fca0925ec5d61d69b0db467370ad6a7b4e5ae6c93897b16a97d67b6ba8f82940241d9edda285f473
|
7
|
+
data.tar.gz: 125396ea6bbc7ed9f9313f14e95f6a8568896c0e7f219a268a3f5419e24a8bae292f470fc7f6abb58b977c5129e0953b06398c7eea657bcd5fe0faa137bdc0a3
|
@@ -24,8 +24,9 @@
|
|
24
24
|
require "virtual_assembly/semantizer"
|
25
25
|
|
26
26
|
class DataFoodConsortium::Connector::Address
|
27
|
+
include VirtualAssembly::Semantizer::SemanticObject
|
27
28
|
|
28
|
-
|
29
|
+
SEMANTIC_TYPE = "dfc-b:Address".freeze
|
29
30
|
|
30
31
|
# @return [String]
|
31
32
|
attr_accessor :street
|
@@ -51,10 +52,10 @@ class DataFoodConsortium::Connector::Address
|
|
51
52
|
@city = city
|
52
53
|
@country = country
|
53
54
|
self.semanticType = "dfc-b:Address"
|
54
|
-
registerSemanticProperty("dfc-b:hasStreet")
|
55
|
-
registerSemanticProperty("dfc-b:hasPostalCode")
|
56
|
-
registerSemanticProperty("dfc-b:hasCity")
|
57
|
-
registerSemanticProperty("dfc-b:hasCountry")
|
55
|
+
registerSemanticProperty("dfc-b:hasStreet", &method("street")).valueSetter = method("street=")
|
56
|
+
registerSemanticProperty("dfc-b:hasPostalCode", &method("postalCode")).valueSetter = method("postalCode=")
|
57
|
+
registerSemanticProperty("dfc-b:hasCity", &method("city")).valueSetter = method("city=")
|
58
|
+
registerSemanticProperty("dfc-b:hasCountry", &method("country")).valueSetter = method("country=")
|
58
59
|
end
|
59
60
|
|
60
61
|
|
@@ -25,8 +25,9 @@
|
|
25
25
|
require "virtual_assembly/semantizer"
|
26
26
|
|
27
27
|
class DataFoodConsortium::Connector::Agent
|
28
|
+
include VirtualAssembly::Semantizer::SemanticObject
|
28
29
|
|
29
|
-
|
30
|
+
SEMANTIC_TYPE = "dfc-b:Agent".freeze
|
30
31
|
|
31
32
|
# @return [IAddress]
|
32
33
|
attr_accessor :localizations
|
@@ -57,11 +58,11 @@ class DataFoodConsortium::Connector::Agent
|
|
57
58
|
@websites = websites
|
58
59
|
@socialMedias = socialMedias
|
59
60
|
self.semanticType = "dfc-b:Agent"
|
60
|
-
registerSemanticProperty("dfc-b:hasAddress")
|
61
|
-
registerSemanticProperty("dfc-b:hasPhoneNumber")
|
62
|
-
registerSemanticProperty("dfc-b:email")
|
63
|
-
registerSemanticProperty("dfc-b:websitePage")
|
64
|
-
registerSemanticProperty("dfc-b:hasSocialMedia")
|
61
|
+
registerSemanticProperty("dfc-b:hasAddress", &method("localizations")).valueSetter = method("localizations=")
|
62
|
+
registerSemanticProperty("dfc-b:hasPhoneNumber", &method("phoneNumbers")).valueSetter = method("phoneNumbers=")
|
63
|
+
registerSemanticProperty("dfc-b:email", &method("emails")).valueSetter = method("emails=")
|
64
|
+
registerSemanticProperty("dfc-b:websitePage", &method("websites")).valueSetter = method("websites=")
|
65
|
+
registerSemanticProperty("dfc-b:hasSocialMedia", &method("socialMedias")).valueSetter = method("socialMedias=")
|
65
66
|
end
|
66
67
|
|
67
68
|
|
@@ -20,14 +20,14 @@
|
|
20
20
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
21
|
# SOFTWARE.
|
22
22
|
|
23
|
-
|
24
23
|
require "datafoodconsortium/connector/characteristic"
|
25
24
|
|
25
|
+
|
26
26
|
require "virtual_assembly/semantizer"
|
27
27
|
|
28
28
|
class DataFoodConsortium::Connector::AllergenCharacteristic < DataFoodConsortium::Connector::Characteristic
|
29
29
|
|
30
|
-
|
30
|
+
SEMANTIC_TYPE = "dfc-b:AllergenCharacteristic".freeze
|
31
31
|
|
32
32
|
# @return [ISKOSConcept]
|
33
33
|
attr_accessor :allergenDimension
|
@@ -39,7 +39,7 @@ class DataFoodConsortium::Connector::AllergenCharacteristic < DataFoodConsortium
|
|
39
39
|
super(unit: unit, value: value)
|
40
40
|
@allergenDimension = allergenDimension
|
41
41
|
self.semanticType = "dfc-b:AllergenCharacteristic"
|
42
|
-
registerSemanticProperty("dfc-b:hasAllergenDimension")
|
42
|
+
registerSemanticProperty("dfc-b:hasAllergenDimension", &method("allergenDimension")).valueSetter = method("allergenDimension=")
|
43
43
|
end
|
44
44
|
|
45
45
|
|
@@ -27,8 +27,9 @@
|
|
27
27
|
require "virtual_assembly/semantizer"
|
28
28
|
|
29
29
|
class DataFoodConsortium::Connector::Catalog
|
30
|
+
include VirtualAssembly::Semantizer::SemanticObject
|
30
31
|
|
31
|
-
|
32
|
+
SEMANTIC_TYPE = "dfc-b:Catalog".freeze
|
32
33
|
|
33
34
|
# @return [ICatalogItem]
|
34
35
|
attr_accessor :items
|
@@ -44,8 +45,8 @@ class DataFoodConsortium::Connector::Catalog
|
|
44
45
|
@items = items
|
45
46
|
@maintainers = maintainers
|
46
47
|
self.semanticType = "dfc-b:Catalog"
|
47
|
-
registerSemanticProperty("dfc-b:lists")
|
48
|
-
registerSemanticProperty("dfc-b:maintainedBy")
|
48
|
+
registerSemanticProperty("dfc-b:lists", &method("items")).valueSetter = method("items=")
|
49
|
+
registerSemanticProperty("dfc-b:maintainedBy", &method("maintainers")).valueSetter = method("maintainers=")
|
49
50
|
end
|
50
51
|
|
51
52
|
|
@@ -27,8 +27,9 @@
|
|
27
27
|
require "virtual_assembly/semantizer"
|
28
28
|
|
29
29
|
class DataFoodConsortium::Connector::CatalogItem
|
30
|
+
include VirtualAssembly::Semantizer::SemanticObject
|
30
31
|
|
31
|
-
|
32
|
+
SEMANTIC_TYPE = "dfc-b:CatalogItem".freeze
|
32
33
|
|
33
34
|
# @return [IDefinedProduct]
|
34
35
|
attr_accessor :product
|
@@ -59,11 +60,11 @@ class DataFoodConsortium::Connector::CatalogItem
|
|
59
60
|
@offers = offers
|
60
61
|
@catalogs = catalogs
|
61
62
|
self.semanticType = "dfc-b:CatalogItem"
|
62
|
-
registerSemanticProperty("dfc-b:references")
|
63
|
-
registerSemanticProperty("dfc-b:sku")
|
64
|
-
registerSemanticProperty("dfc-b:stockLimitation")
|
65
|
-
registerSemanticProperty("dfc-b:offeredThrough")
|
66
|
-
registerSemanticProperty("dfc-b:listedIn")
|
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=")
|
67
68
|
end
|
68
69
|
|
69
70
|
|
@@ -21,14 +21,12 @@
|
|
21
21
|
# SOFTWARE.
|
22
22
|
|
23
23
|
|
24
|
-
require "datafoodconsortium/connector/quantitative_value"
|
25
24
|
|
25
|
+
require "datafoodconsortium/connector/quantitative_value"
|
26
26
|
require "virtual_assembly/semantizer"
|
27
27
|
|
28
28
|
class DataFoodConsortium::Connector::Characteristic < DataFoodConsortium::Connector::QuantitativeValue
|
29
29
|
|
30
|
-
|
31
|
-
|
32
30
|
|
33
31
|
# @param unit [ISKOSConcept]
|
34
32
|
# @param value [Real]
|
@@ -21,6 +21,8 @@
|
|
21
21
|
# SOFTWARE.
|
22
22
|
|
23
23
|
require 'singleton'
|
24
|
+
require 'datafoodconsortium/connector/context'
|
25
|
+
require 'datafoodconsortium/connector/importer'
|
24
26
|
require 'datafoodconsortium/connector/json_ld_serializer'
|
25
27
|
|
26
28
|
class DataFoodConsortium::Connector::Connector
|
@@ -37,6 +39,10 @@ class DataFoodConsortium::Connector::Connector
|
|
37
39
|
return @exporter.process(subject, *subjects)
|
38
40
|
end
|
39
41
|
|
42
|
+
def import(json_string_or_io)
|
43
|
+
DataFoodConsortium::Connector::Importer.new.import(json_string_or_io)
|
44
|
+
end
|
45
|
+
|
40
46
|
def loadFacets(data)
|
41
47
|
@FACETS = loadThesaurus(data)
|
42
48
|
end
|
@@ -57,14 +63,7 @@ class DataFoodConsortium::Connector::Connector
|
|
57
63
|
# used to prefix properties
|
58
64
|
# so the DFC's context can be used.
|
59
65
|
# See https://github.com/datafoodconsortium/connector-ruby/issues/11.
|
60
|
-
inputContext =
|
61
|
-
"dfc-b" => "https://github.com/datafoodconsortium/ontology/releases/latest/download/DFC_BusinessOntology.owl#",
|
62
|
-
"dfc-p" => "https://github.com/datafoodconsortium/ontology/releases/latest/download/DFC_ProductGlossary.owl#",
|
63
|
-
"dfc-t" => "https://github.com/datafoodconsortium/ontology/releases/latest/download/DFC_TechnicalOntology.owl#",
|
64
|
-
"dfc-m" => "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/measures.rdf#",
|
65
|
-
"dfc-pt" => "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/productTypes.rdf#",
|
66
|
-
"dfc-f" => "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/facets.rdf#"
|
67
|
-
}
|
66
|
+
inputContext = DataFoodConsortium::Connector::Context.inputContext
|
68
67
|
|
69
68
|
@context = "https://www.datafoodconsortium.org"
|
70
69
|
|
@@ -77,7 +76,9 @@ class DataFoodConsortium::Connector::Connector
|
|
77
76
|
end
|
78
77
|
|
79
78
|
def loadThesaurus(data)
|
80
|
-
|
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"])
|
81
82
|
end
|
82
83
|
|
83
84
|
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'json/ld'
|
4
|
+
|
5
|
+
# Preload the DFC context.
|
6
|
+
#
|
7
|
+
# Similar to: https://github.com/ruby-rdf/json-ld-preloaded/
|
8
|
+
module DataFoodConsortium
|
9
|
+
module Connector
|
10
|
+
class Context < JSON::LD::Context
|
11
|
+
VERSION_1_8 = JSON.parse <<~JSON
|
12
|
+
{
|
13
|
+
"rdfs": "http://www.w3.org/2000/01/rdf-schema#",
|
14
|
+
"skos" : "http://www.w3.org/2004/02/skos/core#",
|
15
|
+
"dfc": "https://github.com/datafoodconsortium/ontology/releases/latest/download/DFC_FullModel.owl#",
|
16
|
+
"dc": "http://purl.org/dc/elements/1.1/#",
|
17
|
+
"dfc-b": "https://github.com/datafoodconsortium/ontology/releases/latest/download/DFC_BusinessOntology.owl#",
|
18
|
+
"dfc-p": "https://github.com/datafoodconsortium/ontology/releases/latest/download/DFC_ProductGlossary.owl#",
|
19
|
+
"dfc-t": "https://github.com/datafoodconsortium/ontology/releases/latest/download/DFC_TechnicalOntology.owl#",
|
20
|
+
"dfc-m": "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/measures.rdf#",
|
21
|
+
"dfc-pt": "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/productTypes.rdf#",
|
22
|
+
"dfc-f": "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/facets.rdf#",
|
23
|
+
"ontosec": "http://www.semanticweb.org/ontologies/2008/11/OntologySecurity.owl#",
|
24
|
+
"dfc-p:hasUnit":{ "@type":"@id" },
|
25
|
+
"dfc-b:hasUnit":{ "@type":"@id" },
|
26
|
+
"dfc-b:hasQuantity":{ "@type":"@id" },
|
27
|
+
"dfc-p:hasType":{ "@type":"@id" },
|
28
|
+
"dfc-b:hasType":{ "@type":"@id" },
|
29
|
+
"dfc-b:references":{ "@type":"@id" },
|
30
|
+
"dfc-b:referencedBy":{ "@type":"@id" },
|
31
|
+
"dfc-b:offeres":{ "@type":"@id" },
|
32
|
+
"dfc-b:supplies":{ "@type":"@id" },
|
33
|
+
"dfc-b:defines":{ "@type":"@id" },
|
34
|
+
"dfc-b:affiliates":{ "@type":"@id" },
|
35
|
+
"dfc-b:hasCertification":{ "@type":"@id" },
|
36
|
+
"dfc-b:manages":{ "@type":"@id" },
|
37
|
+
"dfc-b:offeredThrough":{ "@type":"@id" },
|
38
|
+
"dfc-b:hasBrand":{ "@type":"@id" },
|
39
|
+
"dfc-b:hasGeographicalOrigin":{ "@type":"@id" },
|
40
|
+
"dfc-b:hasClaim":{ "@type":"@id" },
|
41
|
+
"dfc-b:hasAllergenDimension":{ "@type":"@id" },
|
42
|
+
"dfc-b:hasNutrientDimension":{ "@type":"@id" },
|
43
|
+
"dfc-b:hasPhysicalDimension":{ "@type":"@id" },
|
44
|
+
"dfc:owner":{ "@type":"@id" },
|
45
|
+
"dfc-t:hostedBy":{ "@type":"@id" },
|
46
|
+
"dfc-t:hasPivot":{ "@type":"@id" },
|
47
|
+
"dfc-t:represent":{ "@type":"@id" }
|
48
|
+
}
|
49
|
+
JSON
|
50
|
+
|
51
|
+
add_preloaded("http://www.datafoodconsortium.org/") { parse(VERSION_1_8) }
|
52
|
+
|
53
|
+
# This is the actual file the DFC website refers to in a link header.
|
54
|
+
alias_preloaded(
|
55
|
+
"https://www.datafoodconsortium.org/wp-content/plugins/wordpress-context-jsonld/context.jsonld",
|
56
|
+
"http://www.datafoodconsortium.org/"
|
57
|
+
)
|
58
|
+
|
59
|
+
# This is the old URL that's not online anymore.
|
60
|
+
# Keep it for compatiblity with all versions before 1.8.
|
61
|
+
alias_preloaded(
|
62
|
+
"http://static.datafoodconsortium.org/ontologies/context.json",
|
63
|
+
"http://www.datafoodconsortium.org/"
|
64
|
+
)
|
65
|
+
|
66
|
+
# The hash serializer expects only string values in the context.
|
67
|
+
def self.inputContext
|
68
|
+
@inputContext = VERSION_1_8.select { |key, value| value.is_a? String }
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -24,8 +24,9 @@
|
|
24
24
|
require "virtual_assembly/semantizer"
|
25
25
|
|
26
26
|
class DataFoodConsortium::Connector::CustomerCategory
|
27
|
+
include VirtualAssembly::Semantizer::SemanticObject
|
27
28
|
|
28
|
-
|
29
|
+
SEMANTIC_TYPE = "dfc-b:CustomerCategory".freeze
|
29
30
|
|
30
31
|
# @return [String]
|
31
32
|
attr_accessor :description
|
@@ -36,7 +37,7 @@ class DataFoodConsortium::Connector::CustomerCategory
|
|
36
37
|
super(semanticId)
|
37
38
|
@description = description
|
38
39
|
self.semanticType = "dfc-b:CustomerCategory"
|
39
|
-
registerSemanticProperty("dfc-b:description")
|
40
|
+
registerSemanticProperty("dfc-b:description", &method("description")).valueSetter = method("description=")
|
40
41
|
end
|
41
42
|
|
42
43
|
|
@@ -30,8 +30,9 @@
|
|
30
30
|
require "virtual_assembly/semantizer"
|
31
31
|
|
32
32
|
class DataFoodConsortium::Connector::DefinedProduct
|
33
|
+
include VirtualAssembly::Semantizer::SemanticObject
|
33
34
|
|
34
|
-
|
35
|
+
SEMANTIC_TYPE = "dfc-b:DefinedProduct".freeze
|
35
36
|
|
36
37
|
# @return [String]
|
37
38
|
attr_accessor :name
|
@@ -117,22 +118,22 @@ class DataFoodConsortium::Connector::DefinedProduct
|
|
117
118
|
@natureOrigin = natureOrigin
|
118
119
|
@partOrigin = partOrigin
|
119
120
|
self.semanticType = "dfc-b:DefinedProduct"
|
120
|
-
registerSemanticProperty("dfc-b:name")
|
121
|
-
registerSemanticProperty("dfc-b:description")
|
122
|
-
registerSemanticProperty("dfc-b:hasType")
|
123
|
-
registerSemanticProperty("dfc-b:hasQuantity")
|
124
|
-
registerSemanticProperty("dfc-b:alcoholPercentage")
|
125
|
-
registerSemanticProperty("dfc-b:lifetime")
|
126
|
-
registerSemanticProperty("dfc-b:hasClaim")
|
127
|
-
registerSemanticProperty("dfc-b:usageOrStorageCondition")
|
128
|
-
registerSemanticProperty("dfc-b:hasAllergenCharacteristic")
|
129
|
-
registerSemanticProperty("dfc-b:hasNutrientCharacteristic")
|
130
|
-
registerSemanticProperty("dfc-b:hasPhysicalCharacteristic")
|
131
|
-
registerSemanticProperty("dfc-b:hasGeographicalOrigin")
|
132
|
-
registerSemanticProperty("dfc-b:referencedBy")
|
133
|
-
registerSemanticProperty("dfc-b:hasCertification")
|
134
|
-
registerSemanticProperty("dfc-b:hasNatureOrigin")
|
135
|
-
registerSemanticProperty("dfc-b:hasPartOrigin")
|
121
|
+
registerSemanticProperty("dfc-b:name", &method("name")).valueSetter = method("name=")
|
122
|
+
registerSemanticProperty("dfc-b:description", &method("description")).valueSetter = method("description=")
|
123
|
+
registerSemanticProperty("dfc-b:hasType", &method("productType")).valueSetter = method("productType=")
|
124
|
+
registerSemanticProperty("dfc-b:hasQuantity", &method("quantity")).valueSetter = method("quantity=")
|
125
|
+
registerSemanticProperty("dfc-b:alcoholPercentage", &method("alcoholPercentage")).valueSetter = method("alcoholPercentage=")
|
126
|
+
registerSemanticProperty("dfc-b:lifetime", &method("lifetime")).valueSetter = method("lifetime=")
|
127
|
+
registerSemanticProperty("dfc-b:hasClaim", &method("claims")).valueSetter = method("claims=")
|
128
|
+
registerSemanticProperty("dfc-b:usageOrStorageCondition", &method("usageOrStorageConditions")).valueSetter = method("usageOrStorageConditions=")
|
129
|
+
registerSemanticProperty("dfc-b:hasAllergenCharacteristic", &method("allergenCharacteristics")).valueSetter = method("allergenCharacteristics=")
|
130
|
+
registerSemanticProperty("dfc-b:hasNutrientCharacteristic", &method("nutrientCharacteristics")).valueSetter = method("nutrientCharacteristics=")
|
131
|
+
registerSemanticProperty("dfc-b:hasPhysicalCharacteristic", &method("physicalCharacteristics")).valueSetter = method("physicalCharacteristics=")
|
132
|
+
registerSemanticProperty("dfc-b:hasGeographicalOrigin", &method("geographicalOrigin")).valueSetter = method("geographicalOrigin=")
|
133
|
+
registerSemanticProperty("dfc-b:referencedBy", &method("catalogItems")).valueSetter = method("catalogItems=")
|
134
|
+
registerSemanticProperty("dfc-b:hasCertification", &method("certifications")).valueSetter = method("certifications=")
|
135
|
+
registerSemanticProperty("dfc-b:hasNatureOrigin", &method("natureOrigin")).valueSetter = method("natureOrigin=")
|
136
|
+
registerSemanticProperty("dfc-b:hasPartOrigin", &method("partOrigin")).valueSetter = method("partOrigin=")
|
136
137
|
end
|
137
138
|
|
138
139
|
|
@@ -20,7 +20,6 @@
|
|
20
20
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
21
|
# SOFTWARE.
|
22
22
|
|
23
|
-
|
24
23
|
require "datafoodconsortium/connector/agent"
|
25
24
|
|
26
25
|
|
@@ -31,11 +30,12 @@ require "datafoodconsortium/connector/agent"
|
|
31
30
|
|
32
31
|
|
33
32
|
|
33
|
+
|
34
34
|
require "virtual_assembly/semantizer"
|
35
35
|
|
36
36
|
class DataFoodConsortium::Connector::Enterprise < DataFoodConsortium::Connector::Agent
|
37
37
|
|
38
|
-
|
38
|
+
SEMANTIC_TYPE = "dfc-b:Enterprise".freeze
|
39
39
|
|
40
40
|
# @return [String]
|
41
41
|
attr_accessor :name
|
@@ -91,15 +91,15 @@ class DataFoodConsortium::Connector::Enterprise < DataFoodConsortium::Connector:
|
|
91
91
|
@technicalProducts = technicalProducts
|
92
92
|
@mainContact = mainContact
|
93
93
|
self.semanticType = "dfc-b:Enterprise"
|
94
|
-
registerSemanticProperty("dfc-b:name")
|
95
|
-
registerSemanticProperty("dfc-b:hasDescription")
|
96
|
-
registerSemanticProperty("dfc-b:VATnumber")
|
97
|
-
registerSemanticProperty("dfc-b:defines")
|
98
|
-
registerSemanticProperty("dfc-b:maintains")
|
99
|
-
registerSemanticProperty("dfc-b:manages")
|
100
|
-
registerSemanticProperty("dfc-b:supplies")
|
101
|
-
registerSemanticProperty("dfc-b:proposes")
|
102
|
-
registerSemanticProperty("dfc-b:hasMainContact")
|
94
|
+
registerSemanticProperty("dfc-b:name", &method("name")).valueSetter = method("name=")
|
95
|
+
registerSemanticProperty("dfc-b:hasDescription", &method("description")).valueSetter = method("description=")
|
96
|
+
registerSemanticProperty("dfc-b:VATnumber", &method("vatNumber")).valueSetter = method("vatNumber=")
|
97
|
+
registerSemanticProperty("dfc-b:defines", &method("customerCategories")).valueSetter = method("customerCategories=")
|
98
|
+
registerSemanticProperty("dfc-b:maintains", &method("catalogs")).valueSetter = method("catalogs=")
|
99
|
+
registerSemanticProperty("dfc-b:manages", &method("catalogItems")).valueSetter = method("catalogItems=")
|
100
|
+
registerSemanticProperty("dfc-b:supplies", &method("suppliedProducts")).valueSetter = method("suppliedProducts=")
|
101
|
+
registerSemanticProperty("dfc-b:proposes", &method("technicalProducts")).valueSetter = method("technicalProducts=")
|
102
|
+
registerSemanticProperty("dfc-b:hasMainContact", &method("mainContact")).valueSetter = method("mainContact=")
|
103
103
|
end
|
104
104
|
|
105
105
|
|
@@ -0,0 +1,112 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "skos_parser"
|
4
|
+
|
5
|
+
module DataFoodConsortium
|
6
|
+
module Connector
|
7
|
+
class Importer
|
8
|
+
def self.type_map
|
9
|
+
unless @type_map
|
10
|
+
@type_map = {}
|
11
|
+
DataFoodConsortium::Connector.semantic_types.each do |type|
|
12
|
+
register_type(type)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
@type_map
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.register_type(clazz)
|
20
|
+
type_map[clazz::SEMANTIC_TYPE] = clazz
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.prefixed_name(uri)
|
24
|
+
RDF::URI.new(uri).pname(prefixes: Context::VERSION_1_8)
|
25
|
+
end
|
26
|
+
|
27
|
+
def import(json_string_or_io)
|
28
|
+
@subjects = {}
|
29
|
+
|
30
|
+
graph = parse_rdf(json_string_or_io)
|
31
|
+
build_subjects(graph)
|
32
|
+
apply_statements(graph)
|
33
|
+
|
34
|
+
if @subjects.size > 1
|
35
|
+
@subjects.values
|
36
|
+
else
|
37
|
+
@subjects.values.first
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
# The `io` parameter can be a String or an IO instance.
|
44
|
+
def parse_rdf(io)
|
45
|
+
io = StringIO.new(io) if io.is_a?(String)
|
46
|
+
RDF::Graph.new << JSON::LD::API.toRdf(io)
|
47
|
+
end
|
48
|
+
|
49
|
+
def build_subjects(graph)
|
50
|
+
graph.query({ predicate: RDF.type }).each do |statement|
|
51
|
+
@subjects[statement.subject] = build_subject(statement)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def build_subject(type_statement)
|
56
|
+
# Not all subjects have an id, some are anonymous.
|
57
|
+
id = if type_statement.subject.respond_to?(:value)
|
58
|
+
type_statement.subject.value
|
59
|
+
end
|
60
|
+
type = type_statement.object.value
|
61
|
+
key = self.class.prefixed_name(type)
|
62
|
+
clazz = self.class.type_map[key]
|
63
|
+
|
64
|
+
clazz.new(*[id].compact)
|
65
|
+
end
|
66
|
+
|
67
|
+
def apply_statements(statements)
|
68
|
+
statements.each do |statement|
|
69
|
+
apply_statement(statement)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def apply_statement(statement)
|
74
|
+
subject = subject_of(statement)
|
75
|
+
property_uri = statement.predicate.value
|
76
|
+
value = resolve_object(statement.object)
|
77
|
+
|
78
|
+
property_id = self.class.prefixed_name(property_uri)
|
79
|
+
|
80
|
+
return unless subject.hasSemanticProperty?(property_id)
|
81
|
+
|
82
|
+
property = subject.semanticProperty(property_id)
|
83
|
+
|
84
|
+
if property.value.is_a?(Enumerable)
|
85
|
+
property.value << value
|
86
|
+
else
|
87
|
+
property.value = value
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def subject_of(statement)
|
92
|
+
@subjects[statement.subject]
|
93
|
+
end
|
94
|
+
|
95
|
+
def resolve_object(object)
|
96
|
+
@subjects[object] || skos_concept(object) || object.object
|
97
|
+
end
|
98
|
+
|
99
|
+
def skos_concept(object)
|
100
|
+
return unless object.uri?
|
101
|
+
|
102
|
+
id = object.value.sub(
|
103
|
+
"http://static.datafoodconsortium.org/data/measures.rdf#", "dfc-m:"
|
104
|
+
).sub(
|
105
|
+
"https://github.com/datafoodconsortium/taxonomies/releases/latest/download/measures.rdf#",
|
106
|
+
"dfc-m:"
|
107
|
+
)
|
108
|
+
SKOSParser.concepts[id]
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
@@ -30,27 +30,20 @@ class DataFoodConsortium::Connector::JsonLdSerializer
|
|
30
30
|
@hashSerializer = VirtualAssembly::Semantizer::HashSerializer.new(inputContext)
|
31
31
|
end
|
32
32
|
|
33
|
-
def process(
|
34
|
-
subjects.
|
33
|
+
def process(*subjects)
|
34
|
+
return "" if subjects.empty?
|
35
35
|
|
36
|
-
if (subjects.empty?)
|
37
|
-
return ""
|
38
|
-
end
|
39
|
-
|
40
|
-
inputs = []
|
41
|
-
|
42
36
|
# Insert an input context on each subject so the properties could be prefixed. This way,
|
43
37
|
# the DFC's context can be used.
|
44
38
|
# See https://github.com/datafoodconsortium/connector-ruby/issues/11.
|
45
|
-
subjects.
|
46
|
-
|
47
|
-
|
48
|
-
inputs.push(input)
|
39
|
+
inputs = subjects.map do |subject|
|
40
|
+
# JSON::LD needs a context on every input using prefixes.
|
41
|
+
subject.serialize(@hashSerializer).merge("@context" => @outputContext)
|
49
42
|
end
|
50
43
|
|
51
44
|
jsonLd = JSON::LD::API.compact(inputs, @outputContext)
|
52
45
|
|
53
|
-
|
46
|
+
JSON.generate(jsonLd)
|
54
47
|
end
|
55
48
|
|
56
|
-
end
|
49
|
+
end
|
@@ -27,7 +27,7 @@ require "virtual_assembly/semantizer"
|
|
27
27
|
|
28
28
|
class DataFoodConsortium::Connector::NutrientCharacteristic < DataFoodConsortium::Connector::Characteristic
|
29
29
|
|
30
|
-
|
30
|
+
SEMANTIC_TYPE = "dfc-b:NutrientCharacteristic".freeze
|
31
31
|
|
32
32
|
# @return [ISKOSConcept]
|
33
33
|
attr_accessor :nutrientDimension
|
@@ -39,7 +39,7 @@ class DataFoodConsortium::Connector::NutrientCharacteristic < DataFoodConsortium
|
|
39
39
|
super(unit: unit, value: value)
|
40
40
|
@nutrientDimension = nutrientDimension
|
41
41
|
self.semanticType = "dfc-b:NutrientCharacteristic"
|
42
|
-
registerSemanticProperty("dfc-b:hasNutrientDimension")
|
42
|
+
registerSemanticProperty("dfc-b:hasNutrientDimension", &method("nutrientDimension")).valueSetter = method("nutrientDimension=")
|
43
43
|
end
|
44
44
|
|
45
45
|
|
@@ -27,8 +27,9 @@
|
|
27
27
|
require "virtual_assembly/semantizer"
|
28
28
|
|
29
29
|
class DataFoodConsortium::Connector::Offer
|
30
|
+
include VirtualAssembly::Semantizer::SemanticObject
|
30
31
|
|
31
|
-
|
32
|
+
SEMANTIC_TYPE = "dfc-b:Offer".freeze
|
32
33
|
|
33
34
|
# @return [IPrice]
|
34
35
|
attr_accessor :price
|
@@ -54,10 +55,10 @@ class DataFoodConsortium::Connector::Offer
|
|
54
55
|
@offeredItem = offeredItem
|
55
56
|
@offeredTo = offeredTo
|
56
57
|
self.semanticType = "dfc-b:Offer"
|
57
|
-
registerSemanticProperty("dfc-b:hasPrice")
|
58
|
-
registerSemanticProperty("dfc-b:stockLimitation")
|
59
|
-
registerSemanticProperty("dfc-b:offeredItem")
|
60
|
-
registerSemanticProperty("dfc-b:offeredTo")
|
58
|
+
registerSemanticProperty("dfc-b:hasPrice", &method("price")).valueSetter = method("price=")
|
59
|
+
registerSemanticProperty("dfc-b:stockLimitation", &method("stockLimitation")).valueSetter = method("stockLimitation=")
|
60
|
+
registerSemanticProperty("dfc-b:offeredItem", &method("offeredItem")).valueSetter = method("offeredItem=")
|
61
|
+
registerSemanticProperty("dfc-b:offeredTo", &method("offeredTo")).valueSetter = method("offeredTo=")
|
61
62
|
end
|
62
63
|
|
63
64
|
|
@@ -27,8 +27,9 @@
|
|
27
27
|
require "virtual_assembly/semantizer"
|
28
28
|
|
29
29
|
class DataFoodConsortium::Connector::Order
|
30
|
+
include VirtualAssembly::Semantizer::SemanticObject
|
30
31
|
|
31
|
-
|
32
|
+
SEMANTIC_TYPE = "dfc-b:Order".freeze
|
32
33
|
|
33
34
|
# @return [String]
|
34
35
|
attr_accessor :number
|
@@ -59,11 +60,11 @@ class DataFoodConsortium::Connector::Order
|
|
59
60
|
@lines = lines
|
60
61
|
@client = client
|
61
62
|
self.semanticType = "dfc-b:Order"
|
62
|
-
registerSemanticProperty("dfc-b:orderNumber")
|
63
|
-
registerSemanticProperty("dfc-b:date")
|
64
|
-
registerSemanticProperty("dfc-b:belongsTo")
|
65
|
-
registerSemanticProperty("dfc-b:hasPart")
|
66
|
-
registerSemanticProperty("dfc-b:orderedBy")
|
63
|
+
registerSemanticProperty("dfc-b:orderNumber", &method("number")).valueSetter = method("number=")
|
64
|
+
registerSemanticProperty("dfc-b:date", &method("date")).valueSetter = method("date=")
|
65
|
+
registerSemanticProperty("dfc-b:belongsTo", &method("saleSession")).valueSetter = method("saleSession=")
|
66
|
+
registerSemanticProperty("dfc-b:hasPart", &method("lines")).valueSetter = method("lines=")
|
67
|
+
registerSemanticProperty("dfc-b:orderedBy", &method("client")).valueSetter = method("client=")
|
67
68
|
end
|
68
69
|
|
69
70
|
|