/*
 *  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);
}