Clair

IDF


SummaryPackage variablesSynopsisDescriptionGeneral documentationMethods

SummaryTop
Clair::IDF - Provides access to an inverse document frequency (IDF) database.

Package variablesTop
No package variables defined.

Included modulesTop
Config
File::Spec
MEAD::MEAD

SynopsisTop
	use Clair::IDF

    open_nidf($dbmname);
    my $idf = get_nidf("word");
    my $output = ($idf == $Clair::IDF::DEFAULT_UNKNOWN_IDF
                            ? "unknown"
                            : $idf);
    print qq(IDF of "word": $output\n);

DescriptionTop
This module provides access to an inverse document frequency (IDF) database via
a tied hash. If $dbmname is not supplied, the database name is assumed to be
$Clair::IDF::DEFAULT_DBMNAME. In any case, calling open_nidf() sets
$Clair::IDF::current_dbmname to the name of the database being opened, which
is assumed to be located in $Clair::IDF::$IDFDIR.
Calling get_nidf($word) returns the IDF of $word in the database opened by
open_nidf(), or $Clair::IDF::DEFAULT_UNKNOWN_IDF if the IDF is not known.

MethodsTop
get_nidfNo descriptionCode
open_nidfNo descriptionCode

Methods description


None available.

Methods code


get_nidfdescriptionprevnextTop
sub get_nidf {
    my $word = shift;

    unless (defined $current_dbmname) {
	open_nidf($DEFAULT_DBMNAME);
    }
    
    if (defined $nidf{$word}) {
	return $nidf{$word};
    }
    
    return $DEFAULT_UNKNOWN_IDF;
}

open_nidfdescriptionprevnextTop
sub open_nidf {
    my $dbmname = shift || $DEFAULT_DBMNAME;

    if ($dbmname eq $DEFAULT_DBMNAME) {
      $dbmname = File::Spec->rel2abs($dbmname, $IDFDIR);
    }

    if ($current_dbmname && $current_dbmname eq $dbmname) {
		return 1;
    }

    unless (dbmopen %nidf, $dbmname, 0666) {
		die "Cannot open DBM $dbmname: $!";
    }

    unless (scalar(keys(%nidf))) {
        die "Empty DBM $dbmname";
    }

    $current_dbmname = $dbmname;

    return 1;
}

General documentation


EXPORTSTop
	open_nidf()
    get_nidf()

CONFIGURATION AND ENVIRONMENTTop
	$current_dbmname       # last dbmname opened by open_nidf()
	$DEFAULT_DBMNAME     = "enidf";
	$DEFAULT_UNKNOWN_IDF = 3;
	$IDFDIR              = File::Spec->catdir($MEAD::MEAD::MEADDIR, "etc");

DEPENDENCIESTop
	Exporter
	File::Spec
	MEAD::MEAD

BUGS AND LIMITATIONSTop
There are no known bugs in this module.
Please report problems to Dragomir R. Radev (radev@umich.edu).
Patches are welcome.

SEE ALSOTop
	Clair::Utils::TF

AUTHORTop
Dragomir R. Radev (radev@umich.edu)

LICENCE AND COPYRIGHTTop
Copyright (c) 2007 the Clair group, all rights reserved.
This module is free software; you can redistribute it and/or
modify it under the same terms as Perl itself. See perlartistic.
This module is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.