ojad 0.0.0 → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -0
- data/Gemfile.lock +23 -1
- data/exe/ojad +8 -0
- data/lib/ojad/cli.rb +28 -0
- data/lib/ojad/client.rb +51 -0
- data/lib/ojad/response.rb +25 -0
- data/lib/ojad/result.rb +39 -0
- data/lib/ojad/verb_presenter.rb +87 -0
- data/lib/ojad/verbs.rb +29 -0
- data/lib/ojad/version.rb +3 -1
- data/ojad.gemspec +3 -0
- metadata +40 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a9bd49fd888f3b51311edb1024c3ac1214157467236ebf97bfb693a886622216
|
4
|
+
data.tar.gz: a3c0c676cb31c63e606023258d3b6b31a494195d2ed5d6379aa61b9b1aadf9ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f6cff41db7d42e6d3d48925a279763e578eff4526b0838a0e1255cd4b93d4bf2938e1254cb4637199267495a61dc5c1c0c6c26a8ea20780b88abe244fa1bd21
|
7
|
+
data.tar.gz: f517b184df1cf232c049e8d288794f8e1416c3bb32afffc4a0e523de7cb5c236be2c7027ba0955ef94cf8b28bb9f19100029edb5499d279bca480e08b334577e
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -2,16 +2,35 @@ PATH
|
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
4
|
ojad (0.0.0)
|
5
|
+
http
|
6
|
+
nokogiri
|
5
7
|
|
6
8
|
GEM
|
7
9
|
remote: https://rubygems.org/
|
8
10
|
specs:
|
11
|
+
addressable (2.6.0)
|
12
|
+
public_suffix (>= 2.0.2, < 4.0)
|
9
13
|
coderay (1.1.2)
|
10
14
|
diff-lcs (1.3)
|
15
|
+
domain_name (0.5.20180417)
|
16
|
+
unf (>= 0.0.5, < 1.0.0)
|
17
|
+
http (4.0.5)
|
18
|
+
addressable (~> 2.3)
|
19
|
+
http-cookie (~> 1.0)
|
20
|
+
http-form_data (~> 2.0)
|
21
|
+
http_parser.rb (~> 0.6.0)
|
22
|
+
http-cookie (1.0.3)
|
23
|
+
domain_name (~> 0.5)
|
24
|
+
http-form_data (2.1.1)
|
25
|
+
http_parser.rb (0.6.0)
|
11
26
|
method_source (0.9.2)
|
27
|
+
mini_portile2 (2.4.0)
|
28
|
+
nokogiri (1.10.1)
|
29
|
+
mini_portile2 (~> 2.4.0)
|
12
30
|
pry (0.12.2)
|
13
31
|
coderay (~> 1.1.0)
|
14
32
|
method_source (~> 0.9.0)
|
33
|
+
public_suffix (3.0.3)
|
15
34
|
rake (10.5.0)
|
16
35
|
rspec (3.8.0)
|
17
36
|
rspec-core (~> 3.8.0)
|
@@ -26,6 +45,9 @@ GEM
|
|
26
45
|
diff-lcs (>= 1.2.0, < 2.0)
|
27
46
|
rspec-support (~> 3.8.0)
|
28
47
|
rspec-support (3.8.0)
|
48
|
+
unf (0.1.4)
|
49
|
+
unf_ext
|
50
|
+
unf_ext (0.0.7.5)
|
29
51
|
|
30
52
|
PLATFORMS
|
31
53
|
ruby
|
@@ -38,4 +60,4 @@ DEPENDENCIES
|
|
38
60
|
rspec
|
39
61
|
|
40
62
|
BUNDLED WITH
|
41
|
-
1.17.
|
63
|
+
1.17.3
|
data/exe/ojad
ADDED
data/lib/ojad/cli.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "client"
|
4
|
+
require_relative "result"
|
5
|
+
|
6
|
+
module OJAD
|
7
|
+
class CLI
|
8
|
+
def self.start(arguments:)
|
9
|
+
new(arguments).start
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize(arguments)
|
13
|
+
@arguments = arguments
|
14
|
+
end
|
15
|
+
|
16
|
+
def start
|
17
|
+
Result.new(response).to_human
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
attr_reader :arguments
|
23
|
+
|
24
|
+
def response
|
25
|
+
Client.call(arguments.first)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/ojad/client.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "http"
|
4
|
+
|
5
|
+
require_relative "response"
|
6
|
+
|
7
|
+
module OJAD
|
8
|
+
class Client
|
9
|
+
def self.call(word)
|
10
|
+
new(word).call
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize(word)
|
14
|
+
@word = word
|
15
|
+
end
|
16
|
+
|
17
|
+
def call
|
18
|
+
Response.new(raw_response)
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
ENDPOINT = "ojad/search/index"
|
24
|
+
HOST = "http://www.gavo.t.u-tokyo.ac.jp"
|
25
|
+
private_constant :ENDPOINT, :HOST
|
26
|
+
|
27
|
+
attr_reader :word
|
28
|
+
|
29
|
+
def raw_response
|
30
|
+
HTTP.get(search_url)
|
31
|
+
end
|
32
|
+
|
33
|
+
def search_url
|
34
|
+
File.join(HOST, ENDPOINT, params)
|
35
|
+
end
|
36
|
+
|
37
|
+
def params
|
38
|
+
File.join(
|
39
|
+
"sortprefix:accent",
|
40
|
+
"narabi1:kata_asc",
|
41
|
+
"narabi2:accent_asc",
|
42
|
+
"narabi3:mola_asc",
|
43
|
+
"yure:visible",
|
44
|
+
"curve:invisible",
|
45
|
+
"details:invisible",
|
46
|
+
"limit:20",
|
47
|
+
"word:#{word}",
|
48
|
+
)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OJAD
|
4
|
+
class Response
|
5
|
+
def initialize(http_response)
|
6
|
+
@http_response = http_response
|
7
|
+
end
|
8
|
+
|
9
|
+
def body
|
10
|
+
@body ||= http_response.body
|
11
|
+
end
|
12
|
+
|
13
|
+
def success?
|
14
|
+
http_response.status.success?
|
15
|
+
end
|
16
|
+
|
17
|
+
def error?
|
18
|
+
http_response.status.server_error?
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
attr_reader :http_response
|
24
|
+
end
|
25
|
+
end
|
data/lib/ojad/result.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "verbs"
|
4
|
+
|
5
|
+
module OJAD
|
6
|
+
class Result
|
7
|
+
def initialize(response)
|
8
|
+
@response = response
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_human
|
12
|
+
if response.success?
|
13
|
+
verbs.each do |verb|
|
14
|
+
verb.to_human
|
15
|
+
puts "-"*80
|
16
|
+
end
|
17
|
+
else
|
18
|
+
error_message
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
attr_reader :response
|
25
|
+
|
26
|
+
def html
|
27
|
+
@_response_string ||= response.body.to_s
|
28
|
+
end
|
29
|
+
|
30
|
+
def verbs
|
31
|
+
Verbs.new(html).to_a
|
32
|
+
end
|
33
|
+
|
34
|
+
def error_message
|
35
|
+
"An error occurred. Please try again later.\n\n" \
|
36
|
+
"Response body:\n\n#{response.body.to_s}" \
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "nokogiri"
|
4
|
+
|
5
|
+
module OJAD
|
6
|
+
class VerbPresenter
|
7
|
+
def initialize(document)
|
8
|
+
@document = document
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_human
|
12
|
+
puts "Group: #{group}"
|
13
|
+
puts "Dictionary: #{dictionary}"
|
14
|
+
puts "Polite: #{polite}"
|
15
|
+
puts "Te: #{te}"
|
16
|
+
puts "Ta: #{ta}"
|
17
|
+
puts "Negative: #{negative}"
|
18
|
+
puts "Past negative: #{past_negative}"
|
19
|
+
puts "Ba: #{ba}"
|
20
|
+
puts "Causative: #{causative}"
|
21
|
+
puts "Passive: #{passive}"
|
22
|
+
puts "Imperative: #{imperative}"
|
23
|
+
puts "Potential: #{potential}"
|
24
|
+
puts "Volitional: #{volitional}"
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
attr_reader :document
|
30
|
+
|
31
|
+
def find_css(lookup)
|
32
|
+
document.css(lookup)
|
33
|
+
end
|
34
|
+
|
35
|
+
def group
|
36
|
+
find_css("td.midashi").text.strip
|
37
|
+
end
|
38
|
+
|
39
|
+
def dictionary
|
40
|
+
find_css("td.katsuyo_jisho_js p").text.strip
|
41
|
+
end
|
42
|
+
|
43
|
+
def polite
|
44
|
+
find_css("td.katsuyo_masu_js p").text.strip
|
45
|
+
end
|
46
|
+
|
47
|
+
def te
|
48
|
+
find_css("td.katsuyo_te_js p").text.strip
|
49
|
+
end
|
50
|
+
|
51
|
+
def ta
|
52
|
+
find_css("td.katsuyo_ta_js p").text.strip
|
53
|
+
end
|
54
|
+
|
55
|
+
def negative
|
56
|
+
find_css("td.katsuyo_nai_js p").text.strip
|
57
|
+
end
|
58
|
+
|
59
|
+
def past_negative
|
60
|
+
find_css("td.katsuyo_nakatta_js p").text.strip
|
61
|
+
end
|
62
|
+
|
63
|
+
def ba
|
64
|
+
find_css("td.katsuyo_ba_js p").text.strip
|
65
|
+
end
|
66
|
+
|
67
|
+
def causative
|
68
|
+
find_css("td.katsuyo_shieki_js p").text.strip
|
69
|
+
end
|
70
|
+
|
71
|
+
def passive
|
72
|
+
find_css("td.katsuyo_ukemi_js p").text.strip
|
73
|
+
end
|
74
|
+
|
75
|
+
def imperative
|
76
|
+
find_css("td.katsuyo_meirei_js p").text.strip.split(/\r\n/).map(&:strip).reject(&:empty?).join(", ")
|
77
|
+
end
|
78
|
+
|
79
|
+
def potential
|
80
|
+
find_css("td.katsuyo_kano_js p").text.strip
|
81
|
+
end
|
82
|
+
|
83
|
+
def volitional
|
84
|
+
find_css("td.katsuyo_ishi_js p").text.strip
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
data/lib/ojad/verbs.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "verb_presenter"
|
4
|
+
|
5
|
+
module OJAD
|
6
|
+
class Verbs
|
7
|
+
def initialize(html)
|
8
|
+
@html = html
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_a
|
12
|
+
verbs.map do |verb_document|
|
13
|
+
VerbPresenter.new(verb_document)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
attr_reader :html
|
20
|
+
|
21
|
+
def document
|
22
|
+
@_document ||= Nokogiri.parse(html)
|
23
|
+
end
|
24
|
+
|
25
|
+
def verbs
|
26
|
+
document.css('tr[id^="word_"]')
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/ojad/version.rb
CHANGED
data/ojad.gemspec
CHANGED
@@ -30,6 +30,9 @@ Gem::Specification.new do |spec|
|
|
30
30
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
31
|
spec.require_paths = ["lib"]
|
32
32
|
|
33
|
+
spec.add_dependency "http"
|
34
|
+
spec.add_dependency "nokogiri"
|
35
|
+
|
33
36
|
spec.add_development_dependency "bundler"
|
34
37
|
spec.add_development_dependency "rake"
|
35
38
|
spec.add_development_dependency "rspec"
|
metadata
CHANGED
@@ -1,15 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ojad
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Juanito Fatas
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-02-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: http
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: nokogiri
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
13
41
|
- !ruby/object:Gem::Dependency
|
14
42
|
name: bundler
|
15
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -69,7 +97,8 @@ dependencies:
|
|
69
97
|
description: 'OJAD: http://www.gavo.t.u-tokyo.ac.jp/ojad'
|
70
98
|
email:
|
71
99
|
- me@juanitofatas.com
|
72
|
-
executables:
|
100
|
+
executables:
|
101
|
+
- ojad
|
73
102
|
extensions: []
|
74
103
|
extra_rdoc_files: []
|
75
104
|
files:
|
@@ -84,7 +113,14 @@ files:
|
|
84
113
|
- Rakefile
|
85
114
|
- bin/hack
|
86
115
|
- bin/setup
|
116
|
+
- exe/ojad
|
87
117
|
- lib/ojad.rb
|
118
|
+
- lib/ojad/cli.rb
|
119
|
+
- lib/ojad/client.rb
|
120
|
+
- lib/ojad/response.rb
|
121
|
+
- lib/ojad/result.rb
|
122
|
+
- lib/ojad/verb_presenter.rb
|
123
|
+
- lib/ojad/verbs.rb
|
88
124
|
- lib/ojad/version.rb
|
89
125
|
- ojad.gemspec
|
90
126
|
homepage: https://github.com/juanitofatas/ojad
|
@@ -109,8 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
109
145
|
- !ruby/object:Gem::Version
|
110
146
|
version: '0'
|
111
147
|
requirements: []
|
112
|
-
|
113
|
-
rubygems_version: 2.7.6
|
148
|
+
rubygems_version: 3.0.2
|
114
149
|
signing_key:
|
115
150
|
specification_version: 4
|
116
151
|
summary: Ruby API Client for OJAD
|