linggle 0.01.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 64a2095b172d47ef16904d2dae722c6ce506627f
4
+ data.tar.gz: a75dee1e38fbddc8a0f9a9a132c858119d0bcd5f
5
+ SHA512:
6
+ metadata.gz: adb488728131acd9855844dbf8a2a86325026df56dfea125972b907ae305351f445ae14d9f9e62b9fd7ae6b280c100dd5a2ba8082d148d61cb2d0a9afcb328a9
7
+ data.tar.gz: cd71176ad080aec5bcf52d02f562801e10186ee20d5f9b7f4e35831826d2e7a59904eaeb9edc38ef8349e03716be213fffa64a0aad5bdad2d2bf1c8ad44705e0
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.2
5
+ before_install: gem install bundler -v 1.16.0.pre.3
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://gems.ruby-china.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in linggle.gemspec
6
+ gemspec
@@ -0,0 +1,37 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ linggle (0.01)
5
+
6
+ GEM
7
+ remote: https://gems.ruby-china.org/
8
+ specs:
9
+ colorize (0.8.1)
10
+ diff-lcs (1.3)
11
+ rake (10.5.0)
12
+ rspec (3.5.0)
13
+ rspec-core (~> 3.5.0)
14
+ rspec-expectations (~> 3.5.0)
15
+ rspec-mocks (~> 3.5.0)
16
+ rspec-core (3.5.4)
17
+ rspec-support (~> 3.5.0)
18
+ rspec-expectations (3.5.0)
19
+ diff-lcs (>= 1.2.0, < 2.0)
20
+ rspec-support (~> 3.5.0)
21
+ rspec-mocks (3.5.0)
22
+ diff-lcs (>= 1.2.0, < 2.0)
23
+ rspec-support (~> 3.5.0)
24
+ rspec-support (3.5.0)
25
+
26
+ PLATFORMS
27
+ ruby
28
+
29
+ DEPENDENCIES
30
+ bundler (~> 1.16.a)
31
+ colorize (~> 0.8.0)
32
+ linggle!
33
+ rake (~> 10.0)
34
+ rspec (~> 3.0)
35
+
36
+ BUNDLED WITH
37
+ 1.16.0.pre.3
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 fangxing
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,75 @@
1
+ # Linggle
2
+ A Linggle(http://linggle.com/) in cli
3
+
4
+ ![linggle cli](https://raw.githubusercontent.com/ffx/linggle-cli/master/assets/short.png)
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'linggle'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install linggle
21
+
22
+ ## Usage
23
+
24
+ - 查询任意一至多个词
25
+ 只要在你想要插入字词的位置使用* (星号)来查询一个词,或是_ (底线)来查询零至多个词就可以了。
26
+
27
+ present a method _
28
+ listen _ music
29
+
30
+
31
+
32
+ - 使用问号查询是否需要某个字
33
+ 小明在报告里写了这么一句话:“I would like to discuss about the issue.”
34
+ 回头检查时,总是觉得哪里怪怪的,他很怀疑“discuss”后面到底需不需要
35
+ 加“about” ⋯⋯这时只要使用Linggle,在你不确定的字前加上? (问号),Linggle就会告诉你需不需要这个字啰!
36
+
37
+ discuss ?about the issue
38
+
39
+ - 使用斜线号查询如何替换某字词
40
+ 介系词这么多常常搞不清楚要用哪一个吗?太多字可以用却不知道哪一个比较适合吗?
41
+ 让Linggle来告诉你该怎么选吧!很简单,只需要在你要抉择的两个字中间加入/ (斜线号)
42
+ 就可以了!不只是介系词,其他词性也可以!
43
+
44
+ in/at the afternoon
45
+ play _ important role/part
46
+ Guide
47
+
48
+ - 使用任意词性查询搭配词
49
+ Linggle最大的特色,就是可以使用「关键词」配合「特定词性」来查询各种搭配词。比如说,
50
+ 可以用v. death penalty来查询“death penalty”搭配的动词,效果不逊于一般搭配词典喔!
51
+
52
+ v. death penalty
53
+ acquire n.
54
+
55
+
56
+ - 精准的搭配词查询
57
+ 想要更加精准的查询搭配词,我们就会建议使用复杂的查询式,例如在想要查询的动词前
58
+ 加上一个“to”,让Linggle 不至于会错意。
59
+
60
+ to v. ?prep. ?det. difficulty/difficulties
61
+
62
+
63
+ ## Development
64
+
65
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
66
+
67
+ 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`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
68
+
69
+ ## Contributing
70
+
71
+ Bug reports and pull requests are welcome on GitHub at https://github.com/fangxing204/linggle.
72
+
73
+ ## License
74
+
75
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
Binary file
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+ require "bundler/setup"
3
+ require "linggle"
4
+
5
+ # You can add fixtures and/or initialization code here to make experimenting
6
+ # with your gem easier. You can also use a different console, if you like.
7
+
8
+ # (If you use this, don't forget to add pry to your Gemfile!)
9
+ # require "pry"
10
+ # Pry.start
11
+
12
+ require "irb"
13
+ IRB.start(__FILE__)
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+ require "bundler/setup"
4
+ require "linggle"
5
+ Linggle.execute
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,51 @@
1
+ require 'json'
2
+ require 'open-uri'
3
+ require 'optionparser'
4
+ require 'colorize'
5
+ require "linggle/version"
6
+ require 'linggle/api'
7
+ require 'linggle/string'
8
+
9
+ # resource
10
+ # https://kpumuk.info/ruby-on-rails/colorizing-console-ruby-script-output/
11
+ module Linggle
12
+
13
+ # Your code goes here...
14
+ def self.execute()
15
+ args = parse()
16
+ query_str = args.join(' ')
17
+ # puts "parse result #{args}"
18
+
19
+ # TODO rescue network exception, and follow redirections..
20
+ entries = query(query_str)
21
+ # {
22
+ # "count"=>13966963,
23
+ # "count_str"=>"14,000,000",
24
+ # "percent"=>"54.5%",
25
+ # "phrase" =>
26
+ # ["very", "good"]
27
+ # }
28
+ entries = entries.take(20).map do |e|
29
+ "#{e['phrase'].join(' ').green} 频率: #{e['count_str'].yellow} #{e['percent']} \n #{e['percent'].percent_line} \n \n"
30
+ end
31
+ puts entries
32
+ end
33
+
34
+
35
+ def self.parse()
36
+ OptionParser.new do |parser|
37
+
38
+ if ARGV.size == 0
39
+ puts HELPS.map{|k,v| v }
40
+ exit 0
41
+ end
42
+
43
+ parser.on("-h", "--help") do
44
+ puts HELPS.map{|k,v| v }
45
+ exit 0
46
+ end
47
+
48
+ end.parse!
49
+
50
+ end
51
+ end
@@ -0,0 +1,95 @@
1
+ module Linggle
2
+ API = 'http://linggle.com/query'.freeze
3
+ TIMEOUT = 10
4
+ COLORS = {
5
+ e: :yellow, # example
6
+ t: :blue # title
7
+ }
8
+
9
+ ##
10
+ # 查询返回结果
11
+ #
12
+ # [
13
+ # {"count"=>13966963, "count_str"=>"14,000,000", "percent"=>"54.5%", "phrase"=>["very", "good"]}
14
+ # {"count"=>4436461, "count_str"=>"4,400,000", "percent"=>"17.3%", "phrase"=>["pretty", "good"]}
15
+ # {"count"=>562220, "count_str"=>"560,000", "percent"=>"2.2%", "phrase"=>["only", "good"]}
16
+ # {"count"=>508737, "count_str"=>"510,000", "percent"=>"2.0%", "phrase"=>["real", "good"]}
17
+ # {"count"=>481831, "count_str"=>"480,000", "percent"=>"1.9%", "phrase"=>["public", "good"]}
18
+ # {"count"=>480872, "count_str"=>"480,000", "percent"=>"1.9%", "phrase"=>["damn", "good"]}
19
+ # {"count"=>429867, "count_str"=>"430,000", "percent"=>"1.7%", "phrase"=>["common", "good"]}
20
+ # {"count"=>409578, "count_str"=>"410,000", "percent"=>"1.6%", "phrase"=>["other", "good"]}
21
+ # {"count"=>308328, "count_str"=>"310,000", "percent"=>"1.2%", "phrase"=>["good", "good"]}
22
+ # {"count"=>303609, "count_str"=>"300,000", "percent"=>"1.2%", "phrase"=>["still", "good"]}
23
+ # {"count"=>256591, "count_str"=>"260,000", "percent"=>"1.0%", "phrase"=>["just", "good"]}
24
+ # {"count"=>225266, "count_str"=>"230,000", "percent"=>"0.9%", "phrase"=>["sound", "good"]}
25
+ # {"count"=>207530, "count_str"=>"210,000", "percent"=>"0.8%", "phrase"=>["like", "good"]}
26
+ # {"count"=>191120, "count_str"=>"190,000", "percent"=>"0.7%", "phrase"=>["greater", "good"]}
27
+ # ...
28
+ # ]
29
+
30
+ def self.query(query_str)
31
+ content = open(
32
+ URI::encode("#{API}/#{query_str}"),
33
+ read_timeout: TIMEOUT
34
+ ).read
35
+
36
+ # puts "conent #{content}"
37
+ entries = JSON.parse(content)
38
+ end
39
+
40
+ HELPS = {
41
+ '_' => <<-DOC,
42
+ #{'查询任意一至多个词'.bold.colorize(COLORS[:t])}
43
+ 只要在你想要插入字词的位置使用* (星号)来查询一个词,或是_ (底线)来查询零至多个词就可以了。
44
+
45
+ #{ 'present a method _
46
+ listen _ music'.colorize(COLORS[:e]) }
47
+
48
+
49
+ DOC
50
+
51
+ '?' => <<-DOC,
52
+ #{'使用问号查询是否需要某个字'.blue}
53
+ 小明在报告里写了这么一句话:“I would like to discuss about the issue.”
54
+ 回头检查时,总是觉得哪里怪怪的,他很怀疑“discuss”后面到底需不需要
55
+ 加“about” ⋯⋯这时只要使用Linggle,在你不确定的字前加上? (问号),Linggle就会告诉你需不需要这个字啰!
56
+
57
+ #{'discuss ?about the issue'.colorize(COLORS[:e]) }
58
+
59
+
60
+ DOC
61
+
62
+ '/' => <<-DOC,
63
+ #{'使用斜线号查询如何替换某字词'.blue}
64
+ 介系词这么多常常搞不清楚要用哪一个吗?太多字可以用却不知道哪一个比较适合吗?
65
+ 让Linggle来告诉你该怎么选吧!很简单,只需要在你要抉择的两个字中间加入/ (斜线号)
66
+ 就可以了!不只是介系词,其他词性也可以!
67
+
68
+ #{ 'in/at the afternoon
69
+ play _ important role/part'.colorize(COLORS[:e]) }
70
+
71
+
72
+ DOC
73
+
74
+ 'w.' => <<-DOC,
75
+ #{'使用任意词性查询搭配词'.blue}
76
+ Linggle最大的特色,就是可以使用「关键词」配合「特定词性」来查询各种搭配词。比如说,
77
+ 可以用v. death penalty来查询“death penalty”搭配的动词,效果不逊于一般搭配词典喔!
78
+
79
+ #{ 'v. death penalty
80
+ acquire n.'.colorize(COLORS[:e]) }
81
+
82
+
83
+ DOC
84
+
85
+ 'more' => <<-DOC,
86
+ #{'精准的搭配词查询'.blue}
87
+ 想要更加精准的查询搭配词,我们就会建议使用复杂的查询式,例如在想要查询的动词前
88
+ 加上一个“to”,让Linggle 不至于会错意。
89
+
90
+ #{'to v. ?prep. ?det. difficulty/difficulties'.colorize(COLORS[:e]) }
91
+
92
+
93
+ DOC
94
+ }.freeze
95
+ end
@@ -0,0 +1,5 @@
1
+ module Linggle
2
+ def self.percents_str
3
+
4
+ end
5
+ end
@@ -0,0 +1,40 @@
1
+ ## copy from:
2
+ # https://stackoverflow.com/a/16363159/5615038
3
+ # only works on unix
4
+
5
+ class String
6
+ def black; "\e[30m#{self}\e[0m" end
7
+ def red; "\e[31m#{self}\e[0m" end
8
+ def green; "\e[32m#{self}\e[0m" end
9
+ def brown; "\e[33m#{self}\e[0m" end
10
+ def blue; "\e[34m#{self}\e[0m" end
11
+ def magenta; "\e[35m#{self}\e[0m" end
12
+ def cyan; "\e[36m#{self}\e[0m" end
13
+ def gray; "\e[37m#{self}\e[0m" end
14
+
15
+ def bg_black; "\e[40m#{self}\e[0m" end
16
+ def bg_red; "\e[41m#{self}\e[0m" end
17
+ def bg_green; "\e[42m#{self}\e[0m" end
18
+ def bg_brown; "\e[43m#{self}\e[0m" end
19
+ def bg_blue; "\e[44m#{self}\e[0m" end
20
+ def bg_magenta; "\e[45m#{self}\e[0m" end
21
+ def bg_cyan; "\e[46m#{self}\e[0m" end
22
+ def bg_gray; "\e[47m#{self}\e[0m" end
23
+
24
+ def bold; "\e[1m#{self}\e[22m" end
25
+ def italic; "\e[3m#{self}\e[23m" end
26
+ def underline; "\e[4m#{self}\e[24m" end
27
+ def blink; "\e[5m#{self}\e[25m" end
28
+ def reverse_color; "\e[7m#{self}\e[27m" end
29
+
30
+ # [:bold, :italic, :blink].each do |name|
31
+ # define_method(:"#{name}) do ||
32
+ # end
33
+
34
+ # 55.6%
35
+ Strips = '|' * 100
36
+ def percent_line
37
+ count = (self[/\d+\.?\d+/].to_f).round
38
+ "[#{ Strips[0..count].red } #{ ' ' * (100 - count) }]"
39
+ end
40
+ end
@@ -0,0 +1,3 @@
1
+ module Linggle
2
+ VERSION = "0.01.1"
3
+ end
@@ -0,0 +1,38 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "linggle/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "linggle"
8
+ spec.version = Linggle::VERSION
9
+ spec.authors = ["fangxing"]
10
+ spec.email = ["fangxing204@gmail.com"]
11
+
12
+ spec.summary = %q{http://linggle.com/ in cli}
13
+ spec.description = %q{use linggle in your command line}
14
+ spec.homepage = "https://github.com/fffx/linggle-cli"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ ##
20
+ # if spec.respond_to?(:metadata)
21
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
22
+ # else
23
+ # raise "RubyGems 2.0 or newer is required to protect against " \
24
+ # "public gem pushes."
25
+ # end
26
+
27
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
28
+ f.match(%r{^(test|spec|features)/})
29
+ end
30
+ spec.bindir = "bin"
31
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
32
+ spec.require_paths = ["lib"]
33
+
34
+ spec.add_development_dependency "bundler", "~> 1.16.a"
35
+ spec.add_development_dependency "rake", "~> 10.0"
36
+ spec.add_development_dependency "rspec", "~> 3.0"
37
+ spec.add_development_dependency "colorize", "~> 0.8.0"
38
+ end
data/test ADDED
@@ -0,0 +1,2 @@
1
+
2
+ puts $:
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: linggle
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.01.1
5
+ platform: ruby
6
+ authors:
7
+ - fangxing
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-12-12 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.16.a
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.16.a
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: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: colorize
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.8.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.8.0
69
+ description: use linggle in your command line
70
+ email:
71
+ - fangxing204@gmail.com
72
+ executables:
73
+ - console
74
+ - linggle
75
+ - setup
76
+ extensions: []
77
+ extra_rdoc_files: []
78
+ files:
79
+ - ".gitignore"
80
+ - ".rspec"
81
+ - ".travis.yml"
82
+ - Gemfile
83
+ - Gemfile.lock
84
+ - LICENSE.txt
85
+ - README.md
86
+ - Rakefile
87
+ - assets/short.png
88
+ - bin/console
89
+ - bin/linggle
90
+ - bin/setup
91
+ - lib/linggle.rb
92
+ - lib/linggle/api.rb
93
+ - lib/linggle/prints.rb
94
+ - lib/linggle/string.rb
95
+ - lib/linggle/version.rb
96
+ - linggle.gemspec
97
+ - test
98
+ homepage: https://github.com/fffx/linggle-cli
99
+ licenses:
100
+ - MIT
101
+ metadata: {}
102
+ post_install_message:
103
+ rdoc_options: []
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubyforge_project:
118
+ rubygems_version: 2.6.14
119
+ signing_key:
120
+ specification_version: 4
121
+ summary: http://linggle.com/ in cli
122
+ test_files: []