C:/Users/Dennis/src/lang/Life_start/Life/life-1.02/source/arity.c

Go to the documentation of this file.
00001 /*      $Id: arity.c,v 1.2 1994/12/08 23:03:22 duchier Exp $     */
00002 
00003 #ifndef lint
00004 static char vcid[] = "$Id: arity.c,v 1.2 1994/12/08 23:03:22 duchier Exp $";
00005 #endif /* lint */
00006 
00007 static int dummy;
00008 
00009 #ifdef ARITY
00010 
00011 #include "extern.h"
00012 #include "trees.h"
00013 
00014 FILE *features;
00015 static int Aunif=0;
00016 static int Amerge=0;
00017 static int Aadd=0;
00018 static int Atop=0;
00019 static int Atoptop=0;
00020 static int Auid=0;
00021 static int Audiff=0;
00022 static int Anil=0;
00023 static int Anilnil=0;
00024 static int Aident=0;
00025 static int Adiff=0;
00026 static int Aglb=0;
00027 
00028 
00029 #define PERUNIF(X)  X,100.0*((double)X/(double)Aunif)
00030 #define PERMERGE(X)  X,100.0*((double)X/(double)Amerge)
00031 
00032 
00033 void arity_init()
00034 {
00035   /*
00036   features=fopen("/udir/rmeyer/LIFE/MODULE/features","w");
00037   if(!features) {
00038     Errorline("Couldn't open feature log file\n");
00039     abort_life();
00040   }
00041   */
00042 }
00043 
00044 
00045 void arity_end()
00046 {
00047   
00048   /* fclose(features); */
00049   
00050   features=fopen("/udir/rmeyer/LIFE/MODULE/profile","w");
00051   if(features) {
00052     fprintf(features,"---- Unifications and Features ----\n\n");
00053     
00054     fprintf(features,"add feature: %d\n\n",Aadd);
00055     
00056     fprintf(features,"unify: %d\n",Aunif);
00057     fprintf(features,"types:\n");
00058     fprintf(features,"\ttop-top: %d = %3.1lf\n",PERUNIF(Atoptop));
00059     fprintf(features,"\ttop-X: %d = %3.1lf\n",PERUNIF(Atop));
00060     fprintf(features,"\tX-X: %d = %3.1lf\n",PERUNIF(Auid));
00061     fprintf(features,"\tX-Y: %d = %3.1lf\n",PERUNIF(Audiff));
00062     fprintf(features,"\tGLB: %d = %3.1lf\n",PERUNIF(Aglb));
00063 
00064     fprintf(features,"merges: %d = %3.1lf\n",PERUNIF(Amerge));
00065 
00066     fprintf(features,"\tnil-nil: %d = %3.1lf\n",PERMERGE(Anilnil));
00067     fprintf(features,"\tnil-X: %d = %3.1lf\n",PERMERGE(Anil));
00068     fprintf(features,"\tX-X: %d = %3.1lf\n",PERMERGE(Aident));
00069     fprintf(features,"\tX-Y: %d = %3.1lf\n",PERMERGE(Adiff));
00070     
00071     fclose(features);
00072   }
00073 }
00074 
00075 
00076 
00077 void rec_print_feat(n)
00078      
00079      ptr_node n;
00080 {
00081   if(n) {
00082     if(n->left) {
00083       rec_print_feat(n->left);
00084       fprintf(features,",");
00085     }
00086     
00087     fprintf(features,n->key);
00088     
00089     if(n->right) {
00090       fprintf(features,",");
00091       rec_print_feat(n->right);
00092     }
00093   }
00094 }
00095 
00096 
00097 
00098 void print_features(u)
00099 
00100      ptr_node u;
00101 {
00102   fprintf(features,"(");
00103   rec_print_feat(u);
00104   fprintf(features,")");
00105 }
00106 
00107 
00108 
00109 int check_equal(u,v)
00110 
00111      ptr_node u;
00112      ptr_node v;
00113 {
00114   int same=TRUE;
00115   
00116   if(u) {
00117     same=check_equal(u->left,v) &&
00118       find(featcmp,u->key,v) &&
00119         check_equal(u->right,v);
00120   }
00121 
00122   return same;
00123 }
00124 
00125 
00126 
00127 void arity_unify(u,v)
00128      ptr_psi_term u;
00129      ptr_psi_term v;
00130 {
00131   Aunif++;
00132 
00133   if(u->type==top)
00134     if(v->type==top)
00135       Atoptop++;
00136     else
00137       Atop++;
00138   else
00139     if(v->type==top)
00140       Atop++;
00141     else
00142       if(u->type==v->type)
00143         Auid++;
00144       else
00145         if(u->type->children || v->type->children)
00146           Aglb++;
00147         else
00148           Audiff++;
00149 
00150   /*
00151     fprintf(features,
00152     "unify: %s %s\n",
00153     u->type->keyword->symbol,
00154     v->type->keyword->symbol);
00155     */
00156 }
00157 
00158 
00159 
00160 void arity_merge(u,v)
00161      ptr_node u;
00162      ptr_node v;
00163 {
00164   Amerge++;
00165   
00166   if(u)
00167     if(v)
00168       if(check_equal(u,v))
00169         Aident++;
00170       else
00171         Adiff++;
00172     else
00173       Anil++;
00174   else
00175     if(v)
00176       Anil++;
00177     else
00178       Anilnil++;
00179 
00180   /*
00181     fprintf(features,"merge: ");
00182     print_features(u);
00183     fprintf(features," ");
00184     print_features(v);
00185     fprintf(features,"\n");
00186     */
00187 }
00188 
00189 
00190 
00191 void arity_add(u,s)
00192 
00193      ptr_psi_term u;
00194      char *s;
00195 {
00196   Aadd++;
00197 
00198   /*
00199   fprintf(features,"add %s to %s",s,u->type->keyword->symbol);
00200   print_features(u->attr_list);
00201   fprintf(features,"\n");
00202   */
00203 }
00204 
00205 #endif

Generated on Sat Jan 26 08:48:06 2008 for WildLife by  doxygen 1.5.4