Class: FreebaseAPI::Topic
- Inherits:
-
Object
- Object
- FreebaseAPI::Topic
- Defined in:
- lib/freebase_api/topic.rb
Constant Summary collapse
- PROPERTIES_LIMIT =
The maximum number of property values to return.
100
Instance Attribute Summary collapse
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
Class Method Summary collapse
-
.get(id, options = {}) ⇒ Topic
Returns a new Topic filled with all the Freebase properties.
-
.search(query, options = {}) ⇒ Hash
Search using a query and returns the results as a hash of topics score based.
Instance Method Summary collapse
- #description ⇒ Object
- #id ⇒ Object
- #image(options = {}) ⇒ Object
-
#initialize(id, options = {}) ⇒ Topic
constructor
A new instance of Topic.
- #inspect ⇒ Object
- #lang ⇒ Object
- #name ⇒ Object
- #properties_domains ⇒ Object
- #property(name) ⇒ Object
- #sync ⇒ Object
- #text ⇒ Object
- #types ⇒ Object
Constructor Details
#initialize(id, options = {}) ⇒ Topic
Returns a new instance of Topic.
69 70 71 72 73 74 75 |
# File 'lib/freebase_api/topic.rb', line 69 def initialize(id, ={}) @properties = {} @excluded_properties = parse_exclusion(.delete(:exclude)) @options = { :filter => 'commons' }.merge() @data = { 'id' => id }.merge([:data] || {}) build end |
Instance Attribute Details
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
7 8 9 |
# File 'lib/freebase_api/topic.rb', line 7 def properties @properties end |
Class Method Details
.get(id, options = {}) ⇒ Topic
Returns a new Topic filled with all the Freebase properties
15 16 17 18 19 |
# File 'lib/freebase_api/topic.rb', line 15 def get(id, ={}) topic = Topic.new(id, ) topic.sync topic end |
.search(query, options = {}) ⇒ Hash
Search using a query and returns the results as a hash of topics score based
26 27 28 29 30 31 32 |
# File 'lib/freebase_api/topic.rb', line 26 def search(query, ={}) hash = {} FreebaseAPI.session.search(query, ).each do |topic| hash[topic['score'].to_f] = Topic.new(topic['mid'], :data => construct_data(topic)) end hash end |
Instance Method Details
#description ⇒ Object
97 98 99 |
# File 'lib/freebase_api/topic.rb', line 97 def description @description ||= extract_description end |
#id ⇒ Object
77 78 79 |
# File 'lib/freebase_api/topic.rb', line 77 def id @data['id'] end |
#image(options = {}) ⇒ Object
120 121 122 |
# File 'lib/freebase_api/topic.rb', line 120 def image(={}) FreebaseAPI::Image.get(self.id, ) end |
#inspect ⇒ Object
124 125 126 |
# File 'lib/freebase_api/topic.rb', line 124 def inspect "#<#{self.class}:0x#{self.__id__.to_s(16)} id: \"#{self.id}\", name: \"#{self.name}\">" end |
#lang ⇒ Object
85 86 87 |
# File 'lib/freebase_api/topic.rb', line 85 def lang @data['lang'] end |
#name ⇒ Object
89 90 91 |
# File 'lib/freebase_api/topic.rb', line 89 def name @name ||= extract_name end |
#properties_domains ⇒ Object
105 106 107 108 109 110 111 112 113 |
# File 'lib/freebase_api/topic.rb', line 105 def properties_domains domains = {} properties.keys.each do |prop| d = prop.split('/')[1] domains[d] ||= 0 domains[d] += properties[prop].size end domains end |
#property(name) ⇒ Object
101 102 103 |
# File 'lib/freebase_api/topic.rb', line 101 def property(name) @properties[name] end |
#sync ⇒ Object
115 116 117 118 |
# File 'lib/freebase_api/topic.rb', line 115 def sync @data = FreebaseAPI.session.topic(self.id, @options) build end |
#text ⇒ Object
81 82 83 |
# File 'lib/freebase_api/topic.rb', line 81 def text @data['text'] end |
#types ⇒ Object
93 94 95 |
# File 'lib/freebase_api/topic.rb', line 93 def types @types ||= extract_types end |