1AI::Categorizer::DocumeUnste(r3pCmo)ntributed Perl DocumAeIn:t:aCtaitoengorizer::Document(3pm)
2
3
4
6 AI::Categorizer::Document - Embodies a document
7
9 use AI::Categorizer::Document;
10
11 # Simplest way to create a document:
12 my $d = new AI::Categorizer::Document(name => $string,
13 content => $string);
14
15 # Other parameters are accepted:
16 my $d = new AI::Categorizer::Document(name => $string,
17 categories => \@category_objects,
18 content => { subject => $string,
19 body => $string2, ... },
20 content_weights => { subject => 3,
21 body => 1, ... },
22 stopwords => \%skip_these_words,
23 stemming => $string,
24 front_bias => $float,
25 use_features => $feature_vector,
26 );
27
28 # Specify explicit feature vector:
29 my $d = new AI::Categorizer::Document(name => $string);
30 $d->features( $feature_vector );
31
32 # Now pass the document to a categorization algorithm:
33 my $learner = AI::Categorizer::Learner::NaiveBayes->restore_state($path);
34 my $hypothesis = $learner->categorize($document);
35
37 The Document class embodies the data in a single document, and contains
38 methods for turning this data into a FeatureVector. Usually documents
39 are plain text, but subclasses of the Document class may handle any
40 kind of data.
41
43 new(%parameters)
44 Creates a new Document object. Document objects are used during
45 training (for the training documents), testing (for the test
46 documents), and when categorizing new unseen documents in an
47 application (for the unseen documents). However, you'll typically
48 only call new() in the latter case, since the KnowledgeSet or
49 Collection classes will create Document objects for you in the
50 former cases.
51
52 The new() method accepts the following parameters:
53
54 name
55 A string that identifies this document. Required.
56
57 content
58 The raw content of this document. May be specified as either a
59 string or as a hash reference, allowing structured document
60 types.
61
62 content_weights
63 A hash reference indicating the weights that should be assigned
64 to features in different sections of a structured document when
65 creating its feature vector. The weight is a multiplier of the
66 feature vector values. For instance, if a "subject" section
67 has a weight of 3 and a "body" section has a weight of 1, and
68 word counts are used as feature vector values, then it will be
69 as if all words appearing in the "subject" appeared 3 times.
70
71 If no weights are specified, all weights are set to 1.
72
73 front_bias
74 Allows smooth bias of the weights of words in a document
75 according to their position. The value should be a number
76 between -1 and 1. Positive numbers indicate that words toward
77 the beginning of the document should have higher weight than
78 words toward the end of the document. Negative numbers
79 indicate the opposite. A bias of 0 indicates that no biasing
80 should be done.
81
82 categories
83 A reference to an array of