Class: SemanticCrawler::Freebase::Country
- Inherits:
-
Object
- Object
- SemanticCrawler::Freebase::Country
- Includes:
- HTTParty
- Defined in:
- lib/semantic_crawler/freebase/country.rb
Overview
Freebase Country entity. Currently it is very abstract and could be each entry on Freebase.
Constant Summary collapse
- @@URI_PREFIX =
The URL prefix of an english Freebase RDF entity.
"http://rdf.freebase.com/rdf/en."
- @@NAMESPACES =
Namespace hash
{ "rdf" => "http://www.w3.org/1999/02/22-rdf-syntax-ns#", "fb" => "http://rdf.freebase.com/ns/", "owl" => "http://www.w3.org/2002/07/owl#" }
Instance Attribute Summary collapse
-
#country_name ⇒ Object
readonly
The read only country name.
Instance Method Summary collapse
-
#administrative_divisions ⇒ Array<String>
Extract fb:location.country.administrative_divisions properties.
-
#agencies ⇒ Array<String>
Extract fb:government.governmental_jurisdiction.agencies.
-
#contains ⇒ Array<String>
Extract the fb:location.location.contains properties.
-
#initialize(new_country_name) ⇒ Country
constructor
Creates a new Freebase object (JSON).
-
#object_name(lang = "en") ⇒ String
Extract the fb:type.object.name property.
-
#query_root_node(xpath_query, namespaces = {}) ⇒ String
Executes a xpath query with optional a hash with namespaces.
-
#same_as ⇒ Array<String>
Extract the owl:sameAs links.
-
#website ⇒ String
Extract the fb:common.topic.topical_webpage property.
-
#xml_document ⇒ String
Outputs the document as XML.
Constructor Details
#initialize(new_country_name) ⇒ Country
Creates a new Freebase object (JSON)
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/semantic_crawler/freebase/country.rb', line 24 def initialize(new_country_name) @country_name = new_country_name if !@country_name.nil? @normalized_country = @country_name.gsub(" ", "_").gsub("USA", "United_States_of_America").downcase @url = @@URI_PREFIX + @normalized_country @subject = "http://rdf.freebase.com/ns/en.#{@normalized_country}" @root_node = nil begin fetch_rdf rescue => e $log.error("Not able to get country information, through exception: #{e}") end end end |
Instance Attribute Details
#country_name ⇒ Object (readonly)
The read only country name
21 22 23 |
# File 'lib/semantic_crawler/freebase/country.rb', line 21 def country_name @country_name end |
Instance Method Details
#administrative_divisions ⇒ Array<String>
Extract fb:location.country.administrative_divisions properties
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/semantic_crawler/freebase/country.rb', line 67 def administrative_divisions return_list = [] list = query_root_node("fb:location.country.administrative_divisions/@rdf:resource", @@NAMESPACES) if !list.nil? list.each do |entry| return_list << entry.to_s end end return_list end |
#agencies ⇒ Array<String>
Extract fb:government.governmental_jurisdiction.agencies
80 81 82 83 84 85 86 87 88 89 |
# File 'lib/semantic_crawler/freebase/country.rb', line 80 def agencies return_list = [] list = query_root_node("fb:government.governmental_jurisdiction.agencies/@rdf:resource", @@NAMESPACES) if !list.nil? list.each do |entry| return_list << entry.to_s end end return_list end |
#contains ⇒ Array<String>
Extract the fb:location.location.contains properties
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/semantic_crawler/freebase/country.rb', line 54 def contains return_list = [] list = query_root_node("fb:location.location.contains/@rdf:resource", @@NAMESPACES) if !list.nil? list.each do |entry| return_list << entry.to_s end end return_list end |
#object_name(lang = "en") ⇒ String
Extract the fb:type.object.name property
48 49 50 |
# File 'lib/semantic_crawler/freebase/country.rb', line 48 def object_name(lang = "en") query_root_node("fb:type.object.name[@xml:lang='#{lang}']/text()", @@NAMESPACES).to_s end |
#query_root_node(xpath_query, namespaces = {}) ⇒ String
Executes a xpath query with optional a hash with namespaces
106 107 108 109 110 |
# File 'lib/semantic_crawler/freebase/country.rb', line 106 def query_root_node(xpath_query, namespaces = {}) if !@root_node.nil? @root_node.xpath(xpath_query, namespaces) end end |
#same_as ⇒ Array<String>
Extract the owl:sameAs links
93 94 95 96 97 98 99 100 101 102 |
# File 'lib/semantic_crawler/freebase/country.rb', line 93 def same_as return_list = [] list = query_root_node("owl:sameAs/@rdf:resource", @@NAMESPACES) if !list.nil? list.each do |entry| return_list << entry.to_s end end return_list end |
#website ⇒ String
Extract the fb:common.topic.topical_webpage property
41 42 43 |
# File 'lib/semantic_crawler/freebase/country.rb', line 41 def website query_root_node("fb:common.topic.topical_webpage/text()", @@NAMESPACES).to_s end |
#xml_document ⇒ String
Outputs the document as XML
114 115 116 |
# File 'lib/semantic_crawler/freebase/country.rb', line 114 def xml_document @root_node.to_s end |