Skip to content

Commit bccb388

Browse files
authored
Merge pull request tyrchen#2 from tyrchen/feature/update-project-layout
move files under data to priv to comply with elixir project req
2 parents 1372886 + b41d185 commit bccb388

File tree

11 files changed

+58
-18511
lines changed

11 files changed

+58
-18511
lines changed

data/s2t_conversion.txt

Lines changed: 0 additions & 18458 deletions
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
defmodule ChineseTranslation.Iterable do
22
@moduledoc """
3-
Utility functions
3+
support for iterable functions
44
"""
55
@not_implemented "not implemented"
66

lib/chinese_translation/pinyin_util.ex

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ defmodule ChineseTranslation.Pinyin.Util do
33
Utility functions to read pinyin_characters.txt / pinyin_words.txt and parse
44
it into a list ordered by the length of the words.
55
"""
6-
alias ChineseTranslation.Iterable
6+
alias ChineseTranslation.{Iterable, Utils}
77

8-
@path Path.join([__DIR__, "..", "..", "data"])
98
# the order is very important here
109
@files ["pinyin_characters.txt", "pinyin_words.txt"]
1110
@tone_file "pinyin_tone.txt"
@@ -51,7 +50,7 @@ defmodule ChineseTranslation.Pinyin.Util do
5150
end
5251

5352
defp get_file_stream(filename) do
54-
@path
53+
Utils.data_path()
5554
|> Path.join(filename)
5655
|> File.stream!()
5756
end

lib/chinese_translation/translation_util.ex

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ defmodule ChineseTranslation.Translation.Util do
33
Utility functions to read s2t_conversion.txt file and parse it into a list
44
ordered by the length of the words.
55
"""
6+
alias ChineseTranslation.Utils
67

7-
@filename Path.join([__DIR__, "..", "..", "data", "s2t_conversion.txt"])
88
@php_regex ~r/\$(?<name>\S+).*\((?<content>[^\)]+)\)/
99
@php_kv ~r/'(?<key>[^']+)'\s*=>\s*'(?<value>[^']+)'/
1010

1111
def get_trans_data do
12-
@filename
12+
Utils.data_path()
13+
|> Path.join("s2t_conversion.txt")
1314
|> get_file_content
1415
|> match
1516
|> Enum.map(fn [_whole, name, content] ->

lib/chinese_translation/utils.ex

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
defmodule ChineseTranslation.Utils do
2+
@moduledoc """
3+
utility functions
4+
"""
5+
def data_path do
6+
:chinese_translation
7+
|> Application.app_dir()
8+
|> Path.join("priv")
9+
end
10+
end

lib/mix/tasks/translation.ex

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ defmodule Mix.Tasks.ChineseTranslation do
33
The task for loading latest data from wikipedia.
44
"""
55
use Mix.Task
6+
alias ChineseTranslation.Utils
67

78
@shortdoc "get the latest version of the translation table and recompile myself"
89

@@ -21,15 +22,9 @@ defmodule Mix.Tasks.ChineseTranslation do
2122
}
2223
]
2324

24-
@name "chinese_translation"
25-
@mod_path "data"
26-
@dep_path "deps/#{@name}/#{@mod_path}"
27-
@beam_path "_build/dev/lib/#{@name}"
28-
2925
def run(_args) do
3026
HTTPoison.start()
3127
get_data_file(@urls)
32-
clean_beam(@beam_path)
3328
recompile()
3429
end
3530

@@ -40,13 +35,9 @@ defmodule Mix.Tasks.ChineseTranslation do
4035
|> Enum.to_list()
4136
end
4237

43-
defp clean_beam(beam_path) do
44-
IO.puts("Cleaning #{beam_path}...")
45-
File.rm_rf(beam_path)
46-
end
47-
4838
defp recompile do
4939
IO.puts("Recompiling chinese_translation...")
40+
System.cmd("mix", ["clean"])
5041
System.cmd("mix", ["compile"])
5142
end
5243

@@ -57,11 +48,7 @@ defmodule Mix.Tasks.ChineseTranslation do
5748
end
5849

5950
def write_file({filename, body}) do
60-
path = case File.exists?(@dep_path) do
61-
true -> Path.join(@dep_path, filename)
62-
_ -> Path.join(@mod_path, filename)
63-
end
64-
51+
path = Path.join(Utils.data_path(), filename)
6552
File.write(path, body)
6653
end
6754
end

mix.exs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,25 @@ defmodule ChineseTranslation.Mixfile do
1010
elixir: "~> 1.5",
1111
description: description(),
1212
package: package(),
13-
deps: deps()
13+
start_permanent: Mix.env() == :prod,
14+
deps: deps(),
15+
16+
# exdocs
17+
# Docs
18+
name: "ChineseTranslation",
19+
source_url: "https://github.com/tyrchen/chinese_translation",
20+
homepage_url: "https://github.com/tyrchen/chinese_translation",
21+
docs: [
22+
main: "ChineseTranslation",
23+
extras: ["README.md"]
24+
]
1425
]
1526
end
1627

17-
# Configuration for the OTP application
18-
#
19-
# Type `mix help compile.app` for more information
2028
def application do
21-
[applications: [:logger, :httpoison]]
29+
[extra_applications: [:logger]]
2230
end
2331

24-
# Type `mix help deps` for more examples and options
2532
defp deps do
2633
[
2734
{:httpoison, "~> 0.13"},
@@ -42,10 +49,13 @@ defmodule ChineseTranslation.Mixfile do
4249

4350
defp package do
4451
[
45-
files: ["lib", "data", "mix.exs", "README*", "LICENSE*"],
46-
contributors: ["Tyr Chen"],
52+
files: ["lib", "priv", "mix.exs", "README*", "LICENSE*", "version"],
4753
licenses: ["MIT"],
48-
links: %{"GitHub" => "https://github.com/tyrchen/chinese_translation"}
54+
maintainers: ["[email protected]"],
55+
links: %{
56+
"GitHub" => "https://github.com/tyrchen/chinese_translation",
57+
"Docs" => "https://hexdocs.pm/chinese_translation"
58+
}
4959
]
5060
end
5161
end
Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10246,7 +10246,7 @@
1024610246
5F88 hěn
1024710247
5F89 yáng
1024810248
5F8A huái
10249-
5F8B l̈ù
10249+
5F8B
1025010250
5F8C hòu
1025110251
5F8D wǎng,wā
1025210252
5F8E chěng,zhèng
@@ -10729,7 +10729,7 @@
1072910729
616B sǒng
1073010730
616C qín,jìn,jǐn
1073110731
616D yìn
10732-
616E l̈ù
10732+
616E
1073310733
616F shāng
1073410734
6170 wèi
1073510735
6171 tuán
@@ -11840,7 +11840,7 @@
1184011840
65C2 qí
1184111841
65C3 zhān
1184211842
65C4 máo
11843-
65C5 l̈ǔ
11843+
65C5
1184411844
65C6 pèi
1184511845
65C7 pī,bì
1184611846
65C8 liú
@@ -15360,7 +15360,7 @@
1536015360
7384 xuán
1536115361
7385 miào
1536215362
7386 xuán,zī
15363-
7387 l̈ù,shuài
15363+
7387 ,shuài
1536415364
7388 lú
1536515365
7389 yù
1536615366
738A sù
@@ -17940,7 +17940,7 @@
1794017940
7D9D *,chēn,lín
1794117941
7D9E duǒ
1794217942
7D9F lì,liè
17943-
7DA0 l̈ù
17943+
7DA0
1794417944
7DA1 liáng
1794517945
7DA2 choú
1794617946
7DA3 quǎn
@@ -18091,7 +18091,7 @@
1809118091
7E34 qiàn
1809218092
7E35 màn
1809318093
7E36 zhí
18094-
7E37 l̈ǔ
18094+
7E37
1809518095
7E38 mù,mò
1809618096
7E39 piǎo,piāo
1809718097
7E3A lián
@@ -18291,7 +18291,7 @@
1829118291
7EFC zōng
1829218292
7EFD zhàn
1829318293
7EFE wǎn
18294-
7EFF l̈ù
18294+
7EFF
1829518295
7F00 zhui
1829618296
7F01 zī
1829718297
7F02 kè
@@ -18313,7 +18313,7 @@
1831318313
7F12 zhuì
1831418314
7F13 huǎn
1831518315
7F14 dì
18316-
7F15 l̈ǔ
18316+
7F15
1831718317
7F16 biān
1831818318
7F17 mín
1831918319
7F18 yuán
@@ -20165,7 +20165,7 @@
2016520165
864E hǔ,hu
2016620166
864F lǔ
2016720167
8650 nüè
20168-
8651 l̈ù
20168+
8651
2016920169
8652 sī
2017020170
8653 xiāo
2017120171
8654 qián
@@ -23349,7 +23349,7 @@
2334923349
92BE hòng,gǒng
2335023350
92BF zhōng,yōng
2335123351
92C0 tōu,dòu,tù
23352-
92C1 l̈ǔ
23352+
92C1
2335323353
92C2 méi,méng
2335423354
92C3 láng
2335523355
92C4 wǎn
@@ -23889,7 +23889,7 @@
2388923889
94DA zhì
2389023890
94DB dang
2389123891
94DC tóng
23892-
94DD l̈ǔ
23892+
94DD
2389323893
94DE diào
2389423894
94DF yīn
2389523895
94E0 kǎi
@@ -25302,7 +25302,7 @@
2530225302
9A5F zhoù
2530325303
9A60 yàn
2530425304
9A61 lóng,zǎng
25305-
9A62 l̈ú
25305+
9A62
2530625306
9A63 téng
2530725307
9A64 xiāng
2530825308
9A65 jì
@@ -25320,7 +25320,7 @@
2532025320
9A71 qū
2532125321
9A72 rì
2532225322
9A73 bó
25323-
9A74 l̈ú
25323+
9A74
2532425324
9A75 zǎng
2532525325
9A76 shǐ
2532625326
9A77 sì
Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6058,7 +6058,7 @@
60586058
侃侃,kǎn kǎn
60596059
侃侃而谈,kǎn kǎn ér tán
60606060
侃价,kǎn jià
6061-
侃大山,kǎn tài shān
6061+
侃大山,kǎn shān
60626062
侃星,kǎn xīng
60636063
侃爷,kǎn yé
60646064
来不及,lái bù jí
@@ -8505,6 +8505,7 @@
85058505
克勒,kè lè
85068506
克劳修斯,kè láo xīu sī
85078507
克劳德,kè láo dé
8508+
一只,yì zhī
85088509
克劳斯,kè láo sī
85098510
克劳福德,kè láo fú dé
85108511
克勤克俭,kè qín kè jiǎn
@@ -22078,7 +22079,7 @@
2207822079
大屠杀,dà tú shā
2207922080
大屠杀事件,dà tú shā shì jiàn
2208022081
大屯火山,dà tún huǒ shān
22081-
大山,tài shān
22082+
大山, shān
2208222083
大山谷州立大学,dà shān gǔ zhōu lì dà xué
2208322084
大山猫,dà shān māo
2208422085
大峡谷,dà xiá gǔ
@@ -51148,7 +51149,6 @@
5114851149
海里,hǎi lǐ
5114951150
海西,hǎi xī
5115051151
海西州,hǎi xī zhōu
51151-
普拉格曼提克,pu la ge man ti ke
5115251152
海西蒙古族藏族自治州,hǎi xī měng gǔ zú zàng zú zì zhì zhōu
5115351153
海角,hǎi jiǎo
5115451154
海角天涯,hǎi jiǎo tiān yá
@@ -61389,7 +61389,7 @@
6138961389
砍伤,kǎn shāng
6139061390
砍价,kǎn jià
6139161391
砍刀,kǎn dāo
61392-
砍大山,kǎn tài shān
61392+
砍大山,kǎn shān
6139361393
砍断,kǎn duàn
6139461394
砍树,kǎn shù
6139561395
砍死,kǎn sǐ
@@ -89152,6 +89152,7 @@
8915289152
电机,diàn jī
8915389153
电机及电子学工程师联合会,diàn jī jí diàn zǐ xué gōng chéng shī lián hé huì
8915489154
电气,diàn qì
89155+
八大山人,bā dà shān rén
8915589156
电气化,diàn qì huà
8915689157
电气工程,diàn qì gōng chéng
8915789158
电气石,diàn qì shí
@@ -95692,7 +95693,6 @@
9569295693
八大锤,bā dà chuí
9569395694
八大胡同,bā dà hú tòng
9569495695
八大家,bā dà jiā
95695-
八大山人,bā tài shān rén
9569695696
八代,bā dài
9569795697
八刀,bā dāo
9569895698
霸道横行,bà dào héng xíng
@@ -145087,7 +145087,7 @@
145087145087
三足,sān zú
145088145088
三足鼎立,sān zú dǐng lì
145089145089
三尊,sān zūn
145090-
三座大山,sān zuò tài shān
145090+
三座大山,sān zuò shān
145091145091
三唑磷,sān zuò lín
145092145092
三唑酮,sān zuò tóng
145093145093
桑白皮,sāng bái pí
@@ -149691,7 +149691,6 @@
149691149691
双鱼宫,shuāng yú gōng
149692149692
双月,shuāng yuè
149693149693
霜月,shuāng yuè
149694-
卢比杠拼音,lu bi gang pin yin
149695149694
双增双节,shuāng zēng shuāng jié
149696149695
双折射,shuāng zhē shè
149697149696
双针,shuāng zhēn
@@ -168619,7 +168618,6 @@
168619168618
原岩,yuán yán
168620168619
羱羊,yuán yáng
168621168620
远洋船,yuǎn yáng chuán
168622-
纽布里奇盖特,niu bu li qi gai te
168623168621
鸳鸯湖,yuān yāng hú
168624168622
鸳鸯锦,yuān yāng jǐn
168625168623
鸳鸯楼,yuān yāng lóu
@@ -175179,4 +175177,4 @@
175179175177
左宗棠,zuǒ zōng táng
175180175178
做作业,zuò zuò yè
175181175179
作作有芒,zuò zuò yǒu máng
175182-
一只,yì zhī
175180+
纽布里奇盖特,niu bu li qi gai te

0 commit comments

Comments
 (0)