Esempio n. 1
0
void transform_text(const char *source_path, const char *dest_path)
{
    FILE *source;
    FILE *dest;
    char *word;
    int offset;

    INFO("Début transformation TEXTE");

    INFO("Ouverture du fichier source : %s", source_path);
    source = fopen(source_path, "r");

    INFO("Ouverture du fichier destination : %s", dest_path);
    dest = fopen(dest_path, "w");

    INFO("Transformation du fichier");
    word = extract_word(source, &islatin1, &latin1_to_ascii, &offset);
    if (word != NULL) {
        fprintf(dest,"%s", word);
        free(word);

        while((word=extract_word(source, &islatin1, &latin1_to_ascii, &offset))
                != NULL){
            fprintf(dest, " %s", word);
            free(word);
        }
    }

    INFO("Fermeture des fichiers");
    fclose(source);
    fclose(dest);

    INFO("Fin transformation TEXTE");
}
Esempio n. 2
0
/* Extract angle from the Message */
void can_proc_set_stop_msg( sCAN* mMsg )
{
	if (mMsg->data[0] == 1)
	{
		EndPoint1.angle = extract_long_int( &(mMsg->data[1]) );
		EndPoint1.value = extract_word	  ( &(mMsg->data[4]) );
	} else {
		EndPoint2.angle = extract_long_int( &(mMsg->data[1]) );
		EndPoint2.value = extract_word	  ( &(mMsg->data[4]) );
	}
	order_stops_by_value();
	compute_range();
	save_cal();
}
Esempio n. 3
0
/* Extrait d'un fichier une liste de séquences */
t_list_single file_to_word_list(const char *filepath)
{
    FILE *f;
    t_list_single l;
    char *word;
    int offset;

    INFO("Ouverture du fichier %s", filepath);
    f = fopen(filepath, "r");
    if (f==NULL) {
        ERROR("Erreur d'ouverture du fichier %s : %s", filepath, 
                strerror(errno));
        return EMPTY_SL;
    }

    INFO("Construction de la liste de mots");
    l = EMPTY_SL;

    INFO("Itération");
    while((word = extract_word(f, &islatin1, &latin1_to_ascii, &offset))) {
        l = cons_single(word, l);
        COUNT_SL(l) = offset;
    }
    INFO("Fin de la construction de la liste de mots");

    /* Fermeture du fichier */
    INFO("Fermeture du fichier %s", filepath);
    fclose(f);

    INFO("Inversion de la liste");
    return reverse(&l);
}
Esempio n. 4
0
/* Extrait d'un fichier une liste de séquences */
t_list_words analyse_file(const char *filepath, int nbr_words, int skip_words,
        t_list_single *allwords, char sorted)
{
    FILE *f;
    t_list_words l;
    char **buffer_words;
    int posbuff;
    int i;
    int count;
    int offset;

    INFO("Analyse du fichier <%s> longueur séquence = %d, décalage = %d", 
            filepath, nbr_words, skip_words);

    /* Ouverture du fichier */
    INFO("Ouverture du fichier %s", filepath);
    f = fopen(filepath, "r");
    if (f==NULL) {
        ERROR("Erreur d'ouverture du fichier %s : %s", filepath, 
                strerror(errno));
        return EMPTY_LIST;
    }

    /* Initialisation d'un buffer contenant les N derniers mots */
    DEBUG("Initialisation d'un buffer pour %d mots", nbr_words);
    buffer_words = malloc(nbr_words*sizeof(char*));
    if (buffer_words == NULL) {
        ERROR("Erreur d'allocation mémoire : %s", strerror(errno));
        exit(100);
    }
    posbuff = nbr_words - 1;

    INFO("Construction de la liste de mots");
    l = EMPTY_LIST;
    *allwords = EMPTY_SL;

    INFO("Amorçage");
    for(i=0;i<nbr_words-1;i++) {
        buffer_words[i] = extract_word(f, &islatin1, &latin1_to_ascii, &offset);
        *allwords = cons_single(buffer_words[i], *allwords);
    }

    INFO("Itération");
    count = 0;
    while((buffer_words[posbuff] = extract_word(f, &islatin1, &latin1_to_ascii,
                    &offset))) {
        *allwords = cons_single(buffer_words[posbuff], *allwords);

        if (count == 0) {
            char **words = malloc(nbr_words*sizeof(char *));
            if (words == NULL) {
                FATAL("Erreur d'allocation mémoire : %s",strerror(errno));
                exit(100);
            }

            for(i = 0; i < nbr_words; i++) {
                words[i] = buffer_words[(posbuff+1+i)%nbr_words];
            }

            if (sorted) {
                add_sorted(build_words(nbr_words, words), &l);
            } else {
                l = cons_new_words(nbr_words, words, l);
            }

            count = skip_words;
        }

        posbuff = (posbuff+1)%nbr_words;
        count -= 1;
    }
    INFO("Fin de la construction de la liste de mots");

    /* Libération de la mémoire */
    DEBUG("Libération du buffer de mots");
    free(buffer_words);

    /* Fermeture du fichier */
    INFO("Fermeture du fichier %s", filepath);
    fclose(f);

    DEBUG("Nombre de séquences : %d", length_list(l));

    return l;
}
Esempio n. 5
0
      struct skipper_sgml
      {
	bool operator()(const symbol_type& word) const
	{
	  return word == vocab_type::EPSILON || (word != vocab_type::BOS && word != vocab_type::EOS && word.is_sgml_tag());
	}
      };
      
      void rnn_score(state_ptr_type& state,
		     const state_ptr_set_type& states,
		     const edge_type& edge,
		     feature_set_type& features,
		     const bool final) const
      {
	if (skip_sgml_tag)
	  rnn_score(state, states, edge, edge.rule->rhs.begin(), edge.rule->rhs.end(), features, extract_word(), skipper_sgml());
	else
	  rnn_score(state, states, edge, edge.rule->rhs.begin(), edge.rule->rhs.end(), features, extract_word(), skipper_epsilon());
      }

      
      template <typename Iterator, typename Extract, typename Skipper>
      void rnn_score(state_ptr_type& state,
		     const state_ptr_set_type& states,
		     const edge_type& edge,
		     Iterator first, Iterator last, 
		     feature_set_type& features,
		     Extract extract,
		     Skipper skipper) const
      {
	const size_type offset1 = 0;