Class: SemanticCrawler::Fao::Country

Inherits:
Object
  • Object
show all
Defined in:
lib/semantic_crawler/fao/country.rb

Overview

Represents Food and Agriculture information about one country.

Constant Summary collapse

@@URI_PREFIX =

The URI prefix of the fao country object

"http://www.fao.org/countryprofiles/geoinfo/geopolitical/data/"
@@NAMESPACES =

Namespace hash

{
    "rdf" => "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
    "fao" => "http://www.fao.org/countryprofiles/geoinfo/geopolitical/resource/",
    "owl" => "http://www.w3.org/2002/07/owl#"
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(new_country_name) ⇒ Country

Initialize a new Fao country object



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/semantic_crawler/fao/country.rb', line 25

def initialize(new_country_name)
    @country_name = new_country_name
    if !@country_name.nil?
        @url = @@URI_PREFIX + @country_name.gsub(" ", "_").gsub("USA", "United_States_of_America")
        @root_node = nil
        begin
            fetch_rdf
        rescue => e
            $log.error("Not able to get country information, through exception: #{e}")
        end
    end
end

Instance Attribute Details

#country_nameObject (readonly)

The read only country name



18
19
20
# File 'lib/semantic_crawler/fao/country.rb', line 18

def country_name
  @country_name
end

#urlObject (readonly)

The read only URL to the FAO resource



22
23
24
# File 'lib/semantic_crawler/fao/country.rb', line 22

def url
  @url
end

Instance Method Details

#code_dbpedia_idString

The dbpedia identifier (from fao:codeDBPediaID)

Returns:

  • (String)


40
41
42
# File 'lib/semantic_crawler/fao/country.rb', line 40

def code_dbpedia_id
    query_root_node("fao:codeDBPediaID/text()", @@NAMESPACES).to_s
end

#has_boarder_with_nameArray<String>

Returns all countries that share a boarder with this country (as name)

Returns:

  • (Array<String>)


167
168
169
170
171
172
173
174
175
176
# File 'lib/semantic_crawler/fao/country.rb', line 167

def has_boarder_with_name
    returnGroup = []
    group = query_root_node("fao:hasBorderWith/@rdf:resource", @@NAMESPACES)
    if !group.nil?
        group.each do |entry|
            returnGroup << entry.to_s.split("/")[7]
        end
    end
    returnGroup
end

#has_boarder_with_urlArray<String>

Returns all countries that share a boarder with this country (as dereferencable URL - from fao:hasBorderWith)

Returns:

  • (Array<String>)


153
154
155
156
157
158
159
160
161
162
# File 'lib/semantic_crawler/fao/country.rb', line 153

def has_boarder_with_url
    returnGroup = []
    group = query_root_node("fao:hasBorderWith/@rdf:resource", @@NAMESPACES)
    if !group.nil?
        group.each do |entry|
            returnGroup << entry.to_s
        end
    end
    returnGroup
end

#is_in_group_nameArray<String>

Classification of this country as name (from fao:isInGroup)

Returns:

  • (Array<String>)


125
126
127
128
129
130
131
132
133
134
# File 'lib/semantic_crawler/fao/country.rb', line 125

def is_in_group_name
    returnGroup = []
    group = query_root_node("fao:isInGroup/@rdf:resource", @@NAMESPACES)
    if !group.nil?
        group.each do |entry|
            returnGroup << entry.to_s.split("/")[7]
        end
    end
    returnGroup
end

#is_in_group_urlArray<String>

Classification of this country as dereferenceable URL (from fao:isInGroup)

Returns:

  • (Array<String>)


139
140
141
142
143
144
145
146
147
148
# File 'lib/semantic_crawler/fao/country.rb', line 139

def is_in_group_url
    returnGroup = []
    group = query_root_node("fao:isInGroup/@rdf:resource", @@NAMESPACES)
    if !group.nil?
        group.each do |entry|
            returnGroup << entry.to_s
        end
    end
    returnGroup
end

#land_area_notesString

Human readable description about the land area (from fao:landAreaNotes)

Returns:

  • (String)


87
88
89
# File 'lib/semantic_crawler/fao/country.rb', line 87

def land_area_notes
    query_root_node("fao:landAreaNotes/text()", @@NAMESPACES).to_s
end

#land_area_totalString

Land area total value (from fao:landAreaTotal)

Returns:

  • (String)


93
94
95
# File 'lib/semantic_crawler/fao/country.rb', line 93

def land_area_total
    query_root_node("fao:landAreaTotal/text()", @@NAMESPACES).to_s
end

#land_area_unitString

Land area unit (from fao:landAreaUnit)

Returns:

  • (String)


99
100
101
# File 'lib/semantic_crawler/fao/country.rb', line 99

def land_area_unit
    query_root_node("fao:landAreaUnit/text()", @@NAMESPACES).to_s
end

#land_area_yearString

Land area year (from fao:landAreaYear)

Returns:

  • (String)


105
106
107
# File 'lib/semantic_crawler/fao/country.rb', line 105

def land_area_year
    query_root_node("fao:landAreaYear/text()", @@NAMESPACES).to_s
end

#max_latitudeString

The maximum latitude (from fao:hasMaxLatitude)

Returns:

  • (String)


63
64
65
# File 'lib/semantic_crawler/fao/country.rb', line 63

def max_latitude
    query_root_node("fao:hasMaxLatitude/text()", @@NAMESPACES).to_s
end

#max_longitudeString

The maximum longitude (from fao:hasMaxLongitude)

Returns:

  • (String)


69
70
71
# File 'lib/semantic_crawler/fao/country.rb', line 69

def max_longitude
    query_root_node("fao:hasMaxLongitude/text()", @@NAMESPACES).to_s
end

#min_latitudeString

The minimum latitude (from fao:hasMinLatitude)

Returns:

  • (String)


75
76
77
# File 'lib/semantic_crawler/fao/country.rb', line 75

def min_latitude
    query_root_node("fao:hasMinLatitude/text()", @@NAMESPACES).to_s
end

#min_longitudeString

The minimum longitude (from fao:hasMinLongitude)

Returns:

  • (String)


81
82
83
# File 'lib/semantic_crawler/fao/country.rb', line 81

def min_longitude
    query_root_node("fao:hasMinLongitude/text()", @@NAMESPACES).to_s
end

#name_currency(lang = 'en') ⇒ String

The currency name.

Parameters:

  • The (String)

    language in which the currency name should be returned

Returns:

  • (String)


112
113
114
# File 'lib/semantic_crawler/fao/country.rb', line 112

def name_currency(lang = 'en')
    query_root_node("fao:nameCurrency[@xml:lang='#{lang}']/text()", @@NAMESPACES).to_s
end

#official_name(lang = 'en') ⇒ String

The official country name

Parameters:

  • The (String)

    language in which the official name should be returned

Returns:

  • (String)


119
120
121
# File 'lib/semantic_crawler/fao/country.rb', line 119

def official_name(lang = 'en')
    query_root_node("fao:nameOfficial[@xml:lang='#{lang}']/text()", @@NAMESPACES).to_s
end

#population_notesString

Population notes (from fao:populationNotes)

Returns:

  • (String)


180
181
182
# File 'lib/semantic_crawler/fao/country.rb', line 180

def population_notes
    query_root_node("fao:populationNotes/text()", @@NAMESPACES).to_s
end

#population_totalString

Population total (from fao:populationTotal)

Returns:

  • (String)


186
187
188
# File 'lib/semantic_crawler/fao/country.rb', line 186

def population_total
    query_root_node("fao:populationTotal/text()", @@NAMESPACES).to_s
end

#population_unitString

Population unit (from fao:populationUnit)

Returns:

  • (String)


192
193
194
# File 'lib/semantic_crawler/fao/country.rb', line 192

def population_unit
    query_root_node("fao:populationUnit/text()", @@NAMESPACES).to_s
end

#population_yearString

Population year (from fao:populationYear)

Returns:

  • (String)


198
199
200
# File 'lib/semantic_crawler/fao/country.rb', line 198

def population_year
    query_root_node("fao:populationYear/text()", @@NAMESPACES).to_s
end

#query_root_node(xpath_query, namespaces = {}) ⇒ String

Executes a xpath query with optional a hash with namespaces

Returns:

  • (String)


216
217
218
219
220
# File 'lib/semantic_crawler/fao/country.rb', line 216

def query_root_node(xpath_query, namespaces = {})
    if !@root_node.nil?
        @root_node.xpath(xpath_query, namespaces)
    end
end

#same_asArray<String>

Links to additional information (from owl:sameAs)

Returns:

  • (Array<String>)


46
47
48
49
50
51
52
53
# File 'lib/semantic_crawler/fao/country.rb', line 46

def same_as
    returnLinks = []
    links = query_root_node("owl:sameAs/@rdf:resource", @@NAMESPACES)
    links.each do |link|
        returnLinks << link.to_s
    end
    returnLinks
end

#type_urlString

The type as URL of this entity (from rdf:type)

Returns:

  • (String)


57
58
59
# File 'lib/semantic_crawler/fao/country.rb', line 57

def type_url
    query_root_node("rdf:type/@rdf:resource", @@NAMESPACES).to_s
end

#valid_sinceString

Entity is valid since (from fao:validSince)

Returns:

  • (String)


204
205
206
# File 'lib/semantic_crawler/fao/country.rb', line 204

def valid_since
    query_root_node("fao:validSince/text()", @@NAMESPACES).to_s
end

#valid_untilString

Entity is valid until (from fao:validUntil)

Returns:

  • (String)


210
211
212
# File 'lib/semantic_crawler/fao/country.rb', line 210

def valid_until
    query_root_node("fao:validUntil/text()", @@NAMESPACES).to_s
end

#xml_documentString

Outputs the document as XML

Returns:

  • (String)

    The document serialized as XML



224
225
226
# File 'lib/semantic_crawler/fao/country.rb', line 224

def xml_document
    @root_node.to_s
end