Friday, 19 May 2017

Categorized words according to parts of speech from english sentence in Ruby

In the English language, words can be considered as the smallest elements that have distinctive meanings. Based on their use and functions, words are categorized into several types or parts of speech.

In this blog we will define and examples for major parts of speech from English sentence with using ruby gem engtagger .



 require 'rubygems'
 require 'engtagger'


 # Initialize a parser object
 tgr = EngTagger.new

 # Sample text
 text = "Ruby is an expressive, dynamic programming language."

 # Add part-of-speech tags to text
 tagged = tgr.add_tags(text)

 # Get all nouns from a tagged output
 nouns = tgr.get_nouns(tagged)

 => {"Ruby"=>1, "programming"=>1, "language"=>1}

 # Get all the adjectives
 adj = tgr.get_adjectives(tagged)

 => {"expressive"=>1, "dynamic"=>1}

 # Get all the verbs
 adj = tgr.get_verbs(tagged)

 => {"is"=>1}
 
 
 
 
 

1 comment:

  1. Reading your blog is always a learning experience

    ReplyDelete