Text::Corpus::Inspec - Interface to Inspec abstracts corpus.
Text::Corpus::Inspec
use Text::Corpus::Inspec; use Data::Dump qw(dump); use Log::Log4perl qw(:easy); Log::Log4perl->easy_init ($INFO); my $corpus = Text::Corpus::Inspec->new (corpusDirectory => $corpusDirectory); dump $corpus->getTotalDocuments;
Text::Corpus::Inspec provides a simple interface for accessing the documents in the Inspec corpus.
The categories, description, title, etc... of a specified document are accessed using Text::Corpus::Inspec::Document. Also, all errors and warnings are logged using Log::Log4perl, which should be initialized.
new
The method new creates an instance of the Text::Corpus::Inspec class with the following parameters:
corpusDirectory
corpusDirectory => '...'
corpusDirectory is the path to the top most directory of the corpus documents. It is the path to the directory containing the sub-directories named Test, Training, and Validation of the corpus and is needed to locate all the documents in the corpus. If it is not defined, then the enviroment variable TEXT_CORPUS_INSPEC_CORPUSDIRECTORY is used if it is defined. A message is logged and an exception is thrown if no directory is specified.
Test
Training
Validation
TEXT_CORPUS_INSPEC_CORPUSDIRECTORY
getDocument
getDocument (index => $index, subsetType => $subsetType)
getDocument returns a Text::Corpus::Inspec::Document object of the document with the specified index and subsetType, which is either 'all', 'test', 'training', or 'validation'; the default is 'all'.
index
subsetType
'all'
'test'
'training'
'validation'
getDocument (uri => $uri)
getDocument returns a Text::Corpus::Inspec::Document object of the document with specified uri.
uri
getTotalDocuments
getTotalDocuments (subsetType => 'all')
getTotalDocuments returns the total number of documents in the specified subset-type of the corpus; which is either 'all', 'test', 'training', or 'validation'; the default is 'all'. The index to the documents in each subset ranges from zero to getTotalDocuments(subsetType => $subsetType) - 1.
getTotalDocuments(subsetType => $subsetType) - 1
test
test ()
test does tests to ensure the documents in the corpus are accessible and can be parsed. It returns true if all tests pass, otherwise a description of the test that failed is logged using Log::Log4perl and false is returned.
For example:
use Text::Corpus::Inspec; use Data::Dump qw(dump); use Log::Log4perl qw(:easy); Log::Log4perl->easy_init ($INFO); my $corpus = Text::Corpus::Inspec->new (corpusDirectory => $corpusDirectory); dump $corpus->test;
The example below will print out all the information for each document in the corpus.
use Text::Corpus::Inspec; use Data::Dump qw(dump); use Log::Log4perl qw(:easy); Log::Log4perl->easy_init ($INFO); my $corpus = Text::Corpus::Inspec->new (corpusDirectory => $corpusDirectory); my $totalDocuments = $corpus->getTotalDocuments (); for (my $i = 0; $i < $totalDocuments; $i++) { eval { my $document = $corpus->getDocument (index => $i); my %documentInfo; $documentInfo{title} = $document->getTitle (); $documentInfo{body} = $document->getBody (); $documentInfo{content} = $document->getContent (); $documentInfo{categories} = $document->getCategories (); $documentInfo{uri} = $document->getUri (); dump \%documentInfo; }; }
To install the module set the environment variable TEXT_CORPUS_INSPEC_CORPUSDIRECTORY to the path of the Inspec corpus and run the following commands:
perl Makefile.PL make make test make install
If you are on a windows box you should use 'nmake' rather than 'make'.
The module will install if TEXT_CORPUS_INSPEC_CORPUSDIRECTORY is not defined, but little testing will be performed. After the Inspec corpus is installed testing of the module can be performed by running:
Jeff Kubina<jeff.kubina@gmail.com>
Copyright (c) 2009 Jeff Kubina. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the LICENSE file included with this module.
inspec, english corpus, information processing
Text::Corpus::Inspec::Document, Log::Log4perl
To install Text::Corpus::Inspec, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Text::Corpus::Inspec
CPAN shell
perl -MCPAN -e shell install Text::Corpus::Inspec
For more information on module installation, please visit the detailed CPAN module installation guide.