TA的每日心情 | 擦汗 2021-11-17 09:18 |
|---|
签到天数: 79 天 [LV.6]常住居民II
|
发表于 2021-10-6 09:52:48
|
显示全部楼层
; x; V% O0 ~, B. o0 I# u(3) 在哪里加入- current_path = os.path.dirname(__file__);current_path+"/OALD4_azure.txt
复制代码 5 O1 X4 u7 V9 T" q0 x2 a, F! l
, [" T( z1 c8 C+ K, s- ^! R6 h
我的版本是 3.9.7 ,目前没有遇到 No such file or directory 报错。 然后是genMDX_ox4.py 文件有部分中文乱码
! ~6 ]! ?0 i, ~2 v6 b6 U5 Q; f& q) ^
- # -*- coding: utf-8 -*-
' L+ F6 ~/ Q, i - # encoding=utf8
# [0 m H8 l1 U4 G2 h6 q - 2 H9 J) a# z- Z' A1 P% _
- from __future__ import unicode_literals,print_function, absolute_import, division9 V+ X2 g+ x* v9 W9 F: a! T g
- + s3 P5 c) p. ], t& A
- " X7 O7 h6 S- B* q! o
- import re. x- k; P' E0 O1 @
- import copy! b9 Q; o& `* i
- import chardet+ |' z8 A* ~9 n; J4 j/ v
- 0 e- Q1 c' t7 y
- import os' T( N5 l6 W9 R& P: B
- import io
, C4 o$ }. u) Q, @ - import sys1 I: v: G6 _. {5 H1 G
- # reload(sys)
H7 y) T: O$ v, ^ - # sys.setdefaultencoding('utf-8')7 ?( f# g* l3 {( i, ^# w. b* x) j
* U) F# e8 A9 T" Y0 v$ ?- import collections2 x! u e: H: W* u2 K% Y
- from collections import defaultdict; E1 S+ w1 B+ t% Q) R- |# j; ~
- & j& F( V& c* c; k+ N
- 9 n# N( q; K- r- g, q
- from writemdict import MDictWriter, encrypt_key+ j0 T2 d5 Q! |; `6 L
- from ripemd128 import ripemd1280 U& T$ d0 j4 b. r" _
) L- x( c) S. Z0 ?$ k9 {5 x
x& h) l, |. }! V0 M- head = 0
, r5 d3 \9 A$ V( r - new_mean =[]
* _; N3 S/ U; e# ^! ^+ x; t - f=io.open('OALD4_azure.txt', 'r',encoding='utf-8')
" _- q N' f# L# A9 L - #f=io.open('oxford2_original.txt', 'r',encoding='utf-8')2 W i- {- g# P
- d = defaultdict(list) #����һ�����ֵ䣬Ҳ��ʹ��{}������
8 q# h6 n; q" } - for line in f: #ÿ�δ�f�ж���һ��
; X( [- P( b( Z9 D R& w - line=line.rstrip('\n')#ȥ����β�Ļ��з�' e- y+ @! S, Q
- if line == '</>':
% S" H: D3 ?5 p# C/ B) ~, q2 @0 c - if head == 2:5 }/ y5 S0 }/ p5 d
- new_mean[0:] = ["".join(new_mean[0:])]7 ^' s" F3 `5 w9 K0 h9 Z* y
- d[word].append(new_mean[0])
' q9 j. ?) ?7 v4 C - head = 1;* Q5 H0 U3 `3 E# y! L6 C
- new_mean =[]+ F4 T& ^/ k0 x4 ?/ x# n
- elif head == 1:! |" P1 u5 u. N0 I5 e- r$ ]/ |
- word = line
% s* F: d- b& I. A - head = 2
- J# e" o* p: J- O9 l - elif head == 2:
# t; h( Y. t* w% Y' p- o K1 F - new_mean.append(line)
6 L5 o6 L9 x7 s. U+ n \ - head = 2
3 r3 x- n5 ~4 X - f.close()
e; R2 x- W1 @ - 4 Z$ p6 x' B! `* g* a6 M/ K
+ n0 a$ l8 t H( P6 u- ff=io.open('about_OX4.txt', 'r',encoding='utf-8')#�ʵ�about��Ϣ��txt�ļ��뱣��Ϊutf-8
* D3 Z8 J: V: E7 ` - about=[]
0 t) Y4 |' x4 ]8 x0 n - for line in ff: #ÿ�δ�f�ж���һ��2 R( Z" h( K* ~6 Z6 Z) y
- about.append(line)
. o( u) h8 N3 m. o - about[0:] = ["".join(about[0:])], K: k- M. i2 E: g+ z
- " x6 ^' ~! w# C4 g* q' h3 e
- 6 W' \7 r! d, a* S$ ?# q
- #outfile = open("example_output/��ţ��Beta_V2.2.1.mdx", "wb")
7 Z& m# x0 k y) }! j( H - #writer = MDictWriter(d, "��ţ��Beta_V2.2.1", about[0])1 ?2 E# @' R9 Q# o0 c7 B' B
- outfile = open("output_ox4/OALD4_Ex.mdx", "wb")1 f- y \0 K( U* Q9 y- r
- writer = MDictWriter(d, "ţ��߽�˫��(���İ�)", about[0])
' B, [0 A `4 E7 | - writer.write(outfile); J+ I8 }$ `9 O! d8 m0 [
- outfile.close()
! ?9 k: B7 t0 F0 u$ A9 R* f
' g L% e: a" \
复制代码
$ _/ M' R }" o: l2 Q6 w8 M# h/ @) z3 C! V/ _# c8 Q
7 t1 G' n' B8 U/ C5 q" r是否可以看看你的文档呢 乱码的部分中文写的是什么? |
|