void NaiveBayesianClassifier::changeWordCount(const QString &category, const QString &word, int change) { long idxsearch=-1; c4_Row findrow; c4_StringProp match("word"); const char* test = word; match(findrow) = test; c4_IntProp count("count"); c4_View cat = getCategory(category); idxsearch = cat.Find(findrow,idxsearch+1); if (idxsearch>=0) { long int zero = 0; count(cat[idxsearch]) = std::max(zero, count(cat[idxsearch]) + change); } else { c4_StringProp newWord("word"); c4_IntProp newCount("count"); c4_Row newRow; QString temp = QString(word); newWord(newRow)=temp; newCount(newRow)=1; cat.Add(newRow); } }
void NaiveBayesianClassifier::changeCount(const QString &category, int change) { long idxsearch=-1; c4_Row findrow; c4_StringProp match("name"); match(findrow)=category; c4_IntProp count("count"); c4_View catCount = getDatabase().GetAs("categories[name:S,count:I]"); idxsearch = catCount.Find(findrow,idxsearch+1); if (idxsearch>=0) { long zero = 0; count(catCount[idxsearch]) = std::max(zero, count(catCount[idxsearch]) + change); } else { c4_StringProp newCat("name"); c4_IntProp newCount("count"); c4_Row newRow; newCat(newRow)=category; newCount(newRow)=std::max(0, change); catCount.Add(newRow); } }
/** * adds a new title to the current playlist * * Core functionality of the mixplay architecture: * - does not play the same artist twice in a row * - prefers titles with lower playcount * * returns the head of the (new/current) playlist */ mpplaylist *addNewTitle( mpplaylist *pl, mptitle *root ) { mptitle *runner=NULL; mptitle *guard=NULL; unsigned long num=0; char *lastpat; unsigned int pcount=getConfig()->playcount; unsigned int cycles=0; int valid=0; /* 0 - nothing checked 1 - namecheck okay 2 - playcount okay 3 - all okay -1 - stuffing */ if( pl != NULL ) { while( pl->next != NULL ) { pl=pl->next; } runner=pl->title; lastpat=pl->title->artist ; } else { valid=1; runner=root; } /* select a random title from the database */ /* skip forward until a title is found that is neither DNP nor MARK */ num = countTitles( MP_ALL, MP_DNP|MP_MARK|MP_CNTD ); runner=skipTitles( runner, rand()%num ); if( runner==NULL ) { if( pl == NULL ) { addMessage( 0, "No titles in database and no playlist to add them to.." ); return NULL; } runner=pl->title; addMessage( 0, "Next round!" ); newCount( ); /* Try again */ num = countTitles( MP_ALL, MP_DNP|MP_MARK|MP_CNTD ); runner=skipTitles( runner, rand()%num ); if( runner == NULL ) { addMessage( 0, "No more titles in the database!?" ); return NULL; } } cycles=0; while( ( valid & 3 ) != 3 ) { if( lastpat == NULL ) valid |=1; /* title did not pass namecheck */ if( ( valid & 1 ) != 1 ) { guard=runner; while( checkSim( runner->artist, lastpat ) ) { addMessage( 3, "%s = %s", runner->artist, lastpat ); activity( "Nameskipping" ); runner=skipOver( runner->next, 1 ); /* hopefully this will not happen */ if( (runner == guard ) || ( runner == NULL ) ) { addMessage( 0, "Only %s left..", lastpat ); newCount( ); return( addNewTitle( pl, root ) ); } } addMessage( 3, "%s != %s", runner->artist, lastpat ); if( guard != runner ) { valid=1; /* we skipped and need to check playcount */ } else { valid |= 1; /* we did not skip, so if playcount was fine it's still fine */ } } guard=runner; /* title did not pass playcountcheck and we are not in stuffing mode */ while( (valid & 2 ) != 2 ) { if( runner->flags & MP_FAV ) { if ( runner-> playcount <= 2*pcount ) { valid|=2; } } else { if ( runner->playcount <= pcount ) { valid|=2; } } if( ( valid & 2 ) != 2 ) { activity( "Playcountskipping" ); /* simply pick a new title at random to avoid edge cases */ runner=skipTitles( runner, rand()%num ); valid=0; if( (runner == NULL ) || ( guard == runner ) ) { pcount++; /* allow more replays */ getConfig()->playcount=pcount; addMessage( 1, "Increasing maxplaycount to %li", pcount ); runner=guard; } } } if( ++cycles > 10 ) { addMessage( 1, "Looks like we ran into a loop" ); cycles=0; pcount++; /* allow replays */ getConfig()->playcount=pcount; addMessage( 1, "Increasing maxplaycount to %li", pcount ); } } /* while( valid != 3 ) */ addMessage( 3, "[+] (%i/%li/%3s) %s", runner->playcount, pcount, ONOFF( runner->flags&MP_FAV ), runner->display ); /* count again in case this is a favourite */ if( runner->flags & MP_FAV ) { runner->flags &= ~MP_CNTD; } addMessage(2,"Added %2d %5d - %s", runner->playcount, runner->key, runner->display ); return appendToPL( runner, pl, -1 ); }
Counter Counter::operator+(Counter rhs) { Counter newCount(this -> getCount() + rhs.getCount()); return newCount; }