Sha256: 47b08e045b121ea148d223e2c310f0807fcb20c2632032179762271728290b7a

Contents?: true

Size: 861 Bytes

Versions: 2

Compression:

Stored size: 861 Bytes

Contents

require 'net/http'
require 'nokogiri'

class TermExtraction
  class Zemanta < TermExtraction
    def terms
      terms = []

      data.search('//name').each do |n|
        terms << n.text
      end

      terms
    end  

    class << self
      def canonical_name
        'zemanta'
      end
    end

    private
      def gateway
        'http://api.zemanta.com/services/rest/0.0/'
      end

      def url
        URI.parse(gateway)
      end

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

      def remote_xml
        Net::HTTP.post_form(url, post_params).body
      end

      def data
        @data ||= Nokogiri::XML.parse(remote_xml)
      end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
alexrabarts-term_extraction-0.1.0 lib/term_extraction/zemanta.rb
alexrabarts-term_extraction-0.1.1 lib/term_extraction/zemanta.rb