|
本帖最后由 qunwang6 于 2017-6-9 00:23 编辑
& E# j' L8 y" S) g# E1 S4 p" g% z0 W- T2 z
- w% V. J0 q" ]
20170609更新:0 h1 d% J* W: }6 j. O
新版pyglossary 要安装以下环境:sudo pip3 install lxml beautifulsoup4 html5lib # Q* E" K) d a8 P+ a' g5 @
Python 改成Python3
s ^" J8 x0 x5 ]5 ]7 l9 o✍准备好以下环境:( ]. ]& a% g! ^6 B
* BeautifulSoup4 required to sanitize html contents.& i$ c) f6 Y4 ?8 F5 ~3 o
sudo easy_install beautifulsoup4 html5lib
4 X/ R" g8 c, u9 k7 A; j* GNU make as part of Command Line Tools for Xcode.' {4 d' G5 P" Z, A6 H
http://developer.apple.com/downloads
& v% T# N: C& M: `- Z* Dictionary Development Kit as part of Auxillary Tools for Xcode
2 F9 n( q8 o& [http://developer.apple.com/downloads.
- @# u+ c$ i4 Y将Dictionary Development Kit解压到/Applications/Utilities/DictionaryDevelopmentKit/
- c) \6 V+ g! ](不含空格,中文名:应用程序/实用工具那里,也可以解压到其它地方。) / G5 a4 |3 S5 `+ v
# r+ W6 e9 B- q& o+ |# |( Y
2 ^0 _0 t' y4 uBGL ===> OSX.dictionary+ A7 p: H9 a0 z8 i( L) ~$ r3 M
转换- python pyglossary.pyw --read-options=resPath=OtherResources --write-format=AppleDict dict.bgl dict.xml
复制代码 编译0 N8 C1 ]1 q W9 X# p. z" y
* 修改Makefile里2个参数,DICT_NAME是生成文件的名称,DICT_BUILD_TOOL_DIR是Dictionary Development Kit的路径,如果错了就不能生成文件。
, n1 e3 _6 K. t2 D% ^# B* 修改Info.plist里3个参数,CFBundleName是在Mac字典程序工具栏下面显示的标签名,CFBundleDisplayName是词典名称,CFBundleIdentifier是词典的ID,需保持唯一性。。
- K: s# F; r8 a/ W5 O: ^2 I; u* 根据模板格式编辑Dictionary.xml、Dictionary.css,如果有图片则放置在OtherResources/目录下.
) L" u" ], I* y2 w4 Y. u) w* 打开终端,cd进入模板文件目录,输入make,稍等一段时间,即可生成字典文件,将object目录下生成的dictionary文件拷贝至 ~/Library/Dictionaries,打开字典程序,即可看到生成的字典。
. z" J6 ~) w- @0 z# q) k. Y$ z或者直接用make && make install这个命令,生成词典后直接安装到了~/Library/Dictionaries。* P" u2 D, v& [; I
+ Y i: V) l& x& p' ~5 h1 h: m: J& [7 W**注意:如果OtherResources里的图片太多的话会出现以下错误:**- u; F0 P: ~4 P- Y( \9 Y5 c
/Volumes/Macintosh HD/Applications/Utilities/DictionaryDevelopmentKit//bin/build_dict.sh: line 206: /bin/cp: Argument list too long
. E4 w8 H" s9 u5 H: qError.! L) A' B4 w p% e% o
make: *** [all] Error 1 - ^& D$ m3 h) C' m+ A8 L6 _
' u4 H" D" {/ z& e. B: M- L7 f
可以在编译前不加入图片、语音文件,在编译完成后将图片、语音文件复制到xxx.dictionary/Contents目录下。$ i/ }# {0 X0 T. K& x
6 j$ F7 N6 W; m; s
( E% Q1 h$ g9 }2 I' a S
\9 ?) h L! D: n7 r i' u
DSL ===> OSX.dictionary
" `8 x$ l% t, o2 x, }4 v! s5 W, r* X
1. Convert DSL from UTF-16 to UTF-8:- iconv -f UTF-16 -t UTF-8 dict_utf16.dsl > dict_utf8.dsl
复制代码
, }% d- Z7 {2 h) K8 f2. 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
复制代码
8 z9 _# W) X" k7 l5 N6 t**lingvo格式.dsl转换成可发音的词典。(注意修改命令参数)**↓- o3 o7 V0 [; @: N! w7 @
audio conversion is optional, "no" by default. The following command works,
* E% i* Y& L! p* {- P/ B0 l~/Development/pyglossary/pyglossary.pyw --read-option="audio=yes" test.dsl test.xml6 q1 b2 ^) n W4 ^: n5 X: R. q' C
make && make install - python /Applications/Utilities/DictionaryDevelopmentKit/pyglossary/pyglossary.pyw --read-options="audio=yes" --write-format=AppleDict ldoce55.dsl ldoce55.xml
复制代码 " v6 T( P/ ^7 q5 R
3. Using Command Line Tools for Xcode and Dictionary Development Kit:编译步骤同BGL ===> OSX.dictionary- v- U# z7 R, T3 Y$ G2 ~' {
- make. B2 }4 ?( C% c% [* X @/ W
- make install
复制代码 2 h' F; e/ H" k. m
x& P- V( P8 w, S5 k! K b% d
MDX ===> OSX.dictionary
2 ^; s& W/ l/ c9 ?6 E3 I4 h3 |; I& J4 ?! Y: G9 [7 O0 ]. r! r$ K! Q4 X
转换 8 J. H U6 @( r4 `2 w
- cd ~/Downloads/oald8/
1 A# Y9 _5 N9 d( P- d7 k# d - ~/Software/pyglossary/pyglossary.pyw --read-options=resPath=OtherResources --write-format=AppleDict oald8.mdx oald8.xml
复制代码 ( j* e3 _" d6 f7 K
修改.xml文件里的链接(如果不是可发音的词典,以下两步可略过)/ @% @- @0 b! m, _. Q% A1 V
- sed -i "" 's:src="/:src=":g' oald8.xml
0 T5 e1 d0 s2 G7 e4 I- @* Y! O - sed -i "" 's|sound://\([/_a-zA-Z0-9]*\).spx|\1.wav|g' oald8.xml
复制代码 第一个是去掉"/"
1 b5 `6 ~4 P3 n* w: e) v! a: u第二个是去掉”sound://" ,".spx"改成".wav"
& s/ v6 f# l4 d. z1 K6 L- I1 |
! t* r, @" _) D5 S$ V 将.spx语音文件转换成.wav(需要安装speex,麻烦!可直接从lingvo那里复制,或者直接从原光盘提取)- find OtherResources -name "*.spx" -execdir sh -c 'spx={};speexdec $spx ${spx%.*}.wav' \
复制代码
% T* M4 c' R' L8 e' l( e编译步骤同BGL ===> OSX.dictionary) h& v* Q t% F) ~6 U, G
注意:如果OtherResources里的图片和语音文件太多的话会出现错误,可以在编译前不加入图片和语音文件,在编译完成后将图片复制到xxx.dictionary/Contents目录下。
9 O0 H2 N/ q' G6 o# c) {8 f3 T : S5 b0 d4 A0 u6 _) z; o- t' ?, k
CD(原词典光盘)===> OSX.dictionary
( d4 K# g2 `# n. }2 J& e以OALECD8为例。0 P5 W1 G. O% @
数据提取:虚拟机xp+python2.7,用IDMSKconv提取。: |4 B( p( g' ~% Q4 N% H7 V' G
制作:从OALECD8安装目录下找到oalecd_master.css.BAK、从提取出的数据里找到output文件、以及图片和语音mp3文件,复制到Mac OSX下备用。
' }; t$ w: v' P2 h& y将output文件重命名为oalecd8.xml,oalecd_master.css.BAK作为CSS文件重命名为oalecd8.css,从Dictionary Development Kit里找到模板文件分别复制出MyInfo.plist、makefile文件,MyInfo.plist重命名为oalecd8.plist,修改oalecd8.plist和makefile里的参数。
, W( c, L4 y5 v排版:里面各种奇形怪状的标签可以不必修改,有oalecd_master.css.BAK作为默认CSS,所以只需要在oalecd8.xml里添加头部和尾部,删除不要的东西,就可以编译出和原版相同的词典。
6 R5 z2 O; {5 W0 g* f: G......
, X5 e3 z$ E7 b9 ?) ~7 k
; {1 [( f! n$ o###参考:
0 `! H0 G3 [9 c: b& x* GoldenDict Mac OS X available - Early Access Builds
2 a0 s; Q1 v! H* _2 i3 x% `- A* PyGlossary Overview 1 H0 l$ }8 @% m, @4 A. m& {2 Z
*https://developer.apple.com/libr ... /doc/uid/TP40006152
3 v) \" F2 E$ w8 ?5 c* E/ I& W7 E7 |# F6 V4 C3 L
细节部分( [9 Y/ Q: b4 A3 z4 h
& O0 U8 ~. e, d& t5 f. kv======* 注意修改单词内部的链接========v
5 Z \$ z+ n( N3 W: p3 N单词跳转用x-dictionary:r:$ J+ O8 X( x. C6 d6 F0 q
(只能在当前词典内跳转且x-dictionary:r:后的单词大小写须与d:entry id="***"里的大小写一致,不能有空格否则不能跳转。)
9 |4 q- A2 [+ \9 m* R& g& |
1 v; P/ c9 [0 e% L单词查找用x-dictionary:d:- U7 _9 Y# Y7 n0 d+ R) _
(会先搜索当前的词典,若没有,会调用其它词典搜索,不限大小写、空格。)
2 y. Y" T3 k9 F0 t+ {) i" H(基本上都是用r,用d很少)1 W' ]; e# n: T/ j
^==============================^
6 J& b! ^4 d& Y. I2 x3 h3 q2 OThe 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スキームに6 t, J! r5 G d9 T) a0 R/ _6 d
次のようなものもあります。
# q R/ e8 ~% h2 j2 N0 H" N4 Q1 V& cx-dictionary:d:key_text:dict_bundle_id
5 |! O) b6 c; jx-dictionary:r:reference_id:dict_bundle_id7 {# M$ @% \4 \$ a/ r _. S: t
**1key_text 調べたい単語; c8 f. O& b7 M( z9 E
**2reference_id 辞書を作るために作成するdictionary.xmlの
: J$ |- U; P7 T# H5 r各タイトルごとに割り当てる固有のエントリーID1 _7 W) p) w {- _& i
<d:entry id="0ABCDE" d:title="案の定"> 8 U( s) }$ E' B+ `
* ex.' a) X( x7 h6 M
8 P7 P, w, y, J I " g- s; H/ Q3 c) k! J# p, s* |0 v
<d:entry id="make a face" d:title="make a face">
$ a2 S( o# f E/ r- C( j <d:index d:value="make a face"/>% B- q% J7 J4 m& }
<html><body><h1>make a face</h1>
* c+ P) h8 [; V' }3 x3 [ <a href="entry://grimace">grimace</a></body></html>: ~: F3 _% p) \: H ~; Y/ [2 _) Y
</d:entry>
! }$ q& L% \: x* v3 i* Y0 x) i+ C* V ?2 a; C
<d:entry id="make faces" d:title="make faces">
" F$ h# o" D- W2 G7 }. }* Y8 c3 j" c <d:index d:value="make faces"/>
% e7 A0 S6 ^' J5 [3 D+ h <html><body><h1>make faces</h1>
; J' W; p7 i- ~: {8 B1 m <a href="entry://make a face">make a face</a></body></html% y; l$ {9 f8 P% A
</d:entry>
; I( O0 d4 M- P2 I/ m4 W
# Q3 t' Q4 i4 G"entry://grimace"* [" x" Y( ^; l
将entry://替换为x-dictionary:r:4 a* K# s* v& Y+ r
===>"x-dictionary:r:grimace"
/ d3 R$ N# o: r" G7 X2 j8 \ S) \+ ]1 ~3 H$ y# b1 h) j0 h
d:entry id="make a face"
5 f0 ~" R/ h$ q7 b( O/ I) B5 Ihref="entry://make a face"
+ @$ B8 \$ ~; U) d- \ t/ W7 o类似上面的单词,中间不能有空格,否则单词间不能跳转。" p! O0 S/ K7 v1 R
===>
/ B6 r" B9 M- j& Od:entry id="make_a_face"* {& P* }; b6 M) ~* a- H
href="x-dictionary:r:make_a_face"
, ~! v1 n" H8 r* D$ P# D- I替换空格需要用到的正则表达式:
; f6 r9 i4 k0 s d% k(在此感谢ryuya,https://pdawiki.com/forum/thread-13044-1-1.html)- (<d:entry id="[^"]+)\s替换为\1_
复制代码- (href="x-dictionary:r:[^"]+)\s替换为\1_
复制代码 ' B5 K% b; v3 h) f# h* n- S) r8 y$ M a
v=========词组/词性跳转、定位===========v9 s& F: `& N" X/ s
词组/词性页面内定位
. E# C# Z0 Z0 i! [' [<a class="LP_OS" href="entry://#L_hkx1">suffix</a>
8 k. ^+ _% |) n4 y) @( J<a name="L_hkx1"></a>
$ L4 ^' q+ q. g" Q==> <a class="LP_OS" href="#L_hkx1">suffix</a>
7 p" m. C1 q* B4 K------------------
. H) ?% e$ g6 e: U' m2 ^4 t词组/词性跳转并定位
' B' a+ \6 V5 E3 P; U<a href="entry://clip#ld3097">clip</a>
( l, Z- F* a0 n' U8 v0 U<a name="ld3097"></a><span class="L_IDOM">$100 / 50 cents etc a clip</span>
4 c2 a; {6 {: U% W4 C. w==> <a href="x-dictionary:r:clip:#ld3097">clip</a>
+ t- G. j5 V& i用到的正则表达式:
# }: j9 w/ i j$ x! G7 Bx-dictionary:r:(.+?)#1 D; D- i* j- x" w6 o: `
替换为:$ K c; b% \9 ?2 G/ d
x-dictionary:r:\1:#
5 a+ U" o" d* J3 T8 r/ D( G相关的词典:朗文当代英语词典英汉双解第4版% |2 _9 e6 O/ V# s3 I6 F, O2 k/ a+ C6 }
Shorter Oxford English Dictionary Sixth Edition. E* E" ^4 R" z; F ?; ]7 N0 r
^=========词组/词性跳转、定位===========^
! A7 h$ G5 U% j& a: R; [
$ @' C* P. |6 b8 Y4 _! c: u
' F) ~ \* b! |+ A! s另外一个开源项目7 j8 A. j, M4 u) _! K
DSL to OS X/iOS dictionary converter(相关教程可到我的空间相册里查看)
q$ F) ]9 M" }) d: S8 }, N! c) _ https://github.com/svintuss/DSLConverter
/ |' }6 C! V1 U% E5 V/ L1 l ~ StarDict转换工具
0 }3 z' Q7 A1 G( ]: C7 mhttps://code.google.com/p/mac-dictionary-kit/7 {1 Z' P; x6 a1 s! q9 h( R6 C
关于金山字体问题
% U8 a' A7 E% k6 |% [5 d# dhttp://www.linuxsir.org/bbs/thread363915.html u S# e+ ]! U; a5 O. l
许多Linux词典也使用了Kingsoft Phonetic Plain字体,但是能下载到的金山字体一般都不是unicode编码的,导致Linux下音标显示为方框。实际上用FontForge修改一下金山字体即可使用。
, C! X3 a; i" m2 l M. F' Q7 [安装FontForge:
7 r. f( q5 L7 A#urpmi fontforge
0 o7 c8 y) o+ n) \然后用FontForge打开金山字体文件,你可以看到FontForge对字体里的每一个字形都分两行显示。上面小的是字符的名称,下面大的就是那个字符的字形了。金山字体本来是对普通拉丁字符赋予音标字形的一个字体,但是因为它不是unicode编码,在Unicode的拉丁字符区一个字形都没有。* H) Q; \/ B$ K+ }1 u* Z: _
所以首先要找到金山字符的位置,比较靠后。注意从一个空格字形开始的。这个空格很重要,因为空格和之后几个符号的字形跟普通拉丁字符的字形没有区别,所以我们用来定位所有的金山字符。
" T6 `& Y1 Q+ \7 f+ d) K; Z( i找到之后,从空格开始选定所有的字符,大约有三四十个。剪切之。
: T* G* W/ y" U) {然后找到拉丁字符区。可以看到所有的字形都是“X”,也就是空。找到表示空格的那个字符位(U+0020),选中,复制。所有的金山字形就按照顺序复制到这个字符位以及之后的字符位去了。4 u9 E' q( O! S0 j7 r
最后保存成.ttf文件就OK了。保存的时候会有一些提示信息,照着做一下就行。
. v6 n2 R( U0 V, s顺便发一个做好的.ttf文件。仅为技术探讨,版权归原作者所有。
1 f$ t, r; |# t7 ~; X$ z, k
3 Q1 d: a: E& l6 i( |; Q 9 k4 q( ]( c- a- t; f1 u9 j
一些小技巧$ Q) N7 n1 S& K% C; [8 a5 H
Mac osx 下可以用三指取词,但在一些第三方软件下是不起作用的。
2 ]4 j6 y; a2 F. G不过结合Alfred这个神器+下面这个脚本可实现热键取词。同理可将网上流传的“142000个单词语音库”解压到同一个文件夹内,借助内置的afplay命令+Alfred+下面的脚本,可做到热键取词发音。- afplay /Users/qunwang6/Sound/Webster/{query}.wav
复制代码
8 P" F5 N7 G9 _0 Z, c- V0 i生词本& ~, ?3 v6 c3 g2 J8 ^. o' q
BetterDictionary
. T3 Z* ~0 _; j6 l' }3 N
2 a' P( {3 K: Z' h...( c* E# @& Q8 J$ ~: m
7 ^5 E% _+ @4 J0 M2 b6 v自己动手,丰衣足食。先发颗种子。* `% J% n/ O' X% p- C# r
1 u b/ ^% i" J: C, R& E- P, W
! \+ C- A( Q" Q: S# `
链接: http://pan.baidu.com/s/1i3rgl7n 密码: vcpf
` E8 C, f5 S6 p u! [) O |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?免费注册
x
评分
-
1
查看全部评分
-
本帖被以下淘专辑推荐:
- · REFIDX|主题: 90, 订阅: 34
- · 工具|主题: 61, 订阅: 28
- · 词典制作|主题: 111, 订阅: 24
|