AI::Ca...ocument(3pm)
๐ AI::Categorizer::Document โ bestie's guide to the Document class ๐
ok so this is the AI::Categorizer::Document page from the User Contributed Perl Documentation section of your perl man pages. she's a whole vibe and she embodies a document. yes literally. that's the job. ๐
โจ NAME โจ
AI::Categorizer::Document โ Embodies a document. that's it. that's the whole personality. she's a document but make it an object. ๐
๐ฆ SYNOPSIS ๐ฆ
here's how you actually use her, in all her forms:
use AI::Categorizer::Document;
# Simplest way to create a document:
my $d = new AI::Categorizer::Document(name => $string,
content => $string);
# Other parameters are accepted:
my $d = new AI::Categorizer::Document(name => $string,
categories => \@category_objects,
content => { subject => $string,
body => $string2, ... },
content_weights => { subject => 3,
body => 1, ... },
stopwords => \%skip_these_words,
stemming => $string,
front_bias => $float,
use_features => $feature_vector,
);
# Specify explicit feature vector:
my $d = new AI::Categorizer::Document(name => $string);
$d->features( $feature_vector );
# Now pass the document to a categorization algorithm:
my $learner = AI::Categorizer::Learner::NaiveBayes->restore_state($path);
my $hypothesis = $learner->categorize($document);
no cap, that first one is the quick-and-easy route and the second one is the "i have opinions about my data" route. both valid. both slay. โจ
๐ธ DESCRIPTION ๐ธ
so the Document class is the one that embodies the data in a single document, and she comes with methods for turning that data into a FeatureVector. it's giving "data glow-up". โจ
most of the time documents are just plain text, but subclasses of the Document class can handle literally any kind of data you throw at them. flexible queen. ๐
๐ METHODS ๐
new(%parameters)
creates a new Document object. ๐
Document objects get used everywhere, bestie:
- during training (for the training documents)
- during testing (for the test documents)
- when categorizing new unseen documents in an application (for the unseen documents)
but lowkey, you'll usually only call new() in that last case, because the KnowledgeSet or Collection classes will make Document objects for you in the first two cases. so like, don't do extra work. let them cook. ๐
the new() method accepts these parameters:
nameโ a string that identifies this document. Required. not optional, bestie, she needs a name. ๐contentโ the raw content of this document. can be either a string, or a hash reference, which is how you do structured document types. โจcontent_weightsโ a hash reference saying what weights should be assigned to features in different sections of a structured document when the feature vector gets created. the weight is a multiplier of the feature vector values. for example: if a"subject"section has a weight of3and a"body"section has a weight of1, and word counts are the feature vector values, then it's as if every word appearing in the"subject"appeared3times. iconic math honestly. ๐งฎ
if no weights are specified, all weights are set to 1.
front_biasโ lets you smoothly bias the weights of words in a document based on their position. the value should be a number between-1and1. ๐- positive numbers โ words toward the beginning of the document get higher weight than words toward the end
- negative numbers โ the opposite
- a bias of
0โ no biasing at all
categoriesโ a reference to an array of Category objects that this document belongs to. optional. ๐stopwordsโ a list/hash of features (words) that should be ignored when parsing document content. a hash reference is preferred, with the features as the keys. if you pass an array reference containing the features, it gets converted to a hash reference internally. we do the conversion for you, no worries. ๐use_featuresโ a Feature Vector specifying the only features that should be considered when parsing this document. this is the alternative to using"stopwords". ๐stemmingโ says which linguistic procedure should be used to convert tokens in the document into features. possible values:"none"โ tokens are used without change"porter"โ the Porter stemming algorithm gets applied to each token. heads up: this one requires the"Lingua::Stem"module from CPAN. ๐ฆ
stopword_behaviorโ okay so there are a few ways you might want the stopword list (that's the"stopwords"parameter) to interact with the stemming algorithm (that's the"stemming"parameter), and this parameter controls all of that. it can take these values:no_stemโ match stopwords against non-stemmed document words.stemโ stem the stopwords according to the'stemming'parameter, then match them against stemmed document words.pre_stemmedโ stopwords are already stemmed, so match them against stemmed document words.
the default value is "stem", which seems to produce the best results in most cases the author has tried. (they're also not aware of any studies comparing the "no_stem" behavior to the "stem" behavior in the general case. honest king. ๐)
this parameter has no effect if there are no stopwords being used, or if stemming is not being used. in that latter case, the list of stopwords will always be matched as-is against the document words.
โ ๏ธ important, bestie: if the"stem"option is used, the data structure you passed as the"stopwords"parameter will be modified in-place to contain the stemmed versions of the stopwords you supplied. she will edit your hash. fr fr. ๐ญ
read( path => $path )
an alternative constructor method. reads a file on disk and returns a document with that file's contents. ๐โจ
parse( content => $content )
this one's listed right here next to the others. ๐
name()
returns this document's "name" property, exactly as it was specified when the document was created. ๐
features()
returns the Feature Vector associated with this document. ๐ฆ
categories()
in a list context, returns a list of Category objects that this document belongs to.
in a scalar context, returns the number of such categories. she's versatile like that. ๐
create_feature_vector()
creates this document's Feature Vector by parsing its content. you won't call this method directly โ it's called by new(). she's a backstage queen, main character energy but offstage. ๐
๐ AUTHOR ๐
Ken Williams <ken@mathforum.org> ๐
๐ COPYRIGHT ๐
this distribution is free software; you can redistribute it and/or modify it under the same terms as Perl itself. these terms apply to every file in the distribution โ if you have questions, please contact the author. ๐ซถ
and that's the whole page, bestie!! this was perl v5.42.0 flavored, dated 2025-07-25, and it's the AI::Ca...ocument(3pm) manual page. go forth and categorize. slay. ๐
โจ๐๐ฆ๐
๐ฆ where this page comes from
- fedora 43: perl-AI-Categorizer 0.09-38.fc43 ยท GPL-1.0-or-later OR Artistic-1.0-Perl
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms