An Alchemy News API Library for Node.js

A few months ago, I worked on a project that required some natural language analysis of recent news articles from around the world. I decided to achieve this  using a third party natural language processing API. This led me to AlchemyAPI.

AlchemyAPI is an IBM company that provides twelve different semantic text analysis APIs that leverage state-of-the-art natural language processing techniques. One of the provided APIs is AlchemyData News. This API provides the ability to carry out targeted semantic search and analysis of recent news articles and blogs from around the world. For instance, using AlchemyData News, one can search forall positive news articles about Google published within the last 30 days.

AlchemyData News was exactly what I needed for my project. Since I was working with AngularJS and Node, my first instinct was to find a Node.js library for AlchemyData News. I felt this was necessary because AlchemyData News provides an extensive query language that I considered to be overkill for basic targeted search queries. I also found the query language to be quite verbose, although I could see why it was so, considering that such a service must support complex and flexible queries. Unfortunately,  at the time, I was only able to find a Node.js library for the more mature and popular AlchemyLanguage API which provides general text analysis services. I eventually resorted to making raw queries to AlchemyData News using the provided query language. However, in that moment, I decided to eventually get around to creating a simple Node.js library for AlchemyData News. My intention was to make it as similar as possible to the excellent Node.js API I had found for AlchemyLanguage.

I have recently completed a basic implementation of a Node.js library that simplifies some of the basic queries supported by the AlchemyData News API. There are a lot of additions and improvements that can be made to the library especially with regard to supporting some of the more flexible querying capabilities provided by AlchemyAPI. However, this basic version provides the ability to retrieve:

  • categorized news content by searching for news on topics you care about e.g. baseball, mobile phones, etc.
  • news content containing abstract concepts e.g. democracy, polygamy, etc.
  • news content containing specific keywords where keywords are terms explicitly mentioned in the article that are determined to be highly relevant to the subject matter of the news article.
  • news articles containing named entities e.g. proper nouns such as people, cities, companies, products, etc.
  • news articles based on positive, negative or neutral sentiment.

The primary purpose of this Node.js library is to simplify the construction of some simple queries supported by AlchemyData News. It works for some basic queries but is far from being a complete mirror of the capabilities provided by AlchemyData News. I encourage everyone who finds this useful to make changes, suggestions and contributions as necessary.

Documentation and source can be found at https://github.com/davidadamojr/alchemy-news-api.

Hacking the Tweet Stream with Cliptext

Sharing images that contain significant amounts of text is something quite a number of Twitter users already do. It also seems like a pretty convenient way to “hack the tweet stream” and avoid the 140-character limit.

Sharing excerpts from online articles is something I do quite often on Twitter.  These excerpts often exceed Twitter’s 140-character limit, so copying and pasting these pieces of text directly into Twitter’s status message box does not always work out as planned. When faced with this 140-character dilemma, one option is to copy these pieces of text into storming.me and share the generated image. But being the “lazy” person that I am, I find that process a little tedious.  Another option is to create a Marc Andreessen-style tweetstorm using an app like tweetstorm.io or WriteRack. Unfortunately, this option does not seem particularly suited to sharing a text excerpt especially seeing that one might want to make a short personal comment about the excerpt being shared. Besides, there is that dreadful copying and pasting that I’m trying very hard to avoid like a plague. Oh, how I eschew the arduous labor involved in copying and pasting.

I eventually decided to whip up a quick and simple solution for myself by hacking up something I called Cliptext.  Cliptext is a chrome extension/web app/Android app that converts text selections into images that can be automatically shared on Twitter. It started out as an excuse to create a chrome extension. Getting some insight into Chrome extensions was nice, but crafting something I knew I was actually going to use quite often was even more delightful.

I am nowhere near being some sort of Kryptonian super-programmer who knows how to do everything off the bat. I typically need a lot of consultation from multiple sources. My first step to conjuring up Cliptext was to read the chrome extension getting started guide  in order to get a feel for how chrome extensions are structured. Subsequently, I needed to figure out how to add items to Chrome’s context menu on text selections. This blog post by Paul Kinlan helped set me straight in that regard.

My starting point on the PHP  side of things was this Stack Overflow question where someone asked how to convert text to an image. Reading the answers to the StackOverflow question suggested that PHP’s GD/Image Processing library was the way, the truth and the life.

Not wanting to mess with PHP Curl, stream contexts and all that jazz, I decided to take advantage of some of the existing Twitter API wrappers/libraries. My first attempt was to use codebird-php, but using it felt like swimming in snake-infested muddy water and I got bitten a few times.  I guess I just could not get it working as quickly as I had hoped.  I decided to try TwitterOauth as an antidote to all that snake venom from using codebird-php. Pure heaven it was! You should try it sometime.

Cliptext did not require any complicated code gymnastics and is as simple as Chrome extensions and web apps get. The intentionally plain user interface is based on Skeleton. Putting these resources together, I eventually came up with a working version of Cliptext that met my requirements. Thanks to the various authors of the resources I used.

I have made the chrome extension available on the Chrome Web Store and the Google Play Store in the hope that it will be useful to someone. I have also provided the source code on my Github page. Maybe someone out there might be able to learn something from it, just as I have been able to learn from others.