alexrabarts-term_extraction 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :minor: 1
3
- :patch: 1
3
+ :patch: 2
4
4
  :major: 0
@@ -3,7 +3,8 @@ require 'nokogiri'
3
3
  class TermExtraction
4
4
  class Yahoo < TermExtraction
5
5
  def terms
6
- terms = []
6
+ terms = []
7
+ data = Nokogiri::XML.parse(remote_xml)
7
8
 
8
9
  unless data.nil?
9
10
  data.search('//s:Result', ns).each do |n|
@@ -43,9 +44,5 @@ class TermExtraction
43
44
  def remote_xml
44
45
  open(url).read
45
46
  end
46
-
47
- def data
48
- @data ||= Nokogiri::XML.parse(remote_xml)
49
- end
50
47
  end
51
48
  end
@@ -5,13 +5,14 @@ class TermExtraction
5
5
  class Zemanta < TermExtraction
6
6
  def terms
7
7
  terms = []
8
+ data = Nokogiri::XML.parse(remote_xml)
8
9
 
9
10
  data.search('//name').each do |n|
10
11
  terms << n.text
11
12
  end
12
13
 
13
14
  terms
14
- end
15
+ end
15
16
 
16
17
  class << self
17
18
  def canonical_name
@@ -41,9 +42,5 @@ class TermExtraction
41
42
  def remote_xml
42
43
  Net::HTTP.post_form(url, post_params).body
43
44
  end
44
-
45
- def data
46
- @data ||= Nokogiri::XML.parse(remote_xml)
47
- end
48
45
  end
49
46
  end
@@ -0,0 +1,3 @@
1
+ <?xml version="1.0"?>
2
+ <ResultSet xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:yahoo:cate" xsi:schemaLocation="urn:yahoo:cate http://api.search.yahoo.com/ContentAnalysisService/V1/TermExtractionResponse.xsd"><Result>fears of war</Result><Result>fears</Result></ResultSet>
3
+ <!-- ws04.search.scd.yahoo.com uncompressed/chunked Thu Feb 26 21:04:16 PST 2009 -->
@@ -0,0 +1,104 @@
1
+ <?xml version="1.0"?>
2
+ <rsp>
3
+ <status>ok</status>
4
+ <articles>
5
+ <article>
6
+ <url>http://www.crunchgear.com/2009/02/24/nvidia-based-imacs-coming-soon/</url>
7
+ <confidence>0.033153</confidence>
8
+ <published_datetime>2009-02-24T18:00:45Z</published_datetime>
9
+ <zemified>0</zemified>
10
+ <title>NVIDIA-based iMacs coming soon?</title>
11
+ </article><article>
12
+ <url>http://www.tuaw.com/2009/02/24/rumor-new-imacs-around-the-bend/</url>
13
+ <confidence>0.028595</confidence>
14
+ <published_datetime>2009-02-24T22:00:00Z</published_datetime>
15
+ <zemified>0</zemified>
16
+ <title>Rumor: New iMacs around the bend</title>
17
+ </article><article>
18
+ <url>http://www.engadget.com/2009/02/24/a-few-new-rumors-point-to-two-new-nvidia-packing-imacs/</url>
19
+ <confidence>0.027595</confidence>
20
+ <published_datetime>2009-02-24T13:03:00Z</published_datetime>
21
+ <zemified>0</zemified>
22
+ <title>A few new rumors point to two new NVIDIA-packing iMacs</title>
23
+ </article><article>
24
+ <url>http://www.techmeme.com/090126/p31</url>
25
+ <confidence>0.019056</confidence>
26
+ <published_datetime>2009-01-26T17:00:22Z</published_datetime>
27
+ <zemified>0</zemified>
28
+ <title>Chip complex delaying Apple's new iMac line, says analyst (Zach Spear/AppleInsider)</title>
29
+ </article><article>
30
+ <url>http://i.gizmodo.com/5143476/apple-warns-resellers-of-reduced-imac-availability-new-models-on-the-way</url>
31
+ <confidence>0.018611</confidence>
32
+ <published_datetime>2009-01-31T16:30:00Z</published_datetime>
33
+ <zemified>0</zemified>
34
+ <title>Apple Warns Resellers of Reduced iMac Availability: New Models On the Way? [Apple]</title>
35
+ </article><article>
36
+ <url>http://cultofmac.com/analyst-new-imacs-delayed-for-chips-snow-leopard/7549</url>
37
+ <confidence>0.01685</confidence>
38
+ <published_datetime>2009-01-26T16:43:44Z</published_datetime>
39
+ <zemified>0</zemified>
40
+ <title>Analyst: New iMacs Delayed For Chips, Snow Leopard</title>
41
+ </article><article>
42
+ <url>http://www.ubergizmo.com/15/archives/2008/12/new_imac_allinone_pc_confirmed.html</url>
43
+ <confidence>0.016311</confidence>
44
+ <published_datetime>2008-12-24T01:06:56Z</published_datetime>
45
+ <zemified>0</zemified>
46
+ <title>New iMac All-In-One PC Confirmed</title>
47
+ </article><article>
48
+ <url>http://www.labnol.org/gadgets/exchange-windows-pc-for-apple-mac/5775/</url>
49
+ <confidence>0.016238</confidence>
50
+ <published_datetime>2008-12-03T08:17:35Z</published_datetime>
51
+ <zemified>0</zemified>
52
+ <title>Exchange Your Windows PC or TV for an Apple iMac</title>
53
+ </article><article>
54
+ <url>http://cultofmac.com/class-action-lawsuit-over-imac-display-problems/6562</url>
55
+ <confidence>0.015608</confidence>
56
+ <published_datetime>2009-01-02T16:17:06Z</published_datetime>
57
+ <zemified>0</zemified>
58
+ <title>Class-Action Lawsuit Over iMac Display Problems</title>
59
+ </article><article>
60
+ <url>http://www.crunchgear.com/2008/12/29/new-imacs-to-include-hotter-components-new-cooling/</url>
61
+ <confidence>0.015093</confidence>
62
+ <published_datetime>2008-12-29T23:50:04Z</published_datetime>
63
+ <zemified>0</zemified>
64
+ <title>New iMacs to include hotter components, new cooling?</title>
65
+ </article>
66
+ </articles><markup>
67
+ <text>apple imac</text>
68
+ </markup><signature>&lt;div class="zemanta-pixie"&gt;&lt;a class="zemanta-pixie-a" href="http://reblog.zemanta.com/zemified/3695b55a-d68e-4328-bf86-c3f01be8b2da/" title="Zemified by Zemanta"&gt;&lt;img class="zemanta-pixie-img" src="http://img.zemanta.com/reblog_e.png?x-id=3695b55a-d68e-4328-bf86-c3f01be8b2da" alt="Reblog this post [with Zemanta]" /&gt;&lt;/a&gt;&lt;/div&gt;</signature>
69
+ <keywords>
70
+ <keyword>
71
+ <confidence>0.404748</confidence>
72
+ <scheme>general</scheme>
73
+ <name>Zapple</name>
74
+ </keyword><keyword>
75
+ <confidence>0.277753</confidence>
76
+ <scheme>general</scheme>
77
+ <name>AMac</name>
78
+ </keyword><keyword>
79
+ <confidence>0.094392</confidence>
80
+ <scheme>general</scheme>
81
+ <name>Tumor</name>
82
+ </keyword><keyword>
83
+ <confidence>0.076399</confidence>
84
+ <scheme>general</scheme>
85
+ <name>Shardware</name>
86
+ </keyword><keyword>
87
+ <confidence>0.072186</confidence>
88
+ <scheme>general</scheme>
89
+ <name>Mvidia</name>
90
+ </keyword><keyword>
91
+ <confidence>0.069183</confidence>
92
+ <scheme>general</scheme>
93
+ <name>Hackintosh</name>
94
+ </keyword><keyword>
95
+ <confidence>0.050487</confidence>
96
+ <scheme>general</scheme>
97
+ <name>Zesktops</name>
98
+ </keyword><keyword>
99
+ <confidence>0.039205</confidence>
100
+ <scheme>general</scheme>
101
+ <name>AllInNone</name>
102
+ </keyword>
103
+ </keywords><rid>3695b55a-d68e-4328-bf86-c3f01be8b2da</rid>
104
+ </rsp>
@@ -27,6 +27,22 @@ class TermExtractionTest < Test::Unit::TestCase
27
27
  assert_equal zemanta.context, context
28
28
  end
29
29
 
30
+ should 'return different response on subsequent calls when different data is returned from Yahoo!' do
31
+ yahoo = TermExtraction::Yahoo.new
32
+ yahoo.stubs(:remote_xml).returns(read_xml_fixture('yahoo'))
33
+ original_terms = yahoo.terms
34
+ yahoo.stubs(:remote_xml).returns(read_xml_fixture('yahoo2'))
35
+ assert_not_equal original_terms, yahoo.terms
36
+ end
37
+
38
+ should 'return different response on subsequent calls when different data is returned from Zemanta' do
39
+ zemanta = TermExtraction::Zemanta.new
40
+ zemanta.stubs(:remote_xml).returns(read_xml_fixture('zemanta'))
41
+ original_terms = zemanta.terms
42
+ zemanta.stubs(:remote_xml).returns(read_xml_fixture('zemanta2'))
43
+ assert_not_equal original_terms, zemanta.terms
44
+ end
45
+
30
46
  private
31
47
  def correct_yahoo_terms
32
48
  ['gears of war', 'gears']
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alexrabarts-term_extraction
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - alex
@@ -38,7 +38,9 @@ files:
38
38
  - lib/term_extraction.rb
39
39
  - test/fixtures
40
40
  - test/fixtures/yahoo.xml
41
+ - test/fixtures/yahoo2.xml
41
42
  - test/fixtures/zemanta.xml
43
+ - test/fixtures/zemanta2.xml
42
44
  - test/term_extraction_test.rb
43
45
  - test/test_helper.rb
44
46
  has_rdoc: true