/* * DocItem.cpp * Classifier * * Daniel Wojcik * */ #include #include "DocItem.h" DocItem::DocItem() { termCount = 0; classification[0] = "-1"; classification[1] = "-1"; classification[2] = "-1"; } //Assumes that term does not already exist //Check beforehand with DocItem::getCount void DocItem::addTerm(const std::string& t) { DocTerm p; p.term = t; p.count = 1; terms[t] = p; termCount++; } unsigned int DocItem::getCount(const std::string& t) { std::map::iterator itr; itr = terms.find(t); if (itr != terms.end()) return itr->second.count; else return 0; } //Increments the number of occurrences of the term in this document void DocItem::increment(const std::string& t) { std::map::iterator itr; itr = terms.find(t); if (itr != terms.end()) itr->second.count++; else return; //Uncaught failure! termCount++; } TermShort statToShort(TermStat& old) { TermShort p; p.count = old.count; p.dCount = old.dCount; p.tCount = old.tCount; p.idf = old.idf; return p; } //Comparison operators for classes and structs bool operator== (const std::pair& left, const std::pair& right) { return (left.first == right.first); }