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[R]

Country name given as input during the object creation.

url[R]

The complete URL of the country. Could be also wrong, if the country_name is not valid.

Public Class Methods

new(new_country_name) click to toggle source

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

airports_total() click to toggle source

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
background() click to toggle source

Returns background information about the country

# File lib/semantic_crawler/factbook/country.rb, line 57
def background
    get_factbook_property("background")
end
climate() click to toggle source

Returns climate description (human readable)

# File lib/semantic_crawler/factbook/country.rb, line 101
def climate
    get_factbook_property("climate")
end
get_factbook_property(property_name, prefix = "/" ) click to toggle source

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
get_rdfs_property(property_name, prefix = "/") click to toggle source

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
heliports() click to toggle source

Returns the number of helicopter airports

# File lib/semantic_crawler/factbook/country.rb, line 96
def heliports
    get_factbook_property("heliports")
end
landboundary() click to toggle source

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
latitude() click to toggle source

Returns geographiccoordinates latitude

# File lib/semantic_crawler/factbook/country.rb, line 67
def latitude
    get_factbook_property("geographiccoordinates_latitude")
end
location() click to toggle source

Returns location description (human readable)

# File lib/semantic_crawler/factbook/country.rb, line 106
def location
    get_factbook_property("location")
end
longitude() click to toggle source

Returns geographiccoordinates longitude

# File lib/semantic_crawler/factbook/country.rb, line 72
def longitude
    get_factbook_property("geographiccoordinates_longitude")
end
name() click to toggle source

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
population_total() click to toggle source

Returns background information about the country

# File lib/semantic_crawler/factbook/country.rb, line 62
def population_total
    get_factbook_property("population_total")
end
terrain() click to toggle source

Returns terrain description (human readable)

# File lib/semantic_crawler/factbook/country.rb, line 86
def terrain
    get_factbook_property("terrain")
end
xml_document() click to toggle source

@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

fetch_rdf() click to toggle source

Retrieves the RDF stream

# File lib/semantic_crawler/factbook/country.rb, line 138
def fetch_rdf
    @doc = Nokogiri::XML(open(@url))
end