Class: SemExtractor::Textwise

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

Instance Attribute Summary

Attributes inherited from SemExtractor

#api_key, #context, #geos

Instance Method Summary collapse

Methods inherited from SemExtractor

#set

Constructor Details

#initialize(options = {}) ⇒ Textwise

I kept methods here instead of variables because,each one leads to a http call



5
6
7
# File 'lib/apis/textwise.rb', line 5

def initialize(options={})
  self.set(options)
end

Instance Method Details

#categoriesObject



14
15
16
17
18
# File 'lib/apis/textwise.rb', line 14

def categories
  @options = {'content' => @context, 'showLabels' => "true" }
  @type = 'category'
  get_entity
end

#filterObject



20
21
22
23
24
# File 'lib/apis/textwise.rb', line 20

def filter
  @options = {'uri' => @context }
  @type = 'filter/web'
  remote_xml
end

#get_entityObject



31
32
33
34
35
36
37
# File 'lib/apis/textwise.rb', line 31

def get_entity
  begin
     Nokogiri::XML(remote_xml).css(@type).map { |h|  {"score" => h['weight'], "name" => h['label']} }
  rescue
    []
  end
end

#matchObject



26
27
28
29
# File 'lib/apis/textwise.rb', line 26

def match
  @type = 'match/rsscombined'
  @options = {'content' => @context }
end

#termsObject



9
10
11
12
# File 'lib/apis/textwise.rb', line 9

def terms
  @options = { 'content' => @context }
  get_entity
end

#uriObject



39
40
41
42
43
# File 'lib/apis/textwise.rb', line 39

def uri
  api_uri = URI.parse(gateway)
  api_uri.query = @options.map { |k,v| "#{URI.escape(k || '')}=#{URI.escape(v || '')}" }.join('&')
  api_uri
end