Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

"A" is related to "B" and "C". How do I show that "B" and "C" might, by this context, be related as well?


Here are a few headlines about a recent Broadway play:

  1. David Mamet's Glengarry Glen Ross, Starring Al Pacino, Opens on Broadway
  2. Al Pacino in 'Glengarry Glen Ross': What did the critics think?
  3. Al Pacino earns lackluster reviews for Broadway turn
  4. Theater Review: Glengarry Glen Ross Is Selling Its Stars Hard
  5. Glengarry Glen Ross; Hey, Who Killed the Klieg Lights?


Running a fuzzy-string match over these records will establish some relationships, but not others, even though a human reader could pick them out from context in much larger datasets.

How do I find the relationship that suggests #3 is related to #4? Both of them can be easily connected to #1, but not to each other.

Is there a (Googlable) name for this kind of data or structure? What kind of algorithm am I looking for?


Given 1,000 headlines, a system that automatically suggests that these 5 items are all probably about the same thing.

To be honest, it's been so long since I've programmed I'm at a loss how to properly articulate this problem. (I don't know what I don't know, if that makes sense).

This is a personal project and I'm writing it in Python. Thanks in advance for any help, advice, and pointers!

share|improve this question
sounds like natural language parsing and/or some other probabilistic technique is required – jk. Dec 10 '12 at 18:34
This is a GREAT question! – Michael Brown Dec 10 '12 at 18:44
I think I've seen systems that can do this implemented in Prolog. – FrustratedWithFormsDesigner Dec 10 '12 at 19:00
@FrustratedWithFormsDesigner I suspect you're thinking of unification in logic programming..? – Izkata Dec 10 '12 at 22:51
up vote 14 down vote accepted

It's called cluster analysis, which is basically grouping objects into clusters with similar properties. It's a huge topic, but that should give you a place to start.

share|improve this answer

You're entering the world of Semantics. There are public services that will parse text and pull out the major concepts (a quick search for Semantic API turned up a few) that will parse a free form document and return the major topics encountered including people, places, things, dates, and concepts. Some of the better ones will return in a format known as [RDF]

If you want to build your own system that can do this, the field is Natural Language Processing and that is a very intriguing rabbit hole to dive down.

share|improve this answer

If at all possible, get the story along with the headline. Headlines can sometimes get "cute" and make only tangential reference to what is being discussed. This works OK with humans (because they have global context), but not so well with NLP.

As mentioned in Karl Bielefeldt's answer, clustering is a good approach, but the Devil is in the details. You not only have to pick a clustering approach that fits your problem/user space, you also have to figure out what is being clustered.

My background is in Information Retrieval (IR) from the 80's-90's, and we focused on similarity searching and centroid-based clustering. Our documents were represented by weighted attribute vectors, which is basically a list of terms and their relative importance in the doc. This approach can work (although better with some collections than others), but it has problems with short-cute headlines, because they lack key vocabulary terms to tie things together. But if you use the whole document, then you get a much richer list of terms (and probably a better sense of importance), and that list of terms will probably make the connection easier to spot (i.e. compute) when you have headlines that are "cute".

My email is in my profile if you would like to get into vector generation issues, etc.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.