Материал из Википедии — свободной энциклопедии
# -*- coding: UTF-8 -*-
__version__='$Id:'
import wikipedia
import re, sys
import codecs
import zperevod as perevod
from zbib_tekst import *
def main(slov,nssvoj,vhjaz,vihjaz,fvh,fvih,fipoln,finesl,fispit,flvsjo):
otch.write(u'len(nssvoj)=%d\n'%len(nssvoj))
otch.flush()
kolotch=1500
f0=codecs.open(fvh,'rb',encoding='utf-8')
f1=codecs.open(fvih, 'w', 'utf-8')
fpoln=codecs.open(fipoln, 'w', 'utf-8')
fnesl=codecs.open(finesl, 'w', 'utf-8')
fspit=codecs.open(fispit, 'w', 'utf-8')
osnp={}
osvap={}
for s in f0.readlines():
# wikipedia.output(u'%d\n' % ord(s[0]))
if ord(s[0]) == 65279:
s=s[1:]
# wikipedia.output(u'%d %d %s %s\n' % (i,j,n,s))
s=s.replace(u'\r',u'').replace(u'_',u' ')
# if s[len(s)-1]!=u'\n':
# s=s+u'\n'
s=ubr_nk_prob(s)
# (rez,fl_perev)=perevod(slov,vhjaz,vihjaz,s)
(rez,stat)=perevod.perevod_stat(slov,vhjaz,vihjaz,s)
if flvsjo or (stat.nnp==0 and stat.nvap==0):
f1.write(s+u'|'+rez+u'\n')
f1.flush()
if nssvoj.has_key(rez):
otch.write(rez+u'\n')
otch.write(u' <- uzxe\n')
otch.flush()
else:
fspit.write(s+u'\n')
fspit.flush()
fpoln.write(rez+u'\n')
fpoln.flush()
perevod.perev_uch_nezsl(osnp,osvap,stat)
perevod.perev_pech_nezsl(slov,vhjaz,vihjaz,osnp,osvap,fnesl,kolotch)
if __name__ == "__main__":
vhjaz = wikipedia.argHandler(sys.argv[1], 'perevod')
vihjaz = wikipedia.argHandler(sys.argv[2], 'perevod')
fslov = wikipedia.argHandler(sys.argv[3], 'perevod')
fvh = wikipedia.argHandler(sys.argv[4], 'perevod')
fi = wikipedia.argHandler(sys.argv[5], 'perevod')
if fi.endswith(u'.txt'):
fi=fi[:len(fi)-4]
fvih= fi+u'.txt'
fotch = fi+u'-ot.txt'
fipoln = fi+u'-pp.txt'
finesl = fi+u'-ns.txt'
fispit = fi+u'-st.txt'
flvsjo=0
if len(sys.argv)>=7 and sys.argv[6]==u'2':
flvsjo=1
otch = codecs.open(fotch, 'w', 'utf-8')
#otch2 = codecs.open(fotch2, 'w', 'utf-8')
slov={}
nssvoj={}
slovdop={}
perevod.zagruzslov(slov,slovdop,nssvoj,vhjaz,vihjaz,fslov)
main(slov,nssvoj,vhjaz,vihjaz,fvh,fvih,fipoln,finesl,fispit,flvsjo)