int main () { vector<double> v(10, 0.0); list<double> L; for (int i = 0; i < 10; i++) { L.push_back(100 - i * i); v.push_back(10-i); } vectorIterator<double> itr(v); for (itr.init(); ! itr; itr++) cout << itr( ) << ' '; cout << '\n'; double total = 0; for (itr.init(); ! itr; itr++) total += itr (); cout << "total is " << total << '\n'; vectorIterator<double> jtr(v); sort1(itr, jtr); for (itr.init(); ! itr; itr++) cout << itr( ) << ' '; cout << '\n'; itr.sort(itr, jtr); for (itr.init(); ! itr; itr++) cout << itr( ) << ' '; cout << '\n'; listIterator<double> lt1(L); for (lt1.init(); ! lt1; lt1++) cout << lt1( ) << ' '; cout << '\n'; total = 0; for (lt1.init(); ! lt1; lt1++) total += lt1 (); cout << "total is " << total << '\n'; listIterator<double> jt1(L); sort1(lt1, jt1); for (lt1.init(); ! lt1; lt1++) cout << lt1( ) << ' '; cout << '\n'; lt1.sort(lt1, jt1); for (lt1.init(); ! lt1; lt1++) cout << lt1( ) << ' '; cout << '\n'; cout << "\nMY STUFF BEGINS HERE!\n"; cout << "VECTOR ITERATOR:\n" << itr; cout << "LIST ITERATOR:\n" << lt1; return 1; }
int main(int argc, char **argv) { Vocab3 vocab; Splitter s(vocab,3,true); s.load_vocab(argv[1]); s.go(); NgramCounter unigrams(1); ifstream ifs1(argv[1]); LineTokenizer lt1(ifs1); while(lt1.next()){ Tokenizer tok(lt1.token(),' '); while(tok.next()){ int wid = vocab.Add(tok.token()); unigrams.increase_count(&wid,1); } } ifstream ifs(argv[1]); LineTokenizer lt(ifs); NgramCounter ng(2); while(lt.next()){ Tokenizer tok(lt.token(),' '); while(tok.next()){ int wid = vocab.Add(tok.token()); int clid = s.get_class(wid); if (clid < 0 || unigrams.get_count(&wid) > 100 ){ clid = wid; } else { string cl = "-" + s.class_set.Get(clid).str(); clid = vocab.Add(LString(cl)); } int key[2] = {clid,wid}; ng.increase_count(key,1); cout << vocab.Get(clid) << " "; } cout << endl; } BtreeIterator it = ng.iterator(); ofstream ofs("my.classes"); while(it.next()){ ofs << vocab.Get(it.key()[1]) << "\t" << vocab.Get(it.key()[0]) << "\t" << (int)it.double_value()[0] << endl; } ofstream ofs2("my.classmap"); it = s.class_map.iterator(); while (it.next()){ ofs2 << vocab.Get(it.key()[0]) << "\t" << s.class_set.Get(it.key()[1]) << endl; } }
TEST( AllElemMatchOp, Matches ) { BSONObj baseOperandgt1 = BSON( "$gt" << 1 ); auto_ptr<ComparisonMatchExpression> gt1( new ComparisonMatchExpression() ); ASSERT( gt1->init( "", ComparisonMatchExpression::GT, baseOperandgt1[ "$gt" ] ).isOK() ); BSONObj baseOperandlt1 = BSON( "$lt" << 10 ); auto_ptr<ComparisonMatchExpression> lt1( new ComparisonMatchExpression() ); ASSERT( lt1->init( "", ComparisonMatchExpression::LT, baseOperandlt1[ "$lt" ] ).isOK() ); auto_ptr<ElemMatchValueMatchExpression> elemMatch1( new ElemMatchValueMatchExpression() ); elemMatch1->init( "x" ); elemMatch1->add( gt1.release() ); elemMatch1->add( lt1.release() ); BSONObj baseOperandgt2 = BSON( "$gt" << 101 ); auto_ptr<ComparisonMatchExpression> gt2( new ComparisonMatchExpression() ); ASSERT( gt2->init( "", ComparisonMatchExpression::GT, baseOperandgt2[ "$gt" ] ).isOK() ); BSONObj baseOperandlt2 = BSON( "$lt" << 110 ); auto_ptr<ComparisonMatchExpression> lt2( new ComparisonMatchExpression() ); ASSERT( lt2->init( "", ComparisonMatchExpression::LT, baseOperandlt2[ "$lt" ] ).isOK() ); auto_ptr<ElemMatchValueMatchExpression> elemMatch2( new ElemMatchValueMatchExpression() ); elemMatch2->init( "x" ); elemMatch2->add( gt2.release() ); elemMatch2->add( lt2.release() ); AllElemMatchOp op; op.init( "x" ); op.add( elemMatch1.release() ); op.add( elemMatch2.release() ); BSONObj nonArray = BSON( "x" << 4 ); ASSERT( !op.matches( nonArray, NULL ) ); BSONObj emptyArray = BSON( "x" << BSONArray() ); ASSERT( !op.matches( emptyArray, NULL ) ); BSONObj nonNumberArray = BSON( "x" << BSON_ARRAY( "q" ) ); ASSERT( !op.matches( nonNumberArray, NULL ) ); BSONObj singleMatch = BSON( "x" << BSON_ARRAY( 5 ) ); ASSERT( !op.matches( singleMatch, NULL ) ); BSONObj otherMatch = BSON( "x" << BSON_ARRAY( 105 ) ); ASSERT( !op.matches( otherMatch, NULL ) ); BSONObj bothMatch = BSON( "x" << BSON_ARRAY( 5 << 105 ) ); ASSERT( op.matches( bothMatch, NULL ) ); BSONObj neitherMatch = BSON( "x" << BSON_ARRAY( 0 << 200 ) ); ASSERT( !op.matches( neitherMatch, NULL ) ); }