Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

word_reference

Package Overview
Dependencies
Maintainers
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

word_reference

  • 0.0.1
  • Rubygems
  • Socket score

Version published
Maintainers
2
Created
Source

WordReference

Authors: malandrina, sandbochs

A Ruby wrapper for the WordReference.com Dictionary API

Documentation for the API can be found here: http://www.wordreference.com/docs/api.aspx

TODO

  • Handle exceptions
  • Handle errors from WordReference.com API
  • Add interface for thesaurus API

Installation

Add this line to your application's Gemfile:

gem 'word_reference'

And then execute:

$ bundle

Or install it yourself as:

$ gem install word_reference

Usage

Include WordReference module

include WordReference

In order to query the WordReference.com API, you will need an API key. You can get one here: http://www.wordreference.com/docs/APIregistration.aspx

Configure your API key

WordReference.configure do |config|
  config.api_key = YOUR_API_KEY
end

Create a new dictionary

A dictionary is referenced by a four-letter code comprising the original language and target language. Note that the WordReference.com API currently supports translations to or from English. If the dictionary does not exist (ex. 'czzh'), the API will return an error message. A list of two-letter language codes is provided below.

french_dictionary = Dictionary.new('enfr')
  • Arabic: ar
  • Chinese: zh
  • Czech: cz
  • English: en
  • French: fr
  • Greek: gr
  • Italian: it
  • Japanese: ja
  • Korean: ko
  • Polish: pl
  • Portuguese: pt
  • Romanian: ro
  • Spanish: es
  • Turkish: tr

Change dictionary

french_dictionary.change_language('iten')
# Or create another dictionary
italian_dictionary = Dictionary.new('iten')

Query API with term

Query terms which include special characters should be converted to UTF-8 Base 16. ("más" => "m%C3%A1s")

UTF Converter

# Returns a Query object
query = italian_dictionary.query('chiave')

Get query results

# Returns an array of translations
query.results

When #query is called on a dictionary, a collection of translation objects is returned.

Get original search term

translation = query.results.first
translation.search_term => {"term"=>"chiave", "POS"=>"nf", "sense"=>"strumento per aprire", "usage"=>"letterale"}
translation.search_term['term'] => 'chiave'
translation.search_term['POS'] => 'nf' # 'POS' stands for 'Particle of Speech'
translation.search_term['sense'] => 'strumento per aprire'
translation.search_term['usage'] => 'letterale'

Get translations

translation = query.results.first
first = translation.results.first
first => {"term"=>"key", "POS"=>"n", "sense"=>""}
first['term'] => 'key'
first['POS'] => 'n' # noun
first['sense'] => '' # no sense
first['usage'] => nil

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

FAQs

Package last updated on 13 Nov 2012

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc