|
本帖最后由 qunwang6 于 2017-6-9 00:23 编辑 ' d# h& L0 b- [" b& {
7 l) ?& `* W; e
) n" A& s1 i, Q20170609更新:
3 ]- \8 F% k1 X) `7 q新版pyglossary 要安装以下环境:sudo pip3 install lxml beautifulsoup4 html5lib 0 R" z4 V5 k3 k/ f; H6 ^
Python 改成Python3 & c# k5 d$ _" E; }8 J e
✍准备好以下环境:' [7 x. R) @. P* t
* BeautifulSoup4 required to sanitize html contents.
* p1 C$ B8 C* t5 j% s8 csudo easy_install beautifulsoup4 html5lib
7 t! X* S3 O7 F. N* GNU make as part of Command Line Tools for Xcode.! k3 a6 W$ H' L, }: }
http://developer.apple.com/downloads
) [2 ~$ ]! z6 ^! G, L+ {7 Z* Dictionary Development Kit as part of Auxillary Tools for Xcode " |! n0 _7 A) U5 I+ J9 b; d
http://developer.apple.com/downloads.
2 w, x* F5 X# L将Dictionary Development Kit解压到/Applications/Utilities/DictionaryDevelopmentKit/
8 S* ?$ U9 L9 | y+ e6 n/ V& J: S(不含空格,中文名:应用程序/实用工具那里,也可以解压到其它地方。) 8 r& m& s) B4 g5 V
r, Z3 C6 |8 f/ N7 ^) K
% k$ Z; R4 j4 C/ R; a0 U; aBGL ===> OSX.dictionary7 r) l/ K4 E" f* b
转换- python pyglossary.pyw --read-options=resPath=OtherResources --write-format=AppleDict dict.bgl dict.xml
复制代码 编译7 q, d; h7 Z0 B2 ?, m1 e! V! z
* 修改Makefile里2个参数,DICT_NAME是生成文件的名称,DICT_BUILD_TOOL_DIR是Dictionary Development Kit的路径,如果错了就不能生成文件。; i4 ~9 j$ I0 r# u# ]8 M
* 修改Info.plist里3个参数,CFBundleName是在Mac字典程序工具栏下面显示的标签名,CFBundleDisplayName是词典名称,CFBundleIdentifier是词典的ID,需保持唯一性。。; V1 s8 e9 N8 B! ^, {
* 根据模板格式编辑Dictionary.xml、Dictionary.css,如果有图片则放置在OtherResources/目录下.
( G8 q1 B a# r2 C* 打开终端,cd进入模板文件目录,输入make,稍等一段时间,即可生成字典文件,将object目录下生成的dictionary文件拷贝至 ~/Library/Dictionaries,打开字典程序,即可看到生成的字典。% ^) K# r. A' z* n! h
或者直接用make && make install这个命令,生成词典后直接安装到了~/Library/Dictionaries。' `: q4 `8 |. M8 W/ ]6 |5 D6 W d
' [5 s* `3 |* w& K2 x$ l+ T9 u**注意:如果OtherResources里的图片太多的话会出现以下错误:**1 s* ]+ Y2 q! Z' k& |1 l% v
/Volumes/Macintosh HD/Applications/Utilities/DictionaryDevelopmentKit//bin/build_dict.sh: line 206: /bin/cp: Argument list too long
0 s' g/ T8 y% ?& m9 b8 M5 oError.
5 I0 J% R* m1 b; h% d8 smake: *** [all] Error 1 # b2 U+ T* P- @7 C6 D% @4 K. O9 @
, J3 E, @3 T( t: k* N; l* Y* K
可以在编译前不加入图片、语音文件,在编译完成后将图片、语音文件复制到xxx.dictionary/Contents目录下。
& h. T" m6 Z. d+ C7 J: S0 V: }( ~" g% L+ e( M
B6 J% W/ Q# z2 G
$ a$ O# x) }* s0 a) N& {/ s* }& \
DSL ===> OSX.dictionary
2 s2 ]3 p; }8 Q0 I3 Y$ l8 {: \5 o5 P; Y( k' `: X7 \" q
1. Convert DSL from UTF-16 to UTF-8:- iconv -f UTF-16 -t UTF-8 dict_utf16.dsl > dict_utf8.dsl
复制代码 * i* J; H: Z- U
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
复制代码 1 ]. P& X7 W6 X5 k4 h
**lingvo格式.dsl转换成可发音的词典。(注意修改命令参数)**↓
) x+ Z0 X3 P2 ?* Z e7 ?audio conversion is optional, "no" by default. The following command works,
* g' f$ {/ U) R" k g~/Development/pyglossary/pyglossary.pyw --read-option="audio=yes" test.dsl test.xml
% `. v- `. a% m! x E. qmake && make install - python /Applications/Utilities/DictionaryDevelopmentKit/pyglossary/pyglossary.pyw --read-options="audio=yes" --write-format=AppleDict ldoce55.dsl ldoce55.xml
复制代码
: N/ G ^7 h- x! v& w1 d" {3. Using Command Line Tools for Xcode and Dictionary Development Kit:编译步骤同BGL ===> OSX.dictionary
, k2 j2 ?: p2 C1 A, `- make) p3 ?8 I, g4 {: q3 M
- make install
复制代码 ! B/ h# ]: q% E
( @) m* e4 @2 z" r8 }* I2 G) tMDX ===> OSX.dictionary/ [8 A1 p, H$ ~7 l8 g! g
8 h5 H6 d0 K% L: H$ f0 D
转换 - V8 `, j7 L/ A; F7 L; z2 s( e
- cd ~/Downloads/oald8/2 l/ X5 v8 ^/ E$ J6 j
- ~/Software/pyglossary/pyglossary.pyw --read-options=resPath=OtherResources --write-format=AppleDict oald8.mdx oald8.xml
复制代码
; \2 M+ Y' A2 y: X7 h8 v- ^# A修改.xml文件里的链接(如果不是可发音的词典,以下两步可略过)
% o" u/ P) u/ X0 ~" ~- O+ ]% M- sed -i "" 's:src="/:src=":g' oald8.xml
7 @) A( }. L; j3 W - sed -i "" 's|sound://\([/_a-zA-Z0-9]*\).spx|\1.wav|g' oald8.xml
复制代码 第一个是去掉"/"& X! _- @5 ]9 N% j9 A; O
第二个是去掉”sound://" ,".spx"改成".wav"! H+ [2 h% a% B- h; P. P5 O
8 u: m# S6 x( C7 G4 a/ R
将.spx语音文件转换成.wav(需要安装speex,麻烦!可直接从lingvo那里复制,或者直接从原光盘提取)- find OtherResources -name "*.spx" -execdir sh -c 'spx={};speexdec $spx ${spx%.*}.wav' \
复制代码
! _+ H. t8 B( Z2 e/ t! O编译步骤同BGL ===> OSX.dictionary3 L0 P: z) s2 z% V4 y
注意:如果OtherResources里的图片和语音文件太多的话会出现错误,可以在编译前不加入图片和语音文件,在编译完成后将图片复制到xxx.dictionary/Contents目录下。% A7 W2 n) J% w, ~3 F
2 q6 ?" b- r: v2 x, D# }! h4 X$ OCD(原词典光盘)===> OSX.dictionary& E9 }' h5 X& L0 D% _
以OALECD8为例。, O+ i" y. V5 k9 A# V
数据提取:虚拟机xp+python2.7,用IDMSKconv提取。
" J, ?+ D4 @$ G5 L4 ^制作:从OALECD8安装目录下找到oalecd_master.css.BAK、从提取出的数据里找到output文件、以及图片和语音mp3文件,复制到Mac OSX下备用。
: K+ r" a. ]' ~$ f: ^7 P将output文件重命名为oalecd8.xml,oalecd_master.css.BAK作为CSS文件重命名为oalecd8.css,从Dictionary Development Kit里找到模板文件分别复制出MyInfo.plist、makefile文件,MyInfo.plist重命名为oalecd8.plist,修改oalecd8.plist和makefile里的参数。
- ^4 A% K+ @1 k; I7 D. S$ X/ a排版:里面各种奇形怪状的标签可以不必修改,有oalecd_master.css.BAK作为默认CSS,所以只需要在oalecd8.xml里添加头部和尾部,删除不要的东西,就可以编译出和原版相同的词典。
: d6 l! {& l" G3 H% f9 @8 L: b......
+ T. n% G( \4 ?5 W; C7 Q5 f
( I e/ U- y. y5 g ?###参考:# C4 D3 t# W" E
* GoldenDict Mac OS X available - Early Access Builds5 t: r8 d& _6 f7 Q0 H
* PyGlossary Overview ; Y- j$ y$ T7 E
*https://developer.apple.com/libr ... /doc/uid/TP40006152
7 _' u7 x& N" B0 q' v9 ^( @5 i- G# a' v, z+ i- Y9 m+ A
细节部分
, b- e4 |) _: T, a# f8 Z9 b+ w5 v* Q% S" W
v======* 注意修改单词内部的链接========v
6 Z+ a+ e2 ~ y, d- w, A' M7 f% b单词跳转用x-dictionary:r:
9 Q6 ~0 S& o3 \( w2 z g0 s6 D; A/ z(只能在当前词典内跳转且x-dictionary:r:后的单词大小写须与d:entry id="***"里的大小写一致,不能有空格否则不能跳转。)
7 x+ Q5 {' n8 q) E
& r3 l8 e3 ~9 \: S$ ?3 h单词查找用x-dictionary:d:
+ C; o/ Q/ B7 _ ~(会先搜索当前的词典,若没有,会调用其它词典搜索,不限大小写、空格。)
3 A4 Y! ]9 x z- w, w+ N(基本上都是用r,用d很少)
. [: r$ _8 Y2 ?% X- N! g- b& C^==============================^
[' S9 O+ ?) `8 v/ bThe 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スキームに8 s4 Q, K; i8 k1 T8 D9 X
次のようなものもあります。
4 d( G. X. x9 n1 G$ Mx-dictionary:d:key_text:dict_bundle_id' f1 ?/ [# `' V& G2 o6 q- Z
x-dictionary:r:reference_id:dict_bundle_id m% e- o) L# R
**1key_text 調べたい単語. k5 @: A+ r9 n( e' I
**2reference_id 辞書を作るために作成するdictionary.xmlの' R1 a& T$ Q. h5 W
各タイトルごとに割り当てる固有のエントリーID
$ K' k; u u* ] o( q% Q2 w<d:entry id="0ABCDE" d:title="案の定">
8 F, C0 \7 t7 t8 z* ex.
. X; u5 x7 l1 U" v, l) T5 j2 L! D( x" p4 x8 Z6 R
' g) X8 X2 z0 ~' \4 c2 d- Y, W
<d:entry id="make a face" d:title="make a face">$ D s: s" }$ i- H8 ], o7 A' j8 p
<d:index d:value="make a face"/>
7 P `# t3 l& W0 t c/ J <html><body><h1>make a face</h1>$ S% W# z# m% W/ \; Z; ~9 z
<a href="entry://grimace">grimace</a></body></html>
" W- t* p- @% ~: R- k </d:entry>- U- ^6 e' C+ R, } I+ G6 N( g
. o' P( B4 n# A <d:entry id="make faces" d:title="make faces">
! J2 r7 \/ d* o% c5 h <d:index d:value="make faces"/>2 N, m. c) K# N
<html><body><h1>make faces</h1>
7 [9 ~: `6 a, l" f <a href="entry://make a face">make a face</a></body></html
0 o, g8 `) r& B4 @; f; G' a; t) Y </d:entry>
* o. L+ j, h: J
1 L3 E( L! y) q0 F0 q" o& a"entry://grimace"* B) `) A: H4 i' R# f" B! H* r
将entry://替换为x-dictionary:r:3 V: R3 C2 f1 F
===>"x-dictionary:r:grimace"
/ D) p7 M: Y m. B0 [" V" m
5 b& }" z6 U0 H4 ld:entry id="make a face"- Y# E/ K% h0 s1 }: w) y
href="entry://make a face"
- Q' L6 N: b3 K. I类似上面的单词,中间不能有空格,否则单词间不能跳转。) |, v& b9 O$ _0 \
===>& d$ G: b$ ?; h$ K# b. P; C' B/ |2 C
d:entry id="make_a_face"# T3 l" A2 W+ K+ t1 |
href="x-dictionary:r:make_a_face"
: _( c; ~) Q l7 f0 [替换空格需要用到的正则表达式:
( r6 e! N) |; L(在此感谢ryuya,https://pdawiki.com/forum/thread-13044-1-1.html)- (<d:entry id="[^"]+)\s替换为\1_
复制代码- (href="x-dictionary:r:[^"]+)\s替换为\1_
复制代码
$ U& [: g" G: L/ X vv=========词组/词性跳转、定位===========v
+ M" E! D `1 S$ F词组/词性页面内定位
5 s3 _- W# b2 ? R! Z<a class="LP_OS" href="entry://#L_hkx1">suffix</a>) c( L9 f9 ^! S+ s9 S0 S
<a name="L_hkx1"></a> G: J2 t. i2 P* H4 x; s9 a1 H
==> <a class="LP_OS" href="#L_hkx1">suffix</a> P. o; Z" f, q# \
------------------0 {! u6 D' n! m8 G9 g
词组/词性跳转并定位4 e" N3 E' M, g2 _" U
<a href="entry://clip#ld3097">clip</a>
1 n) i+ D+ z, N' f; s<a name="ld3097"></a><span class="L_IDOM">$100 / 50 cents etc a clip</span>
' P$ q+ R0 l4 c( [$ I==> <a href="x-dictionary:r:clip:#ld3097">clip</a>
- o9 T7 H% M6 K+ J8 F; R用到的正则表达式:
( A8 ?+ f- v; ^7 N' B6 p; m* n+ C; Rx-dictionary:r:(.+?)#
% D( y3 [! S( i, i; g4 S替换为:; G0 m* s9 H) @2 T* A& s4 Y3 Q
x-dictionary:r:\1:#- E3 }5 H- s$ A: t6 G0 }" e5 U7 F: \
相关的词典:朗文当代英语词典英汉双解第4版
0 T3 M) N3 p) z1 P* rShorter Oxford English Dictionary Sixth Edition% g! L/ F% @, C
^=========词组/词性跳转、定位===========^# ]$ h3 o+ ~4 z, a
% C9 M2 d R2 U; f) B, ~& r1 S0 l
5 E+ [3 Q( t0 D( \另外一个开源项目
4 _5 u1 H/ t, Y1 T- sDSL to OS X/iOS dictionary converter(相关教程可到我的空间相册里查看)$ [& i4 j8 C9 e
https://github.com/svintuss/DSLConverter
" I# v, O$ J) \ StarDict转换工具
4 O& Y/ m7 l6 ?+ qhttps://code.google.com/p/mac-dictionary-kit/% i: d! |* ^% {7 _
关于金山字体问题
8 i$ }( J% m: {, r1 A. L5 Lhttp://www.linuxsir.org/bbs/thread363915.html
! M4 P* w, C1 p& f许多Linux词典也使用了Kingsoft Phonetic Plain字体,但是能下载到的金山字体一般都不是unicode编码的,导致Linux下音标显示为方框。实际上用FontForge修改一下金山字体即可使用。. X+ M+ `- d! k7 o7 Q( t
安装FontForge:3 U9 L+ x# z7 S' ?/ H
#urpmi fontforge
* y5 n' C/ |/ l8 \然后用FontForge打开金山字体文件,你可以看到FontForge对字体里的每一个字形都分两行显示。上面小的是字符的名称,下面大的就是那个字符的字形了。金山字体本来是对普通拉丁字符赋予音标字形的一个字体,但是因为它不是unicode编码,在Unicode的拉丁字符区一个字形都没有。
1 G9 z5 p, S F" t3 _ D/ h* L所以首先要找到金山字符的位置,比较靠后。注意从一个空格字形开始的。这个空格很重要,因为空格和之后几个符号的字形跟普通拉丁字符的字形没有区别,所以我们用来定位所有的金山字符。0 q! C+ M3 H$ g/ T5 B, C
找到之后,从空格开始选定所有的字符,大约有三四十个。剪切之。
- `/ {1 ]9 L% Q& H然后找到拉丁字符区。可以看到所有的字形都是“X”,也就是空。找到表示空格的那个字符位(U+0020),选中,复制。所有的金山字形就按照顺序复制到这个字符位以及之后的字符位去了。
( ^6 A2 L, S, h3 W最后保存成.ttf文件就OK了。保存的时候会有一些提示信息,照着做一下就行。
+ }2 j; S. Q3 e4 }3 I2 v( M顺便发一个做好的.ttf文件。仅为技术探讨,版权归原作者所有。 3 J7 W7 m0 F& Y1 `" x5 X' H0 d
* F- l: Z) \0 Y& B3 Q
9 P8 P' r1 o6 i$ @5 g一些小技巧4 X1 j- @, a- w; D
Mac osx 下可以用三指取词,但在一些第三方软件下是不起作用的。
9 u( W5 l3 e: M- L+ J不过结合Alfred这个神器+下面这个脚本可实现热键取词。同理可将网上流传的“142000个单词语音库”解压到同一个文件夹内,借助内置的afplay命令+Alfred+下面的脚本,可做到热键取词发音。- afplay /Users/qunwang6/Sound/Webster/{query}.wav
复制代码 ! g5 I; b" J7 T- ^3 W7 t: l3 G+ U5 n
生词本
/ ~5 O7 h, ]2 r- M* L/ \% A1 Y1 TBetterDictionary
; g! M! w3 k" s) ~8 Q7 \
, G/ m0 D/ P0 D* G- F4 D...
+ I: d+ p% d4 s9 T* J, O, C' a
' G, U. M U/ H5 c自己动手,丰衣足食。先发颗种子。
2 K- f# f* j6 c4 l4 x6 v( M; n( A# A" o2 W/ y! a
* }, Q4 F0 A2 Z0 m, w2 W- \2 M
链接: http://pan.baidu.com/s/1i3rgl7n 密码: vcpf
+ j* e7 i _. b2 P& o. ~2 @/ G |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?免费注册
x
评分
-
1
查看全部评分
-
本帖被以下淘专辑推荐:
- · REFIDX|主题: 90, 订阅: 34
- · 工具|主题: 61, 订阅: 28
- · 词典制作|主题: 111, 订阅: 24
|