Finding occurrences of a useful words and phrases in strings

stringstext processing

I am building an app that analyzes posts by people by pulling their Tweets and Facebook posts. I need to process all the posts and find useful phrases. What I mean by useful is that, any word or phrase that is a noun/adjective/verb that would represent a discrete object or an idea, or in other words, I am looking for keywords.

For example, if someone has posted those three posts (in a very simple sense):

i am a big fan of progressive metal music! it is fantastic!

Look what I've found: a new Progressive Metal band!

a good genre in music is progressive metal

Analyzing those simple examples, I need to extract progressive metal and music with the highest occurrence rank. But if I pass the occurrences of words simply, I'll be getting a, is, I as the most common words. If I get away with the propositions, then I'll be getting single words such as progressive, metal, music. What I really need is to get phrases such as progressive metal, or progressive metal music, which together actually make sense. As a word, progressive and metal have other meanings, but the phrase progressive metal defines a musical genre, which has nothing to do with the single words themselves. Iteratively searching occurrence of every possible phrase in all the posts (e.g. first search i in all posts, then i am, then i am a etc.) is computationally extremely expensive and is not an option.

I've looked at some similar questions:

Available options for classifying words in text?

Language parsing to find important words

But both are overkills, solving (or trying to solve) more general problems. My problem is more specific and I'm thinking of a simpler solution that doesn't involve NLP. An idea one might come up with is to compare the posts against a valid word/phrase list, but people might be talking about a brand related name, or a specific event, that are not available in a dictionary, such as Twitter API, or death of Michael Jackson.

I am currently evaluating posts against the user's Facebook likes, which makes a good dictionary of valid phrases about the user, but it fails when we are on Twitter, without the notion of "likes", hence, no valid dictionary. Is there any simple way of checking occurrence of valıd terms in a large array of sentences? (not necessarily grammatically correct)

UPDATE: It's an iOS app so I'm in Objective-C, to keep in mind in library recommendations.

Best Answer

A very rough outline how this could be done with Apache Solr.

Solr is a full text search engine with many setup options and very flexible ways to handle the indexing and faceting. Using the right combinations of tokenizers (split text in single elements, mostly words) and filters (post process the tokens like removing stop words as "a", "and", "I" etc or converting to lower case) you could get reasonable results. Especially since you can handle a single text in several ways at the same time by tokenizing and filtering it into more than one field.

Doing this would allow to index single words and word groups with or without stopwords. Running a facet search would count the occurrences of such words or groups.

The main work would be to find a good way to create the word groups. I'm not sure right now if one of the default tokenizers or filters would be good for that. Though you could write your own as a plugin in Java.

I guess there are better solutions with specialized tools, but I'm rather sure with Solr it could be done to a certain degree.

Related Topic