datafoodconsortium-connector 1.0.0.pre.alpha.9 → 1.0.0.pre.alpha.11
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 +25 -6
- data/lib/datafoodconsortium/connector/agent.rb +14 -7
- 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 +25 -18
- data/lib/datafoodconsortium/connector/enterprise.rb +14 -13
- data/lib/datafoodconsortium/connector/{allergen_dimension.rb → flow.rb} +15 -3
- 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 +26 -7
- data/lib/datafoodconsortium/connector/order_line.rb +7 -6
- data/lib/datafoodconsortium/connector/person.rb +8 -7
- data/lib/datafoodconsortium/connector/phone_number.rb +4 -3
- data/lib/datafoodconsortium/connector/physical_characteristic.rb +3 -3
- data/lib/datafoodconsortium/connector/{certification.rb → planned_consumption_flow.rb} +25 -3
- data/lib/datafoodconsortium/connector/{characteristic_dimension.rb → planned_production_flow.rb} +25 -3
- data/lib/datafoodconsortium/connector/planned_transformation.rb +59 -0
- 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 -7
- data/lib/datafoodconsortium/connector/supplied_product.rb +5 -4
- data/lib/datafoodconsortium/connector/technical_product.rb +5 -4
- data/lib/datafoodconsortium/connector.rb +23 -13
- metadata +13 -41
- 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: 2c1487755e51bd985e7599d98c95fad225a3b4978c97e67cecef5d13f9248810
|
4
|
+
data.tar.gz: e0ceaf49a623e3888e1f367c0486e169e7b9e8faa823ffca2ddc31b8d2936a53
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa17e1874a8eb4ccff56c027da9aeddb8605a9c886f42ce7f5a80d8c21730da57ce4aa46f13672a9ff6f6d2dd4bbd8ce949e954e673ab5ff120489f754fb8fee
|
7
|
+
data.tar.gz: 470abfb781c9405fdddd6e97e9f72d03447f7e5ebcc27e39a818db5cb594b55cd7a5709175c4d50466e8a6193782787c9b441f862632f0a2ad825a0d7b0ab9a2
|
@@ -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
|
@@ -39,22 +40,40 @@ class DataFoodConsortium::Connector::Address
|
|
39
40
|
# @return [String]
|
40
41
|
attr_accessor :country
|
41
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
|
+
|
42
52
|
# @param semanticId [String]
|
43
53
|
# @param street [String]
|
44
54
|
# @param postalCode [String]
|
45
55
|
# @param city [String]
|
46
56
|
# @param country [String]
|
47
|
-
|
57
|
+
# @param latitude [Real]
|
58
|
+
# @param longitude [Real]
|
59
|
+
# @param region [String]
|
60
|
+
def initialize(semanticId, street: "", postalCode: "", city: "", country: "", latitude: 0.0, longitude: 0.0, region: "")
|
48
61
|
super(semanticId)
|
49
62
|
@street = street
|
50
63
|
@postalCode = postalCode
|
51
64
|
@city = city
|
52
65
|
@country = country
|
66
|
+
@latitude = latitude
|
67
|
+
@longitude = longitude
|
68
|
+
@region = region
|
53
69
|
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")
|
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=")
|
58
77
|
end
|
59
78
|
|
60
79
|
|
@@ -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
|
@@ -43,25 +44,31 @@ class DataFoodConsortium::Connector::Agent
|
|
43
44
|
# @return [ISocialMedia]
|
44
45
|
attr_accessor :socialMedias
|
45
46
|
|
47
|
+
# @return [String]
|
48
|
+
attr_accessor :logo
|
49
|
+
|
46
50
|
# @param semanticId [String]
|
47
51
|
# @param localizations [IAddress]
|
48
52
|
# @param phoneNumbers [IPhoneNumber]
|
49
53
|
# @param emails [String]
|
50
54
|
# @param websites [String]
|
51
55
|
# @param socialMedias [ISocialMedia]
|
52
|
-
|
56
|
+
# @param logo [String]
|
57
|
+
def initialize(semanticId, localizations: [], phoneNumbers: [], emails: [], websites: [], socialMedias: [], logo: "")
|
53
58
|
super(semanticId)
|
54
59
|
@localizations = localizations
|
55
60
|
@phoneNumbers = phoneNumbers
|
56
61
|
@emails = emails
|
57
62
|
@websites = websites
|
58
63
|
@socialMedias = socialMedias
|
64
|
+
@logo = logo
|
59
65
|
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")
|
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=")
|
65
72
|
end
|
66
73
|
|
67
74
|
|
@@ -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
|
@@ -81,6 +82,9 @@ class DataFoodConsortium::Connector::DefinedProduct
|
|
81
82
|
# @return [ISKOSConcept]
|
82
83
|
attr_accessor :partOrigin
|
83
84
|
|
85
|
+
# @return [String]
|
86
|
+
attr_accessor :images
|
87
|
+
|
84
88
|
# @param semanticId [String]
|
85
89
|
# @param name [String]
|
86
90
|
# @param description [String]
|
@@ -98,7 +102,8 @@ class DataFoodConsortium::Connector::DefinedProduct
|
|
98
102
|
# @param certifications [ISKOSConcept]
|
99
103
|
# @param natureOrigin [ISKOSConcept]
|
100
104
|
# @param partOrigin [ISKOSConcept]
|
101
|
-
|
105
|
+
# @param images [String]
|
106
|
+
def initialize(semanticId, name: "", description: "", productType: nil, quantity: nil, alcoholPercentage: 0.0, lifetime: "", claims: [], usageOrStorageConditions: "", allergenCharacteristics: [], nutrientCharacteristics: [], physicalCharacteristics: [], geographicalOrigin: nil, catalogItems: [], certifications: [], natureOrigin: [], partOrigin: [], images: [])
|
102
107
|
super(semanticId)
|
103
108
|
@name = name
|
104
109
|
@description = description
|
@@ -116,23 +121,25 @@ class DataFoodConsortium::Connector::DefinedProduct
|
|
116
121
|
@certifications = certifications
|
117
122
|
@natureOrigin = natureOrigin
|
118
123
|
@partOrigin = partOrigin
|
124
|
+
@images = images
|
119
125
|
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")
|
126
|
+
registerSemanticProperty("dfc-b:name", &method("name")).valueSetter = method("name=")
|
127
|
+
registerSemanticProperty("dfc-b:description", &method("description")).valueSetter = method("description=")
|
128
|
+
registerSemanticProperty("dfc-b:hasType", &method("productType")).valueSetter = method("productType=")
|
129
|
+
registerSemanticProperty("dfc-b:hasQuantity", &method("quantity")).valueSetter = method("quantity=")
|
130
|
+
registerSemanticProperty("dfc-b:alcoholPercentage", &method("alcoholPercentage")).valueSetter = method("alcoholPercentage=")
|
131
|
+
registerSemanticProperty("dfc-b:lifetime", &method("lifetime")).valueSetter = method("lifetime=")
|
132
|
+
registerSemanticProperty("dfc-b:hasClaim", &method("claims")).valueSetter = method("claims=")
|
133
|
+
registerSemanticProperty("dfc-b:usageOrStorageCondition", &method("usageOrStorageConditions")).valueSetter = method("usageOrStorageConditions=")
|
134
|
+
registerSemanticProperty("dfc-b:hasAllergenCharacteristic", &method("allergenCharacteristics")).valueSetter = method("allergenCharacteristics=")
|
135
|
+
registerSemanticProperty("dfc-b:hasNutrientCharacteristic", &method("nutrientCharacteristics")).valueSetter = method("nutrientCharacteristics=")
|
136
|
+
registerSemanticProperty("dfc-b:hasPhysicalCharacteristic", &method("physicalCharacteristics")).valueSetter = method("physicalCharacteristics=")
|
137
|
+
registerSemanticProperty("dfc-b:hasGeographicalOrigin", &method("geographicalOrigin")).valueSetter = method("geographicalOrigin=")
|
138
|
+
registerSemanticProperty("dfc-b:referencedBy", &method("catalogItems")).valueSetter = method("catalogItems=")
|
139
|
+
registerSemanticProperty("dfc-b:hasCertification", &method("certifications")).valueSetter = method("certifications=")
|
140
|
+
registerSemanticProperty("dfc-b:hasNatureOrigin", &method("natureOrigin")).valueSetter = method("natureOrigin=")
|
141
|
+
registerSemanticProperty("dfc-b:hasPartOrigin", &method("partOrigin")).valueSetter = method("partOrigin=")
|
142
|
+
registerSemanticProperty("dfc-b:image", &method("images")).valueSetter = method("images=")
|
136
143
|
end
|
137
144
|
|
138
145
|
|
@@ -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
|
@@ -79,8 +79,9 @@ class DataFoodConsortium::Connector::Enterprise < DataFoodConsortium::Connector:
|
|
79
79
|
# @param emails [String]
|
80
80
|
# @param websites [String]
|
81
81
|
# @param socialMedias [ISocialMedia]
|
82
|
-
|
83
|
-
|
82
|
+
# @param logo [String]
|
83
|
+
def initialize(semanticId, name: "", description: "", vatNumber: "", customerCategories: [], catalogs: [], catalogItems: [], suppliedProducts: [], technicalProducts: [], mainContact: nil, localizations: [], phoneNumbers: [], emails: [], websites: [], socialMedias: [], logo: "")
|
84
|
+
super(semanticId, localizations: localizations, phoneNumbers: phoneNumbers, emails: emails, websites: websites, socialMedias: socialMedias, logo: logo)
|
84
85
|
@name = name
|
85
86
|
@description = description
|
86
87
|
@vatNumber = vatNumber
|
@@ -91,15 +92,15 @@ class DataFoodConsortium::Connector::Enterprise < DataFoodConsortium::Connector:
|
|
91
92
|
@technicalProducts = technicalProducts
|
92
93
|
@mainContact = mainContact
|
93
94
|
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")
|
95
|
+
registerSemanticProperty("dfc-b:name", &method("name")).valueSetter = method("name=")
|
96
|
+
registerSemanticProperty("dfc-b:hasDescription", &method("description")).valueSetter = method("description=")
|
97
|
+
registerSemanticProperty("dfc-b:VATnumber", &method("vatNumber")).valueSetter = method("vatNumber=")
|
98
|
+
registerSemanticProperty("dfc-b:defines", &method("customerCategories")).valueSetter = method("customerCategories=")
|
99
|
+
registerSemanticProperty("dfc-b:maintains", &method("catalogs")).valueSetter = method("catalogs=")
|
100
|
+
registerSemanticProperty("dfc-b:manages", &method("catalogItems")).valueSetter = method("catalogItems=")
|
101
|
+
registerSemanticProperty("dfc-b:supplies", &method("suppliedProducts")).valueSetter = method("suppliedProducts=")
|
102
|
+
registerSemanticProperty("dfc-b:proposes", &method("technicalProducts")).valueSetter = method("technicalProducts=")
|
103
|
+
registerSemanticProperty("dfc-b:hasMainContact", &method("mainContact")).valueSetter = method("mainContact=")
|
103
104
|
end
|
104
105
|
|
105
106
|
|
@@ -20,15 +20,27 @@
|
|
20
20
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
21
|
# SOFTWARE.
|
22
22
|
|
23
|
-
|
23
|
+
|
24
24
|
|
25
25
|
require "virtual_assembly/semantizer"
|
26
26
|
|
27
|
-
class DataFoodConsortium::Connector::
|
27
|
+
class DataFoodConsortium::Connector::Flow
|
28
|
+
include VirtualAssembly::Semantizer::SemanticObject
|
28
29
|
|
29
|
-
|
30
|
+
SEMANTIC_TYPE = "".freeze
|
30
31
|
|
32
|
+
# @return [IQuantity]
|
33
|
+
attr_accessor :quantity
|
31
34
|
|
35
|
+
# @param semanticId [String]
|
36
|
+
# @param quantity [IQuantity]
|
37
|
+
def initialize(semanticId, quantity: nil)
|
38
|
+
super(semanticId)
|
39
|
+
@quantity = quantity
|
40
|
+
self.semanticType = ""
|
41
|
+
registerSemanticProperty("dfc-b:hasQuantity", &method("quantity")).valueSetter = method("quantity=")
|
42
|
+
end
|
43
|
+
|
32
44
|
|
33
45
|
|
34
46
|
end
|
@@ -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
|