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.
106 107 108 109 110 111 112 |
# File 'lib/freebase_api/topic.rb', line 106 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
134 135 136 |
# File 'lib/freebase_api/topic.rb', line 134 def description @description ||= extract_description end |
#id ⇒ Object
114 115 116 |
# File 'lib/freebase_api/topic.rb', line 114 def id @data['id'] end |
#image(options = {}) ⇒ Object
157 158 159 |
# File 'lib/freebase_api/topic.rb', line 157 def image(={}) FreebaseAPI::Image.get(self.id, ) end |
#inspect ⇒ Object
161 162 163 |
# File 'lib/freebase_api/topic.rb', line 161 def inspect "#<#{self.class}:0x#{self.__id__.to_s(16)} id: \"#{self.id}\", name: \"#{self.name}\">" end |
#lang ⇒ Object
122 123 124 |
# File 'lib/freebase_api/topic.rb', line 122 def lang @data['lang'] end |
#name ⇒ Object
126 127 128 |
# File 'lib/freebase_api/topic.rb', line 126 def name @name ||= extract_name end |
#properties_domains ⇒ Object
142 143 144 145 146 147 148 149 150 |
# File 'lib/freebase_api/topic.rb', line 142 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
138 139 140 |
# File 'lib/freebase_api/topic.rb', line 138 def property(name) @properties[name] end |
#sync ⇒ Object
152 153 154 155 |
# File 'lib/freebase_api/topic.rb', line 152 def sync @data = FreebaseAPI.session.topic(self.id, @options) build end |
#text ⇒ Object
118 119 120 |
# File 'lib/freebase_api/topic.rb', line 118 def text @data['text'] end |
#types ⇒ Object
130 131 132 |
# File 'lib/freebase_api/topic.rb', line 130 def types @types ||= extract_types end |