/* * Concordance Programming Language Synonym Management Program * * Copyright (c) 1992 Dataflight Software, Inc. * ALL RIGHTS RESERVED. * 3200 Airport Avenue, Suite 19 * Santa Monica, CA 90230 * * Unauthorized distribution, adaptation or use may be * subject to civil and criminal penalties. * * You may incorporate this program into your own programs * ONLY if you incorporate the following copyright notice: * * Copyright (c) 1992 YOUR NAME. ALL RIGHTS RESERVED. * Portions copyright (c) 1991 Dataflight Software, Inc. */ text copyright = "Copyright (c) 1992 Dataflight Software, Inc. "+ "ALL RIGHTS RESERVED."; main() { BuildSynonymList(); } /**************************************************************** * Name: BuildSynonymList * * Synopsis: Loads a text file containing synonyms into a * * Concordance .SYN b+tree file for Search mode. * * * * Description:1.) A blank line separates one synonym group from * * another. * * 2.) Words in a group (not preceeded by anything) * * are stored as synonyms. * * 3.) Words preceeded by a minus sign are sub- * * categories of the main word. * * 4.) Words preceeded by a plus sign are stored as * * synonyms AND have their own sub-groups. * * * * Examples: Words preceded by a - are stored as related * * terms but are not stored as synonyms. In the * * following example the word "colors" would pull * * up red, green, and blue. But searching for red * * would only search for red. * * colors * * -red * * -green * * -blue * * * * This allows you to create additional synonym groups * * as subcategories, i.e. Use the + sign if a word in a * * synonym group has its own group. * * * * colors * * +red * * -green * * -blue * * * * red * * reddish * * -ochre * * -brick * * * * Now "red" has its own group and its own set of narrower * * terms. In this case searching for "colors" would pull up * * red, which in turn would pull up the red group. Searching * * "red" or "reddish" would pull up ochre and brick as well. * * However, searching for ochre, brick, green, or blue would * * not pull up any additional synonyms. * * * * The synonyms are not limited to single word entries, they * * can contain any query logic that can be typed in from the * * search screen. This includes parenthetical logic, search * * operators, and even fixed field searches. Note that * * synonyms on different lines are OR'ed together during the * * search processing. * ****************************************************************/ BuildSynonymList() { int key, i, file; int group; int tree; int db; int narrowTerm, expandTerm; char buffer[200]; text screen; /* There must be an opened database when this program starts. */ /* Exit if one isn't available. */ if (db.documents < 0) return(Message("Open a database first.")); /* Get the name of the plain text file containing the synonym */ /* definitions and open it. Exit if it isn't available. */ if (getfile("Input File","*.TXT",buffer) <> CR) return(0); else if ((file = open(buffer,"r")) == EOF) return(Message("Couldn't open the input text file.")); /* Create the synonym b+tree file, it has the database's name */ /* and the .SYN file extension. Exit if we can't create it. */ buffer = db.database+".SYN"; erase(buffer); if ((tree = btcreate(buffer,0)) < 0) { close(file); return(Message("Couldn't create "+buffer)); } key = 0; cursor(0,0); cursoroff(); screen = save(9,39,13,64); scroll(9,39,12,62,0,1,MenuHighlight_); box(9,39,13,64,'dd',MenuHighlight_); puts(10,41,"Lines",MenuHighlight_); puts(11,41,"Groups",MenuHighlight_); group = 1; while((readln(file,buffer) <> EOF) and (key <> ESC)) { /* Display the number of lines and groups processed */ puts(10,50,str(i = i + 1,11,0,','),MenuHighlight_); puts(11,50,str(group,11,0,','),MenuHighlight_); /* If the word has a minus sign in front of it, it */ /* is a narrower term and should not be included as */ /* a major synonym in the synonym grouping. */ /* If the word is preceded by a plus sign, it will */ /* expanded as a synonym itself when pulled by the */ /* major synonym(s) in this group. */ expandTerm = narrowTerm = FALSE; while(buffer[0] and (isalnum(buffer[0]) == FALSE) and (buffer[0] <> '"') and (buffer[0] <> '(')) { switch(buffer[0]) { case '-': narrowTerm = TRUE; break; case '+': narrowTerm = TRUE; expandTerm = TRUE; break; } buffer = substr(buffer,2); } /* Each synonym belongs to a group, increment the */ /* group number whenever we encounter a blank line. */ if (len(buffer = upper(trim(buffer))) == 0) group = group + 1; else { /* Insert this word twice if it didn't have a */ /* + or - sign preceding it. Once as a synonym, */ /* and a second time as a narrower term. */ /* Narrower terms are inserted with an equal */ /* sign preceding them, a 10 digit wide group */ /* number, and then the word itself. The data */ /* value determines if the term can be expanded.*/ if (narrowTerm == FALSE) btinserta(tree,buffer,group); btinserta(tree,"="+str(group,10,0,0)+buffer,expandTerm); } if (keypress()) key = getkey(); } close(file); btclose(tree); restore(9,39,screen); } /* BuildSynonymList() */ /**************************************************************** * Name: Message * * Synopsis: Displays error message and waits for key. * ****************************************************************/ Message(text message) { text screen; int key; cursoroff(); screen = save(5,13,10,69); box(7,13,10,69,"DS", MenuColor_); puts(8,14,pad(message,'C',53),MenuColor_); key = getkey(); restore(5,13,screen); if (islower(key)) key = key - ('a' - 'A'); /* asc(upper(chr(key))); */ return(key); } /* Message() */ /************************************************** ********** Global Variable Declarations *********** **************************************************/ char EOF = -1, ESC = 27, CR = 13, LF = 10; short FALSE, TRUE = 1, F1 = 15104, F2 = 15360, F3 = 15616, F4 = 15872, F5 = 16128, F6 = 16384, F7 = 16640, F8 = 16896, F9 = 17152, F10 = 17408, LEFT = 19200, RIGHT = 19712, PGUP = 18688, PGDN = 20736, HOME = 18176, END = 20224;