asiasearch 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/Gemfile +5 -0
- data/asiasearch.gemspec +21 -0
- data/lib/asiasearch.rb +60 -37
- data/lib/generators/asiasearch/USAGE +0 -0
- data/lib/generators/asiasearch/asiasearch_generator.rb +11 -0
- data/lib/generators/asiasearch/templates/asiasearch.yml.example +8 -0
- metadata +13 -21
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
*.gem
|
data/Gemfile
ADDED
data/asiasearch.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "asiasearch"
|
3
|
+
s.version = "0.0.2"
|
4
|
+
s.date = "2011-05-05"
|
5
|
+
s.authors = ["Yi-Ting Cheng"]
|
6
|
+
s.email = ["xuite.joke@gmail.com"]
|
7
|
+
s.homepage = "https://github.com/xdite/asiasearch"
|
8
|
+
s.summary = "Yahoo Asia Search provides user an interface for automated semantic analysis and language treatment."
|
9
|
+
s.description = "Yahoo Asia Search provides user an interface for automated semantic analysis and language treatment."
|
10
|
+
|
11
|
+
|
12
|
+
s.add_dependency('json_pure')
|
13
|
+
s.add_dependency('mechanize')
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
|
20
|
+
|
21
|
+
end
|
data/lib/asiasearch.rb
CHANGED
@@ -1,44 +1,67 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'hpricot'
|
3
1
|
require 'mechanize'
|
4
2
|
require 'json'
|
5
3
|
|
6
|
-
|
7
|
-
|
8
|
-
def initialize
|
9
|
-
@paths = {
|
10
|
-
:ke => "http://asia.search.yahooapis.com/cas/v1/ke",
|
11
|
-
:ws => "http://asia.search.yahooapis.com/cas/v1/ws",
|
12
|
-
}
|
13
|
-
end
|
14
|
-
|
15
|
-
def ws(appid, content)
|
16
|
-
agent = WWW::Mechanize.new
|
17
|
-
params = {
|
18
|
-
:appid => appid,
|
19
|
-
:content => content,
|
20
|
-
:format => "json"
|
21
|
-
}
|
4
|
+
module AsiaSearch
|
5
|
+
class Error < StandardError; end
|
22
6
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
return result
|
7
|
+
def self.config(environment=RAILS_ENV)
|
8
|
+
@config ||= {}
|
9
|
+
@config[environment] ||= YAML.load(File.open(RAILS_ROOT + '/config/asiasearch.yml').read)[environment]
|
27
10
|
end
|
28
|
-
|
29
|
-
def ke(appid,content,threshold=30,maxnum=10)
|
30
|
-
agent = WWW::Mechanize.new
|
31
|
-
params = {
|
32
|
-
:appid => appid,
|
33
|
-
:content => content,
|
34
|
-
:threshold => threshold,
|
35
|
-
:maxnum => maxnum,
|
36
|
-
:format => "json"
|
37
|
-
}
|
38
11
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
12
|
+
module Base
|
13
|
+
extend ActiveSupport::Concern
|
14
|
+
|
15
|
+
included do
|
16
|
+
end
|
17
|
+
|
18
|
+
module ClassMethods
|
19
|
+
def has_keyword(column_name, options = {})
|
20
|
+
define_method "keyword_content" do
|
21
|
+
self.send(column_name)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
module InstanceMethods
|
27
|
+
attr_reader :threshold, :maxnum
|
28
|
+
|
29
|
+
KE = "http://asia.search.yahooapis.com/cas/v1/ke"
|
30
|
+
WS = "http://asia.search.yahooapis.com/cas/v1/ws"
|
31
|
+
|
32
|
+
def initialize
|
33
|
+
end
|
34
|
+
|
35
|
+
def ws
|
36
|
+
params = {
|
37
|
+
:content => keyword_content,
|
38
|
+
}
|
39
|
+
result = request(WS, params)
|
40
|
+
return result
|
41
|
+
end
|
42
|
+
|
43
|
+
def ke(maxnum=5,threshold=30)
|
44
|
+
params = {
|
45
|
+
:content => keyword_content,
|
46
|
+
:threshold => threshold,
|
47
|
+
:maxnum => maxnum,
|
48
|
+
}
|
49
|
+
result = request(KE, params)
|
50
|
+
return result
|
51
|
+
end
|
52
|
+
|
53
|
+
def request(path, params)
|
54
|
+
agent = Mechanize.new
|
55
|
+
appid = AsiaSearch.config["appid"]
|
56
|
+
|
57
|
+
params.merge!({:appid => appid, :format => "json" })
|
58
|
+
|
59
|
+
agent.post(path,params)
|
60
|
+
data = agent.current_page.body
|
61
|
+
result = JSON.parse(data)
|
62
|
+
return result
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
43
66
|
end
|
44
|
-
end
|
67
|
+
end
|
File without changes
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'rails/generators/base'
|
2
|
+
|
3
|
+
class AsiasearchGenerator < Rails::Generators::Base
|
4
|
+
def self.source_root
|
5
|
+
@source_root ||= File.expand_path('../templates', __FILE__)
|
6
|
+
end
|
7
|
+
|
8
|
+
def copy_config_file
|
9
|
+
copy_file "asiasearch.yml.example", "config/asiasearch.yml.example"
|
10
|
+
end
|
11
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: asiasearch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Yi-Ting Cheng
|
@@ -15,11 +15,11 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2011-05-05 00:00:00 +08:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
|
-
name:
|
22
|
+
name: json_pure
|
23
23
|
prerelease: false
|
24
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
25
|
none: false
|
@@ -33,7 +33,7 @@ dependencies:
|
|
33
33
|
type: :runtime
|
34
34
|
version_requirements: *id001
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
|
-
name:
|
36
|
+
name: mechanize
|
37
37
|
prerelease: false
|
38
38
|
requirement: &id002 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
@@ -46,20 +46,6 @@ dependencies:
|
|
46
46
|
version: "0"
|
47
47
|
type: :runtime
|
48
48
|
version_requirements: *id002
|
49
|
-
- !ruby/object:Gem::Dependency
|
50
|
-
name: mechanize
|
51
|
-
prerelease: false
|
52
|
-
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
-
none: false
|
54
|
-
requirements:
|
55
|
-
- - ">="
|
56
|
-
- !ruby/object:Gem::Version
|
57
|
-
hash: 3
|
58
|
-
segments:
|
59
|
-
- 0
|
60
|
-
version: "0"
|
61
|
-
type: :runtime
|
62
|
-
version_requirements: *id003
|
63
49
|
description: Yahoo Asia Search provides user an interface for automated semantic analysis and language treatment.
|
64
50
|
email:
|
65
51
|
- xuite.joke@gmail.com
|
@@ -70,8 +56,14 @@ extensions: []
|
|
70
56
|
extra_rdoc_files: []
|
71
57
|
|
72
58
|
files:
|
73
|
-
-
|
59
|
+
- .gitignore
|
60
|
+
- Gemfile
|
74
61
|
- README.mkdn
|
62
|
+
- asiasearch.gemspec
|
63
|
+
- lib/asiasearch.rb
|
64
|
+
- lib/generators/asiasearch/USAGE
|
65
|
+
- lib/generators/asiasearch/asiasearch_generator.rb
|
66
|
+
- lib/generators/asiasearch/templates/asiasearch.yml.example
|
75
67
|
has_rdoc: true
|
76
68
|
homepage: https://github.com/xdite/asiasearch
|
77
69
|
licenses: []
|