Python - NLTK 语料库中 tagged_sents 和 tagged_words 的区别

Python - difference between tagged_sents and tagged_words in NLTK corpora

nltktagged_sents和tagged_words有什么区别?

它们似乎都是包含元组(单词、标签)​​的列表。如果你做 type(),它们都是

nltk.collections.LazySubsequence

来自docs

Corpus reader functions are named based on the type of information they return.  
Some common examples, and their return types, are:
- words(): list of str
- sents(): list of (list of str)
- paras(): list of (list of (list of str))
- tagged_words(): list of (str,str) tuple
- tagged_sents(): list of (list of (str,str))
- tagged_paras(): list of (list of (list of (str,str)))
- chunked_sents(): list of (Tree w/ (str,str) leaves)
- parsed_sents(): list of (Tree with str leaves)
- parsed_paras(): list of (list of (Tree with str leaves))
- xml(): A single xml ElementTree
- raw(): unprocessed corpus contents


>>> from nltk.corpus import brown

>>> brown.tagged_words()
[(u'The', u'AT'), (u'Fulton', u'NP-TL'), ...]

>>> len(brown.tagged_words()) # no. of words in the corpus.
1161192


>>> len(brown.tagged_sents()) # no. of sentence in the corpus.
57340

# Loop through the sentences and counts the words per sentence.
>>> sum(len(sent) for sent in brown.tagged_sents()) # no. of words in the corpus.
1161192