dca_interface  6.3.4
dca::TextClassificationResults Class Reference

#include <text_classification_results.h>

Detailed Description

Overall results of a text classification.

Encapsulates the overall results of a text classification.

See also
TextClassification, HtmlTextClassifier, TextClassificationResult, TextCategories, HtmlText, CategoriesInfo
// assume we have a valid DcaInstance (myDca) and License (myLicense)
// initialize the Text Classification module
dca::TextClassification myTextClassification =
dca::TextClassification::create( myDca, myLicense );
// create an HTML Text Classifier
dca::HtmlTextClassifier myHtmlTextClassifier =
myTextClassification.createHtmlClassifier();
// create an HTML text object
// assume we have the contents of a valid HTML page in std::string
// myHtmlTextContents
dca::HtmlText myHtmlText =
dca::HtmlText::create( myDca, myHtmlTextContents );
// declare the classification results
dca::TextClassificationResults myTextClassificationResults;
// run the classification
myHtmlTextClassifier.classify( myHtmlText, myTextClassificationResults );
// if myResult returns false an error occured
if( !myResult ) {
cout << "Received error from Text Classification (Error code: " <<
myResult.getReturnCode() << ", Description: " <<
myResult.getDescription() << ")." << endl;
return;
}
if( !myTextClassificationResults.isCategorized() ) {
cout << "No categories found for given HTML data." << endl;
return;
}
// we received results and simply want to print them out
const DCA_SIZE_TYPE count = myTextClassificationResults.size();
// iterate through all matched categories
for( DCA_INDEX_TYPE i = 0; i < count; ++i ) {
const dca::TextClassificationResult myTCResult =
myTextClassificationResults[ i ];
cout << "Got result #" << (i+1) << " category id:" <<
myTCResult.id() << ", Score:" <<
myTCResult.score() << endl;
}

Definition at line 29 of file text_classification_results.h.

Public Member Functions

TextClassificationResult at (DCA_INDEX_TYPE index) const
 Returns one result of the matched results (if any) with the given index. More...
 
TextClassificationResult operator[] (DCA_INDEX_TYPE index) const
 Similar to at() but allows a more C++ style access. More...
 
DCA_SIZE_TYPE size () const
 Returns the number of results in the container. More...
 
bool isCategorized () const
 Returns whether there are any results for the text classification.
 
bool contains (DCA_CATEGORY_ID_TYPE catid) const
 Fast method to see whether the results contain a given category or not. More...
 
bool byId (DCA_CATEGORY_ID_TYPE catid, TextClassificationResult &result) const
 If the results contain the given category the detailed result item is returned. More...
 

Member Function Documentation

◆ at()

TextClassificationResult dca::TextClassificationResults::at ( DCA_INDEX_TYPE  index) const

Returns one result of the matched results (if any) with the given index.

Parameters
[in]indexThe index of the result item. Range is from 0 to size() - 1
Returns
The result item for the given index in the container.

◆ operator[]()

TextClassificationResult dca::TextClassificationResults::operator[] ( DCA_INDEX_TYPE  index) const

Similar to at() but allows a more C++ style access.

Parameters
[in]indexThe index of the result item. Range is from 0 to size() - 1
Returns
The result item for the given index in the container.

◆ size()

DCA_SIZE_TYPE dca::TextClassificationResults::size ( ) const

Returns the number of results in the container.

Returns
The size of the container or 0 if the container is empty.

◆ contains()

bool dca::TextClassificationResults::contains ( DCA_CATEGORY_ID_TYPE  catid) const

Fast method to see whether the results contain a given category or not.

Parameters
[in]catidThe category id to match
Returns
true, if the given catid has been found in the container, false otherwise.

◆ byId()

bool dca::TextClassificationResults::byId ( DCA_CATEGORY_ID_TYPE  catid,
TextClassificationResult result 
) const

If the results contain the given category the detailed result item is returned.

Parameters
[in]catidThe category id to match with
[out]resultDetailed text classification result item
Returns
true, if the given catid has been found in the container, false otherwise.

The documentation for this class was generated from the following file:
Single result of a text classification.
HtmlTextClassifier createHtmlClassifier() const
Creates a HtmlTextClassifier that is used to classify HtmlText objects.
DCA_RESULT_TYPE getReturnCode() const
Returns the last error code (if any).
double score() const
Returns the score of the classification (if any), range is from 0.0 to 1.0.
bool isCategorized() const
Returns whether there are any results for the text classification.
DCA_SIZE_TYPE size() const
Returns the number of results in the container.
static HtmlText create(const DcaInstance &aDcaInstance, const std::string &htmlContent)
Creates an HTML text object, used as an input parameter for text classification.
HTML text classifier object for text classification.
FunctionResult classify(const HtmlText &aText, TextClassificationResults &aTextResults) const
The HTML Text Classification method. The method takes an initialized HtmlText object and returns the ...
DCA_CATEGORY_ID_TYPE id() const
Returns the category id of the classification (if any).
size_t DCA_INDEX_TYPE
Type for index access (used for arrays and collections).
Definition: base_types.h:66
std::string getDescription() const
Returns the description for the error or warning.
Encapsulates an HTML text object.
Definition: base_htmltext.h:24
Overall results of a text classification.
size_t DCA_SIZE_TYPE
Type for size (used for size of array and collections).
Definition: base_types.h:72
static TextClassification create(const DcaInstance &aDcaInstance, const License &aLicense)
Initializes the TextClassification module.
Standard function result.
Definition: base_classes.h:148
The HTML Text Classification module class.