Sunday 9 July 2017

Get synonyms and antonyms of a word in Rails.

In this blog, we will integrate Big Huge Labs Thesaurus API in our Rails app for getting synonyms and antonyms of a word. For this we will use dinosaurus gem.

So, in Gemfile.

 gem 'dinosaurus'

Run bundle.

Before initializing this we have to get an api key for configuration. We can get it from here.

For initializing, create a file dinosaurus.rb in config/initializer and put below code in this file.


 
 Dinosaurus.configure do |config|
   config.api_key = 'your_api_key'
 end 
 

Now, we can use it as

 > Dinosaurus.synonyms_of('word')

 => ["news", "intelligence", "tidings", "discussion", "give-and-take", "parole", "word of honor", "Son", "Word", "Logos", "password",   "watchword", "countersign", "Bible", "Christian Bible", "Book", "Good Book", "Holy Scripture", "Holy Writ", "Scripture", "Word of God",  "arcanum", "computer memory unit", "hypostasis", "hypostasis of Christ", "info", "information", "language", "language unit",   "linguistic unit", "oral communication", "order", "positive identification", "promise", "religious text", "religious writing", "sacred   text", "sacred writing", "secret", "speech", "speech communication", "spoken communication", "spoken language", "statement", "voice   communication", "give voice", "formulate", "phrase", "articulate", "evince", "express", "show"]


  > Dinosaurus.antonyms_of('synonyms')

  => ["antonym"]


You can get synonyms and antonyms together with lookup method. It will return a hash like this


 > Dinosaurus.lookup('word')

  => {"noun"=>{"syn"=>["news", "intelligence", "tidings", "discussion", "give-and-take", "parole", "word of honor", "Son", "Word",   "Logos", "password", "watchword", "countersign", "Bible", "Christian Bible", "Book", "Good Book", "Holy Scripture", "Holy Writ",   "Scripture", "Word of God", "arcanum", "computer memory unit", "hypostasis", "hypostasis of Christ", "info", "information", "language",  "language unit", "linguistic unit", "oral communication", "order", "positive identification", "promise", "religious text", "religious   writing", "sacred text", "sacred writing", "secret", "speech", "speech communication", "spoken communication", "spoken language",   "statement", "voice communication"]}, "verb"=>{"syn"=>["give voice", "formulate", "phrase", "articulate", "evince", "express", "show"]}}

2 comments:

  1. It is very informative blog and useful article thank you for sharing with us , keep posting learn more aboutrubyonrails more info on Ruby on Rails Online course Bangalore

    ReplyDelete
  2. AldaimSolutions as an offshore e-Commerce website development company provides a wide range of online business solutions in web and mobile space.Popular rails gemsRails is basically a web application framework, which is consist of everything needs to create database baked web application. It helps the developers to create websites and applications by providing structures for all codes written by them. Moreover, common repetitive tasks are simplified with the help of this technology.
    Websites made with PHP and Shopify
    Best Ecommerces Company Audacity24
    Websites made with PHP and Shopify
    Best ruby APIS
    React native and React Js
    Node Js and React Js

    ReplyDelete