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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ae4a506c3e070f95b66f15ea7428c97290fc905ff14a61ace6f08d7b887178fa
4
- data.tar.gz: 74de3191cbae02a656273013af90dd6b9c9b27eb99b3f4b32cd8e3f2ff023acf
3
+ metadata.gz: 5a40f9ca2c1c3f081bfbe3cd4b4371b2652ff6afe8bf8ccf48e7c53fd2e452b8
4
+ data.tar.gz: 842158b8b92e0b93b8dbdd46bb2bca6737bf9e8a6790664ec97b696be58c32eb
5
5
  SHA512:
6
- metadata.gz: 671d1f4379a533ed57bd0b7259d110aa2fe4b7f0c6b114269e959d95b3dc601e3e54fdeaa03ec23e898abcbceb03c8c94d6ccd94cf519feccfdb54f0771e174e
7
- data.tar.gz: 6d8c3fd9adb09b81528aaab0eff671ebdfec9d3c37afbb7664a52b212b7cd8eb0c8c091a1d9112c08aaffc5e33147e08aa969d40a8bcec8c971eeaee7754de5b
6
+ metadata.gz: d941b57de26d9e6a873c3c7b90fb428bc96a23563b952a84f1613b8f9a4fe9ca7d70865c0d232d4269e37728f5f84f5d59ef098929ab1aeeac2c55ff4ea25c2c
7
+ data.tar.gz: 9c45078edf7e1ad5f887cc389e8d4b843875503feb01ff430065bd5330e2c3c4dc5cb12c9ab4cbfb70e11cfbeeeeb9a82bf0b47aafb063fbf735f003ed116609
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- chinese_phrases (0.1.3)
4
+ chinese_phrases (0.1.4)
5
5
  httparty (~> 0.17)
6
6
  thor (~> 0.20)
7
7
  tradsim (~> 0.5)
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: 100
59
+ # Default: 50
45
60
  [--trad], [--no-trad]
46
61
  # Default: true
47
62
 
@@ -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: 100
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)
@@ -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] || 100, # number of examples from api call
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
- puts "Writing #{a["recentTrslation"]} #{example}"
54
+ pinyin = a["pinyin"]
55
+
56
+ puts "Writing #{a["recentTrslation"]} #{example} #{pinyin}"
47
57
 
48
- csv << [a["recentTrslation"], example, a["pinyin"]]
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
 
@@ -1,3 +1,3 @@
1
1
  module ChinesePhrases
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
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.3
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-20 00:00:00.000000000 Z
11
+ date: 2020-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty