【问题标题】:How do I split Dutch text from the Spanish part in NLTK?如何从 NLTK 中的西班牙语部分拆分荷兰语文本?
【发布时间】:2016-02-11 13:00:37
【问题描述】:

NLTK 包含一个荷兰语标记语料库,我如何从中打印最常见的标记?

为此,我需要知道荷兰语标签包含在 conll2002 语料库中。

conll2002 语料库也包含西班牙语文本,所以我只需要阅读荷兰语部分。


代码:

conll_tagged = nltk.corpus.conll2002.tagged_words()

tag_fd = nltk.FreqDist(conll_tagged 中 (word,tag) 的标签)

tag_fd.most_common()

[(u'NC', 89469), (u'N', 77188), (u'SP', 61145), (u'V', 40744), (u'Punc', 39354), ( u'DA', 35574), (u'Prep', 32114), (u'AQ', 31249), (u'Art', 28875), (u'Pron', 22037), (u'Adv', 21987), (u'Fc', 20719), (u'Adj', 20553), (u'VMI', 19650), (u'Conj', 14281), (u'Num', 11226), (u 'Fp', 10266), (u'Z', 9291), (u'CC', 8543), (u'DI', 7630), (u'Fe', 7544), (u'RG', 7396 ), (u'PR', 7128), (u'VMN', 6435), (u'CS', 6408), (u'VMP', 3547), (u'P0', 3509), (u' Fpt', 3314), (u'Fpa', 3307), (u'DP', 2817), (u'VAI', 2437), (u'Fg', 2345), (u'VSI', 2238) , (u'DD', 2224), (u'DN', 1875), (u'NP', 1846), (u'VMS', 1624), (u'RN', 1546), (u'PP ', 1302), (u'AO', 1281), (u'PI', 864), (u'VMM', 854), (u'PN', 820), (u'Misc', 616), (u'VMG', 528), (u'Fd', 365), (u'VSN', 291), (u'VSP', 258), (u'PD', 231), (u'Int' , 231), (u'Fx', 211), (u'VSS', 176), (u'Fz', 157), (u'VAN', 146), (u'I', 136), ( u'VAS', 129), (u'PT', 95), (u'Fh', 72), (u'Y', 34), (u'VSG', 26), (u'Fs', 25), (u'Fit', 18), (u'Fia', 18), (u'VAP', 18), (u'DT', 17), (u'Fat', 5), (u'Ft', 4), (u'PX', 4), (u'Faa', 4), (u'VSM', 3), (u'DE', 2), (u 'VAM', 1)]

【问题讨论】:

    标签: python tags nltk text-mining


    【解决方案1】:

    正确的conll2002 也包含西班牙语和荷兰语。

    print nltk.corpus.conll2002.fileids()
    Output:
    ['esp.testa', 'esp.testb', 'esp.train', 'ned.testa', 'ned.testb', 'ned.train']
    

    我们只对荷兰语感兴趣,这是如何做到的。

    from nltk.corpus import conll2002
    for doc in conll2002.tagged_sents('ned.testa')[:]: #you need change the file name according to your requirement
         conll_tagged += doc
    tag_fd = nltk.FreqDist(tag for (word,tag) in conll_tagged)
    tag_fd.items()
    

    输出是:

    [(u'N', 38789),
     (u'V', 21032),
     (u'Prep', 16540),
     (u'Punc', 16472),
     (u'Art', 14816),
     (u'Adv', 10824),
     (u'Adj', 10296),
     (u'Pron', 10232),
     (u'Conj', 7184),
     (u'Num', 4268),
     (u'Misc', 244),
     (u'Int', 52)]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-15
      • 2014-09-22
      • 1970-01-01
      • 2013-01-21
      • 2021-01-01
      相关资源
      最近更新 更多