Exemplo n.º 1
0
cassys_tokens_list *add_replaced_text( const char *text, cassys_tokens_list *list,
		 int transducer_id, const char *alphabet_name,int mask_encoding_compatibility_input) {


	Alphabet *alphabet = load_alphabet(alphabet_name);

	struct snt_files *snt_text_files = new_snt_files(text);

	struct fifo *stage_concord = read_concord_file(snt_text_files->concord_ind, mask_encoding_compatibility_input);

	// performance enhancement
	cassys_tokens_list *current_list_position = list;
	long current_token_position = 0;

	int nb_sentence = 0;
	while (!is_empty(stage_concord)) {
		nb_sentence++;

		locate_pos *l = (locate_pos*) take_ptr(stage_concord);

		struct list_ustring *new_sentence_lu = cassys_tokenize_word_by_word(l->label,
				alphabet);

		cassys_tokens_list *new_sentence_ctl =
				new_list(new_sentence_lu, transducer_id);

		// performance enhancement :
		// Since matches are sorted, we begin the search from the last known position in the list.
		// We have to substract from the text position the current token position.
		cassys_tokens_list *list_position = get_element_at(current_list_position, transducer_id - 1,
				l->token_start_offset - current_token_position);

		int replaced_sentence_length = l->token_end_offset
				- l->token_start_offset+1;
		int new_sentence_length = length(new_sentence_lu);

		add_output(list_position, new_sentence_ctl, transducer_id,
				replaced_sentence_length, new_sentence_length-1);


		// performance enhancement
		current_list_position = list_position;
		current_token_position = l-> token_start_offset;

		free(l->label);
		free(l);
		free_list_ustring(new_sentence_lu);
	}

	free_fifo(stage_concord);
	free_snt_files(snt_text_files);
    free_alphabet(alphabet);

	return list;
}
Exemplo n.º 2
0
void		free_fifo(t_fifo *fifo)
{
  t_fifo_elem	*tmp;
  t_fifo_elem	*next;

  tmp = NULL;
  if (fifo != NULL)
    tmp = fifo->cur;
  while (tmp != NULL)
    {
      next = tmp->next;
      if (tmp->down != NULL)
	{
	  fifo->cur = tmp->down;
	  free_fifo(fifo);
	}
      free_argv(tmp->data.argv);
      free(tmp);
      tmp = next;
    }
}
Exemplo n.º 3
0
Arquivo: lifo.c Projeto: vlnk/isima
void inversion_pile(lifo_t * p)
{
    /*variables locales*/
    fifo_t *        f = NULL;   /*file*/
    type_t          tmp;        /*valeurs a afficher*/
    int             err;        /*erreur*/

    /*initialisation*/
    f = (fifo_t *)malloc(sizeof(fifo_t));
    err = init_fifo(f,p->t_max);

    if (! err)
    {
        printf("Pile a inverser :\n");
        afficher_lifo(p);

        /*parcours de la pile*/
        while (!lifo_vide(p))
        {
            tmp = depiler(p);   /*passage des valeurs*/
            enfiler(f,tmp);
        }

        printf("Etat de la file :\n");
        afficher_fifo(f);

        while (! fifo_vide(f))
        {
            tmp = defiler(f);   /*passage des valeurs*/
            empiler(p,tmp);
        }

        /*liberation de la file*/
        free_fifo(f);
    }

    printf("Pile inversee :\n");
    afficher_lifo(p);
}
Exemplo n.º 4
0
int main_Cassys(int argc,char* const argv[]) {
	if (argc==1) {
		usage();
		return 0;
	}

	char transducer_list_file_name[FILENAME_MAX];
	bool has_transducer_list = false;

	char text_file_name[FILENAME_MAX];
	bool has_text_file_name = false;

	char alphabet_file_name[FILENAME_MAX];
    char transducer_filename_prefix[FILENAME_MAX];
	bool has_alphabet = false;
    char negation_operator[0x20];

	Encoding encoding_output = DEFAULT_ENCODING_OUTPUT;
	int bom_output = DEFAULT_BOM_OUTPUT;
	int mask_encoding_compatibility_input = DEFAULT_MASK_ENCODING_COMPATIBILITY_INPUT;
    int must_create_directory = 1;
    int in_place = 0;

    struct transducer_name_and_mode_linked_list* transducer_name_and_mode_linked_list_arg=NULL;

	// decode the command line
	int val;
	int index = 1;
    negation_operator[0]='\0';
    transducer_filename_prefix[0]='\0';
	struct OptVars* vars=new_OptVars();
	while (EOF != (val = getopt_long_TS(argc, argv, optstring_Cassys,
			lopts_Cassys, &index, vars))) {
		switch (val) {
		case 'h': usage(); 
                  free_OptVars(vars);
                  free_transducer_name_and_mode_linked_list(transducer_name_and_mode_linked_list_arg); 
                  return 0;
		case 'k': if (vars->optarg[0]=='\0') {
                fatal_error("Empty input_encoding argument\n");
             }
             decode_reading_encoding_parameter(&mask_encoding_compatibility_input,vars->optarg);
             break;
		case 'q': if (vars->optarg[0]=='\0') {
                fatal_error("Empty output_encoding argument\n");
             }
             decode_writing_encoding_parameter(&encoding_output,&bom_output,vars->optarg);
             break;
		case 't': {
			if (vars -> optarg[0] == '\0') {
				fatal_error("Command line error : Empty file name argument\n");
			}

			char extension_text_name[FILENAME_MAX];
			get_extension(vars -> optarg, extension_text_name);
			if (strcmp(extension_text_name, ".snt") != 0) {
				fatal_error(
						"Command line error : File name argument %s must be a preprocessed snt file\n",
						vars -> optarg);
			}

			strcpy(text_file_name, vars -> optarg);
			has_text_file_name = true;

			break;
		}
		case 'l': {
			if(vars -> optarg[0] == '\0'){
				fatal_error("Command line error : Empty transducer list argument\n");
			} else {
				strcpy(transducer_list_file_name, vars -> optarg);
				has_transducer_list = true;
			}
			break;
		}
		case 'r': {
			if(vars -> optarg[0] == '\0'){
				fatal_error("Command line error : Empty transducer directory argument\n");
			} else {
				strcpy(transducer_filename_prefix, vars -> optarg);
				has_transducer_list = true;
			}
			break;
		}
		case 's': {
			if(vars -> optarg[0] == '\0'){
				fatal_error("Command line error : Empty transducer filename argument\n");
			} else {
				transducer_name_and_mode_linked_list_arg=add_transducer_linked_list_new_name(transducer_name_and_mode_linked_list_arg,vars -> optarg);
			}
			break;
		}
		case 'm': {
			if(vars -> optarg[0] == '\0'){
				fatal_error("Command line error : Empty transducer mode argument\n");
			} else {
				set_last_transducer_linked_list_mode_by_string(transducer_name_and_mode_linked_list_arg,vars -> optarg);
			}
			break;
		}
		case 'a':{
			if (vars -> optarg[0] == '\0') {
				fatal_error("Command line error : Empty alphabet argument\n");
			} else {
				strcpy(alphabet_file_name, vars -> optarg);
				has_alphabet = true;
			}
			break;
		}
   	    case 'g': if (vars->optarg[0]=='\0') {
                fatal_error("You must specify an argument for negation operator\n");
             }
             if ((strcmp(vars->optarg,"minus")!=0) && (strcmp(vars->optarg,"-")!=0) && 
                 (strcmp(vars->optarg,"tilde")!=0) && (strcmp(vars->optarg,"~")!=0))
             {
                 fatal_error("You must specify a valid argument for negation operator\n");
             }
             strcpy(negation_operator,vars->optarg);
             break;
        case 'i': {
            in_place = 1;
			break;
		}
        case 'd': {
            must_create_directory = 0;
			break;
		}
		default :{
			fatal_error("Unknown option : %c\n",val);
			break;
		}
		}
	}
	index = -1;

	if(has_alphabet == false){
		fatal_error("Command line error : no alphabet provided\nRerun with --help\n");
	}
	if(has_text_file_name == false){
		fatal_error("Command line error : no text file provided\nRerun with --help\n");
	}
	if((has_transducer_list == false) && (transducer_name_and_mode_linked_list_arg == NULL)){
		fatal_error("Command line error : no transducer list provided\nRerun with --help\n");
	}



	// Load the list of transducers from the file transducer list and stores it in a list
	//struct fifo *transducer_list = load_transducer(transducer_list_file_name);
    if ((transducer_name_and_mode_linked_list_arg == NULL) && has_transducer_list)
        transducer_name_and_mode_linked_list_arg = load_transducer_list_file(transducer_list_file_name);
    struct fifo *transducer_list=load_transducer_from_linked_list(transducer_name_and_mode_linked_list_arg,transducer_filename_prefix);

	cascade(text_file_name, in_place, must_create_directory, transducer_list, alphabet_file_name,negation_operator,encoding_output,bom_output,mask_encoding_compatibility_input);
	free_fifo(transducer_list);
    free_OptVars(vars);
    free_transducer_name_and_mode_linked_list(transducer_name_and_mode_linked_list_arg);
	return 0;
}
Exemplo n.º 5
0
int main (int argc, char** argv)
{
  bound_t* limit; /* limites globais */
  cdf_t* dict;   /* o dicionario com simbolos */
  FILE* msg; /* o arquivo com a mensagem codificada */
  FILE* dmsg; /* o arquivo com a mensagem decodificada */
  fifo_t* coded; /* a mensagem codificada */
  unsigned long buff; /* caracter decodificado */
  clock_t start, end; /* cronometro */
  double cpu_time_used;
  unsigned long lsize; /* um contador */

#ifdef DEBUGGING
  mtrace();
#endif

  if (argc != 3) {
    fprintf(stderr, "uso: %s <dicionario> <arquivo-codificada>\n", argv[0]);
    exit(1);
  }

  /* carrega dicionario */
  dict = cdf_load(argv[1]);

  /* inicializa limites */
  limit = init_bound(); /* ajusta limites para 0 e 1 */
  cdf_min_ulimit(dict,limit); /* ajusta limite */

  /* inicializa fifo com a mensagem a ser decodificada */
  coded = init_fifo();
  if ( (msg = fopen(argv[2],"r")) == NULL ) {
    perror("[test_encode] *ERROR* ");
    exit(1);
  }
  fifo_load(coded, msg);
  fclose(msg);
#ifdef DEBUGGING
  fprintf(stderr, "[test_decode] fifo inicializada.\n");
#endif

  /* decodifica mensagem */
  if ( (dmsg = fopen("decoded.mesg","w")) == NULL ) {
    perror("[test_encode] *ERROR* ");
    exit(1);
  }

  lsize = 0;
  start = clock();
  for (;;) /* forever */ {
    arith_decode(dict, coded, limit, &buff);
    if ( buff == cdf_terminator(dict) ) break;
    ++lsize;
    fprintf(dmsg, "%lu\n", buff);
  }
  end = clock();
  cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC;
  fclose(dmsg);
    
  fprintf(stderr, "[test_decode] mensagem decodificada,");
  fprintf(stderr, " %lu simbolos\n", lsize);
  fprintf(stderr, "[test_cdf] Tempo total = %e s\n",cpu_time_used);
  fprintf(stderr, "[test_cdf] Por simbolo ~= %e s\n",cpu_time_used/lsize);

  /* libera memoria alocada */
  free_bound(limit);
  free_cdf(dict);
  free_fifo(coded);

  return 0;
}