tags4free 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +6 -0
- data/Manifest.txt +7 -0
- data/README.txt +46 -0
- data/Rakefile +20 -0
- data/lib/tags_4_free.rb +33 -0
- data/spec/spec_helper.rb +9 -0
- data/spec/tags_4_free_spec.rb +33 -0
- data.tar.gz.sig +3 -0
- metadata +102 -0
- metadata.gz.sig +2 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
data/README.txt
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
= Tags4Free
|
2
|
+
|
3
|
+
== DESCRIPTION:
|
4
|
+
|
5
|
+
Tags4Free allows you to easily extract tags or keywords from any stringish
|
6
|
+
content using the Yahoo! search API.
|
7
|
+
|
8
|
+
== SYNOPSIS:
|
9
|
+
|
10
|
+
require 'rubygems'
|
11
|
+
require 'tags_4_free'
|
12
|
+
|
13
|
+
Tags4Free.for("Tags4Free allows you to easily extract tags or keywords from any stringish content using the Yahoo! search API.") # => ["search api", "yahoo search", "yahoo"]
|
14
|
+
|
15
|
+
== REQUIREMENTS:
|
16
|
+
|
17
|
+
* HTTParty gem by John Nunemaker (http://railstips.org/2008/7/29/it-s-an-httparty-and-everyone-is-invited)
|
18
|
+
|
19
|
+
== INSTALL:
|
20
|
+
|
21
|
+
* sudo gem install tags4free
|
22
|
+
|
23
|
+
== LICENSE:
|
24
|
+
|
25
|
+
(The MIT License)
|
26
|
+
|
27
|
+
Copyright (c) 2008 FIX
|
28
|
+
|
29
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
30
|
+
a copy of this software and associated documentation files (the
|
31
|
+
'Software'), to deal in the Software without restriction, including
|
32
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
33
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
34
|
+
permit persons to whom the Software is furnished to do so, subject to
|
35
|
+
the following conditions:
|
36
|
+
|
37
|
+
The above copyright notice and this permission notice shall be
|
38
|
+
included in all copies or substantial portions of the Software.
|
39
|
+
|
40
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
41
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
42
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
43
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
44
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
45
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
46
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'hoe'
|
5
|
+
require 'httparty'
|
6
|
+
require './lib/tags_4_free.rb'
|
7
|
+
|
8
|
+
Hoe.new('tags4free', Tags4Free::VERSION) do |p|
|
9
|
+
p.rubyforge_name = "kickassrb"
|
10
|
+
p.name = "tags4free"
|
11
|
+
p.author = "Thorben Schröder"
|
12
|
+
p.description = "Free tag extraction from content using Yahoo! search API."
|
13
|
+
p.email = 'thorben@fetmab.net'
|
14
|
+
p.summary = "Free tag extraction from content using Yahoo! search API."
|
15
|
+
p.remote_rdoc_dir = '' # Release to root
|
16
|
+
p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
|
17
|
+
p.extra_deps << ['httparty'," >=0.1.3"]
|
18
|
+
end
|
19
|
+
|
20
|
+
# vim: syntax=Ruby
|
data/lib/tags_4_free.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
module Tags4Free
|
2
|
+
require 'rubygems'
|
3
|
+
require 'httparty'
|
4
|
+
include HTTParty
|
5
|
+
|
6
|
+
VERSION = '0.1.0'
|
7
|
+
|
8
|
+
class YahooApiError < ArgumentError; end
|
9
|
+
|
10
|
+
class YahooApiFormatError < ArgumentError
|
11
|
+
def initialize(content, result_set)
|
12
|
+
super "Malformed answer by Yahoo! for `#{content}`: #{result_set.inspect}"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
APPID = 'Tags4Free'
|
17
|
+
SERVICE_URL =
|
18
|
+
'http://api.search.yahoo.com/ContentAnalysisService/V1/termExtraction'
|
19
|
+
format :xml
|
20
|
+
|
21
|
+
#
|
22
|
+
# Generate tags for a string
|
23
|
+
#
|
24
|
+
# tags = Tags4Free.for('The content that should be tagged')
|
25
|
+
def self.for(content)
|
26
|
+
result_set = get(SERVICE_URL, :query => {:appid => APPID, :context => content})
|
27
|
+
|
28
|
+
raise YahooApiError.new(result_set['Error']['Message']) if result_set['Error']
|
29
|
+
raise YahooApiFormatError.new(content, result_set) unless result_set['ResultSet']
|
30
|
+
|
31
|
+
result_set['ResultSet']['Result'] || []
|
32
|
+
end
|
33
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
+
|
3
|
+
describe Tags4Free do
|
4
|
+
it "should return an empty array if no tags were found" do
|
5
|
+
Tags4Free.should_receive(:get).and_return({"ResultSet"=>{"xsi:schemaLocation"=>"urn:yahoo:cate http://api.search.yahoo.com/ContentAnalysisService/V1/TermExtractionResponse.xsd", "xmlns:xsi"=>"http://www.w3.org/2001/XMLSchema-instance", "xmlns"=>"urn:yahoo:cate"}})
|
6
|
+
|
7
|
+
Tags4Free.for("No keywords extractable.").should eql([])
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should raise an exception if Yahoo! reports an error" do
|
11
|
+
Tags4Free.should_receive(:get).and_return({"Error"=>{"Message"=>"invalid value: context", "xmlns"=>"urn:yahoo:api"}})
|
12
|
+
|
13
|
+
begin
|
14
|
+
Tags4Free.for("Erroneous content")
|
15
|
+
rescue Tags4Free::YahooApiError => e
|
16
|
+
e.message.should include('invalid value: context')
|
17
|
+
else
|
18
|
+
violated('YahooApiError should be raised!')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should raise an exception if Yahoo! answers with wired bullshit" do
|
23
|
+
Tags4Free.should_receive(:get).and_return({"Some"=>{"Stupid"=>"bullshit", "xmlns"=>"urn:yahoo:api"}})
|
24
|
+
|
25
|
+
begin
|
26
|
+
Tags4Free.for("Content that causes a bullshit answer")
|
27
|
+
rescue Tags4Free::YahooApiFormatError => e
|
28
|
+
else
|
29
|
+
violated('YahooApiFormatError should be raised!')
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
data.tar.gz.sig
ADDED
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tags4free
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- "Thorben Schr\xC3\xB6der"
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain:
|
11
|
+
- |
|
12
|
+
-----BEGIN CERTIFICATE-----
|
13
|
+
MIIDMjCCAhqgAwIBAgIBADANBgkqhkiG9w0BAQUFADA/MRAwDgYDVQQDDAd0aG9y
|
14
|
+
YmVuMRYwFAYKCZImiZPyLGQBGRYGZmV0bWFiMRMwEQYKCZImiZPyLGQBGRYDbmV0
|
15
|
+
MB4XDTA4MTAwOTIxNTQwNloXDTA5MTAwOTIxNTQwNlowPzEQMA4GA1UEAwwHdGhv
|
16
|
+
cmJlbjEWMBQGCgmSJomT8ixkARkWBmZldG1hYjETMBEGCgmSJomT8ixkARkWA25l
|
17
|
+
dDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAOTrBWJAhXdd4FALdaz4
|
18
|
+
+2KKe6Loz7L8AQxvhYedX7trYpqrWmXNLyCZKvNDf7Hp0EmOn8k5Iti161bcWxwY
|
19
|
+
fj8ejQ02U3OUyKSQM7V7zUrzB9pkmZ8ROGWJmw+nWVu7ZF7UU6+kWwaSMU/unPno
|
20
|
+
c1PcfOQrwCjvXbedMTFPZ1b/W37DoaoVQJLzzx95ewXSZ7iPtLxTrjHESjWBPxFi
|
21
|
+
JMEVCZDM+5UTEm41ucAJJ58z54mKryRap4NMux9YmPFp13f0xFVKP5kST16Q96IV
|
22
|
+
qJaPKd4WApsB8WOOyxGVFzp6Lf1fAHKjrXca6ywHeAM070Ki6GzAXKPBzUV13/R7
|
23
|
+
azECAwEAAaM5MDcwCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAwHQYDVR0OBBYEFMCo
|
24
|
+
Q0fsO/qD4FD6zVoAIBw5ehlOMA0GCSqGSIb3DQEBBQUAA4IBAQCT+qucnHSHu9t0
|
25
|
+
Ntxpnm5gpQPVFz+kI6WCAqUeVlV5cbifH7/T+HKEePe+H3sF1eHG2X0QiXMYDZ26
|
26
|
+
Vgp6S9LCofXhJySOGYO26gcUyGfmkmQ//+YiwpJ0k+uznEM+RBNw/CSpFoXrnKa2
|
27
|
+
39/buzR3VtgPAcAOHb+5+WDIdX6NGgrKFF8udOqQ+rAvsoQXpJXfpfdqoFiOdfCa
|
28
|
+
Bqd6tQGVy0qUttoqMCOTxwMYWzoNs5GFXqtmbXxV6W2F81ipkELVVoWtSvRRkqtx
|
29
|
+
dX2CCcpgG+qXnji1CJyb6Dgm5ICJO/+B8ZKQ5qAYg798KOB7gyddzwRZWImtRoYU
|
30
|
+
kX4sVHCM
|
31
|
+
-----END CERTIFICATE-----
|
32
|
+
|
33
|
+
date: 2008-10-10 00:00:00 +02:00
|
34
|
+
default_executable:
|
35
|
+
dependencies:
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: httparty
|
38
|
+
type: :runtime
|
39
|
+
version_requirement:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: 0.1.3
|
45
|
+
version:
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: hoe
|
48
|
+
type: :development
|
49
|
+
version_requirement:
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.8.0
|
55
|
+
version:
|
56
|
+
description: Free tag extraction from content using Yahoo! search API.
|
57
|
+
email: thorben@fetmab.net
|
58
|
+
executables: []
|
59
|
+
|
60
|
+
extensions: []
|
61
|
+
|
62
|
+
extra_rdoc_files:
|
63
|
+
- History.txt
|
64
|
+
- Manifest.txt
|
65
|
+
- README.txt
|
66
|
+
files:
|
67
|
+
- History.txt
|
68
|
+
- Manifest.txt
|
69
|
+
- README.txt
|
70
|
+
- Rakefile
|
71
|
+
- lib/tags_4_free.rb
|
72
|
+
- spec/spec_helper.rb
|
73
|
+
- spec/tags_4_free_spec.rb
|
74
|
+
has_rdoc: true
|
75
|
+
homepage:
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options:
|
78
|
+
- --main
|
79
|
+
- README.txt
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: "0"
|
87
|
+
version:
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: "0"
|
93
|
+
version:
|
94
|
+
requirements: []
|
95
|
+
|
96
|
+
rubyforge_project: kickassrb
|
97
|
+
rubygems_version: 1.2.0
|
98
|
+
signing_key:
|
99
|
+
specification_version: 2
|
100
|
+
summary: Free tag extraction from content using Yahoo! search API.
|
101
|
+
test_files: []
|
102
|
+
|
metadata.gz.sig
ADDED