English Dictionary API served with MongoDB
As an exercise with the no-SQL database platform MongoDB, I created a free account on mongolabs, created a database called webtropy, and within this, created a collection with the name “dictionary”. I then downloaded a English dictionary in text format from http://www.isc.ro/en/commands/lists.html (TWL06), Importing this into Mongo was mongoimport, specifying fields as “word”.
They offer a REST API via their HTTP interface, such as:
https://api.mongolab.com/api/1/databases/webtropy/collections/dictionary?apiKey=5FdV2ICC_dTrXGyumdVcIaBB2xYztY_n&q={‘word’:’HELLO‘}
Where “HELLO” is the word being checked. If the word is missing, i.e. “HELLOY” then the result is an empty JSON array “[]”
For the full English dictionary in JSON format, you can download this from Box.com at https://www.box.com/s/dvvuv4d6kqet4xbu7nvw
A use of this dictionary, is a javascript spell-checker:
<html>
<head>
<script src="http://code.jquery.com/jquery-1.10.0.min.js"></script>
<script src="mydictionary.json"></script>
<style> #result {color:red}</style>
<script language="javascript">
$(document).ready(function() {
$("#btnCheck").bind("click",btnCheck_click);
});
function btnCheck_click() {
var word = $("#tbWord").val().toUpperCase();
var arrPos = $.inArray(word,dictionary);
if (arrPos != -1)
{
$("#result").text("It's a word!");
}
else
{
$("#result").text("It's not a word!");
}
}
</script>
</head>
<body>
Is it a word?<br>
<input id="tbWord" type="text">
<input type="button" id="btnCheck" value="Check"/><br>
<span id="result"></span>
</body>
</html>
LikeLike
I’m now expanding this to include multiple languages using Bing Translate API. Limited to 2 Million chars per month, so it might take some time…
LikeLike
The import was done using mongoimport like this: mongoimport -h ds039078.mongolab.com -d celltower -c celltower
–type csv –file “C:\Users\Fiach\Desktop\With markers and location.csv” –head
erline -u fiach -p xxxxxxx –port 39078
LikeLike