Class: SemanticCrawler::Factbook::Country
- Inherits:
-
Object
- Object
- SemanticCrawler::Factbook::Country
- Defined in:
- lib/semantic_crawler/factbook/country.rb
Overview
Extracted from the RDF Dump of the CIA Factbook. Contains all relevant, but maybe deprecated information about countries.
Constant Summary collapse
- @@URI_PREFIX =
The prefixed used for each country
"http://www4.wiwiss.fu-berlin.de/factbook/data/"
- @@NAMESPACES =
Predefined RDFS/OWL namespaces used for RDF file parsing.
{ "factbook" => "http://www4.wiwiss.fu-berlin.de/factbook/ns#", "rdfs" => "http://www.w3.org/2000/01/rdf-schema#", "rdf" => "http://www.w3.org/1999/02/22-rdf-syntax-ns#" }
Instance Attribute Summary collapse
-
#country_name ⇒ Object
readonly
Country name given as input during the object creation.
-
#url ⇒ Object
readonly
The complete URL of the country.
Instance Method Summary collapse
-
#airports_total ⇒ Object
Returns the total number of airports in the country.
-
#background ⇒ Object
Returns background information about the country.
-
#climate ⇒ Object
Returns climate description (human readable).
-
#get_factbook_property(property_name, prefix = "/") ⇒ Object
Abstract method that allows to fetch factbook properties via xpath.
-
#get_rdfs_property(property_name, prefix = "/") ⇒ Object
Abstract method that allows to fetch rdfs properties via xpath.
-
#heliports ⇒ Object
Returns the number of helicopter airports.
-
#initialize(new_country_name) ⇒ Country
constructor
Get Country Information from the CIA Factbook.
-
#landboundary ⇒ Object
Returns landboundary.
-
#latitude ⇒ Object
Returns geographiccoordinates latitude.
-
#location ⇒ Object
Returns location description (human readable).
-
#longitude ⇒ Object
Returns geographiccoordinates longitude.
-
#name ⇒ Object
Returns the country name (rdfs:label) XXX: If nothing was found this method returns <?xml version=“1.0”?>.
-
#population_total ⇒ Object
Returns background information about the country.
-
#terrain ⇒ Object
Returns terrain description (human readable).
-
#xml_document ⇒ String
The document serialized as XML.
Constructor Details
#initialize(new_country_name) ⇒ Country
Get Country Information from the CIA Factbook. see www4.wiwiss.fu-berlin.de/factbook/
Example:
>> austria = SemanticCrawler::Factbook::Country.new("austria")
>> puts austria.background
Arguments:
new_country_name: (String)
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/semantic_crawler/factbook/country.rb', line 37 def initialize(new_country_name) if !new_country_name.nil? @country_name = new_country_name @url = @@URI_PREFIX + @country_name.downcase.gsub(" ", "_").gsub("usa", "united_states") 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)
Country name given as input during the object creation.
22 23 24 |
# File 'lib/semantic_crawler/factbook/country.rb', line 22 def country_name @country_name end |
#url ⇒ Object (readonly)
The complete URL of the country. Could be also wrong, if the country_name is not valid.
26 27 28 |
# File 'lib/semantic_crawler/factbook/country.rb', line 26 def url @url end |
Instance Method Details
#airports_total ⇒ Object
Returns the total number of airports in the country
91 92 93 |
# File 'lib/semantic_crawler/factbook/country.rb', line 91 def airports_total get_factbook_property("airports_total") end |
#background ⇒ Object
Returns background information about the country
57 58 59 |
# File 'lib/semantic_crawler/factbook/country.rb', line 57 def background get_factbook_property("background") end |
#climate ⇒ Object
Returns climate description (human readable)
101 102 103 |
# File 'lib/semantic_crawler/factbook/country.rb', line 101 def climate get_factbook_property("climate") end |
#get_factbook_property(property_name, prefix = "/") ⇒ Object
Abstract method that allows to fetch factbook properties via xpath
113 114 115 116 117 118 119 |
# File 'lib/semantic_crawler/factbook/country.rb', line 113 def get_factbook_property(property_name, prefix = "/" ) if !@doc.nil? @doc.xpath(prefix + "/factbook:" + property_name + "/text()", @@NAMESPACES) else nil end end |
#get_rdfs_property(property_name, prefix = "/") ⇒ Object
Abstract method that allows to fetch rdfs properties via xpath
128 129 130 131 132 133 134 |
# File 'lib/semantic_crawler/factbook/country.rb', line 128 def get_rdfs_property(property_name, prefix = "/") if !@doc.nil? @doc.xpath(prefix + "/rdfs:" + property_name + "/text()", @@NAMESPACES) else nil end end |
#heliports ⇒ Object
Returns the number of helicopter airports
96 97 98 |
# File 'lib/semantic_crawler/factbook/country.rb', line 96 def heliports get_factbook_property("heliports") end |
#landboundary ⇒ Object
Returns landboundary
77 78 79 80 81 82 83 |
# File 'lib/semantic_crawler/factbook/country.rb', line 77 def landboundary if !@doc.nil? @doc.xpath("//factbook:landboundary/rdf:Description/@rdf:about", @@NAMESPACES) else nil end end |
#latitude ⇒ Object
Returns geographiccoordinates latitude
67 68 69 |
# File 'lib/semantic_crawler/factbook/country.rb', line 67 def latitude get_factbook_property("geographiccoordinates_latitude") end |
#location ⇒ Object
Returns location description (human readable)
106 107 108 |
# File 'lib/semantic_crawler/factbook/country.rb', line 106 def location get_factbook_property("location") end |
#longitude ⇒ Object
Returns geographiccoordinates longitude
72 73 74 |
# File 'lib/semantic_crawler/factbook/country.rb', line 72 def longitude get_factbook_property("geographiccoordinates_longitude") end |
#name ⇒ Object
Returns the country name (rdfs:label) XXX: If nothing was found this method returns <?xml version=“1.0”?>
52 53 54 |
# File 'lib/semantic_crawler/factbook/country.rb', line 52 def name get_rdfs_property("label", "/rdf:RDF/rdf:Description/factbook:landboundary/factbook:Country") end |
#population_total ⇒ Object
Returns background information about the country
62 63 64 |
# File 'lib/semantic_crawler/factbook/country.rb', line 62 def population_total get_factbook_property("population_total") end |
#terrain ⇒ Object
Returns terrain description (human readable)
86 87 88 |
# File 'lib/semantic_crawler/factbook/country.rb', line 86 def terrain get_factbook_property("terrain") end |
#xml_document ⇒ String
Returns The document serialized as XML.
122 123 124 |
# File 'lib/semantic_crawler/factbook/country.rb', line 122 def xml_document @doc.to_s end |