Class: SemanticCrawler::Fao::Country
- Inherits:
-
Object
- Object
- SemanticCrawler::Fao::Country
- 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
-
#country_name ⇒ Object
readonly
The read only country name.
-
#url ⇒ Object
readonly
The read only URL to the FAO resource.
Instance Method Summary collapse
-
#code_dbpedia_id ⇒ String
The dbpedia identifier (from fao:codeDBPediaID).
-
#has_boarder_with_name ⇒ Array<String>
Returns all countries that share a boarder with this country (as name).
-
#has_boarder_with_url ⇒ Array<String>
Returns all countries that share a boarder with this country (as dereferencable URL - from fao:hasBorderWith).
-
#initialize(new_country_name) ⇒ Country
constructor
Initialize a new Fao country object.
-
#is_in_group_name ⇒ Array<String>
Classification of this country as name (from fao:isInGroup).
-
#is_in_group_url ⇒ Array<String>
Classification of this country as dereferenceable URL (from fao:isInGroup).
-
#land_area_notes ⇒ String
Human readable description about the land area (from fao:landAreaNotes).
-
#land_area_total ⇒ String
Land area total value (from fao:landAreaTotal).
-
#land_area_unit ⇒ String
Land area unit (from fao:landAreaUnit).
-
#land_area_year ⇒ String
Land area year (from fao:landAreaYear).
-
#max_latitude ⇒ String
The maximum latitude (from fao:hasMaxLatitude).
-
#max_longitude ⇒ String
The maximum longitude (from fao:hasMaxLongitude).
-
#min_latitude ⇒ String
The minimum latitude (from fao:hasMinLatitude).
-
#min_longitude ⇒ String
The minimum longitude (from fao:hasMinLongitude).
-
#name_currency(lang = 'en') ⇒ String
The currency name.
-
#official_name(lang = 'en') ⇒ String
The official country name.
-
#population_notes ⇒ String
Population notes (from fao:populationNotes).
-
#population_total ⇒ String
Population total (from fao:populationTotal).
-
#population_unit ⇒ String
Population unit (from fao:populationUnit).
-
#population_year ⇒ String
Population year (from fao:populationYear).
-
#query_root_node(xpath_query, namespaces = {}) ⇒ String
Executes a xpath query with optional a hash with namespaces.
-
#same_as ⇒ Array<String>
Links to additional information (from owl:sameAs).
-
#type_url ⇒ String
The type as URL of this entity (from rdf:type).
-
#valid_since ⇒ String
Entity is valid since (from fao:validSince).
-
#valid_until ⇒ String
Entity is valid until (from fao:validUntil).
-
#xml_document ⇒ String
Outputs the document as XML.
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_name ⇒ Object (readonly)
The read only country name
18 19 20 |
# File 'lib/semantic_crawler/fao/country.rb', line 18 def country_name @country_name end |
#url ⇒ Object (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_id ⇒ String
The dbpedia identifier (from fao:codeDBPediaID)
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_name ⇒ Array<String>
Returns all countries that share a boarder with this country (as name)
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_url ⇒ Array<String>
Returns all countries that share a boarder with this country (as dereferencable URL - from fao:hasBorderWith)
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_name ⇒ Array<String>
Classification of this country as name (from fao:isInGroup)
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_url ⇒ Array<String>
Classification of this country as dereferenceable URL (from fao:isInGroup)
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_notes ⇒ String
Human readable description about the land area (from fao:landAreaNotes)
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_total ⇒ String
Land area total value (from fao:landAreaTotal)
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_unit ⇒ String
Land area unit (from fao:landAreaUnit)
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_year ⇒ String
Land area year (from fao:landAreaYear)
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_latitude ⇒ String
The maximum latitude (from fao:hasMaxLatitude)
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_longitude ⇒ String
The maximum longitude (from fao:hasMaxLongitude)
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_latitude ⇒ String
The minimum latitude (from fao:hasMinLatitude)
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_longitude ⇒ String
The minimum longitude (from fao:hasMinLongitude)
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.
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
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_notes ⇒ String
Population notes (from fao:populationNotes)
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_total ⇒ String
Population total (from fao:populationTotal)
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_unit ⇒ String
Population unit (from fao:populationUnit)
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_year ⇒ String
Population year (from fao:populationYear)
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
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_as ⇒ Array<String>
Links to additional information (from owl:sameAs)
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_url ⇒ String
The type as URL of this entity (from rdf:type)
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_since ⇒ String
Entity is valid since (from fao:validSince)
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_until ⇒ String
Entity is valid until (from fao:validUntil)
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_document ⇒ String
Outputs the document as XML
224 225 226 |
# File 'lib/semantic_crawler/fao/country.rb', line 224 def xml_document @root_node.to_s end |