Sha256: 6cfbc23dfb53cb4c94554dd09ea4060e1cc6917892ccb98568fbb1ed3e1144e3

Contents?: true

Size: 657 Bytes

Versions: 2

Compression:

Stored size: 657 Bytes

Contents

module YaCan::Keyphrase
  @@path = '/KeyphraseService/V1/extract'

  def analyze(text)
    xml = YaCan::YahooAPI.request(@@path, {'sentence' => text})
    return Result.new(xml)
  end

  def extract(text)
    analyze(text)
  end

  module_function :analyze, :extract

  class Result
    def initialize(xml)
      @xml = xml
      pairs = Nokogiri::XML(xml).search('Result')
      @results = pairs.map{ |p|
        [p.at('Keyphrase').text, p.at('Score').text.to_i]
      }
    end

    def phrases
      @phrases ||= @results.map{ |r| r[0]}
    end

    def scores
      @scores ||= @results.map{ |r| r[1]}
    end

    attr_reader :xml, :results
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
yacan-0.1.1 lib/yacan/keyphrase.rb
yacan-0.1.0 lib/yacan/keyphrase.rb