class SemanticCrawler::Factbook::Country
Extracted from the RDF Dump of the CIA Factbook
. Contains all relevant, but maybe deprecated information about countries.
Attributes
Country
name given as input during the object creation.
The complete URL of the country. Could be also wrong, if the country_name
is not valid.
Public Class Methods
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)
# 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
Public Instance Methods
Returns the total number of airports in the country
# File lib/semantic_crawler/factbook/country.rb, line 91 def airports_total get_factbook_property("airports_total") end
Returns background information about the country
# File lib/semantic_crawler/factbook/country.rb, line 57 def background get_factbook_property("background") end
Returns climate description (human readable)
# File lib/semantic_crawler/factbook/country.rb, line 101 def climate get_factbook_property("climate") end
Abstract method that allows to fetch factbook properties via xpath
# 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
Abstract method that allows to fetch rdfs properties via xpath
# 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
Returns the number of helicopter airports
# File lib/semantic_crawler/factbook/country.rb, line 96 def heliports get_factbook_property("heliports") end
Returns landboundary
# 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
Returns geographiccoordinates latitude
# File lib/semantic_crawler/factbook/country.rb, line 67 def latitude get_factbook_property("geographiccoordinates_latitude") end
Returns location description (human readable)
# File lib/semantic_crawler/factbook/country.rb, line 106 def location get_factbook_property("location") end
Returns geographiccoordinates longitude
# File lib/semantic_crawler/factbook/country.rb, line 72 def longitude get_factbook_property("geographiccoordinates_longitude") end
Returns the country name (rdfs:label) XXX: If nothing was found this method returns <?xml version=“1.0”?>
# File lib/semantic_crawler/factbook/country.rb, line 52 def name get_rdfs_property("label", "/rdf:RDF/rdf:Description/factbook:landboundary/factbook:Country") end
Returns background information about the country
# File lib/semantic_crawler/factbook/country.rb, line 62 def population_total get_factbook_property("population_total") end
Returns terrain description (human readable)
# File lib/semantic_crawler/factbook/country.rb, line 86 def terrain get_factbook_property("terrain") end
@return [String] The document serialized as XML
# File lib/semantic_crawler/factbook/country.rb, line 122 def xml_document @doc.to_s end
Private Instance Methods
Retrieves the RDF stream
# File lib/semantic_crawler/factbook/country.rb, line 138 def fetch_rdf @doc = Nokogiri::XML(open(@url)) end