Code # 1: filter_insignificant () class to filter irrelevant words
|
filter_insignificant ()
checks if this tag (for each tag) ends with suffix tags iterating over the tagged words in the chunk. A tagged word is skipped if the tag ends with any of the tag_suffixes
. Otherwise, if all is well with the tag, the tagged word is added to the new valid snippet that is returned.
Code # 2: Using filter_insignificant ()
for a phrase
|
Output:
Significant words: [(’terrible’,’ JJ’), (’movie’,’ NN’)]
We can give different tag suffixes using filter_insignificant ()
... In the code below, we are talking about pronouns and possessive words like "you", "you", "them" and "them", they are useless, but the words "DT" and "CC" are fine. Then the tag suffixes are PRP and PRP $:
Code # 3: Passing custom tag suffixes using filter_insignificant()
|
Output:
Significant words: [(’book’,’ NN’), (’is’,’ VBZ’), (’great’,’ JJ’)]