I’m writing a script that takes a news article as input and returns a list of all publicly traded companies mentioned in the article and their corresponding symbols. There are ~6,500 unique company names that could possible be mentioned.
My first thought was using a regular expression to pull out of the article all names that could possibly be company names. Company names can be pretty different, but almost always every word in the name starts with a capital letter, so I think this could work with only a few false positives (situations where an individual shares a name with a company, probably).
The next problem is comparing possible company names to the list of all companies and symbols. How should I store the list? As a table with each entry having a company and symbol field? It seems like this is the ideal place to use a hashmap of company mapping to symbol. Would it be faster than the mysql solution to serialize an array with the aforementioned mapping and just unserialize it at the beginning of my script that finds names in articles?
There is a reason why we use prefixing like
#or@for tags or name referral, it helps create a pattern match. I think you will be shooting yourself in the foot if you allow for “false positives” on this scale.I would follow suit to standard ‘stock ticker’ article formats, include a company name or stock ticket format reference like
American Company Co. (ACCO), this would allow you to simply look for(*)references.Other than sticking to a format, you will have a hard time getting quick, relevant and accurate results.
The complex solution would be server side processing for false positives, loading the full list of names and crunching away for matches, with some alert system with review alerts, but that is just so much overhead, when a simple format adjustment can go a long way)