yacan 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +4 -0
- data/Gemfile +15 -0
- data/Gemfile.lock +30 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +52 -0
- data/VERSION +1 -0
- data/lib/yacan/dependency.rb +68 -0
- data/lib/yacan/keyphrase.rb +35 -0
- data/lib/yacan/morphem.rb +63 -0
- data/lib/yacan/yahoo_api.rb +29 -0
- data/lib/yacan.rb +33 -0
- data/spec/dependency_spec.rb +51 -0
- data/spec/keyphrase_spec.rb +40 -0
- data/spec/morphem_spec.rb +24 -0
- data/spec/spec_helper.rb +12 -0
- data/spec/test_source/dependency.xml +108 -0
- data/spec/test_source/keyphrase.xml +16 -0
- data/spec/yacan_spec.rb +10 -0
- data/spec/yahoo_api_spec.rb +13 -0
- data/yacan.gemspec +84 -0
- metadata +149 -0
data/.document
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
gem 'nokogiri'
|
7
|
+
|
8
|
+
# Add dependencies to develop your gem here.
|
9
|
+
# Include everything needed to run rake, tests, features, etc.
|
10
|
+
group :development do
|
11
|
+
gem "rspec", "~> 2.3.0"
|
12
|
+
gem "bundler", "~> 1.0.0"
|
13
|
+
gem "jeweler", "~> 1.5.2"
|
14
|
+
gem "rcov", ">= 0"
|
15
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
diff-lcs (1.1.2)
|
5
|
+
git (1.2.5)
|
6
|
+
jeweler (1.5.2)
|
7
|
+
bundler (~> 1.0.0)
|
8
|
+
git (>= 1.2.5)
|
9
|
+
rake
|
10
|
+
nokogiri (1.4.4)
|
11
|
+
rake (0.8.7)
|
12
|
+
rcov (0.9.9)
|
13
|
+
rspec (2.3.0)
|
14
|
+
rspec-core (~> 2.3.0)
|
15
|
+
rspec-expectations (~> 2.3.0)
|
16
|
+
rspec-mocks (~> 2.3.0)
|
17
|
+
rspec-core (2.3.1)
|
18
|
+
rspec-expectations (2.3.0)
|
19
|
+
diff-lcs (~> 1.1.2)
|
20
|
+
rspec-mocks (2.3.0)
|
21
|
+
|
22
|
+
PLATFORMS
|
23
|
+
ruby
|
24
|
+
|
25
|
+
DEPENDENCIES
|
26
|
+
bundler (~> 1.0.0)
|
27
|
+
jeweler (~> 1.5.2)
|
28
|
+
nokogiri
|
29
|
+
rcov
|
30
|
+
rspec (~> 2.3.0)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 pokutuna
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= yacan
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Contributing to yacan
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
9
|
+
* Fork the project
|
10
|
+
* Start a feature/bugfix branch
|
11
|
+
* Commit and push until you are happy with your contribution
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2011 pokutuna. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'rake'
|
11
|
+
|
12
|
+
require 'jeweler'
|
13
|
+
Jeweler::Tasks.new do |gem|
|
14
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
15
|
+
gem.name = "yacan"
|
16
|
+
gem.homepage = "http://github.com/pokutuna/yacan"
|
17
|
+
gem.license = "MIT"
|
18
|
+
gem.summary = %Q{YaCan}
|
19
|
+
gem.description = %Q{YaCan is a wrapper for Yahoo Japan Text Analysis Web API}
|
20
|
+
gem.email = "popopopopokutuna@gmail.com"
|
21
|
+
gem.authors = ["pokutuna"]
|
22
|
+
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
23
|
+
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
24
|
+
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
|
25
|
+
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
26
|
+
gem.add_dependency 'nokogiri'
|
27
|
+
end
|
28
|
+
Jeweler::RubygemsDotOrgTasks.new
|
29
|
+
|
30
|
+
require 'rspec/core'
|
31
|
+
require 'rspec/core/rake_task'
|
32
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
33
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
34
|
+
end
|
35
|
+
|
36
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
37
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
38
|
+
spec.rcov = true
|
39
|
+
end
|
40
|
+
|
41
|
+
task :default => :spec
|
42
|
+
|
43
|
+
require 'rake/rdoctask'
|
44
|
+
Rake::RDocTask.new do |rdoc|
|
45
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
46
|
+
|
47
|
+
rdoc.rdoc_dir = 'rdoc'
|
48
|
+
rdoc.title = "yacan #{version}"
|
49
|
+
rdoc.rdoc_files.include('README*')
|
50
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
51
|
+
rdoc.options = ['--charset', 'utf-8', '--line-numbers']
|
52
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module YaCan::Dependency
|
2
|
+
YaCan::DA = YaCan::Dependency
|
3
|
+
@@path = '/DAService/V1/parse'
|
4
|
+
|
5
|
+
def analyze(text)
|
6
|
+
xml = YaCan::YahooAPI.request(@@path, { 'sentence' => text })
|
7
|
+
return Result.new(xml)
|
8
|
+
end
|
9
|
+
|
10
|
+
def parse(text)
|
11
|
+
analyze(text)
|
12
|
+
end
|
13
|
+
|
14
|
+
module_function :analyze, :parse
|
15
|
+
|
16
|
+
class Result
|
17
|
+
def initialize(xml)
|
18
|
+
@xml = xml
|
19
|
+
xml_chunks = Nokogiri::XML(xml).search('Chunk')
|
20
|
+
@chunks = xml_chunks.map{ |c| Chunk.new(c, lambda{ @chunks }) }
|
21
|
+
@morphems = chunks.map{|c| c.morphems}.flatten
|
22
|
+
end
|
23
|
+
|
24
|
+
attr_reader :xml, :chunks, :morphems
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
class Chunk
|
29
|
+
def initialize(xml, chunks)
|
30
|
+
@id = xml.at('Id').text.to_i
|
31
|
+
@dependency = xml.at('Dependency').text.to_i
|
32
|
+
@morphems = xml.search('Morphem').map{ |m| Morphem.new(m) }
|
33
|
+
@chunks = chunks
|
34
|
+
end
|
35
|
+
|
36
|
+
def to_s
|
37
|
+
"#{@id} #{dependency} #{@morphems.map{ |m| m.surface}.join('')}"
|
38
|
+
end
|
39
|
+
|
40
|
+
def depends_on
|
41
|
+
@depends_o ||= @chunks.call.find{ |c| c.id == @dependency }
|
42
|
+
end
|
43
|
+
|
44
|
+
def depends_from
|
45
|
+
@depends_f ||= @chunks.call.find_all{ |c| c.dependency == @id }
|
46
|
+
end
|
47
|
+
|
48
|
+
attr_reader :id, :dependency, :morphems
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
class Morphem
|
53
|
+
def initialize(xml)
|
54
|
+
@surface = xml.at('Surface').text
|
55
|
+
@reading = xml.at('Reading').text
|
56
|
+
@baseform = xml.at('Baseform').text
|
57
|
+
@pos = xml.at('POS').text
|
58
|
+
@feature = xml.at('Feature').text.split(',')
|
59
|
+
end
|
60
|
+
|
61
|
+
def to_s
|
62
|
+
"#{@surface}: #{@feature.join(',')}"
|
63
|
+
end
|
64
|
+
|
65
|
+
attr_reader :surface, :reading, :baseform, :pos, :feature
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module YaCan::Keyphrase
|
2
|
+
@@path = '/KeyphraseService/V1/extract'
|
3
|
+
|
4
|
+
def analyze(text)
|
5
|
+
xml = YaCan::YahooAPI.request(@@path, {'sentence' => text})
|
6
|
+
return Result.new(xml)
|
7
|
+
end
|
8
|
+
|
9
|
+
def extract(text)
|
10
|
+
analyze(text)
|
11
|
+
end
|
12
|
+
|
13
|
+
module_function :analyze, :extract
|
14
|
+
|
15
|
+
class Result
|
16
|
+
def initialize(xml)
|
17
|
+
@xml = xml
|
18
|
+
pairs = Nokogiri::XML(xml).search('Result')
|
19
|
+
@results = pairs.map{ |p|
|
20
|
+
[p.at('Keyphrase').text, p.at('Score').text.to_i]
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
def phrases
|
25
|
+
@phrases ||= @results.map{ |r| r[0]}
|
26
|
+
end
|
27
|
+
|
28
|
+
def scores
|
29
|
+
@scores ||= @results.map{ |r| r[1]}
|
30
|
+
end
|
31
|
+
|
32
|
+
attr_reader :xml, :results
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module YaCan::Morphem
|
2
|
+
YaCan::MA = YaCan::Morphem
|
3
|
+
@@path = '/MAService/V1/parse'
|
4
|
+
|
5
|
+
@@default_params = {
|
6
|
+
'results' => 'ma,uniq',
|
7
|
+
'filter' => (1..13).to_a.join('|'),
|
8
|
+
'ma_response' => 'surface,reading,pos,baseform,feature',
|
9
|
+
'uniq_response' => 'surface,reading,pos,baseform,feature',
|
10
|
+
}
|
11
|
+
|
12
|
+
def analyze(text, params={})
|
13
|
+
params['sentence'] = text
|
14
|
+
params = @@default_params.merge(params)
|
15
|
+
xml = YaCan::YahooAPI.request(@@path, params)
|
16
|
+
return Result.new(xml)
|
17
|
+
end
|
18
|
+
|
19
|
+
def parse(text, params={})
|
20
|
+
analyze(text)
|
21
|
+
end
|
22
|
+
|
23
|
+
module_function :analyze, :parse
|
24
|
+
|
25
|
+
class Result
|
26
|
+
def initialize(xml)
|
27
|
+
@xml = xml
|
28
|
+
wrapped = Nokogiri::XML(xml)
|
29
|
+
@ma_result = MaOrUniq.new(wrapped.at('ma_result'))
|
30
|
+
@uniq_result = MaOrUniq.new(wrapped.at('uniq_result'))
|
31
|
+
end
|
32
|
+
attr_reader :xml, :ma_result, :uniq_result
|
33
|
+
end
|
34
|
+
|
35
|
+
class MaOrUniq
|
36
|
+
def initialize(xml)
|
37
|
+
@total_count = xml.at('total_count').text.to_i rescue nil
|
38
|
+
@filtered_count = xml.at('filtered_count').text.to_i rescue nil
|
39
|
+
@morphems = xml.search('word').map{ |w| Morphem.new(w) } rescue nil
|
40
|
+
end
|
41
|
+
attr_reader :total_count, :filtered_count, :morphems
|
42
|
+
end
|
43
|
+
|
44
|
+
class Morphem
|
45
|
+
def initialize(xml)
|
46
|
+
@count = xml.at('count').text.to_i rescue nil
|
47
|
+
@surface = xml.at('surface').text
|
48
|
+
@reading = xml.at('reading').text rescue nil
|
49
|
+
@pos = xml.at('pos').text
|
50
|
+
@baseform = xml.at('baseform').text rescue nil
|
51
|
+
@feature = xml.at('feature').text.split(',') rescue nil
|
52
|
+
end
|
53
|
+
attr_reader :count, :surface, :reading, :pos, :baseform, :feature
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module YaCan::YahooAPI
|
2
|
+
|
3
|
+
@@host = 'jlp.yahooapis.jp'
|
4
|
+
@@appid = nil
|
5
|
+
|
6
|
+
def appid
|
7
|
+
return @@appid || (raise AppIDUnconfiguredError)
|
8
|
+
end
|
9
|
+
|
10
|
+
def appid=(appid)
|
11
|
+
@@appid = appid
|
12
|
+
end
|
13
|
+
|
14
|
+
def request(path, params={})
|
15
|
+
params['appid'] = appid
|
16
|
+
Net::HTTP::Proxy(YaCan.proxy_host, YaCan.proxy_port).start(@@host){ |http|
|
17
|
+
res = http.post(path, params.map{ |k,v| "#{URI.encode(k)}=#{URI.encode(v)}"}.join('&'))
|
18
|
+
res.body
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
def analyze(*args)
|
23
|
+
raise NotImplementedError
|
24
|
+
end
|
25
|
+
|
26
|
+
module_function :appid, :appid=, :request
|
27
|
+
|
28
|
+
class AppIDUnconfiguredError < StandardError; end
|
29
|
+
end
|
data/lib/yacan.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'rubygems'
|
3
|
+
require 'nokogiri'
|
4
|
+
|
5
|
+
module YaCan
|
6
|
+
$LOAD_PATH.unshift File.dirname(__FILE__)
|
7
|
+
|
8
|
+
require 'yacan/yahoo_api'
|
9
|
+
require 'yacan/dependency'
|
10
|
+
require 'yacan/keyphrase'
|
11
|
+
require 'yacan/morphem'
|
12
|
+
|
13
|
+
@@proxy_host, @@proxy_port = (ENV["http_proxy"] || '').sub(/http:\/\//, '').split(':')
|
14
|
+
|
15
|
+
def proxy_host
|
16
|
+
@@proxy_host
|
17
|
+
end
|
18
|
+
|
19
|
+
def proxy_host=(host)
|
20
|
+
@@proxy_host = host
|
21
|
+
end
|
22
|
+
|
23
|
+
def proxy_port
|
24
|
+
@@proxy_port
|
25
|
+
end
|
26
|
+
|
27
|
+
def proxy_port=(port)
|
28
|
+
@@proxy_port = port
|
29
|
+
end
|
30
|
+
|
31
|
+
include YaCan::YahooAPI
|
32
|
+
module_function :appid, :appid=, :proxy_host, :proxy_host=, :proxy_port, :proxy_port=
|
33
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
3
|
+
|
4
|
+
describe "Dependency" do
|
5
|
+
before(:all) do
|
6
|
+
YaCan.appid = ENV['YAHOO_API_APPID']
|
7
|
+
@phrase = 'うちの庭には二羽鶏が居ます。'
|
8
|
+
@xml = File.open(File.expand_path(File.dirname(__FILE__) + '/test_source/dependency.xml')).read
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should analyze sentence' do
|
12
|
+
YaCan::YahooAPI.stub!(:request).and_return @xml
|
13
|
+
res = YaCan::Dependency.analyze(@phrase)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should have alias method :parse' do
|
17
|
+
YaCan::Dependency.parse(@phrase).chunks.to_s.should == YaCan::Dependency.analyze(@phrase).chunks.to_s
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should have module name shortened' do
|
21
|
+
YaCan::Dependency.should == YaCan::DA
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "Result" do
|
25
|
+
before(:all) do
|
26
|
+
@result = YaCan::Dependency::Result.new(@xml)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should have chunks' do
|
30
|
+
@result.chunks.should have(4).items
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should be gettable a chunk from dependency' do
|
34
|
+
@result.chunks.first.depends_on.id.should == 1
|
35
|
+
@result.chunks.last.depends_on.should == nil
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should be gettable chunks from a chunk depends from' do
|
39
|
+
@result.chunks.last.depends_from.map{ |c| c.id }.should == [1,2]
|
40
|
+
@result.chunks.first.depends_from.should be_empty
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
3
|
+
|
4
|
+
describe 'Keyphrase' do
|
5
|
+
|
6
|
+
before(:all) do
|
7
|
+
YaCan.appid = ENV['YAHOO_API_APPID']
|
8
|
+
@phrase = '東京ミッドタウンから国立新美術館まで歩いて5分で着きます。'
|
9
|
+
@xml = File.open(File.expand_path(File.dirname(__FILE__) + '/test_source/keyphrase.xml')).read
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should have alias method :extract' do
|
13
|
+
YaCan::YahooAPI.stub!(:request).and_return @xml
|
14
|
+
YaCan::Keyphrase.extract(@phrase).results.should == YaCan::Keyphrase.analyze(@phrase).results
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "Result" do
|
18
|
+
before(:all) do
|
19
|
+
@res = YaCan::Keyphrase::Result.new(@xml)
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should analyze sentence' do
|
23
|
+
@res.results.should have(3).items
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should take phrases' do
|
27
|
+
@res.phrases.sort.should == ["国立新美術館", "東京ミッドタウン", "5分"].sort
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
|
40
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
3
|
+
|
4
|
+
describe "Morphem" do
|
5
|
+
before(:all) do
|
6
|
+
YaCan.appid = ENV['YAHOO_API_APPID']
|
7
|
+
@phrase = '庭には二羽鶏がいる。'
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should analyze sentence' do
|
11
|
+
res = YaCan::Morphem.analyze(@phrase)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should take params' do
|
15
|
+
res = YaCan::Morphem.analyze(@phrase, {'results' => 'ma', 'filter' => '9'})
|
16
|
+
res.ma_result.total_count.should == 9
|
17
|
+
res.ma_result.filtered_count.should == 3
|
18
|
+
res.uniq_result.total_count.should == nil
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should have module name shortened' do
|
22
|
+
YaCan::MA.should == YaCan::Morphem
|
23
|
+
end
|
24
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'yacan'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
|
12
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8" ?>
|
2
|
+
<ResultSet xsi:schemaLocation="urn:yahoo:jp:jlp:DAService http://jlp.yahooapis.jp/DAService/V1/parseResponse.xsd">
|
3
|
+
<Result>
|
4
|
+
<ChunkList>
|
5
|
+
<Chunk>
|
6
|
+
<Id>0</Id>
|
7
|
+
<Dependency>1</Dependency>
|
8
|
+
<MorphemList>
|
9
|
+
<Morphem>
|
10
|
+
<Surface>うち</Surface>
|
11
|
+
<Reading>うち</Reading>
|
12
|
+
<Baseform>うち</Baseform>
|
13
|
+
<POS>名詞</POS>
|
14
|
+
<Feature>名詞,地名町名,*,うち,うち,うち</Feature>
|
15
|
+
</Morphem>
|
16
|
+
<Morphem>
|
17
|
+
<Surface>の</Surface>
|
18
|
+
<Reading>の</Reading>
|
19
|
+
<Baseform>の</Baseform>
|
20
|
+
<POS>助詞</POS>
|
21
|
+
<Feature>助詞,助詞連体化,*,の,の,の</Feature>
|
22
|
+
</Morphem>
|
23
|
+
</MorphemList>
|
24
|
+
</Chunk>
|
25
|
+
<Chunk>
|
26
|
+
<Id>1</Id>
|
27
|
+
<Dependency>3</Dependency>
|
28
|
+
<MorphemList>
|
29
|
+
<Morphem>
|
30
|
+
<Surface>庭</Surface>
|
31
|
+
<Reading>にわ</Reading>
|
32
|
+
<Baseform>庭</Baseform>
|
33
|
+
<POS>名詞</POS>
|
34
|
+
<Feature>名詞,名詞場所,*,庭,にわ,庭</Feature>
|
35
|
+
</Morphem>
|
36
|
+
<Morphem>
|
37
|
+
<Surface>に</Surface>
|
38
|
+
<Reading>に</Reading>
|
39
|
+
<Baseform>に</Baseform>
|
40
|
+
<POS>助詞</POS>
|
41
|
+
<Feature>助詞,格助詞,*,に,に,に</Feature>
|
42
|
+
</Morphem>
|
43
|
+
<Morphem>
|
44
|
+
<Surface>は</Surface>
|
45
|
+
<Reading>は</Reading>
|
46
|
+
<Baseform>は</Baseform>
|
47
|
+
<POS>助詞</POS>
|
48
|
+
<Feature>助詞,係助詞,*,は,は,は</Feature>
|
49
|
+
</Morphem>
|
50
|
+
</MorphemList>
|
51
|
+
</Chunk>
|
52
|
+
<Chunk>
|
53
|
+
<Id>2</Id>
|
54
|
+
<Dependency>3</Dependency>
|
55
|
+
<MorphemList>
|
56
|
+
<Morphem>
|
57
|
+
<Surface>二羽</Surface>
|
58
|
+
<Reading>2わ</Reading>
|
59
|
+
<Baseform>2羽</Baseform>
|
60
|
+
<POS>接尾辞</POS>
|
61
|
+
<Feature>接尾辞,助数,*,二羽,2わ,2羽</Feature>
|
62
|
+
</Morphem>
|
63
|
+
<Morphem>
|
64
|
+
<Surface>鶏</Surface>
|
65
|
+
<Reading>にわとり</Reading>
|
66
|
+
<Baseform>鶏</Baseform>
|
67
|
+
<POS>名詞</POS>
|
68
|
+
<Feature>名詞,名詞,*,鶏,にわとり,鶏</Feature>
|
69
|
+
</Morphem>
|
70
|
+
<Morphem>
|
71
|
+
<Surface>が</Surface>
|
72
|
+
<Reading>が</Reading>
|
73
|
+
<Baseform>が</Baseform>
|
74
|
+
<POS>助詞</POS>
|
75
|
+
<Feature>助詞,格助詞,*,が,が,が</Feature>
|
76
|
+
</Morphem>
|
77
|
+
</MorphemList>
|
78
|
+
</Chunk>
|
79
|
+
<Chunk>
|
80
|
+
<Id>3</Id>
|
81
|
+
<Dependency>-1</Dependency>
|
82
|
+
<MorphemList>
|
83
|
+
<Morphem>
|
84
|
+
<Surface>い</Surface>
|
85
|
+
<Reading>い</Reading>
|
86
|
+
<Baseform>い</Baseform>
|
87
|
+
<POS>動詞</POS>
|
88
|
+
<Feature>動詞,一段,未然ウ接続,い,い,い</Feature>
|
89
|
+
</Morphem>
|
90
|
+
<Morphem>
|
91
|
+
<Surface>ます</Surface>
|
92
|
+
<Reading>ま</Reading>
|
93
|
+
<Baseform>ま</Baseform>
|
94
|
+
<POS>助動詞</POS>
|
95
|
+
<Feature>助動詞,助動詞ます,基本形,ます,ま,ま</Feature>
|
96
|
+
</Morphem>
|
97
|
+
<Morphem>
|
98
|
+
<Surface>。</Surface>
|
99
|
+
<Reading>。</Reading>
|
100
|
+
<Baseform>。</Baseform>
|
101
|
+
<POS>特殊</POS>
|
102
|
+
<Feature>特殊,句点,*,。,。,。</Feature>
|
103
|
+
</Morphem>
|
104
|
+
</MorphemList>
|
105
|
+
</Chunk>
|
106
|
+
</ChunkList>
|
107
|
+
</Result>
|
108
|
+
</ResultSet>
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8" ?>
|
2
|
+
<ResultSet xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:yahoo:jp:jlp:KeyphraseService"
|
3
|
+
xsi:schemaLocation="urn:yahoo:jp:jlp:KeyphraseService http://jlp.yahooapis.jp/KeyphraseService/V1/extract.xsd">
|
4
|
+
<Result>
|
5
|
+
<Keyphrase>東京ミッドタウン</Keyphrase>
|
6
|
+
<Score>100</Score>
|
7
|
+
</Result>
|
8
|
+
<Result>
|
9
|
+
<Keyphrase>国立新美術館</Keyphrase>
|
10
|
+
<Score>54</Score>
|
11
|
+
</Result>
|
12
|
+
<Result>
|
13
|
+
<Keyphrase>5分</Keyphrase>
|
14
|
+
<Score>9</Score>
|
15
|
+
</Result>
|
16
|
+
</ResultSet>
|
data/spec/yacan_spec.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe 'YahooAPI' do
|
4
|
+
it 'should set&get appid' do
|
5
|
+
YaCan::YahooAPI.appid = 'yahoo_api_spec'
|
6
|
+
YaCan::YahooAPI.appid.should == 'yahoo_api_spec'
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should raise exception when appid is nil' do
|
10
|
+
YaCan::YahooAPI.appid = nil
|
11
|
+
expect{ YaCan::YahooAPI.appid }.to raise_error(YaCan::YahooAPI::AppIDUnconfiguredError)
|
12
|
+
end
|
13
|
+
end
|
data/yacan.gemspec
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{yacan}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["pokutuna"]
|
12
|
+
s.date = %q{2011-04-30}
|
13
|
+
s.description = %q{YaCan is a wrapper for Yahoo Japan Text Analysis Web API}
|
14
|
+
s.email = %q{popopopopokutuna@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".rspec",
|
22
|
+
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
24
|
+
"LICENSE.txt",
|
25
|
+
"README.rdoc",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"lib/yacan.rb",
|
29
|
+
"lib/yacan/dependency.rb",
|
30
|
+
"lib/yacan/keyphrase.rb",
|
31
|
+
"lib/yacan/morphem.rb",
|
32
|
+
"lib/yacan/yahoo_api.rb",
|
33
|
+
"spec/dependency_spec.rb",
|
34
|
+
"spec/keyphrase_spec.rb",
|
35
|
+
"spec/morphem_spec.rb",
|
36
|
+
"spec/spec_helper.rb",
|
37
|
+
"spec/test_source/dependency.xml",
|
38
|
+
"spec/test_source/keyphrase.xml",
|
39
|
+
"spec/yacan_spec.rb",
|
40
|
+
"spec/yahoo_api_spec.rb",
|
41
|
+
"yacan.gemspec"
|
42
|
+
]
|
43
|
+
s.homepage = %q{http://github.com/pokutuna/yacan}
|
44
|
+
s.licenses = ["MIT"]
|
45
|
+
s.require_paths = ["lib"]
|
46
|
+
s.rubygems_version = %q{1.7.2}
|
47
|
+
s.summary = %q{YaCan}
|
48
|
+
s.test_files = [
|
49
|
+
"spec/dependency_spec.rb",
|
50
|
+
"spec/keyphrase_spec.rb",
|
51
|
+
"spec/morphem_spec.rb",
|
52
|
+
"spec/spec_helper.rb",
|
53
|
+
"spec/yacan_spec.rb",
|
54
|
+
"spec/yahoo_api_spec.rb"
|
55
|
+
]
|
56
|
+
|
57
|
+
if s.respond_to? :specification_version then
|
58
|
+
s.specification_version = 3
|
59
|
+
|
60
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
61
|
+
s.add_runtime_dependency(%q<nokogiri>, [">= 0"])
|
62
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
|
63
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
64
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
65
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
66
|
+
s.add_runtime_dependency(%q<nokogiri>, [">= 0"])
|
67
|
+
else
|
68
|
+
s.add_dependency(%q<nokogiri>, [">= 0"])
|
69
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
70
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
71
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
72
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
73
|
+
s.add_dependency(%q<nokogiri>, [">= 0"])
|
74
|
+
end
|
75
|
+
else
|
76
|
+
s.add_dependency(%q<nokogiri>, [">= 0"])
|
77
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
78
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
79
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
80
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
81
|
+
s.add_dependency(%q<nokogiri>, [">= 0"])
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
metadata
ADDED
@@ -0,0 +1,149 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: yacan
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.1.0
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- pokutuna
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-04-30 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: nokogiri
|
17
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: "0"
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *id001
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: rspec
|
28
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.3.0
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *id002
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: bundler
|
39
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ~>
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: 1.0.0
|
45
|
+
type: :development
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: *id003
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: jeweler
|
50
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ~>
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 1.5.2
|
56
|
+
type: :development
|
57
|
+
prerelease: false
|
58
|
+
version_requirements: *id004
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: rcov
|
61
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: "0"
|
67
|
+
type: :development
|
68
|
+
prerelease: false
|
69
|
+
version_requirements: *id005
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: nokogiri
|
72
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: "0"
|
78
|
+
type: :runtime
|
79
|
+
prerelease: false
|
80
|
+
version_requirements: *id006
|
81
|
+
description: YaCan is a wrapper for Yahoo Japan Text Analysis Web API
|
82
|
+
email: popopopopokutuna@gmail.com
|
83
|
+
executables: []
|
84
|
+
|
85
|
+
extensions: []
|
86
|
+
|
87
|
+
extra_rdoc_files:
|
88
|
+
- LICENSE.txt
|
89
|
+
- README.rdoc
|
90
|
+
files:
|
91
|
+
- .document
|
92
|
+
- .rspec
|
93
|
+
- Gemfile
|
94
|
+
- Gemfile.lock
|
95
|
+
- LICENSE.txt
|
96
|
+
- README.rdoc
|
97
|
+
- Rakefile
|
98
|
+
- VERSION
|
99
|
+
- lib/yacan.rb
|
100
|
+
- lib/yacan/dependency.rb
|
101
|
+
- lib/yacan/keyphrase.rb
|
102
|
+
- lib/yacan/morphem.rb
|
103
|
+
- lib/yacan/yahoo_api.rb
|
104
|
+
- spec/dependency_spec.rb
|
105
|
+
- spec/keyphrase_spec.rb
|
106
|
+
- spec/morphem_spec.rb
|
107
|
+
- spec/spec_helper.rb
|
108
|
+
- spec/test_source/dependency.xml
|
109
|
+
- spec/test_source/keyphrase.xml
|
110
|
+
- spec/yacan_spec.rb
|
111
|
+
- spec/yahoo_api_spec.rb
|
112
|
+
- yacan.gemspec
|
113
|
+
homepage: http://github.com/pokutuna/yacan
|
114
|
+
licenses:
|
115
|
+
- MIT
|
116
|
+
post_install_message:
|
117
|
+
rdoc_options: []
|
118
|
+
|
119
|
+
require_paths:
|
120
|
+
- lib
|
121
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
122
|
+
none: false
|
123
|
+
requirements:
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
hash: -4218313778255877313
|
127
|
+
segments:
|
128
|
+
- 0
|
129
|
+
version: "0"
|
130
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
|
+
none: false
|
132
|
+
requirements:
|
133
|
+
- - ">="
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: "0"
|
136
|
+
requirements: []
|
137
|
+
|
138
|
+
rubyforge_project:
|
139
|
+
rubygems_version: 1.7.2
|
140
|
+
signing_key:
|
141
|
+
specification_version: 3
|
142
|
+
summary: YaCan
|
143
|
+
test_files:
|
144
|
+
- spec/dependency_spec.rb
|
145
|
+
- spec/keyphrase_spec.rb
|
146
|
+
- spec/morphem_spec.rb
|
147
|
+
- spec/spec_helper.rb
|
148
|
+
- spec/yacan_spec.rb
|
149
|
+
- spec/yahoo_api_spec.rb
|