class SemanticCrawler::Fao::Country

Represents Food and Agriculture information about one country.

Attributes

country_name[R]

@attribute [r] The read only country name

url[R]

@attribute [r] The read only URL to the FAO resource

Public Class Methods

new(new_country_name) click to toggle source

Initialize a new Fao country object

# 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

Public Instance Methods

code_dbpedia_id() click to toggle source

The dbpedia identifier (from fao:codeDBPediaID) @return [String]

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

Returns all countries that share a boarder with this country (as name) @return [Array<String>]

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

Returns all countries that share a boarder with this country (as dereferencable URL - from fao:hasBorderWith) @return [Array<String>]

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

Classification of this country as name (from fao:isInGroup) @return [Array<String>]

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

Classification of this country as dereferenceable URL (from fao:isInGroup) @return [Array<String>]

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

Human readable description about the land area (from fao:landAreaNotes) @return [String]

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

Land area total value (from fao:landAreaTotal) @return [String]

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

Land area unit (from fao:landAreaUnit) @return [String]

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

Land area year (from fao:landAreaYear) @return [String]

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

The maximum latitude (from fao:hasMaxLatitude) @return [String]

# File lib/semantic_crawler/fao/country.rb, line 63
def max_latitude
    query_root_node("fao:hasMaxLatitude/text()", @@NAMESPACES).to_s
end
max_longitude() click to toggle source

The maximum longitude (from fao:hasMaxLongitude) @return [String]

# File lib/semantic_crawler/fao/country.rb, line 69
def max_longitude
    query_root_node("fao:hasMaxLongitude/text()", @@NAMESPACES).to_s
end
min_latitude() click to toggle source

The minimum latitude (from fao:hasMinLatitude) @return [String]

# File lib/semantic_crawler/fao/country.rb, line 75
def min_latitude
    query_root_node("fao:hasMinLatitude/text()", @@NAMESPACES).to_s
end
min_longitude() click to toggle source

The minimum longitude (from fao:hasMinLongitude) @return [String]

# 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') click to toggle source

The currency name. @param [String] The language in which the currency name should be returned @return [String]

# 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') click to toggle source

The official country name @param [String] The language in which the official name should be returned @return [String]

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

Population notes (from fao:populationNotes) @return [String]

# File lib/semantic_crawler/fao/country.rb, line 180
def population_notes
    query_root_node("fao:populationNotes/text()", @@NAMESPACES).to_s
end
population_total() click to toggle source

Population total (from fao:populationTotal) @return [String]

# File lib/semantic_crawler/fao/country.rb, line 186
def population_total
    query_root_node("fao:populationTotal/text()", @@NAMESPACES).to_s
end
population_unit() click to toggle source

Population unit (from fao:populationUnit) @return [String]

# File lib/semantic_crawler/fao/country.rb, line 192
def population_unit
    query_root_node("fao:populationUnit/text()", @@NAMESPACES).to_s
end
population_year() click to toggle source

Population year (from fao:populationYear) @return [String]

# 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 = {}) click to toggle source

Executes a xpath query with optional a hash with namespaces @return [String]

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

Links to additional information (from owl:sameAs) @return [Array<String>]

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

The type as URL of this entity (from rdf:type) @return [String]

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

Entity is valid since (from fao:validSince) @return [String]

# File lib/semantic_crawler/fao/country.rb, line 204
def valid_since
    query_root_node("fao:validSince/text()", @@NAMESPACES).to_s
end
valid_until() click to toggle source

Entity is valid until (from fao:validUntil) @return [String]

# File lib/semantic_crawler/fao/country.rb, line 210
def valid_until
    query_root_node("fao:validUntil/text()", @@NAMESPACES).to_s
end
xml_document() click to toggle source

Outputs the document as XML @return [String] The document serialized as XML

# File lib/semantic_crawler/fao/country.rb, line 224
def xml_document
    @root_node.to_s
end

Private Instance Methods

fetch_rdf() click to toggle source

Retrieves the RDF file

# File lib/semantic_crawler/fao/country.rb, line 230
def fetch_rdf
    @doc = Nokogiri::XML(open(@url))
    @root_node = @doc.xpath("/rdf:RDF/rdf:Description", @@NAMESPACES)
end