Skip to content

Commit

Permalink
StreamingStringFeatures libshogun example.
Browse files Browse the repository at this point in the history
  • Loading branch information
frx committed Aug 26, 2011
1 parent 66c4ffd commit 65a020c
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions examples/undocumented/libshogun/streaming_stringfeatures.cpp
@@ -0,0 +1,46 @@
#include <shogun/io/StreamingAsciiFile.h>
#include <shogun/features/StreamingStringFeatures.h>

using namespace shogun;

void display_vector(const SGString<char> &vec)
{
printf("\nNew Vector\n------------------\n");
printf("Length=%d.\n", vec.slen);
for (int32_t i=0; i<vec.slen; i++)
{
printf("%c", vec.string[i]);
}
printf("\n");
}

int main(int argc, char **argv)
{
init_shogun_with_defaults();

CStreamingAsciiFile* file = new CStreamingAsciiFile("../data/fm_train_dna.dat");

CStreamingStringFeatures<char>* feat = new CStreamingStringFeatures<char>(file, false, 1024);
feat->use_alphabet(DNA);

feat->start_parser();
while (feat->get_next_example())
{
SGString<char> vec = feat->get_vector();
display_vector(vec);
feat->release_example();
}
feat->end_parser();

CAlphabet* alpha = feat->get_alphabet();

printf("\nThe histogram is:\n");
alpha->print_histogram();

SG_UNREF(alpha);
SG_UNREF(feat);
SG_UNREF(file);

exit_shogun();
return 0;
}

0 comments on commit 65a020c

Please sign in to comment.