Class: SemanticCrawler::LinkedGeoData::RelevantNodes

Inherits:
Object
  • Object
show all
Defined in:
lib/semantic_crawler/linked_geo_data/relevant_nodes.rb

Overview

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

Constant Summary collapse

@@NAMESPACES =

Namespace hash

{
    "rdf" => "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(new_latitude, new_longitude, new_radius, type = nil) ⇒ RelevantNodes

Returns a new instance of RelevantNodes.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# 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

Instance Attribute Details

#latitudeObject (readonly)

The input latitude value



15
16
17
# File 'lib/semantic_crawler/linked_geo_data/relevant_nodes.rb', line 15

def latitude
  @latitude
end

#longitudeObject (readonly)

The input longitude value



19
20
21
# File 'lib/semantic_crawler/linked_geo_data/relevant_nodes.rb', line 19

def longitude
  @longitude
end

#radiusObject (readonly)

The input radius value in meters



23
24
25
# File 'lib/semantic_crawler/linked_geo_data/relevant_nodes.rb', line 23

def radius
  @radius
end

#urlObject (readonly)

The linkedgeodata.org link to the relevant nodes



27
28
29
# File 'lib/semantic_crawler/linked_geo_data/relevant_nodes.rb', line 27

def url
  @url
end

Instance Method Details

#query_root_node(xpath_query, namespaces = {}) ⇒ Object

Query the root_node



62
63
64
65
66
# 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_nodesArray<SemanticCrawler::LinkedGeoData::RelevantNode>

Returns an array of SemanticCrawler::LinkedGeoData::RelevantNode objects



49
50
51
52
53
54
55
56
57
58
59
# 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_documentString

Outputs the document as XML

Returns:

  • (String)

    The document serialized as XML



70
71
72
# File 'lib/semantic_crawler/linked_geo_data/relevant_nodes.rb', line 70

def xml_document
    @root_node.to_s
end