/usr/share/doc/libmythes-dev/examples/example.cxx is in libmythes-dev 2:1.2.4-1ubuntu3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | #include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "mythes.hxx"
#include <hunspell.hxx>
extern char * mystrdup(const char * s);
void myfreelist(char *** list, int n)
{
if (list && (n > 0)) {
for (int i = 0; i < n; i++) if ((*list)[i]) free((*list)[i]);
free(*list);
*list = NULL;
}
}
int main(int argc, char** argv)
{
FILE* wtclst;
/* first parse the command line options
* arg1 - index file, arg2 thesaurus data file, arg3 - file of words to check,
* arg4, arg5 - opt. Hunspell affix and dic file for stemming and
* morphological generation
*/
if (argc < 3) {
fprintf(stderr,"correct syntax is:\n");
fprintf(stderr,"example index_file thesaurus_file file_of_words_to_check [affix_file dic_file]\n");
exit(1);
}
/* open the words to check list */
wtclst = fopen(argv[3], "r");
if (!wtclst) {
fprintf(stderr,"Error - could not open file of words to check\n");
exit(1);
}
// Hunspell for stemming and morphological generation of affixes synonyms
Hunspell * pH = NULL;
if (argc >= 5) pH = new Hunspell(argv[4], argv[5], (const char *) NULL);
// open a new thesaurus object
MyThes * pMT = new MyThes(argv[1], argv[2]);
// get the encoding used for the thesaurus data
char * encoding = pMT->get_th_encoding();
printf("Thesaurus uses encoding %s\n\n", encoding);
int k;
char buf[101];
char oldbuf[101];
mentry * pmean;
while(fgets(buf,100,wtclst)) {
oldbuf[0] = '\0';
k = strlen(buf);
*(buf + k - 1) = '\0';
int len = strlen(buf);
int count = pMT->Lookup(buf,len,&pmean);
// don't change value of pmean
// or count since needed for CleanUpAfterLookup routine
if (!count) {
int stemcount = 0;
char **stem;
if (pH) stemcount = pH->stem(&stem, buf); else stemcount = 0;
if (stemcount) {
printf("stem: %s\n", stem[0]);
strncpy(oldbuf,buf, sizeof(oldbuf)-1);
oldbuf[sizeof(oldbuf)-1] = 0;
strncpy(buf, stem[0], sizeof(buf)-1);
buf[sizeof(buf)-1] = 0;
len = strlen(buf);
count = pMT->Lookup(buf, len, &pmean);
myfreelist(&stem, stemcount);
} else oldbuf[0] = '\0';
}
mentry* pm = pmean;
if (count) {
printf("%s has %d meanings\n",buf,count);
for (int i=0; i < count; i++) {
printf(" meaning %d: %s\n",i,pm->defn);
for (int j=0; j < pm->count; j++) {
char ** gen;
int l = 0;
if (pH && oldbuf[0]) l = pH->generate(&gen, pm->psyns[j], oldbuf);
if (l) {
int k;
printf(" %s",gen[0]);
for (k = 1; k < l; k++) printf(", %s",gen[k]);
printf("\n");
myfreelist(&gen, l);
} else printf(" %s\n",pm->psyns[j]);
}
printf("\n");
pm++;
}
printf("\n\n");
// now clean up all allocated memory
pMT->CleanUpAfterLookup(&pmean,count);
} else {
printf("\"%s\" is not in thesaurus!\n",buf);
}
}
fclose(wtclst);
delete pMT;
if (pH) delete pH;
return 0;
}
|