我正在尝试获取带有标点符号的文本,因为在我的 doc2vec 模型中考虑后者很重要。然而,维基语料库只检索文本。在网上搜索后,我找到了这些页面:
我决定使用第 1 页中提供的代码。我当前的代码 (mywikicorpus.py):
import sys
import os
sys.path.append('C:\\Users\\Ghaliamus\\Anaconda2\\envs\\wiki\\Lib\\site-packages\\gensim\\corpora\\')
from wikicorpus import *
def tokenize(content):
# override original method in wikicorpus.py
return [token.encode('utf8') for token in utils.tokenize(content, lower=True, errors='ignore')
if len(token) <= 15 and not token.startswith('_')]
def process_article(args):
# override original method in wikicorpus.py
text, lemmatize, title, pageid = args
text = filter_wiki(text)
if …Run Code Online (Sandbox Code Playgroud)