Class: DataFoodConsortium::Connector::SKOSParserElement

Inherits:
Object
  • Object
show all
Defined in:
lib/datafoodconsortium/connector/skos_parser_element.rb

Overview

MIT License

Copyright © 2023 Maxime Lecoq <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(element) ⇒ SKOSParserElement

Returns a new instance of SKOSParserElement.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/datafoodconsortium/connector/skos_parser_element.rb', line 33

def initialize(element)
  @broader = []
  @narrower = []
  @label = {}

  if element
    @id = element["@id"]

    if element["http://www.w3.org/1999/02/22-rdf-syntax-ns#type"]
      @type = extractId(element["http://www.w3.org/1999/02/22-rdf-syntax-ns#type"])
    elsif element["@type"]
      @type = extractId(element["@type"])
    else
      @type = "undefined"
    end

    if element["http://www.w3.org/2004/02/skos/core#broader"]
      element["http://www.w3.org/2004/02/skos/core#broader"].each do |broader|
        @broader.push(broader["@id"])
      end
    end

    if element["http://www.w3.org/2004/02/skos/core#narrower"]
      element["http://www.w3.org/2004/02/skos/core#narrower"].each do |narrower|
        @narrower.push(narrower["@id"])
      end
    end

    if element["http://www.w3.org/2004/02/skos/core#prefLabel"]
      element["http://www.w3.org/2004/02/skos/core#prefLabel"].each do |label|
        @label[label["@language"].to_sym] = label["@value"]
      end
    end
  else
    @id = ""
    @type = ""
  end
end

Instance Attribute Details

#broaderObject (readonly)

Returns the value of attribute broader.



29
30
31
# File 'lib/datafoodconsortium/connector/skos_parser_element.rb', line 29

def broader
  @broader
end

#idObject (readonly)

Returns the value of attribute id.



27
28
29
# File 'lib/datafoodconsortium/connector/skos_parser_element.rb', line 27

def id
  @id
end

#labelObject (readonly)

Returns the value of attribute label.



31
32
33
# File 'lib/datafoodconsortium/connector/skos_parser_element.rb', line 31

def label
  @label
end

#narrowerObject (readonly)

Returns the value of attribute narrower.



30
31
32
# File 'lib/datafoodconsortium/connector/skos_parser_element.rb', line 30

def narrower
  @narrower
end

#typeObject (readonly)

Returns the value of attribute type.



28
29
30
# File 'lib/datafoodconsortium/connector/skos_parser_element.rb', line 28

def type
  @type
end

Instance Method Details

#hasBroaderObject



72
73
74
# File 'lib/datafoodconsortium/connector/skos_parser_element.rb', line 72

def hasBroader()
  @broader.count > 0
end

#isCollection?Boolean

Returns:

  • (Boolean)


80
81
82
# File 'lib/datafoodconsortium/connector/skos_parser_element.rb', line 80

def isCollection?()
  @type == "http://www.w3.org/2004/02/skos/core#Collection" || @type == "skos:Collection"
end

#isConcept?Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/datafoodconsortium/connector/skos_parser_element.rb', line 76

def isConcept?()
  @type == "http://www.w3.org/2004/02/skos/core#Concept" || @type == "skos:Concept"
end

#isConceptScheme?Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/datafoodconsortium/connector/skos_parser_element.rb', line 84

def isConceptScheme?
  @type == "http://www.w3.org/2004/02/skos/core#ConceptScheme"
end