Search code examples
algorithmhadoopphrase

Efficient Phrase Matching Algorithm


I have a set of about 7 Million phrases to be matched to about 300 Million queries.

Queries can be sub-strings or contain the phrases themselves. Basically I want a measure of 'similarity' between two phrases [ not necessarily the edit distance ]

Can someone give some pointers to efficient algorithms to do this. I would prefer distributed algorithms since I am going to do this on Hadoop via streaming using python.


Solution

  • This a at least not very trivial, because you have on the one side very much data and on the other side even more.

    The ultra simplest approach would be a lucene index on the 7 mio. phrases and let the hadoop job query the index. Not quite sure if you need a solr server for that, or any similar implementations in python.

    The mapper should write out the phrase id or linenumber, whatever you have to indentify it. Or at least the phrase itself, along with the matchingscore.

    In the reduce step you could go for a reducing on a phrase key and write out all the related phrases with the score. (or whatever you want to)
    For similarity you can read further here:

    Similarity of Apache Lucene
    Apache Lucene itself