使用ConditionalFreqDis时出现语法错误

2024-04-20 14:16:32 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试获取ConditionalFreqDist,但是Python在第三行一直给我一个语法错误(对于..中的category)。我想不出这个问题,有什么想法(我是初学者)。你知道吗

 def persoonlijkvnw(mijn_corpus):
    cfd = nltk.ConditionalFreqDist(category,word)
    for category in mijn_corpus.categories()
    for word in mijn_corpus.words(categories=category)
    category = mijn_corpus.categories()
    persoonlijke_vnw = ['ik','jij','hij','wij','jullie','zij']
    cfd.tabulate(conditions=category, samples=persoonlijke_vnw)

Tags: infordefcorpuswordcategoriescategory语法错误
1条回答
网友
1楼 · 发布于 2024-04-20 14:16:32

首先,有关基本语法的信息,您应该参考Python教程。你知道吗

我将引用compound statements上的官方文档:

Compound statements consist of one or more ‘clauses.’ A clause consists of a header and a ‘suite.’ The clause headers of a particular compound statement are all at the same indentation level. Each clause header begins with a uniquely identifying keyword and ends with a colon. A suite is a group of statements controlled by a clause. A suite can be one or more semicolon-separated simple statements on the same line as the header, following the header’s colon, or it can be one or more indented statements on subsequent lines. Only the latter form of suite can contain nested compound statements

(重点是我的)。你知道吗

正如您在同一页中所看到的,for循环也is a compound statement,因为在您的例子中,“suites”与“headers”不在同一行,所以它们应该缩进。此外,在“header”的末尾还需要一个冒号。你知道吗

如果没有缩进,我们就不能说循环体在哪里结束,但是我提到的可能只是这个代码问题的一部分。你知道吗

例如,category变量用作外循环计数器,但在循环中被重新分配。这不是语法错误,但可能是作者的疏忽。你知道吗

相关问题 更多 >