Пример #1
0
int main(int argc,char** argv)
{
    char* ifo_name="../dict/stardict-langdao-ec-gb-2.4.2/langdao-ec-gb.ifo";
    char* idx_name="../dict/stardict-langdao-ec-gb-2.4.2/langdao-ec-gb.idx";
    char* dict_name="../dict/stardict-langdao-ec-gb-2.4.2/langdao-ec-gb.dict";
    DICT_INFO* dict_info;
    dict_info=get_dict_info(ifo_name);
    WORD_IDX* idx=(WORD_IDX*)malloc(sizeof(WORD_IDX)*dict_info->word_count);

    get_words(idx_name,dict_info,idx);

    WORD_IDX* word=get_idx(argv[1],idx,dict_info);
    if(word==NULL){
        printf("<NULL>\n");
        exit(0);
    }
    printf("%s,%d,%d\n",word->word,word->offset,word->length);
    FILE* dict=fopen(dict_name,"r");
    if(NULL==dict)
    {
        printf("dict error!\n");
        return EXIT_FAILURE;
    }
    if(0!=fseek(dict,word->offset,SEEK_SET))
    {
        printf("seek error\n");
        return EXIT_FAILURE;
    }
    char explain[word->length+1];
    memset(explain,'\0',word->length+1);
    fread(explain,word->length,1,dict);
    printf("%s\n",explain);
    free(idx);
    return EXIT_SUCCESS;
}
Пример #2
0
int main(int argc, char **argv) {
    if (argc < 3) {
        std::cerr << "Please provide an input file and a page size." << std::endl;
        return -1;
    }
    std::string input(argv[1]);
    
    int page_size = std::stoi(argv[2]);
    auto words = get_words(input);
    std::vector<int> dyn(words.size(), -1),
        solution(words.size(), -1);
    justify_text(page_size, words, solution, dyn, 0);
    print_justified_text(words, page_size, solution);
    return 0;
}
Пример #3
0
int main(void)
{
    int size;
    char ** words;
    printf("How many words do you wish to enter? ");
    scanf("%d", &size);

    words = make_array(size);
    if (words)
    {
        get_words(words, size);
        print_words(words, size);
    }

    free(words);
    return 0;
}
Пример #4
0
int main(int argc, char *argv[])
{
	if(argc < 2)
		return 1;
	std::ifstream in_file(argv[1], std::ifstream::in);
	std::istream_iterator<std::string> in_iter_file(in_file), in_iter_eof;
	std::unordered_set<std::string> uset_words(in_iter_file, in_iter_eof);
	std::vector<std::string> text = get_words();

	std::cout << "Found errors:" << std::endl;
	for(auto word_iter = text.begin(); word_iter < text.end(); ++word_iter)
	{
		if(!spellchecker(*word_iter, uset_words))
		{
			std::cout << print_with_context(word_iter, text.begin(), text.end());
		}
	}

	return 0; //Huge success!
}
Пример #5
0
int track_info_matches(struct track_info *ti, const char *text, unsigned int flags)
{
	const char *artist = comments_get_val(ti->comments, "artist");
	const char *album = comments_get_val(ti->comments, "album");
	const char *title = comments_get_val(ti->comments, "title");
	char **words;
	int i, matched = 1;

	words = get_words(text);
	if (words[0] == NULL)
		matched = 0;
	for (i = 0; words[i]; i++) {
		const char *word = words[i];

		if ((flags & TI_MATCH_ARTIST && artist) ||
		    (flags & TI_MATCH_ALBUM && album) ||
		    (flags & TI_MATCH_TITLE && title)) {
			if (flags & TI_MATCH_ARTIST && artist && u_strcasestr(artist, word))
				continue;
			if (flags & TI_MATCH_ALBUM && album && u_strcasestr(album, word))
				continue;
			if (flags & TI_MATCH_TITLE && title && u_strcasestr(title, word))
				continue;
		} else {
			/* compare with url or filename without path */
			char *filename = ti->filename;

			if (!is_url(filename)) {
				char *slash = strrchr(ti->filename, '/');
				if (slash)
					filename = slash + 1;
			}
			if (u_strcasestr_filename(filename, word))
				continue;
		}
		matched = 0;
		break;
	}
	free_str_array(words);
	return matched;
}
Пример #6
0
int main(int argc, char *argv[]) {
	time_t clock;
	
	FILE *log = fopen("log.log", "a+");
	time(&clock);
	fprintf(log, "#%s\n", ctime(&clock));
	system("mkdir Bases");
	FILE *textBase = fopen("Bases/base_descripteur_text.base", "a");

	//les cas d'erreur
	if (argc < 2) {
		fprintf(stderr, "Need filename\n");
		return EXIT_FAILURE;
	}		
	FILE *fic = fopen(argv[1], "r");
	if (fic != NULL) {
		fprintf(log, "Opening success : %s\n", argv[1]);
	}
	else if (fic == NULL) {
		fprintf(log, "ERROR : Can't open this text'\n");
		fflush(stdout);
		return (EXIT_FAILURE);		
	}
	else {
		fprintf(log, "ERROR : Can't open config file'\n");
		fflush(stdout);
	}
	
	//l'indexation
	get_words(fic, log, textBase, argv[1]);
	
	//on ferme le fichier
	fclose(fic);
	fprintf(log, "Indexation of %s DONE !\n", argv[1]);
	fprintf(log, "Closing %s\n\n", argv[1]);
	fclose(log);
	
	return(EXIT_SUCCESS);
}
Пример #7
0
void
shell (func_t * scope)
{
  /**
   * shell - when FACT is run by default it comes to here. The
   * main user interface for FACT, this function grabs an
   * expression of input, parses it, runs it, and repeats. It
   * will continue to do so until the user does a C-d, C-c,
   * returns a value from the main scope, or calls the exit
   * function.
   *
   * @scope  - the scope to use when evaluating expressions.
   */
  FACT_t       returned;  // The value returned by the interpreter.
  unsigned int end_line;  // ...
  unsigned int hold_line; // ...

  int  *newlines;
  char *input;
  char *hold_input;   // Used in the main loop to check for else clauses.
  char **tokenized;   // input, tokenized.
  char **hold_tokens; // Also used to check for else clauses.

  /* Before we start, print out the copyright info, logo and
   * a guide to some helpful functions.
   */
  print_logo ();
  printf ("The FACT programming language interactive shell\n"
	  "© 2010, 2011 Matthew Plant, under the GPL version 3.\n");

  hold_input = NULL;
  scope->file_name = "stdin";
  scope->line = 1;
  end_line = 0;
  
  for (;;) // Heh, that looks like a spider.
    {
      /* Set the line number to end_line, in case we missed any while evaluating
       * the last expression.
       */
      scope->line += end_line;
      end_line = 0;

      // Then, get raw input for an entire expression.
      if (hold_input == NULL)
	input = get_input (stdin, &end_line, "S>", "C>");
      else
	{
	  input = hold_input;
	  hold_input = NULL;
	}

      /* We do two checks for EOF signals: once before tokenizing, and once after.
       * I am not completely sure as to why this is the case, but I do remember at
       * some point it didn't exit so I added the second check.
       */
      if (input == NULL)
	break;

      // Tokenize the input.
      tokenized = get_words (input);
      if (tokenized == NULL)
	break;
      
      /* If the first token in the expression is if/on_error, continue to get input
       * as long as the first token is else. I could forsee this being an issue in
       * places where the else is placed erroneosly, but that'll be fixed later I
       * assume.
       */ 
      if ((tokenized[0][0] == '\n'
	   && (!tokcmp (tokenized[1], "if")
	       || !tokcmp (tokenized[1], "error")))
	  || (!tokcmp (tokenized[0], "if")
	      || !tokcmp (tokenized[0], "error")))
	{
	  for (;;)
	    {
	      /* Go through all the steps we went through from the start of the loop
               * down to here.
	       */
	      hold_input = get_input (stdin, &end_line, "?>", "C>");

	      if (hold_input == NULL|| (hold_tokens = get_words (hold_input)) == NULL)
		break;
	      // Check to see if the statement starts with else.
	      if ((hold_tokens[0][0] == '\n'
		   && !tokcmp (hold_tokens[1], "else"))
		  || !tokcmp (hold_tokens[0], "else"))
		{
		  input[strlen (input) - 1] = '\0';
		  input = combine_strs (input, hold_input);
		  hold_input = NULL;
		}
	      else
		break;
	    }
          printf ("\n");
	  tokenized = get_words (input);
	}

      // Get the newlines and parse the string.
      tokenized = parse (tokenized, "stdin", scope->line, &newlines);

      if (tokenized == NULL)
        continue;

      // Reset the instruction pointer.
      reset_ip ();

      // Evaluate the expression.
      returned = eval_expression (scope, make_syn_tree (tokenized, newlines));

      /* If there were errors, print them out. Otherwise,
       * print the value of the variable or the name of
       * the function returned.
       */
      if (returned.type == ERROR_TYPE)
	errorman_dump (returned.error);
      else if (returned.type == VAR_TYPE)
	printf ("Returned value: %s\n", mpc_get_str (returned.v_point->data));
      else
	printf ("Returned object [%s]\n", returned.f_point->name);

      /* Check to see if the value is to be returned, and
       * if so, exit.
       */
      if (returned.return_signal)
	break;
    }
  puts ("\nExiting...");
}
Пример #8
0
bool CPly::ImportPly(t_model& scene, const char* mfilename)
{
  FILE *infile;
  char mefilename[FILENAMESIZE];
  char buffer[250];
  infile = fopen(mfilename, "r+");
  if (infile == (FILE *) NULL) {
    wxLogInfo(_("File I/O Error:  Cannot open file %s.\n"), mefilename);
    return false;
  }

  unsigned int sizeVertices=0;
  unsigned int sizeFaces=0;
  int nwords=0;
  char **words;
  char *orig_line;

  /* Lecture du fichier d'entete */

  words = get_words (infile, &nwords, &orig_line);
  while (words)
  {
    //Pour chaque ligne
	if (nwords==3 && equal_strings (words[0], "element"))
	{
		//Le premier mot de la ligne est element
		if (equal_strings (words[1], "vertex")) //Nous indique le nombre de
		{
			sizeVertices=Convertor::ToInt(words[2]);
		}else if(equal_strings (words[1], "face"))
		{
			sizeFaces=Convertor::ToInt(words[2]);
		}
	}
	if (equal_strings (words[0], "end_header")) //Fin du bloc d'entete
	{
		break;
	}
	words = get_words (infile, &nwords, &orig_line);
  }

  //Lecture des vertices
  unsigned int idvec=0;

  char x[20];
  char y[20];
  char z[20];

  scene.modelVertices.reserve(sizeVertices);
  while(idvec<sizeVertices && !feof(infile))
  {
	vec3 newVec;
	fscanf(infile,"%20s %20s %20s\n",x,y,z);
	newVec[0]=Convertor::ToFloat(wxString(x));
	newVec[1]=Convertor::ToFloat(wxString(y));
	newVec[2]=Convertor::ToFloat(wxString(z));
	scene.modelVertices.push_back(newVec);
	idvec++;
  }
  //Lectures des triangles

  unsigned int idtri=0;

  short dim;
  unsigned int a;
  unsigned int b;
  unsigned int c;
  unsigned int d;
  scene.modelFaces.reserve(sizeFaces);
  while(idtri<sizeFaces && !feof(infile))
  {

    words = get_words (infile, &nwords, &orig_line);
	if(nwords>0)
	{
		dim=Convertor::ToInt(words[0]);
		if(dim==3)
		{
			t_face newFace;
			newFace.indicesSommets.set(Convertor::ToInt(words[1]),Convertor::ToInt(words[2]),Convertor::ToInt(words[3]));
			scene.modelFaces.push_back(newFace);
		}else if(dim==4)
		{
			t_face newFace;
			newFace.indicesSommets.set(Convertor::ToInt(words[1]),Convertor::ToInt(words[2]),Convertor::ToInt(words[3]));
			scene.modelFaces.push_back(newFace);
			newFace.indicesSommets.set(Convertor::ToInt(words[3]),Convertor::ToInt(words[4]),Convertor::ToInt(words[1]));
			scene.modelFaces.push_back(newFace);
		}
		/*
		fscanf(infile,"%5s %10s %10s %10s\n",dim,a,b,c);
		*/
		idtri++;
	}
  }

  fclose(infile);

  return true;
}
Пример #9
0
static inline int ohci_read_iso_td(OHCIState *ohci,
                                   uint32_t addr, struct ohci_iso_td *td)
{
    return (get_dwords(ohci, addr, (uint32_t *)td, 4) &&
            get_words(ohci, addr + 16, td->offset, 8));
}
Пример #10
0
int main(int argc, char **argv) {
    int i, idx;
    int interact=false;
    vocab::iterator vocab_itr;

    c_word_file_name = (char*)malloc(sizeof(char) * MAX_FULLPATH_NAME);
    c_list_file_name = (char*)malloc(sizeof(char) * MAX_FULLPATH_NAME);
    c_vocab_file_name = (char*)malloc(sizeof(char) * MAX_FULLPATH_NAME);

    if (argc == 1) {
        printf("HPCA: Hellinger PCA for Word Embeddings, nearest neighbors\n");
        printf("Author: Remi Lebret ([email protected])\n\n");
        printf("Usage options:\n");
        printf("\t-verbose <int>\n");
        printf("\t\tSet verbosity: 0=off or 1=on (default)\n");
        printf("\t-word-file <file>\n");
        printf("\t\tFile containing word embeddings to evaluate\n");
        printf("\t-vocab-file <file>\n");
        printf("\t\tFile containing word vocabulary\n");
        printf("\t-list-file <file>\n");
        printf("\t\tFile containing a list of words from which the nearest neighbors will be computed, otherwise interactive mode\n");
        printf("\t-top <int>\n");
        printf("\t\tNumber of nearest neighbors; default 10\n");
        printf("\t-threads <int>\n");
        printf("\t\tNumber of threads; default 8\n");
        printf("\nExample usage:\n");
        printf("./eval -word-file path_to_words -vocab-file path_to_vocab -top 10\n\n");
        return 0;
    }

    if ((i = find_arg((char *)"-verbose", argc, argv)) > 0) verbose = atoi(argv[i + 1]);
    if ((i = find_arg((char *)"-word-file", argc, argv)) > 0) strcpy(c_word_file_name, argv[i + 1]);
    if ((i = find_arg((char *)"-list-file", argc, argv)) > 0) strcpy(c_list_file_name, argv[i + 1]);
    else interact=true;
    if ((i = find_arg((char *)"-vocab-file", argc, argv)) > 0) strcpy(c_vocab_file_name, argv[i + 1]);
    if ((i = find_arg((char *)"-top", argc, argv)) > 0) top = atoi(argv[i + 1]);
    if ((i = find_arg((char *)"-threads", argc, argv)) > 0) num_threads = atoi(argv[i + 1]);


    if (verbose){
        fprintf(stderr, "HPCA: Hellinger PCA for Word Embeddings\n");
        fprintf(stderr, "Author: Remi Lebret ([email protected])\n");
        fprintf(stderr, "---------------------------------------\n");
        fprintf(stderr, "nearest neighbors\n" );
        fprintf(stderr, "---------------------------------------\n\n");
    }

    /* set the optimal number of threads */
    num_threads = MultiThread::optimal_nb_thread(num_threads, 1, num_threads);
    if (verbose) fprintf(stderr, "number of pthreads = %d\n", num_threads);
    // set threads
    Eigen::setNbThreads(num_threads);

    /* check whether files exist */
    is_file(c_word_file_name);
    is_file(c_vocab_file_name);

    /* get vocabulary */
    vocab_size = get_vocab(c_vocab_file_name, hash);
    tokename = get_words(c_vocab_file_name, vocab_size);
    if (verbose) fprintf(stderr, "number of words in vocabulary = %d\n",vocab_size);

    /* get words */
    Eigen::MatrixXf words;
    read_eigen_matrix(c_word_file_name, words);
    /* check whether number of lines in words is equal to the number of words into vocab file */
    if (words.rows() != vocab_size){
        throw std::runtime_error("Size mismatch between words and vocabulary files!!!\n");
    }
    if (verbose) fprintf(stderr, "words vector size = %d\n",words.cols());

    fprintf(stderr, "---------------------------------------\n");
    if (interact){
        /* initialize random seed: */
        srand (time(NULL));

        fprintf(stderr,"Interactive mode, please enter words.\nAlternative options:\n - press 'R' key for a random sample\n - press 'Q' key to exit\n");
        fprintf(stderr, "---------------------------------------\n");
        while(1){
            char w[MAX_TOKEN];
            fprintf(stderr, "\nEnter a word: ");
            scanf("%s",w);

            if ( (strcmp(w,"q") == 0) || (strcmp(w,"Q") == 0) ){ // exit
                break;
            }else{
                if ( (strcmp(w,"r") == 0) || (strcmp(w,"R") == 0) ){
                    idx = rand() % vocab_size + 1;
                }
                else{
                    if ( (vocab_itr = hash.find(w)) == hash.end() ){
                        fprintf(stderr, "unknown word, please enter a new one\n\n");
                        continue;
                    }else{
                        idx = vocab_itr->second;
                    }
                }
                fprintf(stderr, "computing nearest neighbors of %s...\n", tokename[idx]);
                getnn(stderr, words, idx);
            }
        }
    }else{
        is_file(c_list_file_name);
        fprintf(stderr, "computing nearest neighbors of words in %s...\n", c_list_file_name);
        File fp((std::string(c_list_file_name)));
        // open file
        fp.open();
        // get vocabulary
        char * line = NULL;
        int i=0;
        while( (line=fp.getline()) != NULL) {
            if ( (vocab_itr = hash.find(line)) != hash.end() ){
                fprintf(stdout, "%s --> ", line);
                getnn(stdout, words, vocab_itr->second);
            }
        }
        fp.close();
    }

    /* release memory */
    free(c_vocab_file_name);
    free(c_word_file_name);
    for (int i=0; i<vocab_size; i++) if (tokename[i]) free(tokename[i]);
    free(tokename);

    if (verbose){
        fprintf(stderr, "\ndone\n");
        fprintf(stderr, "---------------------------------------\n");
    }
    return 0;
}
Пример #11
0
/******************************************************************************
Read an element from an ascii file.

Entry:
  plyfile  - file identifier
  elem_ptr - pointer to element
******************************************************************************/
void ascii_get_element(PlyFile *plyfile, char *elem_ptr)
{
    //int i,j,k;
    int j,k;
    PlyElement *elem;
    PlyProperty *prop;
    char **words;
    int nwords;
    int which_word;
    //FILE *fp = plyfile->fp;
    char *elem_data,*item;
    char *item_ptr;
    int item_size;
    int int_val;
    unsigned int uint_val;
    double double_val;
    int list_count;
    int store_it;
    char **store_array;
    char *orig_line;
    char *other_data;
    int other_flag;
    other_data = NULL;

    // the kind of element we're reading currently
    elem = plyfile->which_elem;

    // do we need to setup for other_props?

    if (elem->other_offset != NO_OTHER_PROPS) {
        char **ptr;
        other_flag = 1;
        // make room for other_props
        other_data = (char *) myalloc (elem->other_size);
        // store pointer in user's structure to the other_props
        ptr = (char **) (elem_ptr + elem->other_offset);
        *ptr = other_data;
    } else {
        other_flag = 0;
    }

    // read in the element

    words = get_words(plyfile->fp, &nwords, &orig_line);
    if (words == NULL) {
        fprintf (stderr, "ply_get_element: unexpected end of file\n");
        exit (-1);
    }

    which_word = 0;

    for (j = 0; j < elem->nprops; j++) {
        prop = elem->props[j];
        store_it = (elem->store_prop[j] | other_flag);

        // store either in the user's structure or in other_props
        if (elem->store_prop[j]) {
            elem_data = elem_ptr;
        } else {
            elem_data = other_data;
        }

        if (prop->is_list) {       // a list
            // get and store the number of items in the list
            get_ascii_item (words[which_word++], prop->count_external,
                            &int_val, &uint_val, &double_val);
            if (store_it) {
                item = elem_data + prop->count_offset;
                store_item(item, prop->count_internal, int_val, uint_val,
                           double_val);
            }

            // allocate space for an array of items and store a ptr to the array
            list_count = int_val;
            item_size = ply_type_size[prop->internal_type];
            store_array = (char **) (elem_data + prop->offset);

            if (list_count == 0) {
                if (store_it) {
                    *store_array = NULL;
                }
            } else {
                if (store_it) {
                    item_ptr = (char *) myalloc (sizeof (char) * item_size * list_count);
                    item = item_ptr;
                    *store_array = item_ptr;
                }

                // read items and store them into the array
                for (k = 0; k < list_count; k++) {
                    get_ascii_item (words[which_word++], prop->external_type,
                                    &int_val, &uint_val, &double_val);
                    if (store_it) {
                        store_item (item, prop->internal_type,
                                    int_val, uint_val, double_val);
                        item += item_size;
                    }
                }
            }
        } else {                     // not a list
            get_ascii_item (words[which_word++], prop->external_type,
                            &int_val, &uint_val, &double_val);
            if (store_it) {
                item = elem_data + prop->offset;
                store_item (item, prop->internal_type, int_val, uint_val, double_val);
            }
        }
    }

    free (words);
}
Пример #12
0
/******************************************************************************
Given a file pointer, get ready to read PLY data from the file.

Entry:
  fp - the given file pointer

Exit:
  nelems     - number of elements in object
  elem_names - list of element names
  returns a pointer to a PlyFile, used to refer to this file, or NULL if error
******************************************************************************/
PlyFile *ply_read(FILE *fp, int *nelems, char ***elem_names)
{
    int i,j;
    PlyFile *plyfile;
    int nwords;
    char **words;
    //int found_format = 0;
    char **elist;
    PlyElement *elem;
    char *orig_line;

    // check for NULL file pointer
    assert(fp != NULL);

    // create record for this object

    plyfile = (PlyFile *) myalloc (sizeof (PlyFile));
    plyfile->nelems = 0;
    plyfile->comments = NULL;
    plyfile->num_comments = 0;
    plyfile->obj_info = NULL;
    plyfile->num_obj_info = 0;
    plyfile->fp = fp;
    //plyfile->other_elems = NULL;

    // read and parse the file's header
    words = get_words(plyfile->fp, &nwords, &orig_line);
    assert(words && (strncmp(words[0], "ply", sizeof("ply ")) == 0));

    while (words) {
        // parse words

        if (strncmp(words[0], "format", sizeof("format")) == 0) {
            if (nwords != 3) {
                return (NULL);
            }
            if (strncmp(words[1], "ascii", sizeof("ascii")) == 0) {
                plyfile->file_type = PLY_ASCII;
            } else {
                return (NULL);
            }
            plyfile->version = atof (words[2]);
            //found_format = 1;
        } else if (strncmp(words[0], "element", sizeof("element")) == 0) {
            add_element (plyfile, words, nwords);
        } else if (strncmp(words[0], "property", sizeof("property")) == 0) {
            add_property (plyfile, words, nwords);
        } else if (strncmp(words[0], "comment", sizeof("comment")) == 0) {
            add_comment (plyfile, orig_line);
        } else if (strncmp(words[0], "obj_info", sizeof("obj_info")) == 0) {
            add_obj_info (plyfile, orig_line);
        } else if (strncmp(words[0], "end_header", sizeof("end_header")) == 0) {
            break;
        }

        // free up words space
        free (words);

        words = get_words (plyfile->fp, &nwords, &orig_line);
    }

    // create tags for each property of each element, to be used
    // later to say whether or not to store each property for the user

    for (i = 0; i < plyfile->nelems; i++) {
        elem = plyfile->elems[i];
        elem->store_prop = (char *) myalloc (sizeof (char) * elem->nprops);
        for (j = 0; j < elem->nprops; j++) {
            elem->store_prop[j] = DONT_STORE_PROP;
        }
        elem->other_offset = NO_OTHER_PROPS; // no "other" props by default
    }

    // set return values about the elements

    elist = (char **) myalloc (sizeof (char *) * plyfile->nelems);
    for (i = 0; i < plyfile->nelems; i++) {
        elist[i] = strdup (plyfile->elems[i]->name);
    }

    *elem_names = elist;
    *nelems = plyfile->nelems;

    // return a pointer to the file's information

    return (plyfile);
}