|
本帖最后由 qunwang6 于 2017-6-9 00:23 编辑 , L. B, K" ^( D/ o
: M" ~" U* c5 o5 f7 r- _) h# e% x# G& w) V
20170609更新:* a, V; D" B, T( T
新版pyglossary 要安装以下环境:sudo pip3 install lxml beautifulsoup4 html5lib / b! A* j* W+ b! u( \ G$ o! c, u
Python 改成Python3 * B! m; s% O! [$ X& _+ ^* ~
✍准备好以下环境:
% G; K. h0 b# d8 S! t4 L3 w, d8 n$ l* BeautifulSoup4 required to sanitize html contents.
v0 U7 b% S# \$ ~6 Msudo easy_install beautifulsoup4 html5lib
$ H; C. f: o$ p9 N( g0 s* GNU make as part of Command Line Tools for Xcode.
Q! H& ~" J2 @; ]http://developer.apple.com/downloads
8 |! K4 `% s: m( L( r* Dictionary Development Kit as part of Auxillary Tools for Xcode ; j: e0 G7 H" g4 Y
http://developer.apple.com/downloads.
0 l: G6 `6 s4 n将Dictionary Development Kit解压到/Applications/Utilities/DictionaryDevelopmentKit/7 `( y" b6 x4 e* ]: e; t7 L
(不含空格,中文名:应用程序/实用工具那里,也可以解压到其它地方。) 8 r" ^. V! A8 p+ r) y7 r1 S5 v
8 ^( N. _/ ~8 O9 Z I; x( J
$ l3 n: T% V8 g( b+ t# p' q3 A2 r3 Z
BGL ===> OSX.dictionary i$ B1 n0 M3 K( a. l2 K! G
转换- python pyglossary.pyw --read-options=resPath=OtherResources --write-format=AppleDict dict.bgl dict.xml
复制代码 编译1 b) p" V/ z4 W8 X" b# ^* E
* 修改Makefile里2个参数,DICT_NAME是生成文件的名称,DICT_BUILD_TOOL_DIR是Dictionary Development Kit的路径,如果错了就不能生成文件。% \7 \/ o$ ~9 y3 I
* 修改Info.plist里3个参数,CFBundleName是在Mac字典程序工具栏下面显示的标签名,CFBundleDisplayName是词典名称,CFBundleIdentifier是词典的ID,需保持唯一性。。& t$ I' E5 |0 x9 Q6 F- _" v# @$ K
* 根据模板格式编辑Dictionary.xml、Dictionary.css,如果有图片则放置在OtherResources/目录下.) z8 a6 {* `- t y& c
* 打开终端,cd进入模板文件目录,输入make,稍等一段时间,即可生成字典文件,将object目录下生成的dictionary文件拷贝至 ~/Library/Dictionaries,打开字典程序,即可看到生成的字典。+ R1 X7 W1 v" I) |" s q6 I. S7 ?
或者直接用make && make install这个命令,生成词典后直接安装到了~/Library/Dictionaries。
- m4 S% ]5 X. g$ B: T5 \
; O+ l5 S4 v; @% x**注意:如果OtherResources里的图片太多的话会出现以下错误:**% s' C/ _1 l# M8 U. |
/Volumes/Macintosh HD/Applications/Utilities/DictionaryDevelopmentKit//bin/build_dict.sh: line 206: /bin/cp: Argument list too long
) g; V/ L8 @5 Y3 q. {& D( OError.
5 V; C4 R5 E; j+ `make: *** [all] Error 1 4 T: B( m a( }7 x1 F* X
3 L n7 U4 U' r2 w% n. [
可以在编译前不加入图片、语音文件,在编译完成后将图片、语音文件复制到xxx.dictionary/Contents目录下。2 O0 U4 C, K2 P* x
5 _) b/ ~$ f$ F7 p
6 i3 `' L7 S! P* s1 l `& I- h* C/ ?/ ?1 B: N& c! z
DSL ===> OSX.dictionary
n! h6 F& P: j0 \# E, V8 P; u+ r0 W2 o8 W
1. Convert DSL from UTF-16 to UTF-8:- iconv -f UTF-16 -t UTF-8 dict_utf16.dsl > dict_utf8.dsl
复制代码 3 M. |- h6 W8 E' I+ M1 H0 ]
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
复制代码
. b2 U1 n0 {1 f' w**lingvo格式.dsl转换成可发音的词典。(注意修改命令参数)**↓
3 x6 e! [% o5 V) h6 C' K8 {audio conversion is optional, "no" by default. The following command works,
# v, k- t7 u- R~/Development/pyglossary/pyglossary.pyw --read-option="audio=yes" test.dsl test.xml! F, U) q* z% |0 J D [9 n
make && make install - python /Applications/Utilities/DictionaryDevelopmentKit/pyglossary/pyglossary.pyw --read-options="audio=yes" --write-format=AppleDict ldoce55.dsl ldoce55.xml
复制代码 , _# I6 Q$ M! N# I4 J
3. Using Command Line Tools for Xcode and Dictionary Development Kit:编译步骤同BGL ===> OSX.dictionary: s0 q( D, o0 R+ [5 v9 m
- make& Y' Q% \3 `" R; _& ]! X8 z
- make install
复制代码
4 j# E% z$ v. s * i6 ]1 A1 \3 s% d/ W
MDX ===> OSX.dictionary
5 y8 u) `* ^5 J$ G0 I, g* R9 W9 ?4 j/ }: p* W7 O
转换
. n) R/ D& \, F) O ~* S4 e3 o0 n- cd ~/Downloads/oald8/, ~" q4 C2 @, e7 p
- ~/Software/pyglossary/pyglossary.pyw --read-options=resPath=OtherResources --write-format=AppleDict oald8.mdx oald8.xml
复制代码
' Q- D5 J; K! C9 E/ k* Y* R修改.xml文件里的链接(如果不是可发音的词典,以下两步可略过)
; k# l. n9 n( m* L- sed -i "" 's:src="/:src=":g' oald8.xml
. @( i% W9 D1 d- A! K& E7 ` - sed -i "" 's|sound://\([/_a-zA-Z0-9]*\).spx|\1.wav|g' oald8.xml
复制代码 第一个是去掉"/"* [, v* p0 e& u" o# Q
第二个是去掉”sound://" ,".spx"改成".wav"
+ {' [* C. a: N9 T6 R* u4 b( s: x5 z! j: W# N
将.spx语音文件转换成.wav(需要安装speex,麻烦!可直接从lingvo那里复制,或者直接从原光盘提取)- find OtherResources -name "*.spx" -execdir sh -c 'spx={};speexdec $spx ${spx%.*}.wav' \
复制代码 . E: V. l3 `/ n
编译步骤同BGL ===> OSX.dictionary
, M) x8 J( ]! ]1 g o" }- _注意:如果OtherResources里的图片和语音文件太多的话会出现错误,可以在编译前不加入图片和语音文件,在编译完成后将图片复制到xxx.dictionary/Contents目录下。2 K: j+ Q1 J3 ?0 X
& D& `& r9 O$ Q3 MCD(原词典光盘)===> OSX.dictionary
, U+ Y8 G0 m0 E6 V/ P9 `以OALECD8为例。
) [6 t. O E' a数据提取:虚拟机xp+python2.7,用IDMSKconv提取。
, ]8 p0 P8 z. ~3 I9 [制作:从OALECD8安装目录下找到oalecd_master.css.BAK、从提取出的数据里找到output文件、以及图片和语音mp3文件,复制到Mac OSX下备用。$ L: |$ u% W4 q" G& \/ g
将output文件重命名为oalecd8.xml,oalecd_master.css.BAK作为CSS文件重命名为oalecd8.css,从Dictionary Development Kit里找到模板文件分别复制出MyInfo.plist、makefile文件,MyInfo.plist重命名为oalecd8.plist,修改oalecd8.plist和makefile里的参数。
; A# r6 [! \0 Z4 i* |0 T排版:里面各种奇形怪状的标签可以不必修改,有oalecd_master.css.BAK作为默认CSS,所以只需要在oalecd8.xml里添加头部和尾部,删除不要的东西,就可以编译出和原版相同的词典。
! }# B; z8 f6 @. x......4 q d. M3 n+ C7 k7 B# w" V
r& ?1 b8 J* [2 a0 ~' h1 `8 F9 e
###参考:
H+ C* d+ J! R Y* GoldenDict Mac OS X available - Early Access Builds
( c/ z6 o' F9 T: D5 g: y* PyGlossary Overview . z) n/ i! J9 Y; z# e- n$ G7 T
*https://developer.apple.com/libr ... /doc/uid/TP40006152
) Z- L$ T$ I! o/ j6 @ z
, ?& k9 V, u7 d/ u# J细节部分
" I" ^5 S" T% a2 y) K0 z8 @
& [; v0 e& F$ `$ h' Tv======* 注意修改单词内部的链接========v
- }, m' z% J7 r+ B单词跳转用x-dictionary:r:/ v7 x3 u' M" z/ S* X6 b
(只能在当前词典内跳转且x-dictionary:r:后的单词大小写须与d:entry id="***"里的大小写一致,不能有空格否则不能跳转。)7 e( I( I5 Z s @
% R/ A9 k: G# N' x. _3 i单词查找用x-dictionary:d:/ {# E' T! F" z! i6 F+ ?
(会先搜索当前的词典,若没有,会调用其它词典搜索,不限大小写、空格。)& ~1 y o0 ~$ C2 x
(基本上都是用r,用d很少)
- f* A1 n) e* Q. j% e' j9 p5 C, E^==============================^% z6 O [/ D* x
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スキームに
3 j6 i6 ^ M/ w0 E次のようなものもあります。
" @) w. k" m# |% y4 ?* Vx-dictionary:d:key_text:dict_bundle_id
. {7 @7 b1 ^3 kx-dictionary:r:reference_id:dict_bundle_id$ W9 e) X: v% w, d
**1key_text 調べたい単語! S" g8 L" e( ^3 k, s
**2reference_id 辞書を作るために作成するdictionary.xmlの7 K/ }5 q, x* t0 j2 y' n
各タイトルごとに割り当てる固有のエントリーID: r" `- ?; C- T' g$ Q- y
<d:entry id="0ABCDE" d:title="案の定">
+ x3 C! r8 _9 K0 a; D$ T* ex.) H8 j; G$ J3 x' |4 z1 o
( w4 G$ p; P9 `0 ] P6 b* ]# D
5 m: P/ A8 b/ t0 a5 } <d:entry id="make a face" d:title="make a face">
$ Y% h* [& Q0 G <d:index d:value="make a face"/>
; Z+ s% H/ g$ @6 E( C <html><body><h1>make a face</h1>! M$ |5 q( O- u; R" S4 ~$ P" _
<a href="entry://grimace">grimace</a></body></html>
3 c( j' u- Z$ C) n0 g" e; n </d:entry>, @/ \, c/ d5 p8 y' i" [$ {8 ]
0 n, m& R: `6 X
<d:entry id="make faces" d:title="make faces">
w! N8 l1 X: }! M) w1 v* s <d:index d:value="make faces"/>2 i; y) L7 J( R' `" ~) _3 \: [) F1 f
<html><body><h1>make faces</h1>
* H- q, M6 d5 w ? <a href="entry://make a face">make a face</a></body></html+ v/ E2 T0 Z A! l$ }' B" X
</d:entry>
8 @/ J: h$ O- G* }# F6 V$ x. q9 l1 D& Q% k8 ?5 E% }
"entry://grimace"
+ l4 a0 t" t$ A$ A' L& y/ q& K将entry://替换为x-dictionary:r:
. K" V6 M2 _5 U8 o===>"x-dictionary:r:grimace"
! u8 X( |! ]; X# D: N7 Q
; V/ ]; P: m1 D& `2 bd:entry id="make a face"
8 }* E' S5 x) x0 _4 ?3 d$ Rhref="entry://make a face"7 Z1 ]! _, Q# s( y/ I& V
类似上面的单词,中间不能有空格,否则单词间不能跳转。& c/ i/ B1 F4 V' \/ ?2 {0 G" z
===>
5 K* R0 K: K. v ed:entry id="make_a_face"; ^& r# T! V; E
href="x-dictionary:r:make_a_face"+ i% x' F+ E- v! v+ |1 j
替换空格需要用到的正则表达式:
. d7 @4 p- W) ]* ~3 c. z- `$ @(在此感谢ryuya,https://pdawiki.com/forum/thread-13044-1-1.html)- (<d:entry id="[^"]+)\s替换为\1_
复制代码- (href="x-dictionary:r:[^"]+)\s替换为\1_
复制代码
1 Y/ M% G3 H7 O2 ?v=========词组/词性跳转、定位===========v2 `+ _) l' w8 U( r
词组/词性页面内定位
4 i5 F7 K9 N% R8 W<a class="LP_OS" href="entry://#L_hkx1">suffix</a>
0 N) F' H# D" u! t' Y<a name="L_hkx1"></a>0 Y& c Y& i1 a$ j+ @; p
==> <a class="LP_OS" href="#L_hkx1">suffix</a>$ Y1 e0 T) W" {
------------------
: e2 H/ c/ S2 P词组/词性跳转并定位# L2 ]- [# I" f) F6 G
<a href="entry://clip#ld3097">clip</a>
' Y# ?7 L" P0 [' Y<a name="ld3097"></a><span class="L_IDOM">$100 / 50 cents etc a clip</span>6 A4 t& e `" [1 S) o* [
==> <a href="x-dictionary:r:clip:#ld3097">clip</a>: e% G: a5 d2 L* r. W; r
用到的正则表达式:
# s* W u1 O) D Xx-dictionary:r:(.+?)#& o O$ k ~& l5 x" ~( `
替换为:8 R4 {. D0 W9 A& o6 o4 S2 A
x-dictionary:r:\1:#
/ S5 M- \4 g2 L: Q; k4 p2 Z相关的词典:朗文当代英语词典英汉双解第4版
" r* b, \8 S3 R. W4 a) i9 a, L3 RShorter Oxford English Dictionary Sixth Edition2 \8 y" D5 K; |% q* b
^=========词组/词性跳转、定位===========^
2 l4 Y! ]% @; ~9 l, u, R 9 \1 F8 p# C9 o* S1 b4 P7 m0 _
. `' `* t" q Q
另外一个开源项目
* J+ R9 |8 l6 t/ m' h- ~DSL to OS X/iOS dictionary converter(相关教程可到我的空间相册里查看)& } m6 s& B, V1 N% p
https://github.com/svintuss/DSLConverter
- j% _' l u8 d: x- f* ] StarDict转换工具
' J+ Z7 s" ]. _/ _https://code.google.com/p/mac-dictionary-kit/- Y* n B1 t1 i2 M
关于金山字体问题4 u+ P- ^4 y$ Z- u
http://www.linuxsir.org/bbs/thread363915.html/ o8 N w2 N" ~: d# @
许多Linux词典也使用了Kingsoft Phonetic Plain字体,但是能下载到的金山字体一般都不是unicode编码的,导致Linux下音标显示为方框。实际上用FontForge修改一下金山字体即可使用。
b* i8 A, O0 w/ `" l2 T4 y" D, A安装FontForge: Z' E1 E/ K; f+ w# c1 Z
#urpmi fontforge( W+ ^" @: y* l) x* [- B
然后用FontForge打开金山字体文件,你可以看到FontForge对字体里的每一个字形都分两行显示。上面小的是字符的名称,下面大的就是那个字符的字形了。金山字体本来是对普通拉丁字符赋予音标字形的一个字体,但是因为它不是unicode编码,在Unicode的拉丁字符区一个字形都没有。
( _# F% n" i: E9 i所以首先要找到金山字符的位置,比较靠后。注意从一个空格字形开始的。这个空格很重要,因为空格和之后几个符号的字形跟普通拉丁字符的字形没有区别,所以我们用来定位所有的金山字符。
1 v5 q9 {+ [/ o4 ?找到之后,从空格开始选定所有的字符,大约有三四十个。剪切之。
7 ?7 p' t' L, {# V2 t1 @然后找到拉丁字符区。可以看到所有的字形都是“X”,也就是空。找到表示空格的那个字符位(U+0020),选中,复制。所有的金山字形就按照顺序复制到这个字符位以及之后的字符位去了。
0 o( N N/ z r' M1 x! [9 `( _- t最后保存成.ttf文件就OK了。保存的时候会有一些提示信息,照着做一下就行。
5 n1 o9 P/ L; @顺便发一个做好的.ttf文件。仅为技术探讨,版权归原作者所有。
3 u& K% J0 _: c) m- n$ ^+ j3 t x3 ~6 p) `$ X. b
, i# W8 Z: ^) C& s2 e
一些小技巧
) C! _7 V* I' D0 K) J9 }Mac osx 下可以用三指取词,但在一些第三方软件下是不起作用的。
+ J6 m+ E! H4 P' M% D不过结合Alfred这个神器+下面这个脚本可实现热键取词。同理可将网上流传的“142000个单词语音库”解压到同一个文件夹内,借助内置的afplay命令+Alfred+下面的脚本,可做到热键取词发音。- afplay /Users/qunwang6/Sound/Webster/{query}.wav
复制代码
$ X7 L5 Q9 }" K) Z9 ~生词本
) U# |- i# k4 v. A& b5 f8 ~! `BetterDictionary4 @, Y* Q5 X4 ~8 s) j, I0 S, j
6 W$ x$ L' m4 a* q4 ?: Q6 ?" o...
8 S) q0 C# ]! ^5 d6 m2 v& s* I# d0 s
0 K7 S) w! z0 G自己动手,丰衣足食。先发颗种子。/ h* a @" i% H i
& n Z+ C- L0 z* d" N
+ ~' F; i7 a2 c5 o( g( S* ~# V, s 链接: http://pan.baidu.com/s/1i3rgl7n 密码: vcpf
6 }( `/ ]. p, E, }0 T. u1 ]8 C) Z" z8 p |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?免费注册
x
评分
-
1
查看全部评分
-
本帖被以下淘专辑推荐:
- · REFIDX|主题: 90, 订阅: 34
- · 工具|主题: 61, 订阅: 28
- · 词典制作|主题: 111, 订阅: 24
|