The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Search::ContextGraph - Run searches using a contextual network graph

SYNOPSIS

 use Search::ContextGraph;
 
 my %docs = ( 'First Document' => { 'elephant' => 2, 'snake' => 1 }
 			   'Other Document' => { 'snake' => 1, 'constrictor' => 1 }
 			   ...
 			  );
 
 my $cg = Search::ContextGraph->new();
 $cg->add_documents( %docs );

 my $results = $cg->search('snake');
 
 foreach my $k ( keys %{ $results } ) {
 		print "$k had relevance ", $results->{$k}, "\n";
 }
 
 	
 

DESCRIPTION

Search a document collection using a spreading activation search. The search algorithm represents the collection as a set of term and document nodes, connected to one another based on a co-occurrence matrix. If a word occurs in a document, we create an edge between the appropriate term and document node. Searches take place by spreading energy from a query node along the edges of the graph according to some simple rules. All result nodes exceeding a threshold T are returned. You can read a full description of this algorithm at http://www.nitle.org/papers/Contextual_Network_Graph.pdf.

The search engine gives expanded recall (relevant results even when there is no keyword match) without incurring the kind of computational and patent issues posed by latent semantic indexing (LSI).

METHODS

new %PARAMS

Object constructor.

[get|set]_threshold

Accessor for threshold value. This value determines how far energy can spread in the graph

[get|set]_initial_energy

Accessor for initial energy value at the query node. The higher this value, the larger the result set

load TDM_FILE [, LM_FILE]

Opens and loads a term-document matrix (TDM) file to initialize the graph. Optionally also opens and loads a document link matrix (DLM) file of document-to-document links. The TDM encodes information about term-to-document links, while the DLM file holds information about inter-document links, like hyperlinks or citation data. For notes on these file formats, see the README file Note that document-document links are NOT YET IMPLEMENTED.

raw_search @NODES

Given a list of nodes, returns a hash of nearest nodes with relevance values, in the format NODE => RELEVANCE, for all nodes above the threshold value

set_debug_mode

Turns verbose comments on if given a true value as its argument

_read_tdm FILE

Opens and reads a term-document matrix (TDM) file. The format for this file is described in the README

add_documents %DOCS

Load up the search engine with documents in the form TITLE => WORDHASH, where WORDHASH is a reference to a hash of terms and occurence counts. In other words,

TITLE => { WORD1 => COUNT1, WORD2 => COUNT2 ... }
search @QUERY

Searches the graph for all of the words in @QUERY. No support yet for document similarity searches, but it's coming. Returns a hashref to a hash of document titles and relevance values.

_energize NODE, ENERGY

Private method. Assigns a starting energy ENERGY to NODE, and recursively distributes the energy to neighbor nodes.

BUGS

AUTHOR

Maciej Ceglowski <maciej@ceglowski.com>

COPYRIGHT AND LICENSE

(C) 2003 Maciej Ceglowski, John Cuadrado, NITLE

This program may be distributed under the same terms as Perl itself.