= keyword_prospector

* http://github.com/latimes/keyword_prospector

== DESCRIPTION:

KeywordProspector is a gem for associating keywords in text with arbitrary
output objects. It uses an Aho-Corasick tree to provide matching that scales
linearly with the length of the text, regardless of the number of keywords.

== FEATURES:

The core KeywordProspector engine has the following properties:
* Once a tree is built, matching against the tree is o(n) where n is the length
of your text, regardless of how mane keywords you have in the tree.
* Arbitrary output objects can be associated with any keyword or set of
keywords.

KeywordLinker can be used to create links to designated url's:
* You can specify a single keyword to associate with a url.
* You can specify an array of keywords to associate with a url.
* Each keyword or group of keywords will be linked only once to the url
provided.
* Hyperlinks are not created within existing hyperlinks.
* Hyperlinks are not generated anywhere they would be illegal in HTML, such as
within attribute values.

== SYNOPSIS:

Use KeywordLinker to create links in HTML text. KeywordLinker will link only
the first alternative that appears in text:

require 'keyword_linker'

linker = KeywordLinker.new
linker.add_url("http://www.latimes.com", ["L.A. Times", "Los Angeles Times"])
linker.link_text("'L.A. Times' or 'Los Angeles Times'?")
=> "'<a href=\"http://www.latimes.com\">L.A. Times</a>' or 'Los Angeles Times'?"

linker.link_text("'Los Angeles Times' or 'L.A. Times'?")
=> "'<a href=\"http://www.latimes.com\">Los Angeles Times</a>' or 'L.A. Times'?"


You can provide html options when adding url's:

linker = KeywordLinker.new
linker.add_url("http://www.latimes.com", "Los Angeles Times",
:title => "Visit the Los Angeles Times")
linker.add_url("http://www.google.com", ["Google", "The Google"],
:title => "Go check it out on The Google!")

linker.link_text("Do you prefer The Google or the Los Angeles Times?")
=> "Do you prefer <a href=\"http://www.google.com\" title=\"Go check it out on The Google!\">The Google</a> or the <a href=\"http://www.latimes.com\" title=\"Visit the Los Angeles Times\">Los Angeles Times</a>?"

== DEPENDENCIES:

* Hpricot

== INSTALL:

sudo gem install keyword_prospector

== AUTHOR:

Alf Mikula <[email protected]>

== ACKNOWLEDGEMENTS:

Thanks to David Johnson for telling me about the Aho-Corasick algorithm, and
for providing the original Aho-Corasick Ruby implementation.

== LICENSE:

(The MIT License)

Copyright (c) 2008 Los Angeles Times

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.