Esempio n. 1
0
void
init_segment()
{
	g_pos = 0;
	load_dict(0);	/* load char dict */
	load_dict(1);	/* load word dict */
}
Esempio n. 2
0
bool DictTrie::load_dict(const char *filename, LemmaIdType start_id,
                         LemmaIdType end_id) {
  if (NULL == filename || end_id <= start_id)
    return false;

  FILE *fp = fopen(filename, "rb");
  if (NULL == fp)
    return false;

  free_resource(true);

  dict_list_ = new DictList();
  if (NULL == dict_list_) {
    fclose(fp);
    return false;
  }

  SpellingTrie &spl_trie = SpellingTrie::get_instance();
  NGram &ngram = NGram::get_instance();

  if (!spl_trie.load_spl_trie(fp) || !dict_list_->load_list(fp) ||
      !load_dict(fp) || !ngram.load_ngram(fp) ||
      total_lma_num_ > end_id - start_id + 1) {
    free_resource(true);
    fclose(fp);
    return false;
  }

  fclose(fp);
  return true;
}
Esempio n. 3
0
bool DictTrie::load_dict_fd(int sys_fd, long start_offset,
                            long length, LemmaIdType start_id,
                            LemmaIdType end_id) {
  if (start_offset < 0 || length <= 0 || end_id <= start_id)
    return false;

  FILE *fp = fdopen(sys_fd, "rb");
  if (NULL == fp)
    return false;

  if (-1 == fseek(fp, start_offset, SEEK_SET)) {
    fclose(fp);
    return false;
  }

  free_resource(true);

  dict_list_ = new DictList();
  if (NULL == dict_list_) {
    fclose(fp);
    return false;
  }

  SpellingTrie &spl_trie = SpellingTrie::get_instance();
  NGram &ngram = NGram::get_instance();

  if (!spl_trie.load_spl_trie(fp) || !dict_list_->load_list(fp) ||
      !load_dict(fp) || !ngram.load_ngram(fp) ||
      ftell(fp) < start_offset + length ||
      total_lma_num_ > end_id - start_id + 1) {
    free_resource(true);
    fclose(fp);
    return false;
  }

  fclose(fp);
  return true;
}
Esempio n. 4
0
//Driver for the Word Challenge bot.  Loads the dictionary, then loops forever
//performing the following process:
//  1. Take ascreenshot
//  2. Cut out the individual letters from the screenshot and run them through
//     Tesseract
//  3. Read the output of Tesseract and use these to send every word
//     combination using these letters to Word Challenge.
//After ten seconds have elapsed, the program kills itself.  If this does not happen,
//no progress is being made and should be restarted (by the perl script that keeps it running.)
//This program is very dependant on your resolution and location/size of the browser you have Word Challenge opened in.
int main(int argc, char *argv[]) {
  int i;
  time_t start, end;
  display = XOpenDisplay(NULL);
  dictionary = malloc( sizeof( char* ) * NUM_WORDS );
  load_dict();

  char* c = malloc( sizeof( char ) * 10 );
  char* old = malloc( 10 );
  start = time (NULL);
  while( true ) {
    end = time (NULL);
    send_key( XKeysymToKeycode( display, XK_Return ), 0);
    send_key( XKeysymToKeycode( display, XK_Control_L ), 0);

    sleep( 1 );
    system( "scrot screen.jpg" );
    system( "convert screen.jpg -crop 40x35+400+500 -type Grayscale letter0.tif" );
    system( "convert screen.jpg -crop 38x35+455+500 -type Grayscale letter1.tif" );
    system( "convert screen.jpg -crop 38x35+510+500 -type Grayscale letter2.tif" );
    system( "convert screen.jpg -crop 38x35+565+500 -type Grayscale letter3.tif" );
    system( "convert screen.jpg -crop 37x35+620+500 -type Grayscale letter4.tif" );
    system( "convert screen.jpg -crop 37x35+675+500 -type Grayscale letter5.tif" );
    system( "tesseract letter0.tif letter0" );
    system( "tesseract letter1.tif letter1" );
    system( "tesseract letter2.tif letter2" );
    system( "tesseract letter3.tif letter3" );
    system( "tesseract letter4.tif letter4" );
    system( "tesseract letter5.tif letter5" );
    FILE* l0 = fopen( "letter0.txt", "r" );
    FILE* l1 = fopen( "letter1.txt", "r" );
    FILE* l2 = fopen( "letter2.txt", "r" );
    FILE* l3 = fopen( "letter3.txt", "r" );
    FILE* l4 = fopen( "letter4.txt", "r" );
    FILE* l5 = fopen( "letter5.txt", "r" );
    fscanf( l0, "%c", c );
    fscanf( l1, "%c", c + 1 );
    fscanf( l2, "%c", c + 2 );
    fscanf( l3, "%c", c + 3 );
    fscanf( l4, "%c", c + 4 );
    fscanf( l5, "%c", c + 5 );
    system( "rm letter*.txt" );
    for( i = 0; c[i]; i++ ){
      if (c[i] == '0' ) c[i] = 'o';
      else if (c[i] < 'A' || c[i] > 'Z' ) c[i] = 'i';
      else c[i] += 32;
    }
    c[6] = 0;
    printf( "%s\n", c );
    if( strcmp(old,  c ) ) {
      start = time (NULL);
      loop_through_dictionary( c );
      strcpy( old, c );
    }
    if (end - start >= 10) {
      XCloseDisplay (display);
      return 0;
    }
  }

  XCloseDisplay( display );
  return 0;
}
Esempio n. 5
0
int
main (int argc, char *argv[])
{
    FILE *FH;
    char *filename = NULL;
    char *program_name = argv[0];
    char *cp;
    char *username, *address;
    char line[BUFSIZE];
    struct ip_user_dict *current_entry;
    int ch;

    setvbuf (stdout, NULL, _IOLBF, 0);
    while ((ch = getopt (argc, argv, "f:")) != -1) {
        switch (ch) {
        case 'f':
            filename = optarg;
            break;
        default:
            usage (program_name);
            exit (1);
        }
    }
    if (filename == NULL) {
        usage (program_name);
        exit(1);
    }
    FH = fopen (filename, "r");
    current_entry = load_dict (FH);

    while (fgets (line, sizeof (line), stdin)) {
        if ((cp = strchr (line, '\n')) == NULL) {
            /* too large message received.. skip and deny */
            fprintf(stderr, "%s: ERROR: Too large: %s\n", argv[0], line);
            while (fgets(line, sizeof(line), stdin)) {
                fprintf(stderr, "%s: ERROR: Too large..: %s\n", argv[0], line);
                if (strchr(line, '\n') != NULL)
                    break;
            }
            goto error;
        }
        *cp = '\0';
        address = strtok (line, " \t");
        username = strtok (NULL, " \t");
        if (!address || !username) {
            fprintf (stderr, "%s: unable to read tokens\n", argv[0]);
            goto error;
        }
        rfc1738_unescape(address);
        rfc1738_unescape(username);
#ifdef DEBUG
        printf ("result: %d\n",
                dict_lookup (current_entry, username, address));
#endif
        if ((dict_lookup (current_entry, username, address)) != 0) {
            printf ("OK\n");
        } else {
error:
            printf ("ERR\n");
        }
    }


    fclose (FH);
    return 0;
}
Esempio n. 6
0
int main(int argc, const char *argv[])
{
	char word[32];
	const char *filename;
	queue *que;
	node *index[26], *res, **results;

	/* load dictionary */
	if (argc < 2) 
		filename = "dict.txt";
	else 
		filename = argv[1];
	que = load_dict(filename);	

	/* bulid index */
	build_index(que, index);
	
	/* run */
	while (1) {
		/* input */
		printf("%s", "Please input a word!\n^_^ : ");
		fgets(word, sizeof(word), stdin);

		/* remove '\n' */
		if (word[strlen(word)-1] == '\n')
			word[strlen(word)-1] = '\0';

		/* empty */
		if (!strlen(word)) {
			putchar('\n');
			continue;
		}

		/* exit */
		if (strchr(word, '$')) {
			puts("~_~");
			break;
		}

		/* search */
		res = search(index, word);
		if (res) {
			search_out(res);
			continue;
		} 

		/* similar search */
		results = similar_search(index, word, results);
		if (*results) {
			printf("%s", "I can't find it. "
					"Show similar? (y/n): ");
			if (confirm())
				similar_search_out(results);
			else
				putchar('\n');
		} else {	/* nothing */
			puts("-_- : Sorry, no results!\n");
		}
		free(results);
	}

	/* unload dictionary */
	unload_dict(que);

	return 0;
}