|
本帖最后由 qunwang6 于 2017-6-9 00:23 编辑 ' G9 n9 t4 @: j% Z, n5 T9 N; @# k
- K+ q6 J# m0 h8 X1 h1 ?5 g
9 Z' F! h* j5 w* r/ q! X
20170609更新:7 z7 U0 o& w8 P9 Y2 _( W& _
新版pyglossary 要安装以下环境:sudo pip3 install lxml beautifulsoup4 html5lib 1 f) l1 F! w! j( Z
Python 改成Python3
1 @7 T- U( E3 d4 X. ] y, o: D✍准备好以下环境:
[1 V" X, O, x m) X6 {* BeautifulSoup4 required to sanitize html contents.( ]1 b' L( _$ A" H( [
sudo easy_install beautifulsoup4 html5lib
+ j6 Y) P& [! J" X& {+ q* GNU make as part of Command Line Tools for Xcode.
- v" i& u' s* d' j; q9 |5 Whttp://developer.apple.com/downloads& m6 t* s& w* j. h/ l' r
* Dictionary Development Kit as part of Auxillary Tools for Xcode
+ [( }# O& |% m' E; I7 G9 d4 d; J* q/ dhttp://developer.apple.com/downloads.: n$ \7 n# c5 s
将Dictionary Development Kit解压到/Applications/Utilities/DictionaryDevelopmentKit/
/ @; ~2 U: q0 n5 i& A0 m(不含空格,中文名:应用程序/实用工具那里,也可以解压到其它地方。)
+ B: e( G' ^5 Q$ z$ ?
! L( p, Z$ ?; C; |
5 c g8 Y' m; b/ @/ ]3 }" ?. d/ [BGL ===> OSX.dictionary
5 B. P3 j- H2 `5 j. W转换- python pyglossary.pyw --read-options=resPath=OtherResources --write-format=AppleDict dict.bgl dict.xml
复制代码 编译9 v" d, a* ~2 n$ b9 k
* 修改Makefile里2个参数,DICT_NAME是生成文件的名称,DICT_BUILD_TOOL_DIR是Dictionary Development Kit的路径,如果错了就不能生成文件。! z) S y0 X; {0 ^/ M
* 修改Info.plist里3个参数,CFBundleName是在Mac字典程序工具栏下面显示的标签名,CFBundleDisplayName是词典名称,CFBundleIdentifier是词典的ID,需保持唯一性。。8 g2 B, \9 T8 R# r. B" o
* 根据模板格式编辑Dictionary.xml、Dictionary.css,如果有图片则放置在OtherResources/目录下.
9 P5 l" l. N' t6 u. v* 打开终端,cd进入模板文件目录,输入make,稍等一段时间,即可生成字典文件,将object目录下生成的dictionary文件拷贝至 ~/Library/Dictionaries,打开字典程序,即可看到生成的字典。
7 m) O5 I0 ?) c/ m$ j" V/ A3 M# _或者直接用make && make install这个命令,生成词典后直接安装到了~/Library/Dictionaries。# y: U9 _; h F$ ~5 e8 h
0 M7 h3 A' `* H**注意:如果OtherResources里的图片太多的话会出现以下错误:**
" J3 }- i, F' f: j7 P# c' \- n/Volumes/Macintosh HD/Applications/Utilities/DictionaryDevelopmentKit//bin/build_dict.sh: line 206: /bin/cp: Argument list too long, d* o7 U5 j9 o9 m
Error.2 S5 h( k0 a3 G- s) r
make: *** [all] Error 1 ' a( {8 G3 l' m$ [, J9 n M8 L" \
/ l/ y- y0 y; Q. `$ _1 ]可以在编译前不加入图片、语音文件,在编译完成后将图片、语音文件复制到xxx.dictionary/Contents目录下。8 x9 {- m& A. u2 [3 {
2 g/ J0 B! h9 a4 d6 T
" ]" h, H1 k0 I) E, v
" [5 n% H# Q% H- l- s) @DSL ===> OSX.dictionary& b. Z( m7 B( V6 ]4 D* U
4 E# f) e( D! i. G1. Convert DSL from UTF-16 to UTF-8:- iconv -f UTF-16 -t UTF-8 dict_utf16.dsl > dict_utf8.dsl
复制代码 % _/ n! t5 z, J1 M" j
2. Using pyGlossary python project, convert UTF-8 DSL to AppleDict XML:- python pyglossary.pyw --read-format=ABBYYLingvoDSL --write-format=AppleDict dict_utf8.dsl dict.xml
复制代码 F2 I2 m/ Y2 H
**lingvo格式.dsl转换成可发音的词典。(注意修改命令参数)**↓" _' m1 S3 w" }! J' o
audio conversion is optional, "no" by default. The following command works,2 T4 w* a8 w) K" |+ N3 Q
~/Development/pyglossary/pyglossary.pyw --read-option="audio=yes" test.dsl test.xml
4 p: Z5 @" M" t3 F6 \ J. Kmake && make install - python /Applications/Utilities/DictionaryDevelopmentKit/pyglossary/pyglossary.pyw --read-options="audio=yes" --write-format=AppleDict ldoce55.dsl ldoce55.xml
复制代码 1 X( A; L6 a$ i$ i
3. Using Command Line Tools for Xcode and Dictionary Development Kit:编译步骤同BGL ===> OSX.dictionary, z2 G+ ~( o, r- A
- make( [2 P1 U) p) E) q8 b* K2 i
- make install
复制代码 7 E5 K. b* i9 I7 W% H- l% e
1 T$ E# T% V* Y: f$ Q' k# T
MDX ===> OSX.dictionary
) c" I2 T# m% `& p H7 c# n& L1 t- [9 U/ I* l$ M6 ]
转换 + B3 b+ K m2 E5 T3 X
- cd ~/Downloads/oald8/5 a" f* @4 j, X4 i
- ~/Software/pyglossary/pyglossary.pyw --read-options=resPath=OtherResources --write-format=AppleDict oald8.mdx oald8.xml
复制代码
; {3 C5 j+ @. a: \& j9 w' E修改.xml文件里的链接(如果不是可发音的词典,以下两步可略过)
$ H9 u- B' Z0 Y) Y- sed -i "" 's:src="/:src=":g' oald8.xml; \) D$ t0 X& F# x1 P
- sed -i "" 's|sound://\([/_a-zA-Z0-9]*\).spx|\1.wav|g' oald8.xml
复制代码 第一个是去掉"/"
5 h$ R& Y' y. d+ S1 m6 d' Y第二个是去掉”sound://" ,".spx"改成".wav"( C# G4 L) B2 `6 n' l) v: d
0 A+ t- ~- `8 @0 K* j 将.spx语音文件转换成.wav(需要安装speex,麻烦!可直接从lingvo那里复制,或者直接从原光盘提取)- find OtherResources -name "*.spx" -execdir sh -c 'spx={};speexdec $spx ${spx%.*}.wav' \
复制代码 ' f) ^& f7 ]7 b' o( L. G! D
编译步骤同BGL ===> OSX.dictionary
; T( \4 `1 B/ Q5 O9 M% W. J: T0 z注意:如果OtherResources里的图片和语音文件太多的话会出现错误,可以在编译前不加入图片和语音文件,在编译完成后将图片复制到xxx.dictionary/Contents目录下。
$ S+ l p. J2 c: [( ]3 K5 W
+ X$ n! `0 Z( k: @0 ~CD(原词典光盘)===> OSX.dictionary
: s! \; ], p6 \# r. z0 T以OALECD8为例。! n! G3 a2 M; P: s
数据提取:虚拟机xp+python2.7,用IDMSKconv提取。
5 d0 M$ r" ]1 L" a, h& S制作:从OALECD8安装目录下找到oalecd_master.css.BAK、从提取出的数据里找到output文件、以及图片和语音mp3文件,复制到Mac OSX下备用。" I) f% \- _6 C) G, {
将output文件重命名为oalecd8.xml,oalecd_master.css.BAK作为CSS文件重命名为oalecd8.css,从Dictionary Development Kit里找到模板文件分别复制出MyInfo.plist、makefile文件,MyInfo.plist重命名为oalecd8.plist,修改oalecd8.plist和makefile里的参数。
* o+ x! R: }+ F3 A1 X排版:里面各种奇形怪状的标签可以不必修改,有oalecd_master.css.BAK作为默认CSS,所以只需要在oalecd8.xml里添加头部和尾部,删除不要的东西,就可以编译出和原版相同的词典。& e) Y, Y% R# Z
......$ A# {1 d; p) u7 k5 \! ^5 V
1 Q3 O* o5 H+ p: B% Z5 u4 Z7 N* O###参考:: ~* z+ K5 d% _( W6 j6 ?$ v- ]
* GoldenDict Mac OS X available - Early Access Builds% G6 q; J8 C* d/ R
* PyGlossary Overview
& r4 A" U! q0 k% [1 O' P1 n*https://developer.apple.com/libr ... /doc/uid/TP40006152
. l; x2 R5 R% q7 p5 ?# s+ H! P
5 @, |' u% m% _- H3 ~$ w) y细节部分1 k" U h) L" P% t% v
5 Y2 S! q& \5 `- R1 Nv======* 注意修改单词内部的链接========v% q, x7 H+ \' l" m
单词跳转用x-dictionary:r:" G2 J7 w: n1 m. L' a
(只能在当前词典内跳转且x-dictionary:r:后的单词大小写须与d:entry id="***"里的大小写一致,不能有空格否则不能跳转。)- h+ H; H. z6 [( m( x P
: j% ]: g, t& b
单词查找用x-dictionary:d:: d5 m6 ]- P; O: J
(会先搜索当前的词典,若没有,会调用其它词典搜索,不限大小写、空格。)
. Q! L: X- H9 H9 F7 U! S1 v1 Q! W(基本上都是用r,用d很少)2 a& S) ?' N' z: m, m2 N2 p
^==============================^( Z2 o3 z6 d; L. ~+ |
The x-dictionary: URI contains three elements separated by colons as the general form—target selector, target text, and dictionary bundle ID. The target selector must be either d (for definition) or r (for reference). Use d if you want to search definitions of the following key text. Use r if you want to refer to the entry specified by the reference ID which must be unique to each dictionary. 辞書.appの辞書を引くURLスキームに% f& C/ z6 r/ U8 s6 E
次のようなものもあります。
+ |* k( V* A# gx-dictionary:d:key_text:dict_bundle_id
% C0 i* O0 b+ F9 Sx-dictionary:r:reference_id:dict_bundle_id
( {! h) L- s3 {$ h**1key_text 調べたい単語
0 s6 g8 k) T* q**2reference_id 辞書を作るために作成するdictionary.xmlの* W& j! I) a& E6 j) o
各タイトルごとに割り当てる固有のエントリーID" Q2 X5 p: |4 \( B; ?! v
<d:entry id="0ABCDE" d:title="案の定"> - \5 d. r! a* h( o8 b$ |
* ex.
- ~1 }0 {* ]1 y* _
3 ^" }) p# f1 d # e( s% b; b) M3 w j4 e
<d:entry id="make a face" d:title="make a face">* W$ q2 ]1 @$ ^' `- |
<d:index d:value="make a face"/>
, Q! D. [- B3 W q g3 I1 V4 Q <html><body><h1>make a face</h1>. ]6 r4 N- f/ L( g* u
<a href="entry://grimace">grimace</a></body></html>2 d5 V& I9 c. D3 F
</d:entry>
6 I4 j& q# ?6 a: b4 J% Y
' z4 m% B+ C7 Z0 s. K <d:entry id="make faces" d:title="make faces">. m/ @9 ^% I+ c6 ?" l( m8 [
<d:index d:value="make faces"/>) G% }$ K8 J7 u6 n
<html><body><h1>make faces</h1>$ f6 B5 i; {+ [4 r
<a href="entry://make a face">make a face</a></body></html
d, x" p' Y+ f, G </d:entry>
* Z; O% T- `, t" @* J7 M+ u
7 U; T9 v# r/ t0 D& }+ ^1 K"entry://grimace"5 j, }4 q' h6 n
将entry://替换为x-dictionary:r:0 C" V' k |; H6 k* x: K( j- p, w
===>"x-dictionary:r:grimace"
# Y, O% _- X3 T" A
& ~, A. r) N) |2 [. c0 Zd:entry id="make a face"
8 E7 y5 M+ L; X6 W8 I/ a. Jhref="entry://make a face"
; z* W; n7 l0 ]8 s) N类似上面的单词,中间不能有空格,否则单词间不能跳转。" s7 q/ a* P2 m* b7 X, M6 v& @
===>
) ?* L$ F f2 ]/ }8 Ed:entry id="make_a_face" c) b R# p, P3 e" Q) p# S; A
href="x-dictionary:r:make_a_face"
9 N) A! D' M) n& A* P5 x2 L- G替换空格需要用到的正则表达式:/ N$ `7 Y7 z6 u) F1 L
(在此感谢ryuya,https://pdawiki.com/forum/thread-13044-1-1.html)- (<d:entry id="[^"]+)\s替换为\1_
复制代码- (href="x-dictionary:r:[^"]+)\s替换为\1_
复制代码 9 W! J& k- h; x) ]
v=========词组/词性跳转、定位===========v
4 }1 |1 k( E/ N4 s7 e2 X词组/词性页面内定位
' {: W( q2 P8 ^: G, A<a class="LP_OS" href="entry://#L_hkx1">suffix</a>4 o# q. S9 O' R6 V e' e
<a name="L_hkx1"></a>( M! S- G* z7 w$ W+ u: B7 M
==> <a class="LP_OS" href="#L_hkx1">suffix</a>
7 S4 m2 w& o& Y6 d- k7 s------------------# }. s7 w' m! s$ A' b
词组/词性跳转并定位* `) q& e- ]9 G* Z# c1 O2 S/ X
<a href="entry://clip#ld3097">clip</a>* _5 }/ d1 L, b' L$ i, i- A
<a name="ld3097"></a><span class="L_IDOM">$100 / 50 cents etc a clip</span>
0 C6 L. H$ v3 y$ I==> <a href="x-dictionary:r:clip:#ld3097">clip</a>
' {& {1 {$ C' h/ e9 _用到的正则表达式:5 U3 Z b6 t! y( s5 p
x-dictionary:r:(.+?)#7 y' G) Q8 d- q% A Y' D: T L: B* L5 C
替换为:
' S/ ?2 t/ i7 ^+ tx-dictionary:r:\1:#
3 H$ g2 ^/ D2 Q2 P( D* B9 l1 @% y相关的词典:朗文当代英语词典英汉双解第4版
. c9 N1 N# g7 t+ F( _$ GShorter Oxford English Dictionary Sixth Edition6 v0 |9 ?( m( c/ K
^=========词组/词性跳转、定位===========^
! N2 B! u! d7 N& ~- k5 ~
# o" C9 h$ h9 \1 Z2 p! {! {7 [9 z
7 _5 Q+ W6 I9 _3 u d, B* V( Z另外一个开源项目
, ?8 R1 y5 `9 O! d6 ]DSL to OS X/iOS dictionary converter(相关教程可到我的空间相册里查看)# k4 ?0 p$ S$ A* A
https://github.com/svintuss/DSLConverter
5 _8 x- W, U% [& L* b StarDict转换工具- a7 R. p- k9 ^; Y) u
https://code.google.com/p/mac-dictionary-kit/' L8 O# n7 p% E) U& |
关于金山字体问题
, x+ ^4 r# Y% r: ~http://www.linuxsir.org/bbs/thread363915.html$ p1 B" X. N5 w1 y6 `: `, Z- }, X$ e
许多Linux词典也使用了Kingsoft Phonetic Plain字体,但是能下载到的金山字体一般都不是unicode编码的,导致Linux下音标显示为方框。实际上用FontForge修改一下金山字体即可使用。
2 [% s2 g: c3 y6 Y! E7 M" r, t, `安装FontForge:- h8 n. F9 C1 E7 i7 g! H
#urpmi fontforge! F, ?$ \: U' M7 i5 t8 B" e) c
然后用FontForge打开金山字体文件,你可以看到FontForge对字体里的每一个字形都分两行显示。上面小的是字符的名称,下面大的就是那个字符的字形了。金山字体本来是对普通拉丁字符赋予音标字形的一个字体,但是因为它不是unicode编码,在Unicode的拉丁字符区一个字形都没有。
; L- |4 d4 R D8 A& q: C所以首先要找到金山字符的位置,比较靠后。注意从一个空格字形开始的。这个空格很重要,因为空格和之后几个符号的字形跟普通拉丁字符的字形没有区别,所以我们用来定位所有的金山字符。
7 V# R6 ~/ n9 Y8 a7 A找到之后,从空格开始选定所有的字符,大约有三四十个。剪切之。" z4 f! j& C6 o
然后找到拉丁字符区。可以看到所有的字形都是“X”,也就是空。找到表示空格的那个字符位(U+0020),选中,复制。所有的金山字形就按照顺序复制到这个字符位以及之后的字符位去了。 E2 Y9 s! u2 H
最后保存成.ttf文件就OK了。保存的时候会有一些提示信息,照着做一下就行。! d/ T2 ?% N) V. E; a
顺便发一个做好的.ttf文件。仅为技术探讨,版权归原作者所有。 # n8 @0 s6 Z$ y9 g8 h6 X
' q0 ` I4 @/ C3 n+ z
( i- b& R5 N( G
一些小技巧' U N- N0 t/ s$ V
Mac osx 下可以用三指取词,但在一些第三方软件下是不起作用的。* h4 X& C# A( {3 p9 I
不过结合Alfred这个神器+下面这个脚本可实现热键取词。同理可将网上流传的“142000个单词语音库”解压到同一个文件夹内,借助内置的afplay命令+Alfred+下面的脚本,可做到热键取词发音。- afplay /Users/qunwang6/Sound/Webster/{query}.wav
复制代码
' w5 B7 n# S8 v生词本- Q0 K4 V5 w) X
BetterDictionary
* s6 j _3 q+ w9 V9 ?/ _3 K. { O4 f9 ^! E) U
...0 A0 v! ?0 T4 B& p$ c
5 V2 T1 I! E6 G n: P8 u/ F) L自己动手,丰衣足食。先发颗种子。
8 o: q- E/ u4 }& t% A
( o( B4 E3 p3 W/ E: W/ G: m' v0 }- o6 I. x
链接: http://pan.baidu.com/s/1i3rgl7n 密码: vcpf
' K# |, @6 H% u" C/ L |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?免费注册
x
评分
-
1
查看全部评分
-
本帖被以下淘专辑推荐:
- · REFIDX|主题: 90, 订阅: 34
- · 工具|主题: 61, 订阅: 28
- · 词典制作|主题: 111, 订阅: 24
|