Class: SynonymScrapper::Nltk
- Inherits:
-
Object
- Object
- SynonymScrapper::Nltk
- Defined in:
- lib/synonym_scrapper/nltk.rb
Overview
Connector and requester of python’s NLTK
Instance Method Summary collapse
-
#synonyms(word, options = {}) ⇒ Object
Obtain synonyms of a
wordfrom the NLTK.
Instance Method Details
#synonyms(word, options = {}) ⇒ Object
Obtain synonyms of a word from the NLTK.
Makes a call to a python script and parses its results.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/synonym_scrapper/nltk.rb', line 15 def synonyms(word, = {}) begin nltk_response = `python3 #{__dir__}/nltk_parser.py "#{word}"` = JSON.parse(nltk_response)["relations"][word] synonyms = Array.new .each do |synonym| synonyms.push({ word: synonym["word"], score: synonym["score"] }) end return synonyms rescue => e puts e return [] end end |