File: homonym.c

package info (click to toggle)
acedb 4.9.39+dfsg.02-5
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 33,796 kB
  • sloc: ansic: 256,989; perl: 2,803; cpp: 2,534; csh: 1,712; python: 862; sh: 658; makefile: 300; awk: 249; lex: 225; yacc: 221
file content (184 lines) | stat: -rw-r--r-- 5,311 bytes parent folder | download | duplicates (3)
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
/*  File: homonym.c
 *  Author: Fred Wobus (fw@sanger.ac.uk)
 *  Copyright (c) J Thierry-Mieg and R Durbin, 1999
 * -------------------------------------------------------------------
 * Acedb is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 * or see the on-line version at http://www.gnu.org/copyleft/gpl.txt
 * -------------------------------------------------------------------
 * This file is part of the ACEDB genome database package, written by
 * 	Richard Durbin (Sanger Centre, UK) rd@sanger.ac.uk, and
 *	Jean Thierry-Mieg (CRBM du CNRS, France) mieg@kaa.crbm.cnrs-mop.fr
 *
 * Description: 
 *      The pupose of this stand alone is to resolve the orthograph conflicts
 *      in author names. It takes as  arguments, a homonym file of the form
 * 
 * correct_name AA =
 * alias1 posibly with several words =
 * alias2 no double quotes expected 
 * dummyentry
 * newname =
 * newalias
 * 
 *    and reads from an ace file.
 *    It will act only on the author entries of the ace file and, on these
 *    will replace the occurences of alias by the correct name 
 * 
 * Exported functions:
 * HISTORY:
 * Last edited: Aug 26 17:25 1999 (fw)
 * * Aug 26 17:25 1999 (fw): added this header
 * Created: Thu Aug 26 17:24:38 1999 (fw)
 * CVS info:   $Id: homonym.c,v 1.3 1999/09/01 11:26:55 fw Exp $
 *-------------------------------------------------------------------
 */

#define ARRAY_NO_CHECK

#include "regular.h"
#include "array.h"

static Stack ss = 0 ;
static Array alias = 0 ;
static int line = 0, transfo = 0 , nnew = 0 ;

typedef struct {int bad; int good; } ALIAS ;

/****************************************************************/

static void scanInput(void)
{  char *cp , cutter ; register int i , n ;
   FILE *new = fopen("newnames","w") ;
   
   if (!new)
     messcrash("Can't open the newname file") ;
 fprintf(stderr,"I begin the scan line %d\n", line) ;
  while(line++ , freeread(stdin))
    { cp = freeword() ;
      if(!cp)
	{ printf("\n") ; continue ;}
      if (   strcmp("Author",cp)
          && strcmp("Mapper",cp)
          && strcmp("From_Author",cp)
          && strcmp("Representative",cp)
	  )  /* Just copy the whole line to the output */
	{ freeback() ;
	  printf("%s\n", freewordcut("\n",&cutter)) ;
	  continue ;
	}
          /* Found author, do check */
      printf("%s : \"",cp) ;
      freenext() ; freestep(':') ; freenext() ;
      cp = freeword() ;
      if(cp)
	{ i = arrayMax(alias) ;
	  while(i--)
	    if(!strcmp(cp,stackText(ss,arr(alias,i,ALIAS).good)))
	      goto found;
	    else if( (n = arr(alias,i,ALIAS).bad) &&
		      !strcmp(cp,stackText(ss,n)))
	      { cp = stackText(ss,arr(alias,i,ALIAS).good) ;
		transfo++ ;
		goto found ;
	      }
	  nnew++ ;
	  fprintf(new,"%s\n",cp) ;
	found: 
	  printf("%s", cp) ;
	}
      printf("\"\n") ;
    }
   filclose(new) ;
}


/****************************************************************/

static BOOL readRules(char *name)
{
  FILE *f = fopen(name,"r") ;
  int nA = 0 , n ;
  char *cp , *cq , cutter ;
  BOOL found = FALSE ;
  int lastnA = 0 ;

  if(!f)
    { fprintf(stdout, "Cannot open the homonym file %s", name) ;
      return FALSE ;
    }

  ss = stackCreate(1000) ;
  pushText(ss,"dummy") ;
  alias = arrayCreate(100, ALIAS) ;

  while (freeread(f))
   if(cp = freewordcut("\n",&cutter))
     { cq = cp + strlen(cp) - 1 ;
       while(cq > cp && *cq == ' ') cq--;
       if(*cq == '=')
	 { *cq = ' ' ;
           found = TRUE ;
	   while(cq > cp && *cq == ' ') cq--;
	   *++cq = 0 ;
	   n = stackMark(ss) ;
	   pushText(ss,cp) ;
           array(alias, nA++,ALIAS).bad = n ;
	 }
       else
	 if (found)
	   { found = FALSE ;
	     *++cq = 0 ;
	     n = stackMark(ss) ;
	     pushText(ss,cp) ;
	     for ( ;lastnA <nA; lastnA++)
	       array(alias, lastnA,ALIAS).good = n ;
	   }
	 else
	   { array(alias, nA++,ALIAS).bad = 0 ;
	     *++cq = 0 ;
	     n = stackMark(ss) ;
	     pushText(ss,cp) ;
	     for ( ;lastnA <nA; lastnA++)
	       array(alias, lastnA,ALIAS).good = n ;
	   }
     }
  fprintf(stderr,"Found %d alias to eliminate\n",nA) ;
  filclose(f) ;
  return nA > 0 ? TRUE : FALSE ;
}

/****************************************************************/

void main (int argc, char **arg)
{
  if (argc != 2)
    { fprintf (stderr,
	       "Usage : homonym homoFile < input > output \n") ;
      return ;
    }
 
  freeinit() ;
  if(readRules(arg[1]))
    scanInput() ; 

  fprintf(stderr,"\n done, scanned %d lines, did %d transformations\n found %d new names ",
	  line, transfo, nnew ) ;
}

/****************************************************************/
/****************************************************************/