chinese_phrases 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +16 -1
- data/bin/chinese_phrases +1 -1
- data/lib/chinese_phrases.rb +19 -3
- data/lib/chinese_phrases/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5a40f9ca2c1c3f081bfbe3cd4b4371b2652ff6afe8bf8ccf48e7c53fd2e452b8
|
4
|
+
data.tar.gz: 842158b8b92e0b93b8dbdd46bb2bca6737bf9e8a6790664ec97b696be58c32eb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d941b57de26d9e6a873c3c7b90fb428bc96a23563b952a84f1613b8f9a4fe9ca7d70865c0d232d4269e37728f5f84f5d59ef098929ab1aeeac2c55ff4ea25c2c
|
7
|
+
data.tar.gz: 9c45078edf7e1ad5f887cc389e8d4b843875503feb01ff430065bd5330e2c3c4dc5cb12c9ab4cbfb70e11cfbeeeeb9a82bf0b47aafb063fbf735f003ed116609
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -2,6 +2,21 @@
|
|
2
2
|
|
3
3
|
Converts a csv of Chinese words to a csv of example sentences for use in Anki.
|
4
4
|
|
5
|
+
*Note:* This uses the free online dictionary at dict.naver.com to pull sentences, please be respectful.
|
6
|
+
|
7
|
+
## Context
|
8
|
+
|
9
|
+
As you're learning Chinese you'll come across new words that you would
|
10
|
+
like to practice. You can use this gem as such:
|
11
|
+
|
12
|
+
* As you read an article or watch a video
|
13
|
+
* Write down any new words you find on a new in line a text file
|
14
|
+
* Enter only one word per line
|
15
|
+
* Once done, save the file
|
16
|
+
* Use this library to convert those words into examples sentences
|
17
|
+
* These sentences can be used for your own study in Anki or whatever you like
|
18
|
+
|
19
|
+
|
5
20
|
## Installation
|
6
21
|
|
7
22
|
Add this line to your application's Gemfile:
|
@@ -41,7 +56,7 @@ Options:
|
|
41
56
|
[--max-per=N]
|
42
57
|
# Default: 10
|
43
58
|
[--page-size=N]
|
44
|
-
# Default:
|
59
|
+
# Default: 50
|
45
60
|
[--trad], [--no-trad]
|
46
61
|
# Default: true
|
47
62
|
|
data/bin/chinese_phrases
CHANGED
@@ -7,7 +7,7 @@ class CLI < Thor
|
|
7
7
|
option :output_file
|
8
8
|
option :max_len, type: :numeric, default: 15
|
9
9
|
option :max_per, type: :numeric, default: 10
|
10
|
-
option :page_size, type: :numeric, default:
|
10
|
+
option :page_size, type: :numeric, default: 50
|
11
11
|
option :trad, type: :boolean, default: true
|
12
12
|
desc "export", "Output given word csv to phrases csv"
|
13
13
|
def export(name)
|
data/lib/chinese_phrases.rb
CHANGED
@@ -15,11 +15,13 @@ module ChinesePhrases
|
|
15
15
|
|
16
16
|
params = {
|
17
17
|
page: options[:page] || 1, # page to check on source
|
18
|
-
page_size: options[:page_size] ||
|
18
|
+
page_size: options[:page_size] || 50, # number of examples from api call
|
19
19
|
max_length: options[:max_len] || 15, # only accept examples length than this
|
20
20
|
max_per: options[:max_per] || 10, # only accept this number of examples
|
21
21
|
}
|
22
22
|
|
23
|
+
puts "Running with params #{params}"
|
24
|
+
|
23
25
|
query_list = []
|
24
26
|
total_examples = []
|
25
27
|
|
@@ -28,6 +30,12 @@ module ChinesePhrases
|
|
28
30
|
query_list << Tradsim::to_sim(csv[input_index])
|
29
31
|
end
|
30
32
|
|
33
|
+
if query_list.empty?
|
34
|
+
puts "CSV file is empty!"
|
35
|
+
elsif query_list.count > 1000
|
36
|
+
puts "[WARNING] CSV file has over 1000 lines, this can take a long time and/or fail! Consider splitting the file."
|
37
|
+
end
|
38
|
+
|
31
39
|
# query each word individually and combine to total list
|
32
40
|
query_list.each do |q|
|
33
41
|
exs = get_examples q, params
|
@@ -43,9 +51,11 @@ module ChinesePhrases
|
|
43
51
|
example = Tradsim::to_trad(example)
|
44
52
|
end
|
45
53
|
|
46
|
-
|
54
|
+
pinyin = a["pinyin"]
|
55
|
+
|
56
|
+
puts "Writing #{a["recentTrslation"]} #{example} #{pinyin}"
|
47
57
|
|
48
|
-
csv << [a["recentTrslation"], example,
|
58
|
+
csv << [a["recentTrslation"], example, pinyin]
|
49
59
|
end
|
50
60
|
end
|
51
61
|
|
@@ -56,6 +66,8 @@ module ChinesePhrases
|
|
56
66
|
query_escaped = CGI::escape query
|
57
67
|
callback = "jQuery1111013304390430117385_1567195383336"
|
58
68
|
|
69
|
+
puts "Fetching examples for #{query}"
|
70
|
+
|
59
71
|
url = "https://dict.naver.com/linedict/cnen/example/search.dict?callback=#{callback}&query=#{query_escaped}&page=#{params[:page]}&page_size=#{params[:page_size]}&examType=normal&fieldType=&author=&country=&ql=default&format=json&platform=isPC&_=1567195383337"
|
60
72
|
|
61
73
|
response = HTTParty.get(url)
|
@@ -81,6 +93,8 @@ module ChinesePhrases
|
|
81
93
|
|
82
94
|
exampleList = data["exampleList"]
|
83
95
|
|
96
|
+
puts "Found #{exampleList.count} examples"
|
97
|
+
|
84
98
|
# collect shortest examples
|
85
99
|
examples = exampleList.filter { |i| i["example"].length < params[:max_length] }
|
86
100
|
|
@@ -88,6 +102,8 @@ module ChinesePhrases
|
|
88
102
|
examples = examples[0..params[:max_per] - 1]
|
89
103
|
end
|
90
104
|
|
105
|
+
puts "Filtered down to #{examples.count} examples"
|
106
|
+
|
91
107
|
examples
|
92
108
|
end
|
93
109
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chinese_phrases
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben D'Angelo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-10-
|
11
|
+
date: 2020-10-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|