|
本帖最后由 qunwang6 于 2017-6-9 00:23 编辑 $ ?+ L6 W4 ]8 a/ n+ r* ~& z% m
" u- j* o% G1 e" ]* p/ u
# _# H; u/ m3 m20170609更新:4 h$ c, \8 i: `$ i& Z
新版pyglossary 要安装以下环境:sudo pip3 install lxml beautifulsoup4 html5lib
1 C% @& S) v t: gPython 改成Python3 ; e+ _" d0 G4 ]) a
✍准备好以下环境:* H: c, b( o5 a4 f" U) c
* BeautifulSoup4 required to sanitize html contents.
+ p% {0 b7 ?3 _( d a3 Z" `sudo easy_install beautifulsoup4 html5lib- @+ B- m. E' ~" T
* GNU make as part of Command Line Tools for Xcode.
9 c% f `% }) l o, e7 K8 L8 Ehttp://developer.apple.com/downloads
1 m2 o( J4 R* N5 j) M7 Y9 G* Dictionary Development Kit as part of Auxillary Tools for Xcode 7 l8 A% E: l$ q Y
http://developer.apple.com/downloads.% w" V# F8 b0 A$ z6 @
将Dictionary Development Kit解压到/Applications/Utilities/DictionaryDevelopmentKit/
7 |0 `+ L4 m( F" T6 D(不含空格,中文名:应用程序/实用工具那里,也可以解压到其它地方。) : Y$ `5 W* {. B* t$ _0 Z
- ~( [' W! l8 Q
5 E( ~( c+ _" F+ ?# h* [- X, _$ Y8 v
BGL ===> OSX.dictionary2 e$ O5 t) G2 o. a4 X* y# R
转换- python pyglossary.pyw --read-options=resPath=OtherResources --write-format=AppleDict dict.bgl dict.xml
复制代码 编译
% o9 ?' Q. ]4 t5 Y0 @: f# w. x* 修改Makefile里2个参数,DICT_NAME是生成文件的名称,DICT_BUILD_TOOL_DIR是Dictionary Development Kit的路径,如果错了就不能生成文件。) ^% j4 T- c7 h/ J, y: F
* 修改Info.plist里3个参数,CFBundleName是在Mac字典程序工具栏下面显示的标签名,CFBundleDisplayName是词典名称,CFBundleIdentifier是词典的ID,需保持唯一性。。& ]+ S# i4 l) q
* 根据模板格式编辑Dictionary.xml、Dictionary.css,如果有图片则放置在OtherResources/目录下.- [ B4 g* n2 V4 V0 l5 s$ H, ~ }
* 打开终端,cd进入模板文件目录,输入make,稍等一段时间,即可生成字典文件,将object目录下生成的dictionary文件拷贝至 ~/Library/Dictionaries,打开字典程序,即可看到生成的字典。
% J9 L: A5 A) }& r或者直接用make && make install这个命令,生成词典后直接安装到了~/Library/Dictionaries。
" H& T5 [0 F8 N. I7 O# ]$ S+ S
- v( Q5 V0 @% i# d' L8 L**注意:如果OtherResources里的图片太多的话会出现以下错误:**
4 T. a+ D# S* C8 F S; w! k7 ~& G3 D/Volumes/Macintosh HD/Applications/Utilities/DictionaryDevelopmentKit//bin/build_dict.sh: line 206: /bin/cp: Argument list too long) |, ~9 I z" P$ Q P( E! h& t' R3 I! D
Error.4 \/ H0 q$ f8 r/ w% @
make: *** [all] Error 1 2 [) ]2 t" o$ J
' }, e. z' C; K0 G
可以在编译前不加入图片、语音文件,在编译完成后将图片、语音文件复制到xxx.dictionary/Contents目录下。
- Z! X6 D1 u" @, [2 D9 [- a; w1 ]1 E9 x5 Q: t
S+ X% `( _' t8 Q! @
3 Y( y/ |9 y+ j i% P3 _; n
DSL ===> OSX.dictionary h9 J' F# C* O' J
0 i( a7 w# ~# {7 J$ _- N# y
1. Convert DSL from UTF-16 to UTF-8:- iconv -f UTF-16 -t UTF-8 dict_utf16.dsl > dict_utf8.dsl
复制代码 ( Y9 U% I3 S9 r( A* z( t
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
复制代码
* P- J! e4 _1 t/ N8 M**lingvo格式.dsl转换成可发音的词典。(注意修改命令参数)**↓
6 h/ {# U# T s1 taudio conversion is optional, "no" by default. The following command works,
1 G+ I9 C" W$ d~/Development/pyglossary/pyglossary.pyw --read-option="audio=yes" test.dsl test.xml: s. y% f9 O: C W3 F
make && make install - python /Applications/Utilities/DictionaryDevelopmentKit/pyglossary/pyglossary.pyw --read-options="audio=yes" --write-format=AppleDict ldoce55.dsl ldoce55.xml
复制代码 $ G/ D" X$ R, L4 J6 t
3. Using Command Line Tools for Xcode and Dictionary Development Kit:编译步骤同BGL ===> OSX.dictionary
2 X# M) x* Z" D9 w9 l4 M- make
8 B& q& W; V" E; r) R - make install
复制代码
" q% `$ z8 n l# T3 L
+ h+ Y7 E0 l8 y& C0 }4 AMDX ===> OSX.dictionary
% i* |' R- g: @( y" R4 k9 W2 Z1 S) u f5 n2 `$ Z3 e* b8 u
转换
/ ^; U+ Y7 X6 B, R4 g$ H* K- cd ~/Downloads/oald8/; P1 M$ p7 O: V( ], v
- ~/Software/pyglossary/pyglossary.pyw --read-options=resPath=OtherResources --write-format=AppleDict oald8.mdx oald8.xml
复制代码 & r% g: Z& W' K% m! w% J4 ~
修改.xml文件里的链接(如果不是可发音的词典,以下两步可略过) M$ o# ~& B, F( X7 d# N
- sed -i "" 's:src="/:src=":g' oald8.xml9 T2 x$ Q7 {/ g6 E$ q
- sed -i "" 's|sound://\([/_a-zA-Z0-9]*\).spx|\1.wav|g' oald8.xml
复制代码 第一个是去掉"/"* `( j4 p4 t# T9 b. N0 A
第二个是去掉”sound://" ,".spx"改成".wav"# e, E% q3 t5 h: c
6 d6 k* [; c( Y# W1 X4 V
将.spx语音文件转换成.wav(需要安装speex,麻烦!可直接从lingvo那里复制,或者直接从原光盘提取)- find OtherResources -name "*.spx" -execdir sh -c 'spx={};speexdec $spx ${spx%.*}.wav' \
复制代码 4 K: m- K0 \9 l9 U4 i+ o! ?: @
编译步骤同BGL ===> OSX.dictionary/ \: N/ r& h8 r- u0 @. u6 |
注意:如果OtherResources里的图片和语音文件太多的话会出现错误,可以在编译前不加入图片和语音文件,在编译完成后将图片复制到xxx.dictionary/Contents目录下。
* C; v! j, u% m
- O& h ?4 T- J9 T+ I+ i' lCD(原词典光盘)===> OSX.dictionary
4 j0 g( E# ]8 [1 U+ J& d' |以OALECD8为例。
! |4 T8 F% v0 b: X* C9 i数据提取:虚拟机xp+python2.7,用IDMSKconv提取。
1 L* \7 X$ o2 u! ~4 D/ P- |制作:从OALECD8安装目录下找到oalecd_master.css.BAK、从提取出的数据里找到output文件、以及图片和语音mp3文件,复制到Mac OSX下备用。1 ? Z' g" s2 |: |7 S1 v8 b8 |6 A
将output文件重命名为oalecd8.xml,oalecd_master.css.BAK作为CSS文件重命名为oalecd8.css,从Dictionary Development Kit里找到模板文件分别复制出MyInfo.plist、makefile文件,MyInfo.plist重命名为oalecd8.plist,修改oalecd8.plist和makefile里的参数。
* M' ]* I' V/ V1 P, |排版:里面各种奇形怪状的标签可以不必修改,有oalecd_master.css.BAK作为默认CSS,所以只需要在oalecd8.xml里添加头部和尾部,删除不要的东西,就可以编译出和原版相同的词典。2 Y! ~: B+ A q5 C& u! N' C6 A" Z
......
- z4 E3 P. c0 C& L4 l3 b
' E0 ?* @+ ?8 v) n* x+ w# k) ~. U( x2 Q###参考:
4 b8 r$ V# [1 }- x4 D* GoldenDict Mac OS X available - Early Access Builds
$ `- N" z' o3 `: m v" J* PyGlossary Overview ! K" D0 o& E% s+ w# V$ j+ n
*https://developer.apple.com/libr ... /doc/uid/TP40006152
+ T0 ~ V5 h$ D, M
$ t1 z s2 h' n+ S) j0 v0 G# `细节部分
. X4 p7 l8 M+ c9 F" Q5 r
. A4 D, f9 T# g7 Z4 hv======* 注意修改单词内部的链接========v! ^5 c7 K2 k" X) S( u
单词跳转用x-dictionary:r:
0 F/ Y, ~6 q, q3 `. K6 C: s(只能在当前词典内跳转且x-dictionary:r:后的单词大小写须与d:entry id="***"里的大小写一致,不能有空格否则不能跳转。)0 I% o5 b3 g- [8 m/ ~- i e
6 L2 c+ {2 N& |2 N
单词查找用x-dictionary:d:; y% a" {% ]. B9 i; o- s) z
(会先搜索当前的词典,若没有,会调用其它词典搜索,不限大小写、空格。)7 a# Q- g9 }$ N; E
(基本上都是用r,用d很少)
6 }+ l5 p5 e" H* a^==============================^0 `9 H- Q( u+ l3 y9 O" c
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スキームに
) [' X2 W6 `/ T3 g D次のようなものもあります。
: { g# y3 U1 Y t) }x-dictionary:d:key_text:dict_bundle_id
5 E8 _2 e' q! @# A, e! c: yx-dictionary:r:reference_id:dict_bundle_id
) y6 r" }. c' H* `0 ]. _- r& j( Y" s**1key_text 調べたい単語
7 Q. L; @' X, d/ j) F2 H! j**2reference_id 辞書を作るために作成するdictionary.xmlの/ M# u/ y6 l I4 z2 I" y7 |
各タイトルごとに割り当てる固有のエントリーID
1 D. G1 u, e- d% b/ V! P<d:entry id="0ABCDE" d:title="案の定"> 5 G! W; k6 Z: l- M% Z& z
* ex.
( Q3 m+ \3 R! j) [* v
9 u4 Q/ N6 [* S1 d$ j0 d' a1 W8 S6 L
8 t7 o1 q& Q: P3 x) p" e: F% C& P; @: j <d:entry id="make a face" d:title="make a face">
4 I$ C, A1 A8 d# M Y( |( d9 t1 |* A% ~ R; m <d:index d:value="make a face"/>8 n5 \' d) i3 |
<html><body><h1>make a face</h1>
( i9 {$ ^$ z- R% L0 X; h) V! T. u <a href="entry://grimace">grimace</a></body></html>2 {+ E, J# N( P0 n2 c/ X
</d:entry>
4 ?7 f A" Q1 @- X" r& M/ ?% s, v% E3 y4 T e4 P" u! L
<d:entry id="make faces" d:title="make faces">
6 S' R3 E& ~3 z <d:index d:value="make faces"/>+ J& K3 e$ @ ^: w, C* g
<html><body><h1>make faces</h1>: c2 p1 R7 _5 ^1 u
<a href="entry://make a face">make a face</a></body></html
I: k4 t i/ y4 T, U </d:entry>
2 j. j- b$ f1 U6 ~" ?) R7 E1 e' M3 b, O1 H+ o ]
"entry://grimace"
4 f7 R! s! }9 S: Z3 Y5 F( d将entry://替换为x-dictionary:r:- e+ |6 @$ v3 d( `
===>"x-dictionary:r:grimace"
4 K% V/ o, k6 A! S% J; H: K$ }3 X; r3 Y
d:entry id="make a face"
3 ]5 ]; y% r4 ~# }href="entry://make a face"
' h' z6 R# J0 O* T3 q类似上面的单词,中间不能有空格,否则单词间不能跳转。2 e5 v' Z2 v7 A
===>/ d M5 N: X: z% p
d:entry id="make_a_face"
. {9 A2 k0 s6 J$ X! Y8 m- m' \href="x-dictionary:r:make_a_face"- g9 r5 d- A7 a' _
替换空格需要用到的正则表达式:
6 V. @/ m5 m4 _(在此感谢ryuya,https://pdawiki.com/forum/thread-13044-1-1.html)- (<d:entry id="[^"]+)\s替换为\1_
复制代码- (href="x-dictionary:r:[^"]+)\s替换为\1_
复制代码 4 D) R+ F9 c9 R; U' n: t
v=========词组/词性跳转、定位===========v
* X% ?) {3 g6 Z6 z- m9 N8 C词组/词性页面内定位
% x( P/ A) e( b/ p; r<a class="LP_OS" href="entry://#L_hkx1">suffix</a> |7 g4 S' _8 K5 b1 I
<a name="L_hkx1"></a>
' t" o0 N+ w4 \( E7 k i==> <a class="LP_OS" href="#L_hkx1">suffix</a>
% h* W$ M( v) Z# x6 u------------------
8 h: }' \# n, {5 n& ~" [; Q词组/词性跳转并定位2 i1 Q' y% f! `2 s+ D/ f' E7 w
<a href="entry://clip#ld3097">clip</a>
. |) z* Q4 a2 F6 ~! ^<a name="ld3097"></a><span class="L_IDOM">$100 / 50 cents etc a clip</span>
) A# T- l! P1 l w1 y8 G==> <a href="x-dictionary:r:clip:#ld3097">clip</a> K) d4 F" a" T% @ v+ W" I+ S6 X. r
用到的正则表达式:
7 k# M2 s, m8 M5 ^5 G* bx-dictionary:r:(.+?)#) ~+ `- w, s) ?. m8 h) T
替换为:" [4 k5 ^$ Y4 J$ k T2 ]
x-dictionary:r:\1:#
5 C4 D$ q3 T3 e. W2 c相关的词典:朗文当代英语词典英汉双解第4版4 Z3 l3 n% B4 }
Shorter Oxford English Dictionary Sixth Edition
5 v" h/ ]" w1 [8 v3 L4 { [^=========词组/词性跳转、定位===========^
* k- D7 Q; v* A/ B) R 0 B l2 L" l- q V4 t1 V/ t/ @
! b) S+ a0 n0 l另外一个开源项目
! v4 D7 p" b9 M, {8 l- HDSL to OS X/iOS dictionary converter(相关教程可到我的空间相册里查看); q. ]) D' L* ~3 A1 E
https://github.com/svintuss/DSLConverter
% ^$ y7 t+ r3 x) [% _( D! s" r% T StarDict转换工具; [' k9 I u+ O5 S$ P# K1 @
https://code.google.com/p/mac-dictionary-kit/
. i* D+ D: y# K/ s9 M关于金山字体问题 o, O/ m0 C2 C" l
http://www.linuxsir.org/bbs/thread363915.html( t$ M5 X' c' U+ s, W4 n) s
许多Linux词典也使用了Kingsoft Phonetic Plain字体,但是能下载到的金山字体一般都不是unicode编码的,导致Linux下音标显示为方框。实际上用FontForge修改一下金山字体即可使用。/ p! p. q- c$ }, D* b8 `6 {' I
安装FontForge:
' c/ f6 l, Q! e- x- w0 w# }#urpmi fontforge% k( c4 s) \6 l/ c- ?0 Y' e! ~% d. d
然后用FontForge打开金山字体文件,你可以看到FontForge对字体里的每一个字形都分两行显示。上面小的是字符的名称,下面大的就是那个字符的字形了。金山字体本来是对普通拉丁字符赋予音标字形的一个字体,但是因为它不是unicode编码,在Unicode的拉丁字符区一个字形都没有。9 O4 @* C9 X" ~3 `2 s& h; a9 U3 T$ V
所以首先要找到金山字符的位置,比较靠后。注意从一个空格字形开始的。这个空格很重要,因为空格和之后几个符号的字形跟普通拉丁字符的字形没有区别,所以我们用来定位所有的金山字符。
n. @0 M: S& ~; N" n' }* ^找到之后,从空格开始选定所有的字符,大约有三四十个。剪切之。
/ y+ m4 z0 H4 @3 w9 W8 P$ V i然后找到拉丁字符区。可以看到所有的字形都是“X”,也就是空。找到表示空格的那个字符位(U+0020),选中,复制。所有的金山字形就按照顺序复制到这个字符位以及之后的字符位去了。% }) `" c7 T/ f! b. c$ u+ R/ I( o
最后保存成.ttf文件就OK了。保存的时候会有一些提示信息,照着做一下就行。8 f9 H% X3 U+ K
顺便发一个做好的.ttf文件。仅为技术探讨,版权归原作者所有。
2 K9 M" \8 H( o6 h8 j; t/ P
; Y t' i% R4 N6 r- h0 C- }0 c& ? . Q' G2 p- F# g; t3 T* @) N
一些小技巧) f Z# B) A& B7 J' H3 R
Mac osx 下可以用三指取词,但在一些第三方软件下是不起作用的。
1 O7 O3 I* O. v7 |0 s不过结合Alfred这个神器+下面这个脚本可实现热键取词。同理可将网上流传的“142000个单词语音库”解压到同一个文件夹内,借助内置的afplay命令+Alfred+下面的脚本,可做到热键取词发音。- afplay /Users/qunwang6/Sound/Webster/{query}.wav
复制代码
F. D9 n% N+ O& [. A生词本+ |; X4 a2 D/ v. M/ m( F
BetterDictionary
/ |. m: K" R/ Y% P. O8 @4 T" J3 t4 v9 h& p9 P# U- j! @% ~
...
7 q: B7 x w2 I o. F( }
$ ^% z. g6 U4 b, r( S% }自己动手,丰衣足食。先发颗种子。. I }& i3 _, D( N' x
D: _8 {& r/ \4 D( @2 E4 |% u: j5 d( H& u7 L W- P. d
链接: http://pan.baidu.com/s/1i3rgl7n 密码: vcpf
+ L. J- U& m+ {( P @" S; \ |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?免费注册
x
评分
-
1
查看全部评分
-
本帖被以下淘专辑推荐:
- · REFIDX|主题: 90, 订阅: 34
- · 工具|主题: 61, 订阅: 28
- · 词典制作|主题: 111, 订阅: 24
|