Table of Contents
- What is Words API?
- How It Works
- Users
- How to Connect to Words API Tutorial – Step by Step
- Explanation of Words API Endpoints
- How to Use Words API with Python
- How to Use Words API with PHP
- How to Use Words API with Ruby
- How to Use Words API with JavaScript
- Benefits of Words API
- Alternatives to Words API
- Summary
Whether you are a developer building a simple dictionary application, or an AI Enthusiast creating the next Smart Assistant like ‘Siri’ and ‘Alexa’ to take over the world. You need to have comprehensive data about the language at your disposal, which should not only allow you to look up word definitions but also have the ability to provide more contextual information such as related words, example usage, relevant categories, etc.
Luckily, you don’t need to scrape through a dozen websites to collect ill-formed information from various sources anymore. You can simply use The Words API which contains well-structured data for over 350,000 words.
If you are new to the APIs, you can go through this post before we dive into the details.
What is Words API?
Words API is a set of Restful APIs that allow developers to look up word definitions, contextual details, and other morphological word-specific information, such as synonyms, example usage, part of speech, rhymes, region of use, etc.
The API also returns some very uncommon information that is very challenging to retrieve using other tools and APIs such as:
- Finding the region where words are used.
- Check if a given word falls in a particular category.
- Allow the users to view example usage.
- Identify if two given words are similar.
- Has Parts (The word “car” returns a list with ‘engine’, ‘trunk’,’ wheel’ etc).
- Member of (The word ‘dory’ returns a list with ‘zeidae’).
- Has Instance (The word ‘president’ may return a list of all u.s presidents)
- Has Types ( The word purple returns a list of its types e.g ‘violet’, ‘lavender’, ‘royal purple’)
- Has Substances ( The word ‘wood’ returns a list of the substance it’s made of e.g ‘lignin’)
Words API also provides a powerful pattern-based searching using both letter and pronunciation patterns. For example: using the pattern ^a.{4}$ will return all the words that start with ‘a’ and are followed by any 4 characters.
It has a freemium pricing model and includes the limited free tier which allows making 2500 API Requests per day. If you need a higher volume for your application you may signup for their paid plans where the per day quota ranges from 25k to 500k.
The API allows seamless integration with mobile or desktop applications using the language of your choice: such as Python, PHP, Ruby, and JavaScript.
How It Works
Following the RESTful model, Words API provides various endpoints that can be invoked over HTTP using the language of your choice.
The Client application requests the data by issuing a GET request to one of its endpoints.
The Words API then sends the data securely via HTTPS Response in JSON Format as illustrated in the diagram below:
Users
Words API targets a vast audience of developers working in various domains.
Education
With the increasing popularity of online education and e-learning, developers nowadays are focusing on creating educational-based apps that can enhance their learning activities and provide accurate information. Using Words API in educational apps is simply a no-brainer, as it allows them to provide features like word lookup, grammar and spelling correction, pronunciation, synonyms, etc.
Mobile Games
The mobile gaming industry is on the rise for both gamers and developers. Many educational institutes have begun implementing ‘gamified learning activities and we are witnessing the rise of educational games such as Crossword-style puzzles, word search, anagram, guess the word, spelling bee, etc. In this fast-paced environment, developers have no time to reinvent the wheel and build their language database – Words API can take care of all the low-level details, so they can focus on the business aspects of the app.
AI and Natural Language Processing
Words API has a comprehensive database for the English language which can be used to train an AI and build applications in the NLP domain – The possibilities are endless.
Below are some of the promising applications where Words API can play a vital role.
Spam Filters:
Words API provides powerful endpoints that can be used to uncover certain words or related phrases that signal a spam message. Finding the relatable words and making sense of the phrases has never been any easier.
Chatbots and Smart Assistants
The Core of AI Development always relies on data. Luckily, Words API provides querying over a comprehensive lexical database containing over 350,000 Words that can be used to build the training dataset which acts as a core building block of creating a Chatbot or a Smart Assistant like Alexa.
Predictive Text
Predictive Text can be found all over the internet, from search engines, to autocomplete input boxes to e-commerce apps. Users tend to prefer the system which can predict, autocorrect and autocomplete as they type. Words API offers powerful wildcard searching which can be used in building components and those services.
Sentiment Analysis
It’s a technique through which the application analyzes a piece of text to identify the sentiment or intent behind it. It also combines machine learning and NLP to achieve this. Words API can be a good fit in this case as well. Because, it can provide more contextual and morphological information about the words.
Music and Poetry
Developers building apps for the poetry and music industry, can make use of Words APIs to provide a rhyming dictionary or word suggestions for songwriters and poets.
How to Connect to Words API Tutorial – Step by Step
Connecting to Words API is a three-step process:
Step1: Signup for an Account on RapidAPI
RapidAPI allows developers to find and connect thousands of APIs using One SDK and one API Key. You can signup for a free account using this link.
Step2: Subscribe to the Words API
Once you have signed up, you need to subscribe to the API. Please follow the below steps to subscribe to the Words API.
- Navigate to Words API and Select Pricing Tab
- Select your desired plan and click on the ‘Subscribe’ button.
Please note that the Basic plan is free for up to 2500 request/day, but you need to provide a credit card to subscribe to the API because this plan has a quota with an overage fee.
Step 3. Test the API Subscription
After a successful subscription, you may begin with testing the API using any of its endpoints.
You can test any endpoint and select the code snippet for any programming language, including Python, JavaScript, PHP, and Ruby.
Note: API Key and other required parameters like (word) will automatically be generated by RapidAPI Console.
In the below sample, we have tested the ‘Word’ endpoint to fetch details about the word ‘example’ and it successfully returned the JSON response with 200 status code.
Note: If the test has failed, the API Server may return one of the following responses which are explained below:
- 400 Bad Request – Client sent an invalid request (missing required parameters).
- 401 Unauthorized – Failed to authenticate with the API server.
- 403 Forbidden – Client authenticated but doesn’t have permission to access the required resource.
- 404 Not Found – The requested resource (endpoint) doesn’t exist.
- 500 Internal Server Error – A generic error occurred on the API server.
- 503 Service Unavailable – The API service is not available.
Explanation of Words API Endpoints
Words API Endpoints are grouped into two categories:
- Words: It contains all the endpoints that allow retrieving information about words such as definitions, synonym, rhymes, examples, etc.
- Related Words: In this category, you can find all the endpoints that are related to finding relationship between words and their contextual details.
Word Endpoint:
This endpoint allows users to retrieve information about a given word. It includes word definitions, pronunciation, syllable count, part of speech, related words, types, and example sentences.
Synonym Endpoint:
It returns a list of synonyms for a given word. For example, invoking this endpoint with the word ‘lovely’ would return Adorable, Endearing.
Antonym Endpoint:
This endpoint returns a list of antonyms for a given word. For example, the word free would return Obstruct, confine, unfree, and bound.
Example Endpoint:
This endpoint returns a list of examples of how the word is used.
Pronunciation Endpoint:
This endpoint can be used to identify the way a word can be pronounced according to the international phonetic alphabet. It returns multiple results if the word is pronounced differently as per its part of speech.
Rhymes Endpoint:
This endpoint gets a list of words that rhymes with the given word.
Syllables Endpoint:
It returns all the syllables of a given word. For example, when provided with the word ‘incredible’ the API will return an array containing items, “in”,”cred”, “i”,”ble”.
Frequency Endpoint:
It returns the frequency score for any given word.
- Zipf score which indicates how common the word is in the English language with a range of 1 to 7
- Per million: the number of times the word is likely to appear in a corpus of one million words.
- Diversity: which shows the likelihood of the word appearing in a document that is part of a corpus.
Random Endpoint:
This endpoint returns a random word and its related information.
Search Endpoint:
This endpoint provides a powerful way to search through a repository of 350,000 words using various search patterns.
Following optional parameters can be passed in the request:
- letterPattern: “^a.{2}$” will return all the words that start with ‘a’ and are followed by any 2 characters.
- pronunciationpattern: *æm$ will filter the records using pronunciation pattern.
- partofspeech : It’s an optional parameter that can be used to check if a word contains at least one definition with a specified part of speech.
- Letters: The number of letters the word must-have.
- LetterMax: The maximum number of letters the word can have
- Soundsmax. The maximum number of sounds the word can have.
- Sounds. The number of sounds the word must have
- Soundsmin: It specifies the minimum number of sounds the word can have.
- SyllablesMin: It specifies the minimum number of syllables the word can have
- Syllables: The number of syllables the word must have
- syllablesMax: The maximum number of syllables the word can have.
- Limit: It specifies the number of results to return per page. The default value is 100.
- Page: The page of results to return.
- Frequencymin: The minimum frequency score of words to return.
- Frequencymax: The maximum frequency score of words to return.
- hasDetails: It takes a comma-delimited list of detail types the word has. For instance, to identify if the words have both ‘typeOf” and “hasCategories” relationship.
Below is the sample response for the search using ‘letterPattern’.
Let’s explore the ‘Related Words’ category which contains endpoints that allows getting more contextual information about words.
Pertains To Endpoint:
This endpoint allows the users to identify the original word which is relevant to the given word. For Instance, if we pass “.22-caliber” it will return the array of words containing the original word, which in this case is ‘caliber’
Region Of Endpoint:
This endpoint allows users to fetch the list of words used in the specified geographical area.
For Instance, invoking this endpoint with the word ‘Canada’ will return the following response:
In Region Endpoint:
This endpoint returns the region where the word is used. For instance, invoking the API with the word ‘chips’ would return the region as ‘britain’.
Has Usages Endpoint:
It returns the words that are examples of the domain the original word defines. The word ‘colloquialism returns the following lists as a response.
Has Categories Endpoint:
This endpoint returns the list of categories for any given word.
For instance, the word ‘math’ would return ‘algebra’,’ arithmetic’,’ calculus’ etc
In Category Endpoint:
It simply returns the domain category to which the original word belongs. For instance, the word ‘chaotic’ would fall in the category of ‘physics’ which will be returned in the API response.
Has Substances Parameter:
It returns all the words that are substances of the given word. For instance, invoking this endpoint with the word ‘wood’ would return a list containing substance e.g ‘lignin’.
Substance Of
It returns the list of substances to which the given word is a part of.
For Instance, invoking this endpoint with ‘water’ would return the following list of substances made of water.
Has Members Endpoint:
This endpoint returns the words that belong to the group defined by the given word.
For instance, the word ‘cosmos’ would have the members ‘galaxy’ and ‘extragalactic nebula’.
Member Of Endpoint:
It returns the group name to which the given word belongs. For instance, the word ‘dory’ would have the member ‘zeidae’.
Entails Endpoint:
It returns the list of words that are implied by the given word. It’s usually used for verbs.
Invoking the endpoint with the word ‘rub’ would return the following list.
Also Endpoint:
This endpoint returns the list of phrases of which the word is a part.
For example, the word ‘bump’ would return the list of the following phrases
- Bump into
- Bump off
Similar To Endpoint:
This endpoint returns the words that are similar to the given word but are not synonyms.
Examples are ‘bloody’ that would return the list containing words, such as ‘red’, ‘violent’, crimson’ etc.
Has Instances Endpoint:
This endpoint returns the list of words that are examples of the given word.
For instance, the word ‘president’ would return the list if all u.s presidents
Is an Instance Of Endpoint:
It returns the list of words that the given word is an example of.
For instance, querying the API with the word ‘einstein’ would have ‘physicist’ as a response.
Has Parts Endpoint:
This endpoint is very helpful as it returns the list of all the parts of the given word.
For instance, the word building would have the following parts:
Part Of Endpoint:
It simply returns the larger whole to which the given word belongs. For instance querying the word ‘finger’ would return the list containing words such as ‘hand’, ‘glove’ etc.
Has Types Endpoint:
This endpoint allows user to get more specific examples of the given word. I.e the word ‘purple’ would following types:
- Violet
- Lavender
- Reddish blue
- Royal purple
- Reddish purple
Is a Type Of Endpoint:
It finds the word that is more general than the given word. Querying this endpoint with the word ‘hatchback’ would return the list containing words such as ‘car door’, ‘auto’, ‘automobile’,’car’ etc.
How to Use Words API with Python
Please make sure that you have installed the Python application.
The below code snippet invokes the word endpoint to fetch the details such as definition, synonyms, part of speech, examples, etc.
import http.client conn = http.client.HTTPSConnection("wordsapiv1.p.rapidapi.com") headers = { 'x-rapidapi-key': "ce19d0164fmsh3d383efc0e85ce5p16dcb1jsnb1a4a3c79541", 'x-rapidapi-host': "wordsapiv1.p.rapidapi.com" } conn.request("GET", "/words/%7Bword%7D", headers=headers) res = conn.getresponse() data = res.read() print(data.decode("utf-8"))
How to Use Words API with PHP
Before running the sample code shared below, please make sure that you have installed PHP. You may follow this guide on how to install this correctly.
The sample code also invokes the word endpoint with the phrase ‘example’ to get its details.
<?php $client = new http\Client; $request = new http\Client\Request; $request->setRequestUrl('https://wordsapiv1.p.rapidapi.com/words/%7Bword%7D'); $request->setRequestMethod('GET'); $request->setHeaders([ 'x-rapidapi-key' => 'ce19d0164fmsh3d383efc0e85ce5p16dcb1jsnb1a4a3c79541', 'x-rapidapi-host' => 'wordsapiv1.p.rapidapi.com' ]); $client->enqueue($request)->send(); $response = $client->getResponse(); echo $response->getBody();
How to Use Words API with Ruby
The below example uses Ruby. Please make sure that you have installed Ruby on your system.
require 'uri' require 'net/http' require 'openssl' url = URI("https://wordsapiv1.p.rapidapi.com/words/%7Bword%7D") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE request = Net::HTTP::Get.new(url) request["x-rapidapi-key"] = 'ce19d0164fmsh3d383efc0e85ce5p16dcb1jsnb1a4a3c79541' request["x-rapidapi-host"] = 'wordsapiv1.p.rapidapi.com' response = http.request(request) puts response.read_body
How to Use Words API with JavaScript
To use the API in JavaScript, you need to first set up the JavaScript environment. You can download text editors such as Atoms, Visual Studio Code, NotePad++, etc.
The following code snippet invokes the Words endpoint using the word ‘example’ and as a result it returns the JSON response containing detailed information as shown below.
fetch("https://wordsapiv1.p.rapidapi.com/words/%7Bword%7D", { "method": "GET", "headers": { "x-rapidapi-key": "ce19d0164fmsh3d383efc0e85ce5p16dcb1jsnb1a4a3c79541", "x-rapidapi-host": "wordsapiv1.p.rapidapi.com" } }) .then(response => { console.log(response); }) .catch(err => { console.error(err); });
Below is the successful response for Word Endpoint.
Benefits of Words API
Words API benefits can be summarized as below:
- Speed: The Words API latency is around 350ms which is critical in real-time apps.
- Comprehensive Source: It has a database of more than 350,000 words which makes it a perfect candidate to be used in NLP (Natural Language Processing) apps.
- It’s more than a Lookup: What separates Words API from its competitors is its ability to provide contextual and other morphological word-specific information that is very hard to collect and often requires integrations from various services.
Alternatives to Words API
- Random Words with Pronunciation: This API offers a single endpoint that returns a random word with definition and pronunciation.
- Analyze NLP Overview: This API allows developers to get a list of synonym for a word.
- Word Dictionary: Word Dictionary also provides rich information for a word with definitions, associations, and examples.
- Text Similarity: This API allows evaluating the similarity between two words, sentences, or paragraphs.
- Words Associations: This API allows developers to identify associations and related words for a given word, phrases, or paragraphs.
- Similar Words: This API returns similar words which can help to find new keywords, adding tags, etc.
Summary
The Words API not only provides a comprehensive database of the English language but makes it incredibly easy for developers to build word games, dictionary apps, and even chatbots and smart assistants. It provides a variety of endpoints that can be seamlessly integrated into various platforms and apps.
Leave a Reply