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 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463
|
/*
grind.c - Driver program for WordNet grinder
*/
#include <stdio.h>
#include <stdlib.h>
#include "wngrind.h"
static char *Id = "$Id: grind.c,v 1.33 2005/01/31 20:03:36 wn Rel $";
static void badarg(), GetSenseCounts(), Stats(), SymStats();
static int grind();
int verifyflag = 0, statsflag = 0, distribflag = 0;
int senseindex = 0;
int ordersenses = 0;
int nominalizations = 0;
int synsetkeys = 0;
int extraflag = 0;
void main(argc,argv)
char **argv;
int argc;
{
/* int i; */
char c;
Argv=argv;
Argc=argc;
if (argc<2)
badarg(Argv[0]);
logfile = stderr; /* initialize log file */
while (*(++argv) && **argv=='-') {
c = (*argv)[1];
if (c == 'v') /* verify only (don't build database) */
verifyflag = 1;
else if (c == 's') /* suppress warnings */
nowarn = 1;
else if (c == 'a') /* generate statistics */
statsflag = 1;
else if (c == 'd') /* generate distribution statistics */
distribflag = 1;
else if (c == 'i') /* if set, build sense index */
senseindex = 1;
else if (c == 'o') /* if set, order senses */
ordersenses = 1;
else if (c == 'n') /* if set, do nominalizations */
nominalizations = 1;
else if (c == 'k') /* if set, generate synset keys */
synsetkeys = 1;
else if (c == 'x') /* if set, output special database */
extraflag = 1;
else if (c == 'L') { /* send log to file */
if ((logfile = fopen((*argv + 2), "w")) == NULL) {
fprintf(stdout,
"%s: cannot open logfile \"%s\" - using stderr\n",
Argv[0], *argv + 2);
logfile = stderr;
}
} else
badarg(Argv[0]);
}
exit(grind()); /* process files */
}
static int grind()
{
int filecnt = 0;
/* parse input files */
while (NextFile()) {
yyparse();
pcount=0;
yylineno=1;
filecnt++;
}
/* If no input files were processed, quit now. */
if (!filecnt) {
if (verifyflag)
fprintf(logfile, "No input files processed.\n");
else
fprintf(logfile,
"No input files processed; no database generated.\n");
return(-1);
}
if (statsflag)
Stats(); /* generate statistics */
if (errcount) {
fprintf(logfile, "%d syntactic %s found%s\n",
errcount,
(errcount == 1 ? "error" : "errors"),
(verifyflag ? "." : "; no database generated"));
return(errcount > 255 ? 255 : errcount);
}
/* If we're only verifying and the user doesn't want to see
warnings, skip the pointer reflections. */
if (!verifyflag || !nowarn) {
fprintf(logfile, "Resolving pointers...\n");
ResolvePointers();
fprintf(logfile, "Done resolving pointers...\n");
}
if (errcount) {
fprintf(logfile, "%d structural %s found%s\n",
errcount,
(errcount == 1 ? "error" : "errors"),
(verifyflag ? "." : "; no database generated"));
return(errcount > 255 ? 255 : errcount);
}
/* get sense counts and dump database */
if (!verifyflag) {
fprintf(stderr, "No errors...\007\n");
fprintf(logfile, "Getting sense counts...\n");
GetSenseCounts();
fprintf(logfile, "Done with sense counts...\n");
FindOffsets(); /* calculate byte offsets in data files */
DumpData(); /* generate data files */
if (ordersenses)
ReadCntlist();
DumpIndex(); /* generate index files */
}
if (senseindex) {
if (verifyflag) {
fprintf(logfile, "Getting sense counts...\n");
GetSenseCounts();
fprintf(logfile, "Done with sense counts...\n");
FindOffsets();
if (ordersenses)
ReadCntlist();
}
DumpSenseIndex();
}
if (errcount)
fprintf(logfile, "%d %s\n", errcount, (errcount == 1 ? "error" : "errors"));
return(errcount > 255 ? 255 : errcount);
}
static void GetSenseCounts()
{
Symbol sym;
SynList sl;
int i, j, pos;
for (i = 0; i < HASHSIZE; i++) {
for (sym = hashtab[i]; sym; sym = sym->symnext) {
for (j = 1; j < NUMPARTS + 1; j++)
sym->sensecnt[j] = 0;
for (sl = sym->syns; sl; sl = sl->snext) {
if ((pos = sl->psyn->ss->part) == SATELLITE)
pos = ADJ;
sym->sensecnt[pos]++;
}
}
}
}
#define PERT_POS (SATELLITE + 1)
static void Stats()
{
register G_Synset ss, fan;
register Pointer p;
register Synonym syn;
int i, gotpert;
int total = 0, dtotal = 0;
int sscount[NUMPARTS + 3], defns[NUMPARTS + 3];
int ptrcount = 0, syncount = 0; /* keep track of each kind too? */
/* add # cross file ptrs when added? */
fprintf(logfile, "\n*** Statistics for ground files:\n\n");
for (i = 1; i <= NUMPARTS + 2; i++)
sscount[i] = defns[i] = 0;
for (ss = headss; ss; ss = ss->ssnext) {
gotpert = 0;
for (syn = ss->syns; syn; syn = syn->synnext)
syncount++;
for (p = ss->ptrs; p; p = p->pnext) {
ptrcount++;
if (ss->part == ADJ && p->ptype == PERTPTR)
gotpert = 1;
}
if (gotpert) {
sscount[PERT_POS]++;
if (ss->defn && *ss->defn)
defns[PERT_POS]++;
} else {
sscount[ss->part]++;
if (ss->defn && *ss->defn)
defns[ss->part]++;
if (ss->fans) {
for (fan = ss->fans; fan; fan = fan->ssnext) {
sscount[SATELLITE]++;
for (syn = fan->syns; syn; syn = syn->synnext)
syncount++;
for (p = fan->ptrs; p; p = p->pnext)
ptrcount++;
if (fan->defn && *fan->defn)
defns[SATELLITE]++;
}
}
}
}
for (i = 1; i <= NUMPARTS; i++) {
fprintf(logfile, "%d %s synsets\n", sscount[i], partnames[i]);
total += sscount[i];
}
if (sscount[PERT_POS]) {
fprintf(logfile, "%d pertainym synsets\n", sscount[PERT_POS]);
total += sscount[PERT_POS];
}
if (sscount[SATELLITE]) {
fprintf(logfile, "%d adjective satellite synsets\n",
sscount[SATELLITE]);
total += sscount[SATELLITE];
}
fprintf(logfile,
"%d synsets in total (including satellite and pertainym synsets)\n", total);
for (i = 1; i <= NUMPARTS; i++) {
fprintf(logfile, "%d %s synsets have definitional glosses\n",
defns[i], partnames[i]);
dtotal += defns[i];
}
if (sscount[PERT_POS]) {
fprintf(logfile,
"%d pertainym synsets have definitional glosses\n",
defns[PERT_POS]);
dtotal += defns[PERT_POS];
}
if (sscount[SATELLITE]) {
fprintf(logfile,
"%d adjective satellite synsets have definitional glosses\n",
defns[SATELLITE]);
dtotal += defns[SATELLITE];
}
fprintf(logfile,
"%d definitional glosses in total (including adjective satellite synsets)\n", dtotal);
fprintf(logfile, "%d pointers in total\n", ptrcount);
fprintf(logfile, "%d synonyms in synsets\n", syncount);
SymStats();
fprintf(logfile, "\n");
}
#define MAXCOL_LEN 10
static void SymStats()
{
register int i, j, k;
register Symbol sym;
SynList sl;
int symcount = 0, ucount;
int wdcnt[MAXCOL_LEN];
int sensecnt[NUMPARTS + 1][MAXCOL_LEN][MAXSENSE];
int totalsenses[NUMPARTS + 1];
for (i = 1; i < MAXCOL_LEN; i++)
wdcnt[i] = 0;
for (i = 1; i < NUMPARTS + 1; i++) {
totalsenses[i] = 0;
for (j = 1; j < MAXCOL_LEN; j++)
for (k = 0; k < MAXSENSE; k++) {
sensecnt[i][j][k] = 0;
}
}
for (i = 0; i < HASHSIZE; i++)
for (sym = hashtab[i]; sym; sym = sym->symnext) {
symcount++;
for (j = 0, ucount = 1; sym->label[j]; j++)
if (sym->label[j] == '_') ucount++;
if (ucount >= MAXCOL_LEN)
fprintf(logfile, "collocation too long: %s\n", sym->label);
else
wdcnt[ucount]++;
if (distribflag) {
/* go down the list of uses of the word */
for (sl = sym->syns; sl; sl = sl->snext)
totalsenses[sl->psyn->ss->part]++;
for (k = 1; k < NUMPARTS + 1; k++) {
if (totalsenses[k]) {
if ((sensecnt[k][ucount][totalsenses[k] + 1]) >
MAXSENSE) {
fprintf(logfile,
"total number of senses exceeded: %s\n",
sym->label);
} else {
sensecnt[k][ucount][totalsenses[k]]++;
totalsenses[k] = 0;
}
}
}
}
}
fprintf(logfile, "%d unique word phrases\n", symcount);
for (i = 1; i < MAXCOL_LEN; i++)
if (wdcnt[i])
fprintf(logfile, "%d word phrases of length %d\n",
wdcnt[i], i);
if (distribflag) {
for (i = 1; i < NUMPARTS + 1; i++) {
fprintf(logfile,
"Distribution of %s senses by string length\n",
partnames[i]);
fprintf(logfile, "\t\tLength of Compound\n");
fprintf(logfile, "1\t2\t3\t4\t5\t6\t7\t8\t9\n\n");
for (k = 1; k < MAXSENSE; k++) {
for (j = 1; j < MAXCOL_LEN; j++)
fprintf(logfile, "%d\t",sensecnt[i][j][k]);
fprintf(logfile, "\n");
}
}
}
}
static void badarg(cmd)
char *cmd;
{
fprintf(stderr, "usage: %s [-v] [-s] [-Llogfile] [-a] [-d] [-i] [-o] [-n] filename [filename...]\n", Argv[0]);
fprintf(stderr, "\t-v\tverifyonly\n");
fprintf(stderr, "\t-s\t suppress cross file pointer warnings\n");
fprintf(stderr, "\t-Llogfile\tsend output to \"logfile\"\n");
fprintf(stderr, "\t-a\tgenerate statistics\n");
fprintf(stderr, "\t-d\tgenerate distribution statistics\n");
fprintf(stderr, "\t-i\tgenerate sense index\n");
fprintf(stderr, "\t-o\torder senses using \"taglist\"\n");
fprintf(stderr, "\t-n\tinclude nominalization pointers\n");
exit(-1);
}
/*
Revision log:
$Log: grind.c,v $
Revision 1.33 2005/01/31 20:03:36 wn
cleaned up and consolidated include files
Revision 1.32 2003/09/18 19:05:24 wn
*** empty log message ***
Revision 1.31 2003/09/18 19:05:00 wn
*** empty log message ***
Revision 1.30 2001/10/08 14:07:17 wn
set line number to 1
Revision 1.29 2001/09/14 13:39:20 wn
initialize yylineno to 0 to try to fix "off by one" problem in error messages
Revision 1.28 2001/09/06 17:55:38 wn
added code for synset keys
Revision 1.27 2001/05/23 14:26:42 wn
changed comment on nominalizations
Revision 1.26 2001/02/15 19:26:51 wn
changed 'usage' to include -n
Revision 1.25 2000/07/11 15:19:33 wn
added '-n' flag for nominalizations
Revision 1.24 1998/01/06 18:43:43 wn
removed "-c" option and senseflag flag
Revision 1.23 1997/09/04 20:15:46 wn
*** empty log message ***
Revision 1.22 1996/08/09 18:27:13 wn
moved GetSenseCounts here
* Revision 1.21 1996/05/30 20:56:48 wn
* *** empty log message ***
*
* Revision 1.20 1995/06/23 16:36:37 wn
* removed -l stuff
*
* Revision 1.19 1995/02/07 20:47:07 wn
* changed FANSS to SATELLITE
*
* Revision 1.18 1995/02/02 21:46:08 wn
* *** empty log message ***
*
* Revision 1.17 1994/07/01 19:21:15 wn
* fixed bug in symstats - off by one in test for ucount
*
* Revision 1.16 1994/03/24 09:53:11 wn
* *** empty log message ***
*
* Revision 1.15 94/03/08 13:43:11 wn
* expanded usage message
*
* Revision 1.14 94/03/08 13:37:25 wn
* *** empty log message ***
*
* Revision 1.13 94/03/03 11:56:17 wn
* added ordersenses and call to ReadCntlist
*
* Revision 1.12 94/02/24 11:09:39 wn
* make bell ring when "No Errors"
*
* Revision 1.11 94/02/03 10:58:50 wn
* added no errors msg
*
* Revision 1.10 93/04/13 13:24:29 wn
* added code for index.sense
*
* Revision 1.9 92/09/17 14:39:10 wn
* added distribflag and associated code
*
* Revision 1.8 92/08/12 15:14:46 wn
* *** empty log message ***
*
* Revision 1.7 92/01/28 16:16:27 wn
* removed use of 'mikeflag' and made grinder always output sense number
* after each word in synset
*
* Revision 1.6 91/12/13 17:10:03 wn
* no changes
*
* Revision 1.5 91/12/13 15:58:17 wn
* changed to use constants and variables in wnconsts and wnglobals.
* removed -w and -m options and stub code
*
* Revision 1.4 91/12/11 10:28:47 wn
* added stuff to stats code
*
* Revision 1.3 91/10/02 13:57:26 wn
* added temporary flag (mikeflag) set with start option -x
* which tells grinder to generate special database for
* mike's testing purposes
*
* Revision 1.2 91/10/02 10:27:33 wn
* made flags global instead of statid
*
* Revision 1.1 91/09/11 14:49:22 wn
* Initial revision
*
*/
|