图片词典索引制作之凌波微步
本帖最后由 ZTO 于 2015-5-18 10:14 编辑以中文词典为例,支持拼音、汉字、页码、原书目录索引。
如图:
https://pdawiki.com/forum/data/attachment/album/201505/17/234101j2z6dden92ezg3wi.png
https://pdawiki.com/forum/data/attachment/album/201505/17/234118cuxxuexti652lin6.png
https://pdawiki.com/forum/data/attachment/album/201505/17/234121qflzzo7v7u7obuuf.png
https://pdawiki.com/forum/data/attachment/album/201505/17/234131kxj1578fx175mx1i.png
索引简单录入:
https://pdawiki.com/forum/data/attachment/album/201505/17/234141elnny0k0s9wgqngn.png
Python代码,针对读秀图片命名方式制作,索引生成为MAC OSX 词典格式,mdx格式见5楼:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#准备好r.txt文件,将要索引的单词输入到r.txt文本文件中,每行一个单词,每行为一页.
#每页含有两个以上的词,每行的单词间用'|'分开:ab|ac|ad
#python pyprint.py,结果写入index.txt文件
#for mac osx
f = open('index.xml','w')
r = open('r.txt')
count = 1
text = '<html><body><link Ahref="DefaultStyle.css" rel="stylesheet" type="text/css"/><div><a class="play" href="" onclick="document.getElementById(\'index\').style.display = \'block\'; return false;"></a><div class="index" id="index"><a class="hide" href="" onclick="document.getElementById(\'index\').style.display = \'none\'; return false;"></a><a class="left" href="x-dictionary:r:%s">☜</a><a class="A" href="A">A</a><a class="B" href="B">B</a><a class="C" href="C">C</a><a class="D" href="D">D</a><a class="E" href="E">E</a><a class="F" href="F">F</a><a class="G" href="G">G</a><a class="H" href="H">H</a><a class="I" href="I">I</a><a class="J" href="J">J</a><a class="K" href="K">K</a><a class="L" href="L">L</a><a class="M" href="M">M</a><a class="N" href="N">N</a><a class="O" href="O">O</a><a class="P" href="P">P</a><a class="Q" href="Q">Q</a><a class="R" href="R">R</a><a class="S" href="S">S</a><a class="T" href="T">T</a><a class="U" href="U">U</a><a class="V" href="V">V</a><a class="W" href="W">W</a><a class="X" href="X">X</a><a class="Y" href="Y">Y</a><a class="Z" href="Z">Z</a><a class="right" href="x-dictionary:r:%s">☞</a></div></div><img class="img" src="images/%s.jpg"/>\n</body></html>\n</d:entry>\n'
line = len(open('r.txt').readlines())
f.write('<?xml version="1.0" encoding="UTF-8"?>\n'
'<d:dictionary xmlns="http://www.w3.org/1999/xhtml" xmlns:d="http://www.apple.com/DTDs/DictionaryService-1.0.rng">\n')
while (count <= line):
n = str(count)
s = n.zfill(6) #自动补0
n1 = str(count-1)
s1 = n1.zfill(6)
n2 = str(count+1)
s2 = n2.zfill(6)
f.write('<d:entry id="%s" d:title="%s">\n' % (s,s))
rd = r.readline()
rw = rd.strip('\n')
for i in rw.split('|'):
f.write(' <d:index d:value="%s"/>\n' % i.strip('\n'))
f.write(' <d:index d:value="%s"/>\n' % count)
f.write(text % (s1,s2,s))
count = count + 1
#目录索引
ml = 1
#参数自行修改
while (ml <= 75):
n = str(ml)
s = n.zfill(5) #自动补0
n1 = str(ml-1)
s1 = n1.zfill(5)
n2 = str(ml+1)
s2 = n2.zfill(5)
p = '!' + s
p1 = '!' + s1
p2 = '!' + s2
f.write('<d:entry id="%s" d:title="%s">\n' % (p,p))
f.write(' <d:index d:value="%s"/>\n' % p)
f.write(text % (p1,p2,p))
ml = ml + 1
f.write('</d:dictionary>\n')
f.close()
#css
c = open('dic.css','w')
c.write('.hide,.A,.B,.C,.D,.E,.F,.G,.H,.I,.J,.K,.L,.M,.N,.O,.P,.Q,.R,.S,.T,.U,.V,.W,.X,.Y,.Z,.left,.right{display: block;text-align: center;text-decoration:none;color:#5484C8;background: #DCDCDC; color: #fff;border-radius:8px;margin:1px;}\na:hover {color: #FF9900;}\n .play,.index{float:right;position:fixed;right:15px;height:100%;line-height:20px;overflow:scroll;margin-top:20%;}\n.left,.right{display: block;font-size:24px;text-decoration:none;line-height:20px;}\n.img{width:100%;}\n .play{text-decoration:none;}')
c.close()
赞一个!
我也希望有朋友能帮忙写一个自动程序,完成全索引图片版词典的最终文件输出。。。
非常感谢,优秀
如果已经有图片mdx词典,怎么加你的方法? 本帖最后由 chigre3 于 2015-5-18 06:30 编辑
请求帮助:
比如我录入的索引文件格式是:使用"/"分隔左右列,然后使用"|"分隔词头。
行号100:词头①|词头②/词头③|词头④
需要经过处理直接变成为(简略形式):
词头①
【→1←词头①】|→2←词头②/→1←词头③|→2←词头④
上一页099 下一页101
页面图片100
上一页099 下一页101
词头②
→1←词头①|【→2←词头②】/→1←词头③|→2←词头④
上一页099 下一页101
页面图片100
上一页099 下一页101
词头③
→1←词头①|→2←词头②/【→1←词头③】|→2←词头④
上一页099 下一页101
页面图片100
上一页099 下一页101
词头④
→1←词头①|→2←词头②/→1←词头③|【→2←词头④】
上一页099 下一页101
页面图片100
上一页099 下一页101
我不会写代码。 shawky.nasr 发表于 2015-5-18 01:35
非常感谢,优秀
如果已经有图片mdx词典,怎么加你的方法?
mdx格式,生成的索引大概是这样的
</>
a
@@@LINK=1
</>
啊
@@@LINK=1
</>
阿
@@@LINK=1
</>
阿姨
@@@LINK=1
</>
1
<link href="DefaultStyle.css" rel="stylesheet" type="text/css"/><div><a class="play" href="" onclick="document.getElementById('index').style.display = 'block'; return false;"></a><div class="index" id="index"><a class="hide" href="" onclick="document.getElementById('index').style.display = 'none'; return false;"></a><a class="left" href="entry://000000">☜</a><a class="A" href="entry://!00001">A</a><a class="B" href="entry://!00001">B</a><a class="C" href="entry://!00003">C</a><a class="D" href="entry://!00005">D</a><a class="E" href="entry://!00007">E</a><a class="F" href="entry://!00008">F</a><a class="G" href="entry://!00009">G</a><a class="H" href="entry://!00011">H</a><a class="I" href="I">I</a><a class="J" href="entry://!00012">J</a><a class="K" href="entry://!00016">K</a><a class="L" href="entry://!00017">L</a><a class="M" href="entry://!00018">M</a><a class="N" href="entry://!00020">N</a><a class="O" href="entry://!00020">O</a><a class="P" href="entry://!00020">P</a><a class="Q" href="entry://!00021">Q</a><a class="R" href="entry://!00023">R</a><a class="S" href="entry://!00024">S</a><a class="T" href="entry://!00027">T</a><a class="U" href="U">U</a><a class="V" href="V">V</a><a class="W" href="entry://!00029">W</a><a class="X" href="entry://!00030">X</a><a class="Y" href="entry://!00032">Y</a><a class="Z" href="entry://!00035">Z</a><a class="right" href="entry://000002">☞</a></div></div><img class="img" src="images/000001.jpg"/>
</>
代码
本帖最后由 ZTO 于 2015-5-18 13:54 编辑
chigre3 发表于 2015-5-18 06:12
请求帮助:
比如我录入的索引文件格式是:使用"/"分隔左右列,然后使用"|"分隔词头。
录入索引格式
a|b/c|d
aa|bb/cc|dd
ee|ff|gg/hh|ii|kk
Python代码
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#准备好r.txt文件,将要索引的单词输入到r.txt文本文件中,每行一个单词,每行为一页.
#每页含有两个以上的词,每行的单词间用'|'分开,左右两列单词用'/'分开:ab|ac|ad/ba|bc|bd
#python pyprint.py,结果写入index.txt文件
#for mdx
f = open('index.txt','w')
r = open('r.txt')
count = 1
text = '<link href="DefaultStyle.css" rel="stylesheet" type="text/css"/>\n<span class="left">☜</span><span class="word1">%s</span><span class="right">☞</span><span class="word2">%s</span><a class="pre" href="entry://%s">上一页</a><a class="nex" href="entry://%s">下一页</a><img class="img" src="images/%s.jpg"/>\n'
#第一行空
f.write('\n</>\n')
#汉字/拼音/字母索引
line = len(open('r.txt').readlines())
while (count <= line):
n = str(count)
s = n.zfill(6) #自动补0
n1 = str(count-1)
s1 = n1.zfill(6)
n2 = str(count+1)
s2 = n2.zfill(6)
rd = r.readline()
rw = rd.strip('\n')
for i in rw.split('/'):
rw2 = i.strip('\n')
for i in rw2.split('|'):
f.write('%s\n' % i.strip('\n'))
f.write('@@@LINK=%s\n' % count)
f.write('</>\n')
rw3 = rw.split('/')
f.write('%s\n' % count)
f.write(text % (rw3,rw3,count-1,count+1,count))
f.write('</>\n')
count = count + 1
f.close()
输出的结果
</>
a
@@@LINK=1
</>
b
@@@LINK=1
</>
c
@@@LINK=1
</>
d
@@@LINK=1
</>
1
<link href="DefaultStyle.css" rel="stylesheet" type="text/css"/>
<span class="left">☜</span><span class="word1">a|b</span><span class="right">☞</span><span class="word2">c|d</span><a class="pre" href="entry://0">上一页</a><a class="nex" href="entry://2">下一页</a><img class="img" src="images/1.jpg"/>
</>
aa
@@@LINK=2
</>
bb
@@@LINK=2
</>
cc
@@@LINK=2
</>
dd
@@@LINK=2
</>
2
<link href="DefaultStyle.css" rel="stylesheet" type="text/css"/>
<span class="left">☜</span><span class="word1">aa|bb</span><span class="right">☞</span><span class="word2">cc|dd</span><a class="pre" href="entry://1">上一页</a><a class="nex" href="entry://3">下一页</a><img class="img" src="images/2.jpg"/>
</>
ee
@@@LINK=3
</>
ff
@@@LINK=3
</>
gg
@@@LINK=3
</>
hh
@@@LINK=3
</>
ii
@@@LINK=3
</>
kk
@@@LINK=3
</>
3
<link href="DefaultStyle.css" rel="stylesheet" type="text/css"/>
<span class="left">☜</span><span class="word1">ee|ff|gg</span><span class="right">☞</span><span class="word2">hh|ii|kk</span><a class="pre" href="entry://2">上一页</a><a class="nex" href="entry://4">下一页</a><img class="img" src="images/3.jpg"/>
</>
ZTO 发表于 2015-5-18 13:50
录入索引格式
Python代码
谢谢你写的代码,我在你的基础上进行修改,希望能成功得到我需要的样子。
;) 只要能检索,图片词典也是很好的 本帖最后由 chigre3 于 2015-5-19 07:05 编辑
https://www.pdawiki.com/forum/data/attachment/forum/201505/19/070049mhux6ve8xi0mk8vg.png
在ZTO提供的py基础上,根据我自己的需要进行了大幅增改, 不过谁让我不会编程呢,马马虎虎弄起来以后还是最后需要在EmEditor里稍微修改一下下。
还有重复词头的问题还没有直接在py里设计起来解决掉。。。
过几天再说。。。 用竖线 | 隔开同页码词头设计不合理,因为竖线在键盘上要用shfit键组合才能输入,不如无需组合键输入的单个约定分割字符来得方便。
页:
[1]