Initial Import
[SXSI/TextCollection.git] / testTextCollection.cpp
1 // Test driver for text collection
2 #include <iostream>
3 using std::cout;
4 using std::endl;
5
6 #include "TextCollection.h"
7 using SXSI::TextCollection;
8
9 void printDocumentResult(TextCollection::document_result dr)
10 {
11     TextCollection::document_result::iterator it;
12     printf("document result:");
13     for (it = dr.begin(); it != dr.end(); ++it)
14         printf(" %i", *it);
15     printf("\n");
16     fflush(stdout);
17 }
18
19 void printFullResult(TextCollection::full_result fr)
20 {
21     TextCollection::full_result::iterator it;
22     printf("full result:");
23     for (it = fr.begin(); it != fr.end(); ++it)
24         printf(" (%i, %lu)", (*it).first, (*it).second);
25     printf("\n");
26     fflush(stdout);
27 }
28
29 int main()
30 {
31     uchar *text = (uchar*) "acabab";
32     TextCollection *csa = TextCollection::InitTextCollection(1);
33     csa->InsertText(text);
34     text = (uchar*) "abaca";
35     csa->InsertText(text);
36     text = (uchar*) "abacb";
37     csa->InsertText(text);
38
39     csa->MakeStatic();
40     
41     text = csa->GetText(0);
42     cout << "Text 0: \"" << text << "\"" << endl;
43     delete [] text;
44     text = csa->GetText(1);
45     cout << "Text 1: \"" << text << "\"" << endl;
46     delete [] text;
47     text = csa->GetText(2);
48     cout << "Text 2: \"" << text << "\"" << endl;
49     delete [] text;
50     
51     text = csa->GetText(2, 2, 4);
52     cout << "Substring of Text 3: \"" << text << "\"" << endl;
53     delete [] text;
54     
55     printf("n:o contains: %u\n", csa->CountContains((uchar *)"ac"));
56     printf("n:o suffix: %u\n", csa->CountSuffix((uchar *)"b"));
57     printf("n:o equal: %u\n", csa->CountEqual((uchar *)"acabab"));
58     printf("is equal: %u\n", csa->IsEqual((uchar *)"abacb"));
59     
60     TextCollection::document_result dr;
61     dr = csa->Contains((uchar*)"ab");
62     printDocumentResult(dr);
63
64     TextCollection::full_result fr;
65     fr = csa->FullContains((uchar *)"ab");
66     printFullResult(fr);
67
68     delete csa;
69 }