int main(int argc, char **argv) { char ch[TailleLigne]; int nb=0; FILE *filein,*fileout=NULL; if (argc<=2) { fprintf(stderr,"Syntaxe : %s <tagged file to split> <output file>\n",argv[0]); exit(0); } if (!(filein=fopen(argv[1],"rt"))) ERREUR("can't open:",argv[1]); while(fgets(ch,TailleLigne,filein)) { if (!strncmp(ch,"<s>",3)) { if (fileout) fclose(fileout); sprintf(ch,"%s.%d",argv[2],++nb); if (!(fileout=fopen(ch,"wt"))) ERREUR("can't write in:",ch); fprintf(fileout,"<s> ZTRM\n"); } else if (fileout) fprintf(fileout,"%s",ch); } fclose(filein); if (fileout) fclose(fileout); }
void add_type_info_from_string(type_info *info,char *key_string,char *desc) { char *item; int i,freq,code; for(item=strtok(desc," \n\t");item;item=strtok(NULL," \n\t"),i++) { /* cat freq lemm */ code=from_POS2code(item); if (code==0) ERREUR("POS unknown:",item); for(i=0;(i<MAX_POS-1)&&(info->l_POS[i]!=0)&&(info->l_POS[i]!=(char)code);i++); if (i>=MAX_POS-1) ERREUR("cste MAX_POS too small for word:",key_string); if (info->l_POS[i]==0) { info->l_POS[i]=code; info->l_freq[i]=0; info->l_lemm[i]=NULL; info->l_POS[i+1]=0; info->l_freq[i+1]=0; info->l_lemm[i+1]=NULL; } item=strtok(NULL," \n\t"); if (item==NULL) ERREUR("bad4 format in:",key_string); if (sscanf(item,"%d",&(freq))!=1) ERREUR("bad format5 in:",key_string); info->l_freq[i]+=freq; item=strtok(NULL," \n\t"); if (item==NULL) ERREUR("bad format6 in:",key_string); if (info->l_lemm[i]==NULL) info->l_lemm[i]=strdup(item); } }
void analyze_tag(char *ch, char **desc, char **type, char **extent) { int i; *desc = *type = *extent = NULL; for (i = 0; ch[i]; i++) if (!strncmp(ch + i, "desc=", 5)) { *desc = ch + i + 6; for (i += 6; (ch[i]) && (ch[i] != '"'); i++); if (!ch[i]) ERREUR("bad format:", ch); ch[i] = '\0'; } else if (!strncmp(ch + i, "type=", 5)) { *type = ch + i + 6; for (i += 6; (ch[i]) && (ch[i] != '"'); i++); if (!ch[i]) ERREUR("bad format:", ch); ch[i] = '\0'; } else if (!strncmp(ch + i, "extent=", 7)) { *extent = ch + i + 8; for (i += 8; (ch[i]) && (ch[i] != '"'); i++); if (!ch[i]) ERREUR("bad format:", ch); ch[i] = '\0'; } }
int main(int argc, char **argv) { char ch[TailleLigne]; int nb,nbentries,i,j; lia_avl_t t_lexique, t_unknown,*table; FILE *file; unsigned long total; if (argc<=2) { fprintf(stderr,"Syntaxe : %s <lexicon> <name report>\n",argv[0]); exit(0); } t_lexique=read_lexicon(argv[1]); t_unknown=checking_corpus(stdin,t_lexique); fprintf(stderr,"- report OOV words\n"); sprintf(ch,"%s.oov",argv[2]); if (!(file=fopen(ch,"wt"))) ERREUR("can't write in :",ch); table=lia_avl_tree2table_freq(t_unknown,&nb); fprintf(stderr,"\t-> %d entree inconnues dans le corpus\n",nb); for(i=0;i<nb;i++) fprintf(file,"\t%5d \t %s\n",table[i]->nb,table[i]->info); fclose(file); free(table); fprintf(stderr,"done\n"); fprintf(stderr,"- report ZEROTON words\n"); sprintf(ch,"%s.zeroton",argv[2]); if (!(file=fopen(ch,"wt"))) ERREUR("can't write in :",ch); table=lia_avl_tree2table_freq(t_lexique,&nb); for(i=j=0;i<nb;i++) if (table[i]->nb==1) { j++; fprintf(file,"%s\n",table[i]->info); } fclose(file); fprintf(stderr,"\t-> %d ZEROTON dans le corpus\n",j); fprintf(stderr,"done\n"); fprintf(stderr,"- report words from the lexicon in the corpus\n"); sprintf(ch,"%s.occ",argv[2]); if (!(file=fopen(ch,"wt"))) ERREUR("can't write in :",ch); for(nbentries=0,i=0,total=0;i<nb;i++) if (table[i]->nb>1) { nbentries++; total+=(unsigned long)(table[i]->nb-1); fprintf(file,"\t%5d \t %s\n",table[i]->nb-1,table[i]->info); } free(table); fclose(file); fprintf(stderr,"\t-> %ld occurences for %d entries\n",total,nbentries); fprintf(stderr,"done\n"); exit(0); }
void debut() { BITMAP *deb = load_bitmap("media/debut.bmp", NULL); if(deb == NULL) ERREUR("Echec chargement intro"); blit(deb, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H); readkey(); }
void add_table( Table* table, const intptr_t cle, intptr_t valeur ) { Table_association* asso = creer_table_association(table, cle, valeur); void* val = avl_probe ( table->root, (void*) asso ); if( val == NULL ) { ERREUR( "Espace insuffisant" ); } Table_association* asso_tree = *( Table_association** ) val; if( asso_tree != asso ) { supprimer_table_association( asso ); asso_tree->valeur = valeur; } }
void gameover() { BITMAP *fin = load_bitmap("media/gameover.bmp", NULL); if(fin == NULL) ERREUR("Echec chargement fin"); blit(fin, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H); textprintf_centre_ex(screen, font, SCREEN_W/2, SCREEN_H/2, makecol(0, 0, 0), makecol(255, 0, 0), " Score : %d ", score); while(keypressed()) readkey(); rest(2000); readkey(); }
void analyze_pos(char *ch, char **chid, char **chpos, char **chword) { int i; for (i = 0; (ch[i]) && (strncmp(ch + i, "token=", 6)); i++); if (!ch[i]) ERREUR("bad POS string:", ch); (*chid) = ch + i + 7; for (i += 7; (ch[i]) && (ch[i] != '"'); i++); if (!ch[i]) ERREUR("bad POS string:", ch); ch[i] = '\0'; for (++i; (ch[i]) && (strncmp(ch + i, "pos=", 4)); i++); if (!ch[i]) ERREUR("bad POS string:", ch); (*chpos) = ch + i + 5; for (i += 5; (ch[i]) && (ch[i] != '"'); i++); if (!ch[i]) ERREUR("bad POS string:", ch); ch[i] = '\0'; for (++i; (ch[i]) && (ch[i] != '>'); i++); if (!ch[i]) ERREUR("bad POS string:", ch); for (++i; (ch[i]) && (ch[i] == ' '); i++); (*chword) = ch + i; for (++i; (ch[i]) && (ch[i] != ' ') && (ch[i] != '<'); i++); if (!ch[i]) ERREUR("bad POS string:", ch); ch[i] = '\0'; }
lia_avl_t read_lexicon(char *filename) { FILE *file; static char ch[TailleLigne],*pt; lia_avl_t resu; if (!(file=fopen(filename,"rt"))) ERREUR("can't open:",filename); for (resu=NULL;fgets(ch,TailleLigne,file);) for(pt=strtok(ch," \t\n");pt;pt=strtok(NULL," \t\n")) resu=lia_ajoute_element_avl(resu,pt,True,NULL); fclose(file); return resu; }
type_info *new_type_info(char *key_string,char *desc) { type_info *pt; char *item; int i; pt=(type_info *)malloc(sizeof(type_info)); if (key_string) pt->key_string=strdup(key_string); else key_string=NULL; for(i=0,item=strtok(desc," \n\t");item;item=strtok(NULL," \n\t"),i++) { /* cat freq lemm */ if (i==MAX_POS-1) ERREUR("cste MAX_POS too small for word:",key_string); pt->l_POS[i]=(char)from_POS2code(item); if (pt->l_POS[i]==0) ERREUR("POS unknown:",item); item=strtok(NULL," \n\t"); if (item==NULL) ERREUR("bad format1 in:",key_string); if (sscanf(item,"%d",&(pt->l_freq[i]))!=1) ERREUR("bad format2 in:",key_string); item=strtok(NULL," \n\t"); if (item==NULL) ERREUR("bad format3 in:",key_string); pt->l_lemm[i]=strdup(item); } pt->l_POS[i]=0; pt->l_freq[i]=0; pt->l_lemm[i]=NULL; return pt; }
int main(int argc, char **argv) { char ch[TailleLigne],*key_string,*desc; int nb; lia_avl_t biglex; type_info *info; for(biglex=NULL,nb=0;fgets(ch,TailleLigne,stdin);nb++) { key_string=strtok(ch," \t\n"); if (key_string) desc=strtok(NULL,"\n"); else desc=NULL; if ((key_string==NULL)||(desc==NULL)) ERREUR("bad format8 in:",ch); info=new_type_info(key_string,desc); biglex=lia_ajoute_element_avl(biglex,info,True,NULL); } lia_affiche_avl_simple(biglex,stdout); exit(0); }
void add_type_info(type_info *info1, type_info *info2) /* from info1 to info2 */ { int n,i,freq,code; for(n=0;(n<MAX_POS-1)&&(info1->l_POS[n]!=0);n++) { for(i=0;(i<MAX_POS-1)&&(info2->l_POS[i]!=0)&&(info2->l_POS[i]!=info1->l_POS[n]);i++); if (i>=MAX_POS-1) ERREUR("cste MAX_POS too small for word:",info1->key_string); if (info2->l_POS[i]==0) { info2->l_POS[i]=info1->l_POS[n]; info2->l_freq[i]=info1->l_freq[n]; info2->l_lemm[i]=strdup(info1->l_lemm[n]); info2->l_POS[i+1]=0; info2->l_freq[i+1]=0; info2->l_lemm[i+1]=NULL; } else info2->l_freq[i]+=info1->l_freq[n]; } }
int main(int argc, char **argv) { char ch[TailleLigne], ch2[TailleLigne], *chid, *chpos, *chword, *chdesc, *chtype, *chextent, chNE[100]; int nb, insent, i, j, beginNE; FILE *file_tk, *file_pos; file_tk = file_pos = NULL; if (argc > 1) for (nb = 1; nb < argc; nb++) if (!strcmp(argv[nb], "-tk")) { if (nb + 1 == argc) ERREUR("an option must follow option:", argv[nb]); if (!(file_tk = fopen(argv[++nb], "rt"))) ERREUR("can't open:", argv[nb]); } else if (!strcmp(argv[nb], "-pos")) { if (nb + 1 == argc) ERREUR("an option must follow option:", argv[nb]); if (!(file_pos = fopen(argv[++nb], "rt"))) ERREUR("can't open:", argv[nb]); } else if (!strcmp(argv[nb], "-h")) { fprintf(stderr, "Syntax: %s [-h] -tk <file> -pos <file>\n", argv[0]); exit(0); } else ERREUR("unknown option:", argv[nb]); if ((!file_tk) || (!file_pos)) ERREUR("bad syntax, check '-h'", ""); while ((fgets(ch2, TailleLigne, file_pos)) && (!strstr(ch2, "<word"))); if (!feof(file_pos)) analyze_pos(ch2, &chid, &chpos, &chword); else ERREUR("empty POS file ??", ""); for (chNE[0] = '\0', beginNE = insent = False, nb = 0; fgets(ch, TailleLigne, file_tk); nb++) if (strstr(ch, "<tokens")) insent = True; else if (strstr(ch, "</tokens")) { insent = False; printf("\n"); } else if (insent) { if (strstr(ch, "<token ")) if (!strstr(ch, "sgmltag")) { if (chid == NULL) ERREUR("files TOKEN and POS are not synchronized !!", ""); for (i = 0; (ch[i]) && (strncmp(ch + i, "id=", 3)); i++); if (!ch[i]) ERREUR("bad token string:", ch); for (j = i + 4; (ch[j]) && (ch[j] != '"'); j++); if (!ch[j]) ERREUR("bad token string:", ch); ch[j] = '\0'; /* * printf("[%s] == * [%s]\n",ch+i+4,chid) ; */ if (!strcmp(ch + i + 4, chid)) { printf("%s\t%s\t", chword, chpos); if (chNE[0]) printf("%c-%s\n", beginNE ? 'B' : 'I', chNE); else printf("O\n"); while ((fgets(ch2, TailleLigne, file_pos)) && (!strstr(ch2, "<word"))); if (!feof(file_pos)) analyze_pos(ch2, &chid, &chpos, &chword); else chid = chpos = chword = NULL; } beginNE = False; } else { analyze_tag(ch, &chdesc, &chtype, &chextent); if (!strcmp(chtype, "entities")) { if (!strcmp(chextent, "begin")) { for (i = 0; (chdesc[i]) && (chdesc[i] != '.'); i++) chNE[i] = SI_MINUSCULE(chdesc[i]) ? chdesc[i] - ('a' - 'A') : chdesc[i]; chNE[i] = '\0'; beginNE = True; } else { beginNE = False; chNE[0] = '\0'; } } } } exit(0); }
int main() { // Ressources unsigned long t_debut, t_fin; float dt, waitShoot = 0; BITMAP *buffer; int fin = 0, v = 200; Map *map; DepthList *depthList; Rect screen_pos, map_pos; Actor *joueur; // Initialisation fprintf(stderr,"Initialisation ...\n"); timeBeginPeriod(1); set_uformat(U_ASCII); set_color_depth(32); allegro_init(); install_keyboard(); install_mouse(); srand(time(NULL)); if(set_gfx_mode(GFX_AUTODETECT_WINDOWED, 1024, 768, 0, 0)) ERREUR("Echec du lancement du mode graphique."); buffer = create_bitmap(SCREEN_W, SCREEN_H); resman_loadSprites(); fprintf(stderr,"Chargement des ressources ...\n"); map = new_map("media/map/test1"); map_pos.x = map_pos.y = 0; map_pos.w = map->w; map_pos.h = map->h; actList = new_glist(); root = new_tree(map_pos); map_addEntities(map, actList, root); depthList = new_dlist(); screen_pos.w = SCREEN_W; screen_pos.h = SCREEN_H; // Ajout du joueur joueur = actor_addJoueur(actList, root, 500, 500); // Intro debut(); // Boucle principale fprintf(stderr,"Debut !\n"); t_debut = timeGetTime(); while(!fin) { // Gestion clavier if(key[KEY_ESC]) { fin = 1; } if(key[KEY_W]) { joueur->vit_y = -v; joueur->direction_regard = HAUT; joueur->etat = ETAT_MARCHE; } else if(key[KEY_S]) { joueur->vit_y = v; joueur->direction_regard = BAS; joueur->etat = ETAT_MARCHE; } else joueur->vit_y = 0; if(key[KEY_A]) { joueur->vit_x = -v; joueur->direction_regard = GAUCHE; joueur->etat = ETAT_MARCHE; } else if(key[KEY_D]) { joueur->vit_x = v; joueur->direction_regard = DROITE; joueur->etat = ETAT_MARCHE; } else joueur->vit_x = 0; if(joueur->vit_x != 0 && joueur->vit_y != 0) { joueur->vit_x /= sqrt(2); joueur->vit_y /= sqrt(2); } if(!key[KEY_W] && !key[KEY_D] && !key[KEY_S] && !key[KEY_A]) joueur->etat = ETAT_REPOS; if(key[KEY_Q]) { if(waitShoot <= 0) { waitShoot = .1; actor_addTree(actList, root, mouse_x + screen_pos.x, mouse_y + screen_pos.y); } } waitShoot -= dt; if(mouse_b&1) { float vx, vy, v; if(waitShoot <= 0) { waitShoot = .3; vx = mouse_x - (joueur->pos_x - screen_pos.x); vy = mouse_y - (joueur->pos_y - screen_pos.y); v = sqrt(vx*vx + vy*vy); vx = vx/v; vy = vy/v; actor_addMissile(actList, root, joueur->pos_x + vx*joueur->w*1.5, joueur->pos_y + vy*joueur->h*1.5, vx*300, vy*300); } } if(key[KEY_P]) { FILE *fd = fopen("arbres.txt", "w+"); Actor *act; glist_startIter(actList); while(!glist_endIter(actList)) { act = glist_getCurrentData(actList); if(act->type == ACT_TREE) fprintf(fd, "%d\n%d\n", (int) act->pos_x, (int) act->pos_y); glist_iter(actList); } fclose(fd); } // Double buffer clear_bitmap(buffer); render_map(buffer, map, screen_pos.x, screen_pos.y); // Mises à jour resman_updateSprites(&dt); actor_spawnMonster(actList, root); actor_ia(actList, joueur); // Deplacement glist_startIter(actList); while(!glist_endIter(actList)) { actor_update(glist_getCurrentData(actList), map_pos, map, dt); if( ((Actor*) glist_getCurrentData(actList))->deleting) { glist_remCell(actList, glist_getCurrentId(actList)); } else glist_iter(actList); } // Cadrage ecran screen_pos.x = joueur->pos_x - SCREEN_W/2; screen_pos.y = joueur->pos_y - SCREEN_H/2; // Collision tree_collisionDetection(root); // Affichage tree_update(root); dlist_getActorsFromTree(depthList, root, screen_pos); dlist_update(depthList, screen_pos); dlist_blit(depthList, buffer, screen_pos); draw_cursor(buffer); textprintf_centre_ex(buffer, font, SCREEN_W/2, 5, makecol(0, 0, 0), makecol(255, 0, 0), " Vies restantes : %d | Score : %d ", joueur->vie, score); // Rafraichissement écran vsync(); blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H); // Gestion du temps t_fin = timeGetTime(); dt = ((float)t_fin - t_debut)/1000; t_debut = t_fin; // Test fin de jeu if(joueur->deleting) fin = 1; resman_freeList(); } // Game over gameover(); // Fin timeEndPeriod(1); delete_map(map); del_tree(root); del_dlist(depthList); del_glist(actList); destroy_bitmap(buffer); resman_freeSprites(); allegro_exit(); return 0; }