class SemanticCrawler::LinkedGeoData::RelevantNodes

Specifies relevant nodes that are near a location. Classified by GPS coordinates and radius

Attributes

latitude[R]

@attribute [r] The input latitude value

longitude[R]

@attribute [r] The input longitude value

radius[R]

@attribute [r] The input radius value in meters

url[R]

@attribute [r] The linkedgeodata.org link to the relevant nodes

Public Class Methods

new(new_latitude, new_longitude, new_radius, type = nil) click to toggle source
# File lib/semantic_crawler/linked_geo_data/relevant_nodes.rb, line 29
def initialize(new_latitude, new_longitude, new_radius, type = nil)
    if !new_latitude.nil? && !new_longitude.nil? && !new_radius.nil?
        @latitude = new_latitude
        @longitude = new_longitude
        @radius = new_radius
        @url = "http://linkedgeodata.org/triplify/near/#{@latitude},#{@longitude}/#{@radius}"
        if !type.nil?
            @url += "/class/#{type}"
        end
        begin
            fetch_rdf
        rescue => e
            $log.error("Not able to get linked geo data information, through exception: #{e}")
        end
    end
end

Public Instance Methods

query_root_node(xpath_query, namespaces = {}) click to toggle source

Query the root_node

# File lib/semantic_crawler/linked_geo_data/relevant_nodes.rb, line 62
def query_root_node(xpath_query, namespaces = {})
    if !@root_node.nil?
        @root_node.xpath(xpath_query, namespaces)
    end
end
relevant_nodes() click to toggle source

Returns an array of SemanticCrawler::LinkedGeoData::RelevantNode objects @return [Array<SemanticCrawler::LinkedGeoData::RelevantNode>]

# File lib/semantic_crawler/linked_geo_data/relevant_nodes.rb, line 49
def relevant_nodes
    nodeset = query_root_node("rdf:Description", @@NAMESPACES)
    @items = []
    if !nodeset.nil?
        nodeset.each do |item|
            node_obj = SemanticCrawler::LinkedGeoData::RelevantNode.new(item)
            @items << node_obj
        end
    end
    @items
end
xml_document() click to toggle source

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

# File lib/semantic_crawler/linked_geo_data/relevant_nodes.rb, line 70
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/linked_geo_data/relevant_nodes.rb, line 76
def fetch_rdf
    @doc = Nokogiri::XML(open(@url, "Accept" => "application/rdf+xml"))
    @root_node = @doc.xpath("/rdf:RDF", @@NAMESPACES)
end