में अपठनीय फ़ाइल को लिखने के लिए लिखता है मैं चीनी ग्रंथों पर पाठ विश्लेषण करने की कोशिश कर रहा हूं। कार्यक्रम नीचे प्रदान किया गया है। मुझे 浜烘皯鏃ユ姤绀捐
जैसे अपठनीय पात्रों के साथ परिणाम मिला। और अगर मैं आउटपुट फ़ाइल result.csv
से result.txt
में बदलता हूं, तो वर्ण 人民日报社论
के रूप में सही हैं। तो इसमें क्या गलत है? मैं समझ नहीं पा रहा हु। मैंने decoder
और encoder
जोड़ने सहित कई तरीकों की कोशिश की।पायथन सीएसवी एक्सेल (चीनी वर्ण)
# -*- coding: utf-8 -*-
import os
import glob
import jieba
import jieba.analyse
import csv
import codecs
segList = []
raw_data_path = 'monthly_raw_data/'
file_name = ["201010", "201011", "201012", "201101", "201103", "201105", "201107", "201109", "201110", "201111", "201112", "201201", "201202", "201203", "201205", "201206", "201208", "201210", "201211"]
jieba.load_userdict("customized_dict.txt")
for name in file_name:
all_text = ""
multi_line_text = ""
with open(raw_data_path + name + ".txt", "r") as file:
for line in file:
if line != '\n':
multi_line_text += line
templist = multi_line_text.split('\n')
for text in templist:
all_text += text
seg_list = jieba.cut(all_text,cut_all=False)
temp_text = []
for item in seg_list:
temp_text.append(item.encode('utf-8'))
stop_list = []
with open("stopwords.txt", "r") as stoplistfile:
for item in stoplistfile:
stop_list.append(item.rstrip('\r\n'))
text_without_stopwords = []
for word in temp_text:
if word not in stop_list:
text_without_stopwords.append(word)
segList.append(text_without_stopwords)
with open("results/result.csv", 'wb') as f:
writer = csv.writer(f)
writer.writerows(segList)
आप अक्षरों को कैसे पहचानते हैं "अपठनीय" हैं। क्या आप Excel के साथ csv-file खोलते हैं? कमांड लाइन टूल जैसे 'कम' के साथ इसे देखें? इसे एक टेक्स्ट एडिटर के साथ खोलें? –
हां, मैं इसे एक्सेल के साथ खोलता हूं, अगर मैं 'result.csv' फ़ाइल को' result.txt' में बदलता हूं, तो मैं सभी पात्रों को पढ़ सकता हूं। यह बड़ा अजीब है। – flyingmouse
एक्सेल में कोई समस्या है जहां यह विशेष वर्णों को जोड़ती है। उदाहरण के लिए नोटपैड ++ में result.csv खोलने का प्रयास करें और देखें कि यह सही है या नहीं। – Untitled123