Class: SemExtractor::Zemanta

Inherits:
SemExtractor show all
Defined in:
lib/apis/zemanta.rb

Instance Attribute Summary

Attributes inherited from SemExtractor

#api_key, #categories, #context, #geos, #terms

Instance Method Summary collapse

Methods inherited from SemExtractor

#set

Constructor Details

#initialize(options = {}) ⇒ Zemanta

Returns a new instance of Zemanta.



4
5
6
7
8
9
# File 'lib/apis/zemanta.rb', line 4

def initialize(options={})
  self.set(options)
  xml = remote_xml
  @categories = Nokogiri::XML(xml).css('category').map { |h|  {"score" => h.at_css('confidence').content, "name" => h.at_css('name').content} }
  @terms = Nokogiri::XML(xml).css('keyword').map { |h|  {"score" => h.at_css('confidence').content, "name" => h.at_css('name').content} }
end

Instance Method Details

#post_paramsObject



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/apis/zemanta.rb', line 15

def post_params
  {
    'method'        =>'zemanta.suggest',
    'api_key'       => @api_key,
    'return_images' => 0,
    'text'          => @context,
    'format'        => 'xml',
    'articles_limit' => 1,
    'return_categories' => 'dmoz'
  }
end

#uriObject



11
12
13
# File 'lib/apis/zemanta.rb', line 11

def uri
  URI.parse(gateway)
end