Change language

NLP | Splitting with Corpus Reader

| | |

How it works:

  • The ChunkedCorpusReader class works similarly to TaggedCorpusReader for receiving tagged tokens, and also provides three new methods for receiving chunks .
  • An instance of nltk.tree.Tree represents each chunk.
  • Nominal phrase trees look like a Tree (& # 39; NP & # 39 ;, [... ]), and Sentence level trees look like Tree (& # 39; S & # 39 ;, [...]).
  • A list of sentence trees with each nominative phrase as a sentence subtree is obtained in n chunked_sents ()
  • A list of noun trees, along with marked tokens of words that were not in the chunk, is obtained in chunked_words ().

A diagram listing the main methods:

Code # 1 : Create ChunkedCorpusReader for words

< / p>

 

# Using ChunkedCorpusReader

from nltk.corpus.reader import ChunkedCorpusReader

 
# initialization

x = ChunkedCorpusReader ( ’.’ , r ’. *. chunk’ )

 

words = x.chunked_words ()

print ( "Words:" , words)

Output:

 Words: [Tree (’NP’, [(’ Earlier’, ’JJR’), (’ staff-reduction’, ’NN’), (’ moves’, ’NNS’)]), (’ have’, ’VBP’), ...] 

Code # 2: for offer

Chunked Sentence = x.chunked_sents ()

print ( "Chunked Sentence:" , tagged_sent)

Output:

 Chunked Sentence: [Tree (’S’, [Tree (’ NP ’, [(’ Earlier’, ’JJR’), (’ staff-reduction’, ’NN’), (’ moves’, ’NNS’)]), (’ have’, ’VBP’), (’ trimmed ’,’ VBN’), (’about’,’ IN’), Tree (’NP’, [(’ 300’, ’CD’), (’ jobs’, ’NNS’)]), (’, ’ , ’,’), Tree (’NP’, [(’ the’, ’DT’), (’ spokesman’, ’NN’)]), (’ said’, ’VBD’), (’ .’, ’.’)])] 

Code # 3: for paragraphs

para = x.chunked_paras () ()

print ( "para:" , para)

Output:

 [[Tree ( ’S’, [Tree (’ NP’, [(’Earlier’,’ JJR’), (’staff-reduction’,’ NN’), (’moves’,’ NNS’)]), (’have’ , ’VBP’), (’ trimmed’, ’VBN’), (’ about’, ’IN’), Tree (’ NP’, [(’300’,’ CD’), (’jobs’,’ NNS ’)]), (’, ’,’, ’), Tree (’ NP’, [(’the’,’ DT’), (’spokesman’,’ NN’)]), (’said’,’ VBD’), (’.’,’ .’)])]] 

Shop

Learn programming in R: courses

$

Best Python online courses for 2022

$

Best laptop for Fortnite

$

Best laptop for Excel

$

Best laptop for Solidworks

$

Best laptop for Roblox

$

Best computer for crypto mining

$

Best laptop for Sims 4

$

Latest questions

NUMPYNUMPY

Common xlabel/ylabel for matplotlib subplots

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

12 answers

NUMPYNUMPY

Flake8: Ignore specific warning for entire file

12 answers

NUMPYNUMPY

glob exclude pattern

12 answers

NUMPYNUMPY

How to avoid HTTP error 429 (Too Many Requests) python

12 answers

NUMPYNUMPY

Python CSV error: line contains NULL byte

12 answers

NUMPYNUMPY

csv.Error: iterator should return strings, not bytes

12 answers

News


Wiki

Python | How to copy data from one Excel sheet to another

Common xlabel/ylabel for matplotlib subplots

Check if one list is a subset of another in Python

sin

How to specify multiple return types using type-hints

exp

Printing words vertically in Python

exp

Python Extract words from a given string

Cyclic redundancy check in Python

Finding mean, median, mode in Python without libraries

cos

Python add suffix / add prefix to strings in a list

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

Python - Move item to the end of the list

Python - Print list vertically