yapi 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 03ac4ce5d221b1d3c0bb68f8661671a776bea1a2
4
+ data.tar.gz: ed302f069050ade5744f7f2bf627d40e16dcb757
5
+ SHA512:
6
+ metadata.gz: ebb817c9791c97a2dabd23360892c8c8f80be1ebf69f3b7c84794536a0c63fbecc369fcc5542e28a7a274e12342d61e44ae542c1038c68191d96f8018e01e229
7
+ data.tar.gz: e4ad62f7ec83c08dae12182c6a8ee503e63e6f8b3eedd1ac3fd989dd4b632b5b846e349da3e1caa98b40e3a3d82a498dd7e170544f5f36e54a14d5ae995f85c9
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.project ADDED
@@ -0,0 +1,17 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <projectDescription>
3
+ <name>yapi</name>
4
+ <comment></comment>
5
+ <projects>
6
+ </projects>
7
+ <buildSpec>
8
+ <buildCommand>
9
+ <name>org.eclipse.dltk.core.scriptbuilder</name>
10
+ <arguments>
11
+ </arguments>
12
+ </buildCommand>
13
+ </buildSpec>
14
+ <natures>
15
+ <nature>org.eclipse.dltk.ruby.core.nature</nature>
16
+ </natures>
17
+ </projectDescription>
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in yapi.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,85 @@
1
+ # Yapi
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/yapi`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ rubyで書かれたYahooAPIのクライアントライブラリです。
6
+ apiについての説明は[ドキュメント一覧](http://developer.yahoo.co.jp/sitemap/)へ
7
+ 公式サイトは[Yahoo!デベロッパーネットワーク](http://developer.yahoo.co.jp/)
8
+ 質問等ありましたらTwitter:[@flum_](https://twitter.com/flum_)までお願いします。
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'yapi'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install yapi
25
+
26
+ ## Usage
27
+
28
+ まず、公式サイトからAPIキーを取得してください。
29
+ 形態素解析する場合はrequireしてから
30
+
31
+ ```
32
+ maservice = Yapi::MAService.new(api_key)
33
+ puts maservice.parse "庭には2羽にわとりがいる"
34
+ ```
35
+
36
+ たったこれだけで形態素解析ができます。
37
+ 詳しいパラメータ等は、公式サイトを参照して、
38
+ ```
39
+ maservice.configure config={
40
+ :results=>"uniq"
41
+ }
42
+ ```
43
+ の様な感じでセットしてください。
44
+
45
+ ##Supported APIs
46
+
47
+ >テキスト解析
48
+
49
+ >>日本語形態素解析
50
+
51
+ >>かな漢字変換
52
+
53
+ >>ルビ振り
54
+
55
+ >>校正支援
56
+
57
+ >>日本語係り受け解析
58
+
59
+ >>キーフレーズ抽出
60
+
61
+ >地図・地域情報
62
+
63
+ >>Yahoo!ジオコーダAPI
64
+
65
+ >>Yahoo!リバースジオコーダAPI
66
+
67
+ >気象情報API
68
+
69
+ >場所情報API
70
+
71
+ >コンテンツジオコーダAPI
72
+
73
+ ## Development
74
+
75
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
76
+
77
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
78
+
79
+ ## Contributing
80
+
81
+ 1. Fork it ( https://github.com/[my-github-username]/yapi/fork )
82
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
83
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
84
+ 4. Push to the branch (`git push origin my-new-feature`)
85
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "yapi"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/example/yapi.rb ADDED
@@ -0,0 +1,43 @@
1
+ # Coding: UTF-8
2
+ lib = File.expand_path('../../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'yapi'
5
+
6
+ api_key = ""
7
+
8
+ maservice = Yapi::MAService.new(api_key)
9
+ maservice.configure config={
10
+ :results=>"uniq"
11
+ }
12
+ parse = maservice.parse "庭には2羽にわとりがいる"
13
+ puts parse
14
+
15
+ jimservice = Yapi::JIMService.new(api_key)
16
+ puts jimservice.conversion "きょうはいいてんきです"
17
+
18
+ furiganasevice = Yapi::FuriganaService.new(api_key)
19
+ puts furiganasevice.furigana "今日はいい天気ですね"
20
+
21
+ kouseiservice = Yapi::KouseiService.new(api_key)
22
+ puts kouseiservice.kousei "人事移動小形飛行機"
23
+
24
+ daservice = Yapi::DAService.new(api_key)
25
+ puts daservice.parse "うちの庭には2羽にわとりがいる"
26
+
27
+ keyphrase = Yapi::KeyphraseService.new(api_key)
28
+ puts keyphrase.extract "山梨県と北海道に行きたい"
29
+
30
+ geocoder = Yapi::OpenLocalPlatform::GeoCoder.new(api_key)
31
+ puts geocoder.geoCoder
32
+
33
+ regeocoder = Yapi::OpenLocalPlatform::ReverseGeoCoder.new(api_key)
34
+ puts regeocoder.geoCoder 35.68381981,139.77456498
35
+
36
+ weather = Yapi::Weather.new(api_key)
37
+ puts weather.place("139.732293,35.663613")
38
+
39
+ contentsgeocoder = Yapi::OpenLocalPlatform::ContentsGeoCoder.new(api_key)
40
+ puts contentsgeocoder.contentsGeoCoder "秋葉原"
41
+
42
+ peaceinfo = Yapi::PlaceInfo.new(api_key)
43
+ puts peaceinfo.get "35.66521320007564","139.7300114513391"
@@ -0,0 +1,31 @@
1
+ require 'active_support'
2
+ require 'active_support/core_ext'
3
+
4
+ module Yapi
5
+ class YahooError < Exception; end
6
+
7
+ class Client
8
+ attr_accessor :api_key
9
+
10
+ def initialize(api_key)
11
+ self.api_key = api_key
12
+ end
13
+
14
+ def get_api_key
15
+ return self.api_key
16
+ end
17
+
18
+ def build_url(options = {})
19
+ url = ""
20
+ options.each do |key, value|
21
+ url << "&" << key.id2name << "=" << value
22
+ end
23
+ return URI.escape(url)
24
+ end
25
+
26
+ def xml_to_json xml
27
+ doc = Hash.from_xml xml
28
+ return JSON.parse(doc.to_json, symbolize_names: true)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,25 @@
1
+ require "yapi/client"
2
+ require 'open-uri'
3
+ require 'json'
4
+
5
+ module Yapi
6
+ class DAService
7
+ attr_accessor :config
8
+
9
+ def initialize(api_key)
10
+ @client = Client.new(api_key)
11
+ self.config = {}
12
+ end
13
+
14
+ def configure(options = {})
15
+ options.each do |key, value|
16
+ self.config[key] = value
17
+ end
18
+ end
19
+
20
+ def parse sentence
21
+ req_url = "http://jlp.yahooapis.jp/DAService/V1/parse?appid=#{@client.get_api_key}#{@client.build_url(self.config)}&sentence=#{sentence}"
22
+ return @client.xml_to_json(open(URI.encode(req_url)).read)[:ResultSet][:Result]
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ require "yapi/client"
2
+ require 'open-uri'
3
+ require 'json'
4
+
5
+ module Yapi
6
+ class FuriganaService
7
+ attr_accessor :config
8
+
9
+ def initialize(api_key)
10
+ @client = Client.new(api_key)
11
+ self.config = {}
12
+ end
13
+
14
+ def configure(options = {})
15
+ options.each do |key, value|
16
+ self.config[key] = value
17
+ end
18
+ end
19
+
20
+ def furigana sentence
21
+ req_url = "http://jlp.yahooapis.jp/FuriganaService/V1/furigana?appid=#{@client.get_api_key}#{@client.build_url(self.config)}&sentence=#{sentence}"
22
+ return @client.xml_to_json(open(URI.encode(req_url)).read)[:ResultSet][:Result]
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ require "yapi/client"
2
+ require 'open-uri'
3
+ require 'json'
4
+
5
+ module Yapi
6
+ class JIMService
7
+ attr_accessor :config
8
+
9
+ def initialize(api_key)
10
+ @client = Client.new(api_key)
11
+ self.config = {}
12
+ end
13
+
14
+ def configure(options = {})
15
+ options.each do |key, value|
16
+ self.config[key] = value
17
+ end
18
+ end
19
+
20
+ def conversion sentence
21
+ req_url = "http://jlp.yahooapis.jp/JIMService/V1/conversion?appid=#{@client.get_api_key}#{@client.build_url(self.config)}&sentence=#{sentence}"
22
+ return @client.xml_to_json(open(URI.encode(req_url)).read)[:ResultSet][:Result]
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ require "yapi/client"
2
+ require 'open-uri'
3
+ require 'json'
4
+
5
+ module Yapi
6
+ class KeyphraseService
7
+ attr_accessor :config
8
+
9
+ def initialize(api_key)
10
+ @client = Client.new(api_key)
11
+ self.config = {}
12
+ end
13
+
14
+ def configure(options = {})
15
+ options.each do |key, value|
16
+ self.config[key] = value
17
+ end
18
+ end
19
+
20
+ def extract sentence
21
+ req_url = "http://jlp.yahooapis.jp/KeyphraseService/V1/extract?appid=#{@client.get_api_key}#{@client.build_url(self.config)}&sentence=#{sentence}"
22
+ return @client.xml_to_json(open(URI.encode(req_url)).read)[:ResultSet][:Result]
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ require "yapi/client"
2
+ require 'open-uri'
3
+ require 'json'
4
+
5
+ module Yapi
6
+ class KouseiService
7
+ attr_accessor :config
8
+
9
+ def initialize(api_key)
10
+ @client = Client.new(api_key)
11
+ self.config = {}
12
+ end
13
+
14
+ def configure(options = {})
15
+ options.each do |key, value|
16
+ self.config[key] = value
17
+ end
18
+ end
19
+
20
+ def kousei sentence
21
+ req_url = "http://jlp.yahooapis.jp/KouseiService/V1/kousei?appid=#{@client.get_api_key}#{@client.build_url(self.config)}&sentence=#{sentence}"
22
+ return @client.xml_to_json(open(URI.encode(req_url)).read)[:ResultSet][:Result]
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ require "yapi/client"
2
+ require 'open-uri'
3
+ require 'json'
4
+
5
+ module Yapi
6
+ class MAService
7
+ attr_accessor :config
8
+
9
+ def initialize(api_key)
10
+ @client = Client.new(api_key)
11
+ self.config = {}
12
+ end
13
+
14
+ def configure(options = {})
15
+ options.each do |key, value|
16
+ self.config[key] = value
17
+ end
18
+ end
19
+
20
+ def parse sentence
21
+ req_url = "http://jlp.yahooapis.jp/MAService/V1/parse?appid=#{@client.get_api_key}#{@client.build_url(self.config)}&sentence=#{sentence}"
22
+ return @client.xml_to_json(open(URI.encode(req_url)).read)[:ResultSet]
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,67 @@
1
+ require "yapi/client"
2
+ require 'open-uri'
3
+ require 'json'
4
+
5
+ module Yapi
6
+ class OpenLocalPlatform
7
+ class GeoCoder
8
+ attr_accessor :config
9
+
10
+ def initialize(api_key)
11
+ @client = Client.new(api_key)
12
+ self.config = {}
13
+ end
14
+
15
+ def configure(options = {})
16
+ options.each do |key, value|
17
+ self.config[key] = value
18
+ end
19
+ end
20
+
21
+ def geoCoder
22
+ req_url = "http://geo.search.olp.yahooapis.jp/OpenLocalPlatform/V1/geoCoder?appid=#{@client.get_api_key}#{@client.build_url(self.config)}"
23
+ return @client.xml_to_json(open(URI.encode(req_url)).read)
24
+ end
25
+ end
26
+
27
+ class ReverseGeoCoder
28
+ attr_accessor :config
29
+
30
+ def initialize(api_key)
31
+ @client = Client.new(api_key)
32
+ self.config = {}
33
+ end
34
+
35
+ def configure(options = {})
36
+ options.each do |key, value|
37
+ self.config[key] = value
38
+ end
39
+ end
40
+
41
+ def geoCoder lat,lon
42
+ req_url = "http://reverse.search.olp.yahooapis.jp/OpenLocalPlatform/V1/reverseGeoCoder?appid=#{@client.get_api_key}#{@client.build_url(self.config)}&lat=#{lat}&lon=#{lon}"
43
+ return @client.xml_to_json(open(URI.encode(req_url)).read)
44
+ end
45
+ end
46
+
47
+ class ContentsGeoCoder
48
+ attr_accessor :config
49
+
50
+ def initialize(api_key)
51
+ @client = Client.new(api_key)
52
+ self.config = {}
53
+ end
54
+
55
+ def configure(options = {})
56
+ options.each do |key, value|
57
+ self.config[key] = value
58
+ end
59
+ end
60
+
61
+ def contentsGeoCoder query
62
+ req_url = "http://contents.search.olp.yahooapis.jp/OpenLocalPlatform/V1/contentsGeoCoder?appid=#{@client.get_api_key}#{@client.build_url(self.config)}&query=#{query}"
63
+ return @client.xml_to_json(open(URI.encode(req_url)).read)
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,25 @@
1
+ require "yapi/client"
2
+ require 'open-uri'
3
+ require 'json'
4
+
5
+ module Yapi
6
+ class PlaceInfo
7
+ attr_accessor :config
8
+
9
+ def initialize(api_key)
10
+ @client = Client.new(api_key)
11
+ self.config = {}
12
+ end
13
+
14
+ def configure(options = {})
15
+ options.each do |key, value|
16
+ self.config[key] = value
17
+ end
18
+ end
19
+
20
+ def get lat,lon
21
+ req_url = "http://placeinfo.olp.yahooapis.jp/V1/get?appid=#{@client.get_api_key}#{@client.build_url(self.config)}&output=xml&lat=#{lat}&lon=#{lon}"
22
+ return @client.xml_to_json(open(URI.encode(req_url)).read)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,3 @@
1
+ module Yapi
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,25 @@
1
+ require "yapi/client"
2
+ require 'open-uri'
3
+ require 'json'
4
+
5
+ module Yapi
6
+ class Weather
7
+ attr_accessor :config
8
+
9
+ def initialize(api_key)
10
+ @client = Client.new(api_key)
11
+ self.config = {}
12
+ end
13
+
14
+ def configure(options = {})
15
+ options.each do |key, value|
16
+ self.config[key] = value
17
+ end
18
+ end
19
+
20
+ def place coordinates
21
+ req_url = "http://weather.olp.yahooapis.jp/v1/place?appid=#{@client.get_api_key}#{@client.build_url(self.config)}&coordinates=#{coordinates}"
22
+ return @client.xml_to_json(open(URI.encode(req_url)).read)
23
+ end
24
+ end
25
+ end
data/lib/yapi.rb ADDED
@@ -0,0 +1,11 @@
1
+ require "yapi/version"
2
+ require "yapi/client"
3
+ require "yapi/da_service"
4
+ require "yapi/furigana_service"
5
+ require "yapi/jim_service"
6
+ require "yapi/keyphrase_service"
7
+ require "yapi/kousei_service"
8
+ require "yapi/ma_service"
9
+ require "yapi/open_local_platform"
10
+ require "yapi/placeinfo"
11
+ require "yapi/weather"
data/yapi.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'yapi/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "yapi"
8
+ spec.version = Yapi::VERSION
9
+ spec.authors = ["flum1025"]
10
+ spec.email = ["flum.1025@gmail.com"]
11
+
12
+ spec.summary = %q{Yahoo Api Library.}
13
+ spec.description = spec.summary
14
+ spec.homepage = "https://github.com/flum1025/Yapi"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.9"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+
24
+ spec.add_dependency 'activesupport'
25
+ spec.add_dependency 'json'
26
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yapi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - flum1025
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-03-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activesupport
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: json
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Yahoo Api Library.
70
+ email:
71
+ - flum.1025@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - .project
78
+ - .travis.yml
79
+ - Gemfile
80
+ - README.md
81
+ - Rakefile
82
+ - bin/console
83
+ - bin/setup
84
+ - example/yapi.rb
85
+ - lib/yapi.rb
86
+ - lib/yapi/client.rb
87
+ - lib/yapi/da_service.rb
88
+ - lib/yapi/furigana_service.rb
89
+ - lib/yapi/jim_service.rb
90
+ - lib/yapi/keyphrase_service.rb
91
+ - lib/yapi/kousei_service.rb
92
+ - lib/yapi/ma_service.rb
93
+ - lib/yapi/open_local_platform.rb
94
+ - lib/yapi/placeinfo.rb
95
+ - lib/yapi/version.rb
96
+ - lib/yapi/weather.rb
97
+ - yapi.gemspec
98
+ homepage: https://github.com/flum1025/Yapi
99
+ licenses: []
100
+ metadata: {}
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - '>='
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubyforge_project:
117
+ rubygems_version: 2.5.2
118
+ signing_key:
119
+ specification_version: 4
120
+ summary: Yahoo Api Library.
121
+ test_files: []