Open Calais Tags

Open Calais Tags is a PHP class for extracting entities and tags from text using Open Calais. Calais performs semantic analysis of the text, using natural language processing to identify concepts like people, companies and technologies discussed in the text. These are especially useful for suggesting tags for your content such as website articles or blog posts. You could even automatically tag archived content that would take days to go through manually.

You can download the class and example usage here:
PHP-OpenCalais.zip (updated 6/10/2015)

Calais is free for both personal and commercial use, and usage of this class requires a Calais API key. Getting an API key is an easy, automated process. Just click the “Access API” link at the site.

The Open Calais Tags class takes a document (text or HTML string) as input, and returns an array as output. The array’s keys are the entity types detected in the text, and the values are the entities found.

Example input:

April 7 (Bloomberg) — Yahoo! Inc., the Internet company that snubbed a $44.6 billion takeover bid from Microsoft Corp., may drop in Nasdaq trading after the software maker threatened to cut its bid if directors fail to give in soon.

If Yahoo’s directors refuse to negotiate a deal within three weeks, Microsoft plans to nominate a board slate and take its case to investors, Chief Executive Officer Steve Ballmer said April 5 in a statement. He suggested the deal’s value might decline if Microsoft has to take those steps.

The ultimatum may send Yahoo Chief Executive Officer Jerry Yang scrambling to find an appealing alternative for investors to avoid succumbing to Microsoft, whose bid was a 62 percent premium to Yahoo’s stock price at the time. The deadline shows Microsoft is in a hurry to take on Google Inc., which dominates in Internet search, said analysts including Canaccord Adams’s Colin Gillis.

Example output:

Array
(
    [Industry Term] => Array
        (
            [0] => Internet
            [1] => software maker
            [2] => Internet search
        )
    [Person] => Array
        (
            [0] => Steve Ballmer
            [1] => Jerry Yang
            [2] => Colin Gillis
        )
    [Company] => Array
        (
            [0] => Google Inc.
            [1] => Canaccord Adams
            [2] => Yahoo!
            [3] => Microsoft Corp.
        )
    [Currency] => Array
        (
            [0] => USD
        )
    [SocialTag] => Array
        (
            [0] => New encyclopedism
            [1] => Microsoft
            [2] => Jerry Yang
            [3] => Steve Ballmer
            [4] => Bing
            [5] => Yahoo!
            [6] => Internet search engines
            [7] => Hypertext
        )
)

Basic usage is simple. Create an instance of the class with your API key, and call the getEntities method using your content string.

require('opencalais.php');
$oc = new OpenCalais('your-api-token');
$entities = $oc->getEntities($content);

This class is distributed under an open source BSD license. The license terms can be found in license.txt of the code archive.

  • http://www.coolcavemen.com Kev

    Anyone to create and maintain a WordPress plugin for tags auto-suggestion ? 🙂

  • http://davidseth.net David Peterson

    Nice!

  • http://www.dangrossman.info Dan

    Kev: I’m hoping to work on that some time this week when I get the chance.

  • Neha

    hey Dan…
    i am new to this.Just downlaoded your source files and tryingto run it..
    can you please tell me how to use your calais class..
    $entities = $oc->getEntities($content);
    the function getEntities returns empty string..
    i have placed proper key in the source code..
    are there any pre-requisites..
    i downloaded calais-client..bu not able to execute submissio-tool.bat…
    can you please help
    thanks

  • http://www.dangrossman.info Dan

    Neha: Does $content contain a string of English content with entities Calais will recognize?

    Kev: The initial WordPress plugin for tag suggestion’s now available here:
    http://www.dangrossman.info/wp-calais-auto-tagger/

  • Pingback: Dan Grossman » WP Calais Auto Tagger: Automatic Tag Suggestion For Your Posts()

  • Neha

    The content is same as your example input.
    I was just trying to run your source code. Downloaded the zip and put it in my web folder and added my Licenseid.Do I need to do anything else.

  • Pingback: Dan Grossman » Tagging Large Post Archives Automatically()

  • Pingback: PHP Weekly Reader - April 13th 2008 : phpaddiction()

  • Neha

    hey dan can you tell me some place where i can test ur PHP class..
    or give me the sample input…

  • http://www.dangrossman.info Dan

    Neha: The sample output above came directly from the example input above.

  • nico.

    Hey Dan,

    Thanks a lot for the file!

    I just think you forgot ‘Country’ on line 75 😉

    cheers

  • http://www.dangrossman.info Dan

    Thanks for mentioning that nico, I’ve added it here and in the copy bundled with the plugins.

  • Neha

    Hi Dan,

    I know that Dan. I downloaded the zip class file for php.Hosted it on my web. And added my API key in octest.php.I am trying to run it. I get an error saying
    Warning: Invalid argument supplied for foreach() in C:\wamp\www\opencalais\octest.php on line 27

    $response = html_entity_decode(curl_exec($ch));
    this line returns nothing

    Can you please tell me whats wrong

    Do I need anything else except the API key to use your class.

  • Pingback: the eXternal mind » links for 2008-05-13()

  • http://www.notely.net Tom

    Hey Dan,

    Was using your OC class on my site and had such a breeze getting it working forgot all about it. Now it seems that something might have changes with the OC API as now it always returns no suggestions. Have you released a new version in line with the new API if it has indeed changed?

    Cheers,
    Tom

  • Pingback: Dan Grossman » Open Calais PHP Class Updated()

  • Andy

    @Neha: If you havent got it working yet, may be you might want to check your php.ini ( if on windows ) for whether this line extension=php_curl.dll
    is uncommented or not and if the dll is actually in place.

    @Tom
    Just ran the example today. Seems to work fine without any alteration to code itself.

    @Dan
    Great job mate thanks. I am now going to try and combine this with Lucene.
    Just a query about your WP exploits. Did you manage to get it working. If so I believe you would be storing the tags into a database? If so could you give me a hint on the table structure.

    Cheers

  • http://www.dangrossman.info Dan

    @Andy: WordPress supports tags out of the box, you don’t need your own database. WP Calais Auto Tagger, WP Calais Archive Tagger

  • Andy

    oh.. ok.
    i thought i read that you were going to work on something like that?
    haha may be i was sleep reading. anyway thanks for the links

  • Andy

    oh and i forgot to mention the query about the tags wasnt for WP itself.
    i am working on a different sort of application in which auto-tagging would help and just thought what was the optimum way to execute a tags DB.
    now that you have implemented it for WP i shall snoop around and dig in, to have a look at the data handling and the table structure.

    cheers

  • http://benhourigan.com Benjamin Hourigan

    When I try to activate the WP Calais Auto Tagger plugin in WP 2.6.1, I get this error:

    Parse error: syntax error, unexpected T_CONST, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or ‘}’ in /home/18214/domains/benhourigan.com/html/wp-content/plugins/opencalais.php on line 17

    What is happening?

  • http://www.dangrossman.info Dan

    You don’t have PHP 5, Ben.

  • http://benhourigan.com Benjamin Hourigan

    Thanks, Dan.

  • Sammy Kanan

    Great!

    Is there any chance of using https instead of http in the request?

  • http://leeclemmer.com Lee

    According to http://opencalais.com/APIcalls:

    “HTTP POST – Obsolete

    In older versions you could also invoke the service via an HTTP POST request using the following URL: http://api.opencalais.com/enlighten/calais.asmx/Enlighten.”

    Does this mean this is about to be obsolete since that URL is what you use?

  • http://www.dangrossman.info Dan

    Hi Lee, it looks like HTTP POST is still supported but they’ve changed the URL a little. I’ll try to update the class and plugins soon.

  • Pingback: Dan Grossman | Calais Class and Plugins Updated()

  • http://www.drapetomaniac.com Drapetomaniac

    Dan,
    Your post says it’s licensed BSD. In the next version, can you put that in the license file?

    I’ll point people this way as the origin and include the original license, but just having a copyright notice without mentioning BSD makes me concerned about using it for come clients. My plan is to use to to start something for Joomla and open it up.

    (I spend time instructing and educating others on open source, etc, so I’m all for reducing ambiguity)

    Thanks for this class!

  • http://www.sonicassault.co.uk Hetal

    I recently came across OpenCalais and was looking around ways to use with PHP and your class is a real life saver… Thank you very much and will let you know if I face any issues. Thanks again.

  • http://lorazepamtaylo.8m.com/avzkh/somat.htm narcoti

    printable weight loss chart

  • http://ultramefxciali.itgo.com/thbie/ancient-slots-3127-industrial-rd-las-vegas.htm wwwsoni

    blackjack 98 return

  • http://reliefottnfrel.s5.com/avizg/wwwcooperplatingcom-online-casinos-free.htm wwwaffo

    sandia resort casino

  • http://plusgilhlkick.8m.com/qtyna-nt/gambling-counseling-seattle.htm wwwaudi

    pioneer dvrk05l dual layer slot loading drive

  • http://honestygnyxwea.8m.com/rdnkd-im/xray-poker-tools.htm casinof

    wwwtopsitecentralcom online casinos free

  • http://tryjslbcircle.i8.com/ftuqh/fastest-way-to-lose-weight-one-month.htm ebooksp

    photonics drug information

  • http://trustmdyflover.8k.com/xbauh/atlantic-city-1-craps.htm blackja

    free multiline slots

  • http://buyvsnwake.4t.com/hpqks/billy-roche-casino-card-dealer-las-vegas-nv.htm socketa

    bum slot cars

  • http://plusgilhlkick.8m.com/rsqle-ft/lady-luck-casino-bettendorf-iowa.htm masquev

    las vegas 98 slot pay back

  • http://honestygnyxwea.8m.com/mexfu-oa/wwwrusticlodgefurnishingscom-online-casinos-free.htm luxorho

    wwwaffordablemovingcompanycom online casinos free

  • http://lorazepamotpeo.4t.com/iifhy/reconditioned-skillplay-slot-machines.htm slotmac

    wwwtopsitecentralcom online casinos free

  • http://lightuawover.s5.com/pknua/depakote-z-pak-mescaline-adalat-cc-foradil-phentermine-cheap.htm fatburn

    got pregnant with first cycle of clomid will it work again

  • http://tramadolkbtbsv.8m.net/czqvk-or/passing-a-drug-test-with-sure-jell.htm propeci

    drug testing xanex

  • http://hotelqqnloraze.s5.com/jfomf/image-img-link-online-seconde-fr-tramadol-html-up.htm nationa

    breast lift weight loss results

  • http://onlineqzwomin.4t.com/fcrqt/slot-car-raceways-in-st-louis.htm casinon

    3qa roulette

  • http://takeoinoftrama.8m.com/bhkeq-wl/online-casinos-katrina.htm cheroke

    easter seals land lake poker run

  • http://soulpffhoultra.itgo.com/tprfq/fitness-specialist.htm somatic

    yamato engine specialists

  • http://officebhainear.4t.com/vvdzm/lady-luck-casino-bettendorf-iowa.htm rjslots

    wwwpaisleycreekcom free online slots

  • http://painraeymbetwe.itgo.com/fqlrd/india-pharmacys.htm diabete

    amateur html index link mature tutularsoman tu funpic org

  • http://viagrafronline.s5.com/qenuu/journal-of-psychosomatics.htm financi

    over the counter pain medications