|
本帖最后由 qunwang6 于 2017-6-9 00:23 编辑
& u1 P d' i3 P
! S5 R0 D7 g4 S. q' a. q5 u: j# A4 k+ h1 M; N" k( K! y+ |0 |
20170609更新:
/ v9 e( Y* _# v. H新版pyglossary 要安装以下环境:sudo pip3 install lxml beautifulsoup4 html5lib 6 L' A: F9 f2 J% E6 _
Python 改成Python3
4 Z: M) c" H$ N3 J8 Q* D- o✍准备好以下环境:
% ^- a+ B5 Z8 P( s9 x) d8 I* BeautifulSoup4 required to sanitize html contents.
% ^7 Z4 _" O3 gsudo easy_install beautifulsoup4 html5lib! w: R1 E; K( a ~( l
* GNU make as part of Command Line Tools for Xcode.
9 O* g' {* p! q7 R" t" h" G$ o- ghttp://developer.apple.com/downloads6 b& A$ o% J+ S6 E' H/ @) J6 C
* Dictionary Development Kit as part of Auxillary Tools for Xcode 7 G) o$ P# T; `( s2 ?8 m
http://developer.apple.com/downloads.
& R6 K" h B. Z! s% O将Dictionary Development Kit解压到/Applications/Utilities/DictionaryDevelopmentKit/! l |% F' d5 {$ \4 c
(不含空格,中文名:应用程序/实用工具那里,也可以解压到其它地方。)
' H; m5 p n8 j0 K
5 N7 {( v/ f) \/ ` L0 W( ]3 L
" B# r9 K: p0 \& p8 j' R1 K& ZBGL ===> OSX.dictionary9 V. N: e) W' f9 P3 ]' a
转换- python pyglossary.pyw --read-options=resPath=OtherResources --write-format=AppleDict dict.bgl dict.xml
复制代码 编译
. w1 v0 ~/ t$ Z9 q9 H2 d* 修改Makefile里2个参数,DICT_NAME是生成文件的名称,DICT_BUILD_TOOL_DIR是Dictionary Development Kit的路径,如果错了就不能生成文件。/ s j! F5 W% p4 O- O# m
* 修改Info.plist里3个参数,CFBundleName是在Mac字典程序工具栏下面显示的标签名,CFBundleDisplayName是词典名称,CFBundleIdentifier是词典的ID,需保持唯一性。。( {# G+ t1 p* S1 J- U3 m. a7 n, ~
* 根据模板格式编辑Dictionary.xml、Dictionary.css,如果有图片则放置在OtherResources/目录下.
# X" z# p0 K5 ]. o5 z* A* 打开终端,cd进入模板文件目录,输入make,稍等一段时间,即可生成字典文件,将object目录下生成的dictionary文件拷贝至 ~/Library/Dictionaries,打开字典程序,即可看到生成的字典。4 ^6 ^4 Z- g) c4 l+ G
或者直接用make && make install这个命令,生成词典后直接安装到了~/Library/Dictionaries。
$ r* ~. @: w* w4 X; a, K% C5 E8 s! V% Z0 y" C1 P4 H
**注意:如果OtherResources里的图片太多的话会出现以下错误:**
+ `' b2 H# ~: d5 i/Volumes/Macintosh HD/Applications/Utilities/DictionaryDevelopmentKit//bin/build_dict.sh: line 206: /bin/cp: Argument list too long. o: A* J7 u! k) ^/ f7 O
Error.4 `: N4 X+ W3 O; E& i
make: *** [all] Error 1 8 s, {8 J, T! o3 o3 S7 w3 U
$ n0 h* L8 Q: a9 C$ @可以在编译前不加入图片、语音文件,在编译完成后将图片、语音文件复制到xxx.dictionary/Contents目录下。6 e, p. p; x' L6 @
, a: ?; a: Y1 Y/ ~8 \8 V, s
: o/ E2 v3 j' g
& m6 n k. ]) B7 G0 k3 ~" d. i9 TDSL ===> OSX.dictionary
% z( p0 q' n$ y5 M. i# H% F' c) s$ n2 W1 X( V1 f1 T
1. Convert DSL from UTF-16 to UTF-8:- iconv -f UTF-16 -t UTF-8 dict_utf16.dsl > dict_utf8.dsl
复制代码 7 [! V- ]. W- [1 t6 V7 m
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
复制代码
/ K" c$ Z4 N& e8 [: [# k**lingvo格式.dsl转换成可发音的词典。(注意修改命令参数)**↓! x- m# L! F+ k/ N- F6 ~4 w
audio conversion is optional, "no" by default. The following command works,9 x: q0 k. C* Y- T: r/ m' }
~/Development/pyglossary/pyglossary.pyw --read-option="audio=yes" test.dsl test.xml
- l. A" T$ m0 f8 h* ^make && make install - python /Applications/Utilities/DictionaryDevelopmentKit/pyglossary/pyglossary.pyw --read-options="audio=yes" --write-format=AppleDict ldoce55.dsl ldoce55.xml
复制代码 # j6 Z1 N. F6 L4 A, x
3. Using Command Line Tools for Xcode and Dictionary Development Kit:编译步骤同BGL ===> OSX.dictionary2 x7 |) y1 i: A- j _
- make
4 }) A6 l8 S) M* g: @ - make install
复制代码
# r! X* `9 M, @3 ~ ' Y! ^( P5 B" F4 ]! M
MDX ===> OSX.dictionary) |6 v- u/ V) O3 x
+ t% z+ U$ U/ z3 R转换 : P; v5 }+ t- E
- cd ~/Downloads/oald8/1 d3 [+ P0 a# M. J
- ~/Software/pyglossary/pyglossary.pyw --read-options=resPath=OtherResources --write-format=AppleDict oald8.mdx oald8.xml
复制代码
" l) Z) P' f, O' ~- t6 \. I修改.xml文件里的链接(如果不是可发音的词典,以下两步可略过)% E4 L3 q1 d# g
- sed -i "" 's:src="/:src=":g' oald8.xml! C9 M R3 e7 X
- sed -i "" 's|sound://\([/_a-zA-Z0-9]*\).spx|\1.wav|g' oald8.xml
复制代码 第一个是去掉"/"
. O( U+ Y/ E5 m. w5 }$ H第二个是去掉”sound://" ,".spx"改成".wav"
0 C- @ G+ m: A- V0 L( b0 G) @- q1 d: Q3 x- y8 _
将.spx语音文件转换成.wav(需要安装speex,麻烦!可直接从lingvo那里复制,或者直接从原光盘提取)- find OtherResources -name "*.spx" -execdir sh -c 'spx={};speexdec $spx ${spx%.*}.wav' \
复制代码
0 E- L. G) ^+ s) Z# C编译步骤同BGL ===> OSX.dictionary. u. X, o$ c/ _7 m
注意:如果OtherResources里的图片和语音文件太多的话会出现错误,可以在编译前不加入图片和语音文件,在编译完成后将图片复制到xxx.dictionary/Contents目录下。% z Y3 s/ j. x1 \9 T
' s8 @' N7 @ O, b2 i6 `CD(原词典光盘)===> OSX.dictionary
- m( S( j- H4 k E$ G以OALECD8为例。" }# ^4 V/ L# ?# G
数据提取:虚拟机xp+python2.7,用IDMSKconv提取。
4 p1 ]# E$ z! y制作:从OALECD8安装目录下找到oalecd_master.css.BAK、从提取出的数据里找到output文件、以及图片和语音mp3文件,复制到Mac OSX下备用。
: M* x( R- M( r9 X5 p将output文件重命名为oalecd8.xml,oalecd_master.css.BAK作为CSS文件重命名为oalecd8.css,从Dictionary Development Kit里找到模板文件分别复制出MyInfo.plist、makefile文件,MyInfo.plist重命名为oalecd8.plist,修改oalecd8.plist和makefile里的参数。' @8 C1 ?! F8 f; A! L3 I5 ]
排版:里面各种奇形怪状的标签可以不必修改,有oalecd_master.css.BAK作为默认CSS,所以只需要在oalecd8.xml里添加头部和尾部,删除不要的东西,就可以编译出和原版相同的词典。' K5 w" k! y/ R) ~/ s
......
. m1 d% ^% q' {1 Z
5 |/ }/ g- H- S# ^3 b' N' A###参考:
" R- @) [# t" Q* GoldenDict Mac OS X available - Early Access Builds8 b! L# ^+ a9 ?, h2 S
* PyGlossary Overview ) O/ n) ?0 N5 _6 h+ Q# \
*https://developer.apple.com/libr ... /doc/uid/TP40006152+ q' ]" d2 w) A- X- p# t- e
( l3 x# o1 l+ S; ^细节部分6 B7 L) m. p8 i F9 H
% F% b7 W) u1 h; E0 |
v======* 注意修改单词内部的链接========v
& ]; s |+ y, i. v单词跳转用x-dictionary:r:
( n. f1 @" @) ?$ |/ A" t1 N(只能在当前词典内跳转且x-dictionary:r:后的单词大小写须与d:entry id="***"里的大小写一致,不能有空格否则不能跳转。)4 s* g0 X. j4 }* }. S7 Q, x
: `" G' y1 l* a# L) I C% g
单词查找用x-dictionary:d:" J) y& ^8 [" P2 [7 V- ~
(会先搜索当前的词典,若没有,会调用其它词典搜索,不限大小写、空格。)
* [8 [8 @7 Q. K1 ^8 d- i4 \$ Q' o# D8 H(基本上都是用r,用d很少)6 p, r U& p1 N5 p
^==============================^8 m0 Z& C( K3 W
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スキームに0 p6 u5 N; u _3 O* R3 Y5 u9 E
次のようなものもあります。
( l& P2 f# \. k9 _" `x-dictionary:d:key_text:dict_bundle_id
. u. A7 Q% d8 L E. ?+ Qx-dictionary:r:reference_id:dict_bundle_id
' n* F, ~7 o/ C0 i" g3 u) a9 X& k**1key_text 調べたい単語
6 n* U6 x3 X I; P**2reference_id 辞書を作るために作成するdictionary.xmlの
( Y4 H! t- S1 f! i& r0 h1 e各タイトルごとに割り当てる固有のエントリーID& i, x! w5 ]: T* P
<d:entry id="0ABCDE" d:title="案の定">
3 y& `: V. j, a* ex.
" Z8 T5 f) I. E0 q# Z }# @4 s. A, r6 Y' L% ^* y/ X! \
# ^+ d6 L# o, f/ N
<d:entry id="make a face" d:title="make a face">3 Q2 T* p/ G; g4 e, f/ g
<d:index d:value="make a face"/>8 C) H3 t4 t0 u! B1 @' T
<html><body><h1>make a face</h1>
! e F" M5 ~8 _# s" ~: P <a href="entry://grimace">grimace</a></body></html>" c0 o2 x% U% f2 U3 H) ]2 t
</d:entry>
2 W6 m0 v4 p3 X, _* E4 q4 t: W, y& t8 l
<d:entry id="make faces" d:title="make faces">" g' W/ e: X$ g" W
<d:index d:value="make faces"/>4 ^" L0 z- y: ?" I# y) `
<html><body><h1>make faces</h1>- w( @* G1 g6 v; C) b C) Z- r
<a href="entry://make a face">make a face</a></body></html, Z; E6 h9 h/ ]& {" ~; m' {; `
</d:entry> & v, ?0 k. |% n: @! h
! }+ v9 W1 S- |3 M1 @"entry://grimace"
( @' \$ {/ J; m6 ?/ Z6 V' T将entry://替换为x-dictionary:r:# c& M+ y" K( `2 t: G9 ]2 K
===>"x-dictionary:r:grimace". x3 J6 t# B# v" l( q% Z2 I" i
. E" m5 o. \5 U( Kd:entry id="make a face"
7 c% o7 I9 G: y5 phref="entry://make a face"' ]" e" l- m3 L5 U; L' g% h9 r
类似上面的单词,中间不能有空格,否则单词间不能跳转。
8 Q8 w$ Z* b! A& u" a# Q# ^===>
$ _" ^8 T, ~ i5 S a. |( Cd:entry id="make_a_face"6 y& k- [2 g' n( V8 h' X
href="x-dictionary:r:make_a_face"
$ }. d; e, J' x9 M) g5 a替换空格需要用到的正则表达式:
5 g% t: j+ q1 N9 A(在此感谢ryuya,https://pdawiki.com/forum/thread-13044-1-1.html)- (<d:entry id="[^"]+)\s替换为\1_
复制代码- (href="x-dictionary:r:[^"]+)\s替换为\1_
复制代码 & \) z0 S& O3 i S0 f0 a; q9 `
v=========词组/词性跳转、定位===========v
( f) V2 C$ L8 V: G$ L词组/词性页面内定位& ` K' T! Z0 k' @ h
<a class="LP_OS" href="entry://#L_hkx1">suffix</a>8 q* j6 ?, K6 k ~
<a name="L_hkx1"></a>+ b* G3 q, p& j7 f
==> <a class="LP_OS" href="#L_hkx1">suffix</a>" Z% E, n4 ]) P: p7 Z; M& ^
------------------
1 b0 e9 s+ |2 I% S5 U词组/词性跳转并定位/ x9 Q' t( D& H2 n
<a href="entry://clip#ld3097">clip</a>
# V! O+ c( D u+ Z<a name="ld3097"></a><span class="L_IDOM">$100 / 50 cents etc a clip</span>* S) K, A, K5 j3 |
==> <a href="x-dictionary:r:clip:#ld3097">clip</a>% Z G+ D8 D [9 ^+ U, `
用到的正则表达式:1 l9 I. Q1 Q: K1 p+ U+ v
x-dictionary:r:(.+?)#
0 l0 h& W: U9 o6 y( z替换为:8 F' f- C9 A+ s+ h" P
x-dictionary:r:\1:#4 W% t- j% K1 {+ [& ]: ]0 u
相关的词典:朗文当代英语词典英汉双解第4版* t8 D2 g3 m3 S8 M3 b6 u# ~
Shorter Oxford English Dictionary Sixth Edition1 F8 T0 }9 } Z$ i- V
^=========词组/词性跳转、定位===========^/ y2 ?0 s5 r* Z
1 N; a' S9 S5 i w0 ~' p# C9 h& M* T M4 ]& C4 y+ k0 {
另外一个开源项目
( G z* f/ O1 t; A: l" PDSL to OS X/iOS dictionary converter(相关教程可到我的空间相册里查看)
" r/ H0 R2 x$ C5 ? https://github.com/svintuss/DSLConverter3 _: W, l8 {! ~
StarDict转换工具
7 H0 k& D2 m( p; |https://code.google.com/p/mac-dictionary-kit/
' G1 R& e; |0 ]: {' L1 B关于金山字体问题6 {+ Z3 [% e4 a/ z0 A3 U
http://www.linuxsir.org/bbs/thread363915.html2 x& ]% ]6 ?8 k- Q. \! p6 a. J
许多Linux词典也使用了Kingsoft Phonetic Plain字体,但是能下载到的金山字体一般都不是unicode编码的,导致Linux下音标显示为方框。实际上用FontForge修改一下金山字体即可使用。
/ l( n) R! j7 Q. {/ ]! W安装FontForge:
, a: R5 D$ J; Y% W#urpmi fontforge% M1 ~2 c% t# N) w; z3 T- x' H
然后用FontForge打开金山字体文件,你可以看到FontForge对字体里的每一个字形都分两行显示。上面小的是字符的名称,下面大的就是那个字符的字形了。金山字体本来是对普通拉丁字符赋予音标字形的一个字体,但是因为它不是unicode编码,在Unicode的拉丁字符区一个字形都没有。
' R, R _ V! \# {5 N所以首先要找到金山字符的位置,比较靠后。注意从一个空格字形开始的。这个空格很重要,因为空格和之后几个符号的字形跟普通拉丁字符的字形没有区别,所以我们用来定位所有的金山字符。
, u, b6 `" y0 C找到之后,从空格开始选定所有的字符,大约有三四十个。剪切之。
5 v9 j3 D9 {9 O. {2 J7 R4 K然后找到拉丁字符区。可以看到所有的字形都是“X”,也就是空。找到表示空格的那个字符位(U+0020),选中,复制。所有的金山字形就按照顺序复制到这个字符位以及之后的字符位去了。! g& n& f; ]4 ~* J6 Z# W
最后保存成.ttf文件就OK了。保存的时候会有一些提示信息,照着做一下就行。9 e9 k5 M; A- b0 h, L
顺便发一个做好的.ttf文件。仅为技术探讨,版权归原作者所有。
1 [5 e! Y* c) @- p
# T/ K- G D: k9 f. g3 U/ V
. M9 I3 m: H' A v- W3 R* @一些小技巧0 ^. N1 @% o* m k5 V
Mac osx 下可以用三指取词,但在一些第三方软件下是不起作用的。
" f8 M& O3 u1 \" b5 v不过结合Alfred这个神器+下面这个脚本可实现热键取词。同理可将网上流传的“142000个单词语音库”解压到同一个文件夹内,借助内置的afplay命令+Alfred+下面的脚本,可做到热键取词发音。- afplay /Users/qunwang6/Sound/Webster/{query}.wav
复制代码
9 ^9 |9 q6 _" [* E9 ~( A$ ^生词本
% _6 W4 H4 K- G/ TBetterDictionary+ a$ |: V% b! e1 m! I: t$ N3 z9 o* |6 v

: D+ i& S8 n7 C1 N! P) x0 c4 b...
6 z" x$ v& b, z7 c5 }
) v& s/ X( P! ~* V3 g7 F1 u自己动手,丰衣足食。先发颗种子。
: U, q( M9 |8 z" d. o ~* e+ a3 y3 ?
8 i' {/ M* h/ l7 w5 v& [) D
链接: http://pan.baidu.com/s/1i3rgl7n 密码: vcpf; J, D& `8 ^+ \3 ~! e c5 p
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?免费注册
x
评分
-
1
查看全部评分
-
本帖被以下淘专辑推荐:
- · REFIDX|主题: 90, 订阅: 34
- · 工具|主题: 61, 订阅: 27
- · 词典制作|主题: 111, 订阅: 24
|