Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
StreamingStringFeatures libshogun example.
- Loading branch information
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
examples/undocumented/libshogun/streaming_stringfeatures.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |