【问题标题】:Processing NLTK Stanford POS Tagger output处理 NLTK Stanford POS Tagger 输出
【发布时间】:2017-11-05 06:04:12
【问题描述】:

我正在使用 NLTK 斯坦福 Pos Tagger 和我自己的模型来标记文本文件中的句子行。我的标注器的输出是这样的:

sentences = [((Word,WordTag),....(Word,WordTag)]

我正在处理印尼语,我在做 Pos 标签后做了 2 步:

  1. 停用词删除
  2. 词干

我在文本文件 (stopword.txt) 中有一个停用词列表,然后对句子进行词干处理。 到目前为止,我已经完成了标记部分。我不知道如何过滤sentences 中的单词并删除stopword.txt 中的单词并阻止sentences 中的单词

到目前为止,我已经尝试使用此代码删除单词,但仍未删除该单词及其单词标签:

stopWords = getStopWordList('id_stopword.txt')
filtered_sentences = [w for w in sentences if not w in stopWords]
    filtered_sentences = []
    for w in sentences:
        if w not in stopWords:
            filtered_sentences.append(w)

【问题讨论】:

    标签: python nltk stanford-nlp


    【解决方案1】:

    我必须假设您的函数getStopWordList() 正确地返回了一个字符串列表。 (你验证了吗?)

    您发布的代码将无法运行,因为它存在缩进错误。但是缩进位并不重要,因为您不需要它。很明显,它只是重复了前一行的逻辑。所以我只是忽略了它。

    要进行过滤,您需要更改:

    filtered_sentences = [w for w in sentences if not w in stopWords]
    

    到这里:

    filtered_sentences = [(w,t) for (w,t) in sentences if not w in stopWords]
    

    【讨论】:

    • 是的,getStopWordList() 返回一个字符串列表。谢谢你。现在剩下的问题是词干。我可以使用以下代码来阻止过滤后的句子吗?
    • 发布一个关于词干提取的单独问题。您的代码没有进入您的评论。可能太长了。
    猜你喜欢
    • 2015-01-26
    • 1970-01-01
    • 2013-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多