📄 wnparse.y
字号:
static G_Synset MakeSynset(int, Synonym, Pointer, Framelist, char *, int);static Synonym AddSynonym(Synonym, Synonym);static Pointer AddPointer(Pointer, Pointer);static Synonym InsertSynonym(Synonym, Synonym);static void AddSynset(G_Synset);static void AddToSynList(G_Synset);static void MakeSyngroup(Pointer, Framelist);static Pointer DoPointer(Symbol, int);static int UniqueSynonym(Synonym, Synonym);static int UniquePointer(Pointer, Pointer);static int UniqueSynSense(Synonym, int);static int UniqueFanSynonym(Synonym, int, int);static char *UseLabel(char *);static G_Synset MakeSynset(int type, Synonym syns, Pointer ptrs, Framelist frames, char *defn, int key){ register Synonym syn; register Pointer p; G_Synset ss; Framelist f; wdcnt = 0; /* reset word counter for next synset */ lastsyn = NULL; /* reset pointer to last synonym */ if (!syns) { yywarn("No valid synonyms: synset discarded\n"); return(NULL); } else if (type == VERB && !frames) { yyerror("No frame list in verb synset: synset discarded\n"); return(NULL); } else if (type == NOUN && foundhyper == FALSE) { yywarn("No hypernyms in synset\n"); if (verifyflag) errcount--; /* don't count as real error */ } foundhyper = FALSE; /* Link in any pointers and frame lists found in syngroups. */ if (ptrlist) { if (ptrs) { for (p = ptrs; p->pnext; p = p->pnext); p->pnext = ptrlist; } else { ptrs = ptrlist; } ptrlist = NULL; } if (frlist) { if (frames) frames->fnext = frlist; else frames = frlist; frlist = NULL; } ss = CreateSynset((unsigned char)type, syns, ptrs, frames, defn, key, yylineno, curfilenum()); /* Add pointer to the synset to each synonym in it. Make sure that the synonym is unique (using sense number) within the file. */ for (syn = syns; syn; syn = syn->synnext) { if ((type != SATELLITE && !UniqueSynSense(syn, FALSE)) || (type == SATELLITE && (curfilenum() != 0) && !UniqueSynSense(syn, TRUE))) { if (syn->sensenum) sprintf(buf, "Synonym \"%s%d\" is not unique in file\n", syn->word->label, syn->sensenum); else sprintf(buf, "Synonym \"%s\" is not unique in file\n", syn->word->label); yyerror(buf); } syn->ss = ss; syn->infanss = (type == SATELLITE) ? TRUE : FALSE; } return(ss);}static Synonym AddSynonym(Synonym syns, Synonym newsyn){ register Synonym s; /* Add synonym to end of list. First make sure this synonym is unique within the synset. */ if (UniqueSynonym(syns, newsyn)) { if (syns) { for (s = syns; s->synnext; s = s->synnext); /* find end of list */ s->synnext = newsyn; } else syns = newsyn; lastsyn = newsyn; /* save last synonym in synset for errors */ } else { if (newsyn->sensenum) sprintf(buf, "Synonym \"%s%d\" is not unique in synset\n", newsyn->word->label, newsyn->sensenum); else sprintf(buf, "Synonym \"%s\" is not unique in synset\n", newsyn->word->label); yyerror(buf); free(newsyn); /* free up space */ } if (newsyn->sensenum > 16) { sprintf(buf, "Sense number must be less than 16: \"%s%d\" - changed to %d\n", newsyn->word->label, newsyn->sensenum, newsyn->sensenum % 16); yywarn(buf); } return(syns);}static Pointer AddPointer(Pointer ptrs, Pointer newptr){ register Pointer p; extern int nominalizations; /* Discard nominalization pointer if we're skipping nominalizations */ if (!nominalizations && (newptr->ptype == DERIVATION) ) { free(newptr); return (ptrs); } if (UniquePointer(ptrs, newptr)) { if (ptrs) { for (p = ptrs; p->pnext; p = p->pnext); /* find end of list */ p->pnext = newptr; } else ptrs = newptr; } else { if (newptr->pfilenum != curfilenum()) { sprintf(buf, "Pointer \"%s:%s\" is not unique: pointer discarded\n", PrintFileName(newptr->pfilenum), PrintPointer(newptr)); } else { sprintf(buf, "Pointer \"%s\" is not unique: pointer discarded\n", PrintPointer(newptr)); } yywarn(buf); free(newptr); /* free up space */ } return(ptrs);}static Synonym InsertSynonym(Synonym syns, Synonym newsyn){ /* Insert synonym onto front of list. First make sure this synonym is unique within the synset. */ if (UniqueSynonym(syns, newsyn)) { newsyn->synnext = syns; syns = newsyn; } else { if (newsyn->sensenum) sprintf(buf, "Synonym \"%s%d\" is not unique in synset\n", newsyn->word->label, newsyn->sensenum); else sprintf(buf, "Synonym \"%s\" is not unique in synset\n", newsyn->word->label); yyerror(buf); free(newsyn); /* free up space */ } return(syns);}static void AddSynset(G_Synset ss){ register G_Synset fan; register Synonym fansyn; int svlineno; if (headss == NULL) headss = ss; else lastss->ssnext = ss; lastss = ss; /* set current end of list to this synset */ AddToSynList(ss); /* update synlists for words in synset */ /* If a cluster, make fans point back to head synset and check for use of a HEADWORD in a fan. */ for (fan = ss->fans; fan; fan = fan->ssnext) { for (fansyn = fan->syns; fansyn; fansyn = fansyn->synnext) if (!UniqueFanSynonym(fansyn, ss->clusnum, fan->lineno)) { sprintf(buf, "\"%s\" is not unique in this cluster\n", fansyn->word->label); svlineno = yylineno; yylineno = fan->lineno; yyerror(buf); yylineno = svlineno; } fan->fans = ss; }} static void AddToSynList(G_Synset ss){ register Synonym syn; register SynList sl; int unique; /* For all words in this synset, add a pointer to this synset to the word's list of pointers to synsets containing the word. (confusing, but if you read it slowly, it makes sense) */ for (syn = ss->syns; syn; syn = syn->synnext) { /* First, make sure that a pointer to this word in this synset isn't already on the list. This can occur if there are multiple spellings of a word in a synset. If only one occurrence in the synset is added to the list, only one pointer to this synset will be output in the index file, and pointer resolution will be easier since we don't have to weed out multiples. */ unique = TRUE; for (sl = syn->word->syns; sl; sl = sl->snext) if (sl->psyn->ss == syn->ss) { unique = FALSE; break; } if (unique) { if (sl = (SynList)malloc(sizeof(Synl))) { sl->psyn = syn; /* add this synonym to list */ sl->snext = syn->word->syns; syn->word->syns = sl; } else { fprintf(logfile, "Cannot malloc space for sslist\n"); exit(-1); } } }}static void MakeSyngroup(Pointer ptrs, Framelist frame){ register Pointer p, lp; register int wc; wc = wdcnt + 1; /* count this word */ /* Set the word count for all pointers specific to this word. Note that since the lists of pointers and synonyms are built with the last entry first, the word count counts from the wrong direction. Once the number of words in the synset is known, the word counts are adjusted. */ if (ptrs) { for (p = ptrs; p; p = p->pnext) { p->fromwdnum = (headword ? -wc : wc); lp = p; } if (!ptrlist) { ptrlist = ptrs; } else { lp->pnext = ptrlist; ptrlist = ptrs; } } if (frame) { frame->frwdnum = wc; if (!frlist) frlist = frame; else { frame->fnext = frlist; frlist = frame; } }}static Pointer DoPointer(Symbol sym, int ptrtype){ Pointer p = NULL; int mode, fn; char ptrbuf[100]; static int pmode[] = { 0, P_NOUN, P_VERB, P_ADJ, P_ADV }; extern int nominalizations; /* Discard nominalization pointer if we're skipping nominalizations */ if (!nominalizations && (ptrtype == DERIVATION) ) { return (NULL); } /* used later to make sure NOUN synset has HYPERNYM */ if (ptrtype == HYPERPTR || ptrtype == INSTANCE) foundhyper = TRUE; fn = (fnbuf[0] ? filenum(fnbuf) : curfilenum()); mode=filemode(fn); p = CreatePointer(sym, satellite, (unsigned char)fn, (unsigned char)sense, (unsigned char)satellite_sense, (unsigned char)ptrtype, ALLWORDS, ALLWORDS); p->phead = headptr; if (mode && (legalptrs[ptrtype] & pmode[mode])) { return(p); } else { /* Construct pretty error message & print it */ if (fnbuf[0]) sprintf(ptrbuf, "\"%s:", fnbuf); else sprintf(ptrbuf, "\""); sprintf(ptrbuf + strlen(ptrbuf), "%s\"", PrintPointer(p)); if (!mode) { /* Don't print this message if only verifyng files */ if (!verifyflag) { sprintf(buf, "Pointer to unknown file %s: pointer discarded\n", ptrbuf); yywarn(buf); } } else if (!legalptrs[ptrtype]) { sprintf(buf, "Invalid pointer type %s in %s file: pointer discarded\n", ptrbuf, partnames[curfilemode()]); yywarn(buf); } else if (!(legalptrs[ptrtype] & pmode[mode])) { sprintf(buf, "%s can't point to a %s file: pointer discarded\n", ptrbuf, partnames[mode]); yywarn(buf); } else { sprintf(buf, "Error in pointer %s: pointer discarded\n", ptrbuf); yywarn(buf); } free(p); return(NULL); }}static int UniqueSynonym(Synonym syns, Synonym syn){ register Synonym s; /* check for uniqueness within this synset */ for (s = syns; s; s = s->synnext) if (s->word == syn->word) { if (s->label || syn->label) continue; /* alternate spelling, ok. */ else return(0); } return(1);}static int UniquePointer(Pointer ptrs, Pointer ptr){ register Pointer p; for (p = ptrs; p; p = p->pnext) if (p->pword == ptr->pword && p->psensenum == ptr->psensenum && p->pfilenum == ptr->pfilenum && p->ptype == ptr->ptype && p->fromwdnum == ptr->fromwdnum && p->towdnum == ptr->towdnum && p->pslite == ptr->pslite && p->pslite_sense == ptr->pslite_sense && p->phead == ptr->phead) return(0); return(1);}static int UniqueSynSense(Synonym syn, int test){ register SynList sl; for (sl = syn->word->syns; sl; sl = sl->snext) if ((sl->psyn->sensenum == syn->sensenum) && (sl->psyn->ss->filenum == curfilenum()) && (sl->psyn->infanss == test)) return(0); return(1);}static int UniqueFanSynonym(Synonym syn, int clusnum, int lineno){ register SynList sl; for (sl = syn->word->syns; sl; sl = sl->snext) if ((sl->psyn->ss->clusnum == clusnum) && (sl->psyn->sensenum == syn->sensenum) && (sl->psyn->ss->lineno != lineno))#ifdef FOOP if ((sl->psyn->ss->part == ADJ) && /* word is an adjective */ (!sl->psyn->infanss) && /* word is in a cluster head */ (sl->psyn->ss->clusnum == clusnum)) /* word is in same cluster */#endif return(0); return(1);}static char *UseLabel(char *s){ register int i = 0; register char *ls; /* Decide if string is lower case or not */ ls = strlower(s); while (*(s + i)) { if (*(s + i) != *(ls + i)) return(s); i++; } return(NULL);}/* Revision Log: (since version 1.5) $Log: wnparse.y,v $ Revision 1.48 2005/01/31 20:04:03 wn cleaned up and consolidated include files Revision 1.47 2004/07/16 15:15:21 wn fixed problem with upper case in adj files that are not in clusters Revision 1.46 2004/07/14 16:14:46 wn only convert upper case adj to lower case if not in adj.all Revision 1.45 2004/01/16 18:13:36 wn added INSTANCE Revision 1.44 2003/10/31 15:33:56 wn added code to support DERIVATION link in adj satellites Revision 1.43 2003/03/27 15:27:12 wn changed NOMIN_START and NOMIN_END with DERIVATION Revision 1.42 2001/09/06 17:55:38 wn added code for synset keys Revision 1.41 2001/02/16 19:52:06 wn *** empty log message *** Revision 1.40 2000/10/27 16:53:29 wn fixed error message Revision 1.39 2000/07/11 15:23:59 wn added code to AddPointer to skip nominalization pointers if !nominalizations (-n not specified) Revision 1.38 1997/08/05 14:23:46 wn added function prototypes, other small cleanups * Revision 1.37 1996/05/30 20:56:48 wn * *** empty log message *** * * Revision 1.36 1995/07/28 21:29:19 wn * added check for wsense > MAXID (only 1 hex digit in databae allowed) * * Revision 1.35 1995/06/16 21:09:34 wn * fixed bug with adj head pointers * * Revision 1.34 1995/05/25 19:00:09 wn * added code to find senses taht are not unique in adj.pert files * * Revision 1.33 1995/02/14 18:50:40 wn * fixed bug in UniquePointer * * Revision 1.32 1995/02/14 18:24:49 wn * *** empty log message *** * * Revision 1.31 1995/02/07 21:40:17 wn * fixed bug in fan and changed NOUNSS to NOUN, etc. * * Revision 1.30 1994/09/27 19:50:46 wn * *** empty log message *** * * Revision 1.29 1994/04/27 09:49:02 wn * *** empty log message *** * * Revision 1.28 94/03/03 11:56:02 wn * no changes * * Revision 1.27 93/07/08 16:23:35 wn * added test to find noun synsets which don't have hypernyms * * Revision 1.26 93/04/21 12:40:33 wn * added new ATTRIBUTE pointer (=) * * Revision 1.1 91/09/11 11:58:56 wn * Initial revision * */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -