datafoodconsortium-connector 1.0.0.pre.alpha.8 → 1.0.0.pre.alpha.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/lib/datafoodconsortium/connector/address.rb +7 -6
  3. data/lib/datafoodconsortium/connector/agent.rb +31 -32
  4. data/lib/datafoodconsortium/connector/allergen_characteristic.rb +6 -7
  5. data/lib/datafoodconsortium/connector/{characteristic_dimension.rb → catalog.rb} +23 -3
  6. data/lib/datafoodconsortium/connector/catalog_item.rb +15 -11
  7. data/lib/datafoodconsortium/connector/characteristic.rb +1 -4
  8. data/lib/datafoodconsortium/connector/connector.rb +10 -9
  9. data/lib/datafoodconsortium/connector/context.rb +72 -0
  10. data/lib/datafoodconsortium/connector/customer_category.rb +4 -3
  11. data/lib/datafoodconsortium/connector/defined_product.rb +33 -112
  12. data/lib/datafoodconsortium/connector/enterprise.rb +43 -23
  13. data/lib/datafoodconsortium/connector/importer.rb +112 -0
  14. data/lib/datafoodconsortium/connector/json_ld_serializer.rb +7 -14
  15. data/lib/datafoodconsortium/connector/nutrient_characteristic.rb +7 -8
  16. data/lib/datafoodconsortium/connector/offer.rb +8 -7
  17. data/lib/datafoodconsortium/connector/order.rb +40 -1
  18. data/lib/datafoodconsortium/connector/order_line.rb +40 -1
  19. data/lib/datafoodconsortium/connector/person.rb +16 -22
  20. data/lib/datafoodconsortium/connector/{geographical_origin.rb → phone_number.rb} +20 -3
  21. data/lib/datafoodconsortium/connector/physical_characteristic.rb +6 -7
  22. data/lib/datafoodconsortium/connector/price.rb +9 -7
  23. data/lib/datafoodconsortium/connector/quantitative_value.rb +7 -6
  24. data/lib/datafoodconsortium/connector/{allergen_dimension.rb → quantity.rb} +20 -3
  25. data/lib/datafoodconsortium/connector/sale_session.rb +64 -0
  26. data/lib/datafoodconsortium/connector/skos_concept.rb +14 -34
  27. data/lib/datafoodconsortium/connector/skos_helper.rb +14 -0
  28. data/lib/datafoodconsortium/connector/skos_parser.rb +122 -100
  29. data/lib/datafoodconsortium/connector/skos_parser_element.rb +72 -53
  30. data/lib/datafoodconsortium/connector/{certification.rb → social_media.rb} +23 -2
  31. data/lib/datafoodconsortium/connector/supplied_product.rb +21 -14
  32. data/lib/datafoodconsortium/connector/technical_product.rb +59 -0
  33. data/lib/datafoodconsortium/connector.rb +21 -18
  34. metadata +12 -40
  35. data/lib/datafoodconsortium/connector/nature_origin.rb +0 -34
  36. data/lib/datafoodconsortium/connector/part_origin.rb +0 -34
  37. data/lib/datafoodconsortium/connector/product_type.rb +0 -34
  38. data/lib/datafoodconsortium/connector/repository.rb +0 -33
  39. data/lib/datafoodconsortium/connector/unit.rb +0 -34
@@ -20,15 +20,32 @@
20
20
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  # SOFTWARE.
22
22
 
23
- require "datafoodconsortium/connector/characteristic_dimension"
23
+
24
24
 
25
25
  require "virtual_assembly/semantizer"
26
26
 
27
- class DataFoodConsortium::Connector::AllergenDimension < DataFoodConsortium::Connector::CharacteristicDimension
27
+ class DataFoodConsortium::Connector::Quantity
28
+ include VirtualAssembly::Semantizer::SemanticObject
28
29
 
29
-
30
+ SEMANTIC_TYPE = "dfc-b:Quantity".freeze
30
31
 
32
+ # @return [ISKOSConcept]
33
+ attr_accessor :unit
31
34
 
35
+ # @return [Real]
36
+ attr_accessor :value
37
+
38
+ # @param unit [ISKOSConcept]
39
+ # @param value [Real]
40
+ def initialize(unit: nil, value: 0.0)
41
+ super()
42
+ @unit = unit
43
+ @value = value
44
+ self.semanticType = "dfc-b:Quantity"
45
+ registerSemanticProperty("dfc-b:hasUnit", &method("unit")).valueSetter = method("unit=")
46
+ registerSemanticProperty("dfc-b:value", &method("value")).valueSetter = method("value=")
47
+ end
48
+
32
49
 
33
50
 
34
51
  end
@@ -0,0 +1,64 @@
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::SaleSession
28
+ include VirtualAssembly::Semantizer::SemanticObject
29
+
30
+ SEMANTIC_TYPE = "dfc-b:SaleSession".freeze
31
+
32
+ # @return [String]
33
+ attr_accessor :beginDate
34
+
35
+ # @return [String]
36
+ attr_accessor :endDate
37
+
38
+ # @return [Real]
39
+ attr_accessor :quantity
40
+
41
+ # @return [IOffer]
42
+ attr_accessor :offers
43
+
44
+ # @param semanticId [String]
45
+ # @param beginDate [String]
46
+ # @param endDate [String]
47
+ # @param quantity [Real]
48
+ # @param offers [IOffer]
49
+ def initialize(semanticId, beginDate: "", endDate: "", quantity: 0.0, offers: [])
50
+ super(semanticId)
51
+ @beginDate = beginDate
52
+ @endDate = endDate
53
+ @quantity = quantity
54
+ @offers = offers
55
+ self.semanticType = "dfc-b:SaleSession"
56
+ registerSemanticProperty("dfc-b:beginDate", &method("beginDate")).valueSetter = method("beginDate=")
57
+ registerSemanticProperty("dfc-b:endDate", &method("endDate")).valueSetter = method("endDate=")
58
+ registerSemanticProperty("dfc-b:quantity", &method("quantity")).valueSetter = method("quantity=")
59
+ registerSemanticProperty("dfc-b:lists", &method("offers")).valueSetter = method("offers=")
60
+ end
61
+
62
+
63
+
64
+ end
@@ -24,10 +24,12 @@
24
24
 
25
25
 
26
26
  require "virtual_assembly/semantizer"
27
-
27
+ require 'datafoodconsortium/connector/skos_helper'
28
28
  class DataFoodConsortium::Connector::SKOSConcept
29
+ include VirtualAssembly::Semantizer::SemanticObject
30
+ include DataFoodConsortium::Connector::SKOSHelper
29
31
 
30
- include VirtualAssembly::Semantizer::SemanticObject
32
+ SEMANTIC_TYPE = "skos:Concept".freeze
31
33
 
32
34
  # @return [ISKOSConcept]
33
35
  attr_accessor :broaders
@@ -41,47 +43,25 @@ class DataFoodConsortium::Connector::SKOSConcept
41
43
  # @return [ISKOSLabel]
42
44
  attr_accessor :prefLabels
43
45
 
46
+ # @param semanticId [String]
44
47
  # @param broaders [ISKOSConcept]
45
48
  # @param schemes [ISKOSConceptScheme]
46
49
  # @param narrowers [ISKOSConcept]
47
50
  # @param prefLabels [ISKOSLabel]
48
- def initialize(broaders: [], schemes: [], narrowers: [], prefLabels: [])
49
- super()
51
+ def initialize(semanticId, broaders: [], schemes: [], narrowers: [], prefLabels: [])
52
+ super(semanticId)
50
53
  @broaders = broaders
51
54
  @schemes = schemes
52
55
  @narrowers = narrowers
53
- @prefLabels = prefLabels
54
- self.semanticType = "http://www.w3.org/2004/02/skos/core#Concept"
55
- registerSemanticProperty("http://www.w3.org/2004/02/skos/core#broader") { self.broaders }
56
- registerSemanticProperty("http://www.w3.org/2004/02/skos/core#inScheme") { self.schemes }
57
- registerSemanticProperty("http://www.w3.org/2004/02/skos/core#narrower") { self.narrowers }
58
- registerSemanticProperty("http://www.w3.org/2004/02/skos/core#prefLabel") { self.prefLabels }
56
+ # Sort locale alphabetically
57
+ @prefLabels = prefLabels.sort.to_h
58
+ self.semanticType = "skos:Concept"
59
+ registerSemanticProperty("skos:broader", &method("broaders")).valueSetter = method("broaders=")
60
+ registerSemanticProperty("skos:inScheme", &method("schemes")).valueSetter = method("schemes=")
61
+ registerSemanticProperty("skos:narrower", &method("narrowers")).valueSetter = method("narrowers=")
62
+ registerSemanticProperty("skos:prefLabel", &method("prefLabels")).valueSetter = method("prefLabels=")
59
63
  end
60
64
 
61
65
 
62
-
63
-
64
-
65
-
66
-
67
- def removeBroader(broader)
68
- raise "Not yet implemented."
69
- end
70
-
71
-
72
- def removeScheme(scheme)
73
- raise "Not yet implemented."
74
- end
75
-
76
-
77
- def removeNarrower(narrower)
78
- raise "Not yet implemented."
79
- end
80
-
81
-
82
- def removePrefLabel(prefLabel)
83
- raise "Not yet implemented."
84
- end
85
-
86
66
 
87
67
  end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DataFoodConsortium::Connector::SKOSHelper
4
+ def addAttribute(name, value)
5
+ self.instance_variable_set("@#{name}", value)
6
+ self.define_singleton_method(name) do
7
+ instance_variable_get("@#{name}")
8
+ end
9
+ end
10
+
11
+ def hasAttribute(name)
12
+ self.methods.include?(:"#{name}")
13
+ end
14
+ end
@@ -1,17 +1,19 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # MIT License
2
- #
4
+ #
3
5
  # Copyright (c) 2023 Maxime Lecoq <maxime@lecoqlibre.fr>
4
- #
6
+ #
5
7
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
8
  # of this software and associated documentation files (the "Software"), to deal
7
9
  # in the Software without restriction, including without limitation the rights
8
10
  # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
11
  # copies of the Software, and to permit persons to whom the Software is
10
12
  # furnished to do so, subject to the following conditions:
11
- #
13
+ #
12
14
  # The above copyright notice and this permission notice shall be included in all
13
15
  # copies or substantial portions of the Software.
14
- #
16
+ #
15
17
  # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
18
  # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
19
  # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -20,125 +22,145 @@
20
22
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
23
  # SOFTWARE.
22
24
 
25
+ require 'datafoodconsortium/connector/skos_helper'
23
26
  require 'datafoodconsortium/connector/skos_concept'
24
27
  require 'datafoodconsortium/connector/skos_parser_element'
25
28
 
26
29
  class DataFoodConsortium::Connector::SKOSInstance
30
+ include DataFoodConsortium::Connector::SKOSHelper
27
31
 
28
- def addAttribute(name, value)
29
- self.instance_variable_set("@#{name}", value)
30
- self.define_singleton_method(name) do
31
- return instance_variable_get("@#{name}")
32
- end
33
- end
34
-
35
- def hasAttribute(name)
36
- return self.methods.include?(:"#{name}")
37
- end
38
-
32
+ # Return a list of singelton methods, ie the list of Concept available
33
+ def topConcepts
34
+ self.methods(false).sort
35
+ end
39
36
  end
40
37
 
41
38
  class DataFoodConsortium::Connector::SKOSParser
39
+ CONCEPT_SCHEMES = ["Facet", "productTypes"].freeze
40
+
41
+ def self.concepts
42
+ @concepts ||= {}
43
+ end
44
+
45
+ def initialize
46
+ @results = DataFoodConsortium::Connector::SKOSInstance.new
47
+ @skosConcepts = {}
48
+ @rootElements = []
49
+ @broaders = {}
50
+ # Flag used to tell the parser to use SkosConcept object when parsing data from Concept Scheme
51
+ # defined in CONCEPT_SCHEMES
52
+ @useSkosConcept = false
53
+ end
54
+
55
+ def parse(data)
56
+ init
57
+
58
+ data.each do |element|
59
+ current = DataFoodConsortium::Connector::SKOSParserElement.new(element)
60
+
61
+ setSkosConceptFlag(current)
62
+
63
+ if current.isConcept? || current.isCollection?
64
+ if !@skosConcepts.has_key?(current.id)
65
+ concept = createSKOSConcept(current)
66
+ @skosConcepts[current.id] = concept
67
+ end
42
68
 
43
- def initialize()
44
- @results = DataFoodConsortium::Connector::SKOSInstance.new
45
- @skosConcepts = {}
46
- @rootElements = []
47
- @broaders = {}
48
- end
49
-
50
- def parse(data)
51
- init()
52
-
53
- data.each do |element|
54
- current = DataFoodConsortium::Connector::SKOSParserElement.new(element)
55
-
56
- if (current.isConcept?() || current.isCollection?())
57
- if (!@skosConcepts.has_key?(current.id))
58
- concept = createSKOSConcept(current)
59
- @skosConcepts[current.id] = concept
60
- end
61
-
62
- if (current.hasBroader())
63
- current.broader.each do |broaderId|
64
- if (!@broaders.has_key?(broaderId))
65
- @broaders[broaderId] = []
66
- end
67
-
68
- @broaders[broaderId].push(current.id)
69
- end
70
-
71
- # No broader, save the concept to the root
72
- else
73
- @rootElements.push(current.id)
74
- end
69
+ if current.hasBroader
70
+ current.broader.each do |broaderId|
71
+ if !@broaders.has_key?(broaderId)
72
+ @broaders[broaderId] = []
75
73
  end
76
- end
77
-
78
- @rootElements.each do |rootElementId|
79
- setResults(@results, rootElementId)
80
- end
81
74
 
82
- return @results
75
+ @broaders[broaderId].push(current.id)
76
+ end
77
+ # No broader, save the concept to the root
78
+ else
79
+ @rootElements.push(current.id)
80
+ end
81
+ end
83
82
  end
84
83
 
85
- protected
86
-
87
- def createSKOSConcept(element)
88
- skosConcept = DataFoodConsortium::Connector::SKOSConcept.new
89
- skosConcept.semanticId = element.id
90
- skosConcept.semanticType = element.type
91
- return skosConcept
84
+ @rootElements.each do |rootElementId|
85
+ setResults(@results, rootElementId)
92
86
  end
93
87
 
94
- def getValueWithoutPrefix(property)
95
- name = 'undefined'
96
-
97
- if (!property.include?('http') && property.include?(':'))
98
- name = property.split(':')[1]
99
- elsif (property.include?('#'))
100
- name = property.split('#')[1]
101
- end
88
+ @results
89
+ end
102
90
 
103
- name = name.gsub('-', '_');
91
+ protected
104
92
 
105
- # workaround to fix concepts starting with a number
106
- # see https://github.com/datafoodconsortium/connector-ruby/issues/3
107
- # see https://github.com/datafoodconsortium/ontology/issues/66
108
- if (name.match?("^[0-9]"))
109
- name = "_" + name
110
- end
93
+ def createSKOSConcept(element)
94
+ skosConcept = DataFoodConsortium::Connector::SKOSConcept.new(
95
+ element.id, broaders: element.broader, narrowers: element.narrower, prefLabels: element.label
96
+ )
97
+ skosConcept.semanticType = element.type
98
+
99
+ self.class.concepts[element.id] = skosConcept
100
+
101
+ skosConcept
102
+ end
111
103
 
112
- return name.upcase
104
+ def getValueWithoutPrefix(property)
105
+ name = 'undefined'
106
+
107
+ if !property.include?('http') && property.include?(':')
108
+ name = property.split(':')[1]
109
+ elsif property.include?('#')
110
+ name = property.split('#')[1]
113
111
  end
114
112
 
115
- private
116
-
117
- def init()
118
- @results = DataFoodConsortium::Connector::SKOSInstance.new
119
- @skosConcepts = {}
120
- @rootElements = []
121
- @broaders = {}
113
+ name = name.gsub('-', '_')
114
+
115
+ # workaround to fix concepts starting with a number
116
+ # see https://github.com/datafoodconsortium/connector-ruby/issues/3
117
+ # see https://github.com/datafoodconsortium/ontology/issues/66
118
+ name = "_" + name if name.match?("^[0-9]")
119
+
120
+ name.upcase
121
+ end
122
+
123
+ private
124
+
125
+ def init
126
+ @results = DataFoodConsortium::Connector::SKOSInstance.new
127
+ @skosConcepts = {}
128
+ @rootElements = []
129
+ @broaders = {}
130
+ @useSkosConcept = false
131
+ end
132
+
133
+ def setResults(parent, id)
134
+ name = getValueWithoutPrefix(id)
135
+
136
+ if !parent.hasAttribute(name)
137
+ if @useSkosConcept && @skosConcepts[id]
138
+ parent.addAttribute(name, @skosConcepts[id])
139
+ else
140
+ parent.addAttribute(name, DataFoodConsortium::Connector::SKOSInstance.new)
141
+ end
122
142
  end
123
143
 
124
- def setResults(parent, id)
125
- name = getValueWithoutPrefix(id)
144
+ # Leaf concepts, stop the process
145
+ if !@broaders.has_key?(id)
146
+ parent.instance_variable_set("@#{name}", @skosConcepts[id])
147
+ return
148
+ end
126
149
 
127
- if (!parent.hasAttribute(name))
128
- parent.addAttribute(name, DataFoodConsortium::Connector::SKOSInstance.new)
129
- end
130
-
131
- # Leaf concepts, stop the process
132
- if (!@broaders.has_key?(id))
133
- parent.instance_variable_set("@#{name}", @skosConcepts[id])
134
- return
135
- end
150
+ @broaders[id].each do |narrower|
151
+ parentSkosInstance = parent.instance_variable_get("@#{name}")
136
152
 
137
- @broaders[id].each do |narrower|
138
- childName = getValueWithoutPrefix(narrower)
139
- parentSkosInstance = parent.instance_variable_get("@#{name}")
140
- setResults(parentSkosInstance, narrower) # recursive call
141
- end
153
+ setResults(parentSkosInstance, narrower) # recursive call
142
154
  end
155
+ end
143
156
 
144
- end
157
+ def setSkosConceptFlag(current)
158
+ @useSkosConcept = true if current.isConceptScheme? && matchingConceptSchemes(current)
159
+ end
160
+
161
+ def matchingConceptSchemes(current)
162
+ regex = /#{CONCEPT_SCHEMES.join("|")}/
163
+
164
+ current.id =~ regex
165
+ end
166
+ end
@@ -1,17 +1,19 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # MIT License
2
- #
4
+ #
3
5
  # Copyright (c) 2023 Maxime Lecoq <maxime@lecoqlibre.fr>
4
- #
6
+ #
5
7
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
8
  # of this software and associated documentation files (the "Software"), to deal
7
9
  # in the Software without restriction, including without limitation the rights
8
10
  # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
11
  # copies of the Software, and to permit persons to whom the Software is
10
12
  # furnished to do so, subject to the following conditions:
11
- #
13
+ #
12
14
  # The above copyright notice and this permission notice shall be included in all
13
15
  # copies or substantial portions of the Software.
14
- #
16
+ #
15
17
  # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
18
  # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
19
  # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -22,57 +24,74 @@
22
24
 
23
25
  class DataFoodConsortium::Connector::SKOSParserElement
24
26
 
25
- attr_reader :id
26
- attr_reader :type
27
- attr_reader :broader
28
-
29
- def initialize(element)
30
- @broader = []
31
-
32
- if (element)
33
- @id = element["@id"]
34
-
35
- if (element["http://www.w3.org/1999/02/22-rdf-syntax-ns#type"])
36
- @type = extractId(element["http://www.w3.org/1999/02/22-rdf-syntax-ns#type"])
37
- elsif (element["@type"])
38
- @type = extractId(element["@type"])
39
- else
40
- @type = "undefined"
41
- end
42
-
43
- if (element["http://www.w3.org/2004/02/skos/core#broader"])
44
- element["http://www.w3.org/2004/02/skos/core#broader"].each do |broader|
45
- @broader.push(broader["@id"])
46
- end
47
- end
48
- else
49
- @id = ""
50
- @type = ""
27
+ attr_reader :id
28
+ attr_reader :type
29
+ attr_reader :broader
30
+ attr_reader :narrower
31
+ attr_reader :label
32
+
33
+ def initialize(element)
34
+ @broader = []
35
+ @narrower = []
36
+ @label = {}
37
+
38
+ if element
39
+ @id = element["@id"]
40
+
41
+ if element["http://www.w3.org/1999/02/22-rdf-syntax-ns#type"]
42
+ @type = extractId(element["http://www.w3.org/1999/02/22-rdf-syntax-ns#type"])
43
+ elsif element["@type"]
44
+ @type = extractId(element["@type"])
45
+ else
46
+ @type = "undefined"
47
+ end
48
+
49
+ if element["http://www.w3.org/2004/02/skos/core#broader"]
50
+ element["http://www.w3.org/2004/02/skos/core#broader"].each do |broader|
51
+ @broader.push(broader["@id"])
51
52
  end
52
- end
53
-
54
- def hasBroader()
55
- return @broader.count > 0
56
- end
57
-
58
- def isConcept?()
59
- return @type == "http://www.w3.org/2004/02/skos/core#Concept" || @type == "skos:Concept"
60
- end
61
-
62
- def isCollection?()
63
- return @type == "http://www.w3.org/2004/02/skos/core#Collection" || @type == "skos:Collection"
64
- end
65
-
66
- private
67
-
68
- def extractId(data)
69
- id = data[0]
70
-
71
- if (id["@id"])
72
- return id["@id"]
53
+ end
54
+
55
+ if element["http://www.w3.org/2004/02/skos/core#narrower"]
56
+ element["http://www.w3.org/2004/02/skos/core#narrower"].each do |narrower|
57
+ @narrower.push(narrower["@id"])
73
58
  end
59
+ end
74
60
 
75
- return id
61
+ if element["http://www.w3.org/2004/02/skos/core#prefLabel"]
62
+ element["http://www.w3.org/2004/02/skos/core#prefLabel"].each do |label|
63
+ @label[label["@language"].to_sym] = label["@value"]
64
+ end
65
+ end
66
+ else
67
+ @id = ""
68
+ @type = ""
76
69
  end
70
+ end
71
+
72
+ def hasBroader()
73
+ @broader.count > 0
74
+ end
75
+
76
+ def isConcept?()
77
+ @type == "http://www.w3.org/2004/02/skos/core#Concept" || @type == "skos:Concept"
78
+ end
79
+
80
+ def isCollection?()
81
+ @type == "http://www.w3.org/2004/02/skos/core#Collection" || @type == "skos:Collection"
82
+ end
83
+
84
+ def isConceptScheme?
85
+ @type == "http://www.w3.org/2004/02/skos/core#ConceptScheme"
86
+ end
87
+
88
+ private
89
+
90
+ def extractId(data)
91
+ id = data[0]
92
+
93
+ return id["@id"] if id["@id"]
77
94
 
78
- end
95
+ id
96
+ end
97
+ end
@@ -20,15 +20,36 @@
20
20
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  # SOFTWARE.
22
22
 
23
- require "datafoodconsortium/connector/skos_concept"
24
23
 
25
24
  require "virtual_assembly/semantizer"
26
25
 
27
- class DataFoodConsortium::Connector::Certification < DataFoodConsortium::Connector::SKOSConcept
26
+ class DataFoodConsortium::Connector::SocialMedia
27
+ include VirtualAssembly::Semantizer::SemanticObject
28
28
 
29
+ SEMANTIC_TYPE = "dfc-b:SocialMedia".freeze
30
+
31
+ # @return [String]
32
+ attr_accessor :name
33
+
34
+ # @return [String]
35
+ attr_accessor :url
36
+
37
+ # @param semanticId [String]
38
+ # @param name [String]
39
+ # @param url [String]
40
+ def initialize(semanticId, name: "", url: "")
41
+ super(semanticId)
42
+ @name = name
43
+ @url = url
44
+ self.semanticType = "dfc-b:SocialMedia"
45
+ registerSemanticProperty("dfc-b:name", &method("name")).valueSetter = method("name=")
46
+ registerSemanticProperty("dfc-b:URL", &method("url")).valueSetter = method("url=")
47
+ end
29
48
 
30
49
 
50
+
31
51
 
52
+
32
53
 
33
54
 
34
55
  end