小编the*_*ern的帖子

使用Python将复数转换为文本文件中的单数

我有txt文件,如下所示:

word, 23
Words, 2
test, 1
tests, 4
Run Code Online (Sandbox Code Playgroud)

我希望它们看起来像这样:

word, 23
word, 2
test, 1
test, 4
Run Code Online (Sandbox Code Playgroud)

我希望能够在Python中获取一个txt文件并将多个单词转换为单数.这是我的代码:

import nltk

f = raw_input("Please enter a filename: ")

def openfile(f):
    with open(f,'r') as a:
       a = a.read()
       a = a.lower()
       return a

def stem(a):
    p = nltk.PorterStemmer()
    [p.stem(word) for word in a]
    return a

def returnfile(f, a):
    with open(f,'w') as d:
        d = d.write(a)
    #d.close()

print openfile(f)
print stem(openfile(f))
print returnfile(f, stem(openfile(f)))
Run Code Online (Sandbox Code Playgroud)

我也尝试过这两个定义而不是stem定义:

def singular(a):
    for line in …
Run Code Online (Sandbox Code Playgroud)

python text stemming plural singular

8
推荐指数
2
解决办法
2万
查看次数

如何创建.onion网站?

我有一个ubuntu linux,一直在使用这个网站:https://scottlinux.com/2013/10/11/how-to-create-a-tor-onion-site/但我对如何使用这个问题感到困惑文件/etc/nginx/nginx.conf,从那里一切都有点令人困惑.如果您知道如何遵循这些说明,请告诉我们.

nginx tor

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

nginx ×1

plural ×1

python ×1

singular ×1

stemming ×1

text ×1

tor ×1