Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18,458 changes: 0 additions & 18,458 deletions data/s2t_conversion.txt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule ChineseTranslation.Iterable do
@moduledoc """
Utility functions
support for iterable functions
"""
@not_implemented "not implemented"

Expand Down
5 changes: 2 additions & 3 deletions lib/chinese_translation/pinyin_util.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ defmodule ChineseTranslation.Pinyin.Util do
Utility functions to read pinyin_characters.txt / pinyin_words.txt and parse
it into a list ordered by the length of the words.
"""
alias ChineseTranslation.Iterable
alias ChineseTranslation.{Iterable, Utils}

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

defp get_file_stream(filename) do
@path
Utils.data_path()
|> Path.join(filename)
|> File.stream!()
end
Expand Down
5 changes: 3 additions & 2 deletions lib/chinese_translation/translation_util.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ defmodule ChineseTranslation.Translation.Util do
Utility functions to read s2t_conversion.txt file and parse it into a list
ordered by the length of the words.
"""
alias ChineseTranslation.Utils

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

def get_trans_data do
@filename
Utils.data_path()
|> Path.join("s2t_conversion.txt")
|> get_file_content
|> match
|> Enum.map(fn [_whole, name, content] ->
Expand Down
10 changes: 10 additions & 0 deletions lib/chinese_translation/utils.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
defmodule ChineseTranslation.Utils do
@moduledoc """
utility functions
"""
def data_path do
:chinese_translation
|> Application.app_dir()
|> Path.join("priv")
end
end
19 changes: 3 additions & 16 deletions lib/mix/tasks/translation.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ defmodule Mix.Tasks.ChineseTranslation do
The task for loading latest data from wikipedia.
"""
use Mix.Task
alias ChineseTranslation.Utils

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

Expand All @@ -21,15 +22,9 @@ defmodule Mix.Tasks.ChineseTranslation do
}
]

@name "chinese_translation"
@mod_path "data"
@dep_path "deps/#{@name}/#{@mod_path}"
@beam_path "_build/dev/lib/#{@name}"

def run(_args) do
HTTPoison.start()
get_data_file(@urls)
clean_beam(@beam_path)
recompile()
end

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

defp clean_beam(beam_path) do
IO.puts("Cleaning #{beam_path}...")
File.rm_rf(beam_path)
end

defp recompile do
IO.puts("Recompiling chinese_translation...")
System.cmd("mix", ["clean"])
System.cmd("mix", ["compile"])
end

Expand All @@ -57,11 +48,7 @@ defmodule Mix.Tasks.ChineseTranslation do
end

def write_file({filename, body}) do
path = case File.exists?(@dep_path) do
true -> Path.join(@dep_path, filename)
_ -> Path.join(@mod_path, filename)
end

path = Path.join(Utils.data_path(), filename)
File.write(path, body)
end
end
28 changes: 19 additions & 9 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,25 @@ defmodule ChineseTranslation.Mixfile do
elixir: "~> 1.5",
description: description(),
package: package(),
deps: deps()
start_permanent: Mix.env() == :prod,
deps: deps(),

# exdocs
# Docs
name: "ChineseTranslation",
source_url: "https://github.com/tyrchen/chinese_translation",
homepage_url: "https://github.com/tyrchen/chinese_translation",
docs: [
main: "ChineseTranslation",
extras: ["README.md"]
]
]
end

# Configuration for the OTP application
#
# Type `mix help compile.app` for more information
def application do
[applications: [:logger, :httpoison]]
[extra_applications: [:logger]]
end

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

defp package do
[
files: ["lib", "data", "mix.exs", "README*", "LICENSE*"],
contributors: ["Tyr Chen"],
files: ["lib", "priv", "mix.exs", "README*", "LICENSE*", "version"],
licenses: ["MIT"],
links: %{"GitHub" => "https://github.com/tyrchen/chinese_translation"}
maintainers: ["tyr.chen@gmail.com"],
links: %{
"GitHub" => "https://github.com/tyrchen/chinese_translation",
"Docs" => "https://hexdocs.pm/chinese_translation"
}
]
end
end
26 changes: 13 additions & 13 deletions data/pinyin_characters.txt → priv/pinyin_characters.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10246,7 +10246,7 @@
5F88 hěn
5F89 yáng
5F8A huái
5F8B l̈ù
5F8B
5F8C hòu
5F8D wǎng,wā
5F8E chěng,zhèng
Expand Down Expand Up @@ -10729,7 +10729,7 @@
616B sǒng
616C qín,jìn,jǐn
616D yìn
616E l̈ù
616E
616F shāng
6170 wèi
6171 tuán
Expand Down Expand Up @@ -11840,7 +11840,7 @@
65C2 qí
65C3 zhān
65C4 máo
65C5 l̈ǔ
65C5
65C6 pèi
65C7 pī,bì
65C8 liú
Expand Down Expand Up @@ -15360,7 +15360,7 @@
7384 xuán
7385 miào
7386 xuán,zī
7387 l̈ù,shuài
7387 ,shuài
7388 lú
7389 yù
738A sù
Expand Down Expand Up @@ -17940,7 +17940,7 @@
7D9D *,chēn,lín
7D9E duǒ
7D9F lì,liè
7DA0 l̈ù
7DA0
7DA1 liáng
7DA2 choú
7DA3 quǎn
Expand Down Expand Up @@ -18091,7 +18091,7 @@
7E34 qiàn
7E35 màn
7E36 zhí
7E37 l̈ǔ
7E37
7E38 mù,mò
7E39 piǎo,piāo
7E3A lián
Expand Down Expand Up @@ -18291,7 +18291,7 @@
7EFC zōng
7EFD zhàn
7EFE wǎn
7EFF l̈ù
7EFF
7F00 zhui
7F01 zī
7F02 kè
Expand All @@ -18313,7 +18313,7 @@
7F12 zhuì
7F13 huǎn
7F14 dì
7F15 l̈ǔ
7F15
7F16 biān
7F17 mín
7F18 yuán
Expand Down Expand Up @@ -20165,7 +20165,7 @@
864E hǔ,hu
864F lǔ
8650 nüè
8651 l̈ù
8651
8652 sī
8653 xiāo
8654 qián
Expand Down Expand Up @@ -23349,7 +23349,7 @@
92BE hòng,gǒng
92BF zhōng,yōng
92C0 tōu,dòu,tù
92C1 l̈ǔ
92C1
92C2 méi,méng
92C3 láng
92C4 wǎn
Expand Down Expand Up @@ -23889,7 +23889,7 @@
94DA zhì
94DB dang
94DC tóng
94DD l̈ǔ
94DD
94DE diào
94DF yīn
94E0 kǎi
Expand Down Expand Up @@ -25302,7 +25302,7 @@
9A5F zhoù
9A60 yàn
9A61 lóng,zǎng
9A62 l̈ú
9A62
9A63 téng
9A64 xiāng
9A65 jì
Expand All @@ -25320,7 +25320,7 @@
9A71 qū
9A72 rì
9A73 bó
9A74 l̈ú
9A74
9A75 zǎng
9A76 shǐ
9A77 sì
Expand Down
File renamed without changes.
16 changes: 7 additions & 9 deletions data/pinyin_words.txt → priv/pinyin_words.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6058,7 +6058,7 @@
侃侃,kǎn kǎn
侃侃而谈,kǎn kǎn ér tán
侃价,kǎn jià
侃大山,kǎn tài shān
侃大山,kǎn shān
侃星,kǎn xīng
侃爷,kǎn yé
来不及,lái bù jí
Expand Down Expand Up @@ -8505,6 +8505,7 @@
克勒,kè lè
克劳修斯,kè láo xīu sī
克劳德,kè láo dé
一只,yì zhī
克劳斯,kè láo sī
克劳福德,kè láo fú dé
克勤克俭,kè qín kè jiǎn
Expand Down Expand Up @@ -22078,7 +22079,7 @@
大屠杀,dà tú shā
大屠杀事件,dà tú shā shì jiàn
大屯火山,dà tún huǒ shān
大山,tài shān
大山, shān
大山谷州立大学,dà shān gǔ zhōu lì dà xué
大山猫,dà shān māo
大峡谷,dà xiá gǔ
Expand Down Expand Up @@ -51148,7 +51149,6 @@
海里,hǎi lǐ
海西,hǎi xī
海西州,hǎi xī zhōu
普拉格曼提克,pu la ge man ti ke
海西蒙古族藏族自治州,hǎi xī měng gǔ zú zàng zú zì zhì zhōu
海角,hǎi jiǎo
海角天涯,hǎi jiǎo tiān yá
Expand Down Expand Up @@ -61389,7 +61389,7 @@
砍伤,kǎn shāng
砍价,kǎn jià
砍刀,kǎn dāo
砍大山,kǎn tài shān
砍大山,kǎn shān
砍断,kǎn duàn
砍树,kǎn shù
砍死,kǎn sǐ
Expand Down Expand Up @@ -89152,6 +89152,7 @@
电机,diàn jī
电机及电子学工程师联合会,diàn jī jí diàn zǐ xué gōng chéng shī lián hé huì
电气,diàn qì
八大山人,bā dà shān rén
电气化,diàn qì huà
电气工程,diàn qì gōng chéng
电气石,diàn qì shí
Expand Down Expand Up @@ -95692,7 +95693,6 @@
八大锤,bā dà chuí
八大胡同,bā dà hú tòng
八大家,bā dà jiā
八大山人,bā tài shān rén
八代,bā dài
八刀,bā dāo
霸道横行,bà dào héng xíng
Expand Down Expand Up @@ -145087,7 +145087,7 @@
三足,sān zú
三足鼎立,sān zú dǐng lì
三尊,sān zūn
三座大山,sān zuò tài shān
三座大山,sān zuò shān
三唑磷,sān zuò lín
三唑酮,sān zuò tóng
桑白皮,sāng bái pí
Expand Down Expand Up @@ -149691,7 +149691,6 @@
双鱼宫,shuāng yú gōng
双月,shuāng yuè
霜月,shuāng yuè
卢比杠拼音,lu bi gang pin yin
双增双节,shuāng zēng shuāng jié
双折射,shuāng zhē shè
双针,shuāng zhēn
Expand Down Expand Up @@ -168619,7 +168618,6 @@
原岩,yuán yán
羱羊,yuán yáng
远洋船,yuǎn yáng chuán
纽布里奇盖特,niu bu li qi gai te
鸳鸯湖,yuān yāng hú
鸳鸯锦,yuān yāng jǐn
鸳鸯楼,yuān yāng lóu
Expand Down Expand Up @@ -175179,4 +175177,4 @@
左宗棠,zuǒ zōng táng
做作业,zuò zuò yè
作作有芒,zuò zuò yǒu máng
一只,yì zhī
纽布里奇盖特,niu bu li qi gai te
Empty file added priv/s2t_conversion.txt
Empty file.