Exemplo n.º 1
0
void Tester_68k::testNot() {
    u16 opcode;

    //MOVE.L    #$12345678, D0
    //MOVE      #0, CCR
    //NOT.B     D0
    setUp();
    opcode = 0x4600 | (0 << 6) | getEA(DR_DIRECT, 0);
    addWord(opcode);
    addWord(0xffff);
    power();
    setRegD(0, 0x12345678);
    process();
    check("NOT.B D0");

    //MOVE.L    #$12340000, D0
    //MOVE      #$1f, CCR
    //NOT.W     D0
    setUp();
    opcode = 0x4600 | (1 << 6) | getEA(DR_DIRECT, 0);
    addWord(opcode);
    addWord(0xffff);
    power();
    setCCR(0x1f);
    setRegD(0, 0x12340000);
    process();
    check("NOT.W D0");

    //MOVE.L    #$ffffff00, D0
    //MOVE      #$1f, CCR
    //NOT.L     D0
    setUp();
    opcode = 0x4600 | (2 << 6) | getEA(DR_DIRECT, 0);
    addWord(opcode);
    addWord(0xffff);
    power();
    setCCR(0x1f);
    setRegD(0, 0xffffff00);
    process();
    check("NOT.L D0");

    //MOVE.L    #$f0012311, $3000
    //MOVE      #$10, CCR
    //NOT.L    ($3000).L
    //MOVE.L    $3000, D0
    setUp();
    opcode = 0x4600 | (2 << 6) | getEA(ABS_LONG);
    addWord(opcode);
    addWord(0);
    addWord(0x3000);
    addWord(0xffff);
    power();
    setCCR(0x10);
    memoryblock.writeLong(0x3000, 0xf0012311);
    process();
    check("NOT.L ($3000).L");

}
Exemplo n.º 2
0
bool XAP_Dictionary::_parseUTF8(void)
{
	UT_GrowBuf gbBlock(1024);
	bool bEatLF = false;
	gchar buf[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
	gint len;

	while (fread(buf, 1, sizeof(gchar), m_fp) > 0)
	{
		switch (buf[0])
		{
		case '\r':
		case '\n':
			if ((buf[0] == '\n') && bEatLF)
			{
				bEatLF = false;
				break;
			}

			if (buf[0] == '\r')
			{
				bEatLF = true;
			}
			
			// we interprete either CRLF, CR, or LF as a word delimiter.
			
			if (gbBlock.getLength() > 0)
			{
				X_ReturnIfFail(addWord(reinterpret_cast<UT_UCS4Char*>(gbBlock.getPointer(0)), gbBlock.getLength()));
				gbBlock.truncate(0);
			}
			break;

		default:
			bEatLF = false;

			len = g_utf8_next_char(buf) - buf;
			if (len > 1) {
				fread (buf + 1, len - 1, sizeof (gchar), m_fp);
			}
			UT_UCSChar uc = g_utf8_get_char(buf);
			X_ReturnIfFail(gbBlock.ins(gbBlock.getLength(),reinterpret_cast<UT_GrowBufElement*>(&uc),1));
			break;
		}
	} 

	if (gbBlock.getLength() > 0)
	{
		X_ReturnIfFail(addWord(reinterpret_cast<UT_UCS4Char*>(gbBlock.getPointer(0)), gbBlock.getLength()));
	}

	return true;
}
Exemplo n.º 3
0
void Tester_68k::testNop() {
    u16 opcode;

    //NOP
    setUp();
    opcode = 0x4e71;
    addWord(opcode);
    addWord(0xffff);
    power();
    process();
    check("nop");
}
Exemplo n.º 4
0
inline void UnigramDictionary::onTerminal(const int probability,
        const TerminalAttributes& terminalAttributes, Correction *correction,
        WordsPriorityQueuePool *queuePool, const bool addToMasterQueue,
        const int currentWordIndex) {
    const int inputIndex = correction->getInputIndex();
    const bool addToSubQueue = inputIndex < SUB_QUEUE_MAX_COUNT;

    int wordLength;
    unsigned short* wordPointer;

    if ((currentWordIndex == FIRST_WORD_INDEX) && addToMasterQueue) {
        WordsPriorityQueue *masterQueue = queuePool->getMasterQueue();
        const int finalProbability =
                correction->getFinalProbability(probability, &wordPointer, &wordLength);
        if (finalProbability != NOT_A_PROBABILITY) {
            addWord(wordPointer, wordLength, finalProbability, masterQueue);

            const int shortcutProbability = finalProbability > 0 ? finalProbability - 1 : 0;
            // Please note that the shortcut candidates will be added to the master queue only.
            TerminalAttributes::ShortcutIterator iterator =
                    terminalAttributes.getShortcutIterator();
            while (iterator.hasNextShortcutTarget()) {
                // TODO: addWord only supports weak ordering, meaning we have no means
                // to control the order of the shortcuts relative to one another or to the word.
                // We need to either modulate the probability of each shortcut according
                // to its own shortcut probability or to make the queue
                // so that the insert order is protected inside the queue for words
                // with the same score. For the moment we use -1 to make sure the shortcut will
                // never be in front of the word.
                uint16_t shortcutTarget[MAX_WORD_LENGTH_INTERNAL];
                const int shortcutTargetStringLength = iterator.getNextShortcutTarget(
                        MAX_WORD_LENGTH_INTERNAL, shortcutTarget);
                addWord(shortcutTarget, shortcutTargetStringLength, shortcutProbability,
                        masterQueue);
            }
        }
    }

    // We only allow two words + other error correction for words with SUB_QUEUE_MIN_WORD_LENGTH
    // or more length.
    if (inputIndex >= SUB_QUEUE_MIN_WORD_LENGTH && addToSubQueue) {
        WordsPriorityQueue *subQueue;
        subQueue = queuePool->getSubQueue(currentWordIndex, inputIndex);
        if (!subQueue) {
            return;
        }
        const int finalProbability = correction->getFinalProbabilityForSubQueue(
                probability, &wordPointer, &wordLength, inputIndex);
        addWord(wordPointer, wordLength, finalProbability, subQueue);
    }
}
Exemplo n.º 5
0
 void add( std::string s, std::string fileName ) {
     std::transform( s.begin(), s.end(), s.begin(), tolower );
     std::string h;
     for( std::string::iterator i = s.begin(); i != s.end(); i++ ) {
         if( *i == 32 ) {
             pushFileName( addWord( h ), fileName );
             h.clear();
             continue;
         }
         h.append( 1, *i );
     }
     if( h.length() )
         pushFileName( addWord( h ), fileName );
 }
Exemplo n.º 6
0
void Tester_68k::testSwap() {
    u16 opcode;

    //MOVE.L    #$12348756, D1
    //SWAP      D1
    setUp();
    opcode = 0x4840 | 1;
    addWord(opcode);
    addWord(0xffff);
    power();
    setRegD(1, 0x12348756);
    process();
    check("SWAP D1");

}
void Program::createHashtable()
{
    std::string word;
    std::ifstream infile("google-10000-english.txt");
    infile >> word;
    //cout<<word<<endl;
    addWord(word);
    while(!infile.eof())
    {
        infile >> word;
        //cout<<word<<endl;
        addWord(word);
    }
    infile.close();
}
Exemplo n.º 8
0
int addToHash(char *filename, char* word){
    if(filename == NULL || word == NULL){
        return -1; // errors or empty pointers.
    }
    TokenizerANT tokenizer = TKANCreate(word);
    if(tokenizer == NULL){
        printf("Error creating tokenizer\n");
        return -1;
    }
    
    char* token =  NULL;
    
    while((token =  TKANGetNextToken(tokenizer)) != NULL){
        //got to convert to lowercase
        for(int i = 0; token[i]; i++){
            token[i] = tolower(token[i]);
        }
        //now add to hash
        addWord(filename, token, tokenizer->copied_string);
        // and free created token!
        free(token);
        }
    //check if tokeniser object is freed or not
    if(tokenizer  != NULL){
        TKANDestroy(tokenizer);
    }
}
Exemplo n.º 9
0
/******************************** Word Counting with Binary Tree
 * *******************************/
WordNode *addWord(WordNode *p, char *w) {
	int cond;

	if (p == NULL) {  /* a new word has arrived */
		p = walloc(); /* make a new node */
		p->word = strdup2(w);
		p->count = 1;
		p->left = p->right = NULL;
	} else if ((cond = strcmp(p->word, w)) == 0)
		p->count++;    /* repeated word */
	else if (cond < 0) /* less than into left subtree */
		p->left = addWord(p->left, w);
	else /* greater than into right subtree */
		p->right = addWord(p->right, w);
	return p;
}
Exemplo n.º 10
0
HTMLGenerator::HTMLGenerator(WordTree* inwords, string inout) {
  outdir = inout;
  if(outdir.find("/") == -1) outdir.append("/");
  words = inwords;
  ofstream outindex((outdir + "index.html").c_str());
  outindex << "<html><head><title>" << endl
	   << "Ged Crimsonclaw's page of Letters" << endl
	   << "</title></head><body>" << endl
	   << "Here Ged has compiled, for your enjoyment "
	   << "a list of the first letters of all the "
	   << "words you may wish to discover. <br>" << endl
	   << "Please enjoy browsing the various links "
	   << "found on these pages. <br><br>" << endl;
  Word* temp = words->pop();
  for(char i = 'a'; i <= 'z'; i++) {
    outindex << "<a href=" << i << ".html>" << (char)toupper(i)
	     << "</a><br>" << endl;
    ofstream outword((outdir + i + ".html").c_str());
    outword << "<html><head><title>" << endl
	    << "Ged Crimsonclaw's " << (char)toupper(i) << " page"
	    << endl << "</title></head><body>" << endl
	    << "Here Ged has compiled, for your enjoyment "
	    << "a list of all the words starting with the "
	    << "letter " << (char)toupper(i) << ".<br>" << endl
	    << "Please enjoy browsing the various " << endl
	    << "links found on these pages.<br><br>" <<endl;
    while(temp != 0 && temp->word[0] == i) {
      addWord(temp, outword);
      delete temp;
      temp = words->pop();
    }//while
    outword << "</body></html>" << endl;
  }//for
  outindex << "</body></html>" << endl;
}
Exemplo n.º 11
0
int afficheMenu(char* dic[])
{
    switch (myMenu())
    {
    case 1:
        printf("\nComparaison de 2 mots :\n\n");
        wordIhm();
        break;
    case 2:
        printf("Comparaison et tri\n\n");
        sortMyArr();
    case 3:
        printf("Rechercher un mot dans le dictionnaire\n\n");
        compareWords(dic);
        break;
    case 4:
        printf("Ajouter un mot dans le dictionnaire\n\n");
        addWord(dic);
        break;
    case 5:
        printf("Supprimer un mot\n\n");
        removeWord(dic);
        break;
    case 6:
        printf("Trier un tableau\n\n");
        sortAnArr();
    case 7:
        printf("Quitter");
        return 1;
    default:
        printf("Quitter");
        return 1;
    }
    return 0;
}
Exemplo n.º 12
0
unsigned AVIFileSink::addZeroWords(unsigned numWords) {
  for (unsigned i = 0; i < numWords; ++i) {
    addWord(0);
  }

  return numWords*4;
}
Exemplo n.º 13
0
int openFile(char* filename){
    FILE *fp = fopen(filename, "r"); //read only
    //empty file
    if(fp == NULL){
        printf("Empty file or NULL error\n");
        return -1;
    }
    char word[100]; // create char array;
    while(fscanf(fp, "%s", word) !=EOF){
        //fscanf(fp, "%s", word);
         fscanf(fp, "%49[a-zA-Z0-9]", word);
        //TokenizerANT* tokenizer = (TokenizerANT*)malloc(sizeof(TokenizerANT));
        //tokenizer = TKANCreate(word);
        TokenizerANT* tokenizer = TKANCreate(word);
        //printf("word is %s\n",word);
	
	if(tokenizer == NULL) {
		printf("Error: unable to create tokenizer\n");
	}
	
	char* token = NULL;
	//printf("here\n");
        //printf("token is %s\n",tokenizer->copied_string);
        token = TKANGetNextToken(tokenizer);
        
        // need to record the token in the file and the count
 
        addWord(token,filename);
        printf("token is %s\n",token);
         }
    fclose(fp);
    return 0;
}
Exemplo n.º 14
0
LOCAL_C TInt findWordSplitterL(TAny *aParams)
	{
	SFindInTextDefWordParser *parser=(SFindInTextDefWordParser *)aParams;
	const TText *ptr=parser->iSearchString->Ptr();
	const TText *end=ptr+parser->iSearchString->Length();
	const TText *startOfWord=NULL;
	FOREVER
		{
		if (ptr==end || !TChar(*ptr).IsAlphaDigit())
			{
			if (startOfWord)
				{
				TPtrC addWord(startOfWord,ptr-startOfWord);
				parser->iWordArray->AppendL(addWord);
				startOfWord=NULL;
				}
			if (ptr==end)
				break;
			}
		else if (!startOfWord)
			startOfWord=ptr;
		ptr++;
		}
	return(KErrNone);
	}
Exemplo n.º 15
0
void MainWindow::createActions()
{
  QString s;

  OEG::Qt::MainWindow::createActions();

  a_add_word = new QAction(_("&Add word ..."), this);
  a_add_translation = new QAction(_("Add t&ranslation ..."), this);
  a_translate = new QAction(_("&Translate"), this);
  a_toggle_direction = new QAction(_("Toggle &direction"), this);

  s = _("Add one or more words to the dictionary.");
  a_add_word->setToolTip(s);
  a_add_word->setStatusTip(s);
  s = _("Add a new word combination to the dictionary.");
  a_add_translation->setToolTip(s);
  a_add_translation->setStatusTip(s);
  s = _("Translate input text.");
  a_translate->setToolTip(s);
  a_translate->setStatusTip(s);
  s = _("Toggle translation direction.");
  a_toggle_direction->setToolTip(s);
  a_toggle_direction->setStatusTip(s);

  connect(a_add_word,         SIGNAL(triggered()),
          this,               SLOT(addWord()));
  connect(a_add_translation,  SIGNAL(triggered()),
          this,               SLOT(addTranslation()));
  connect(a_translate,        SIGNAL(triggered()),
          this,               SLOT(translate()));
  connect(a_toggle_direction, SIGNAL(triggered()),
          this,               SLOT(toggleDirection()));
}
Exemplo n.º 16
0
void addWord(QNFA *lexer, const QString& w, int action, bool cs)
{
	if ( !lexer || !(lexer->type & CxtBeg) || !lexer->out.branch )
		return;
	
	// try using the fastest way if possible
	
	QString pt;
	
	if ( plain(w, &pt) && cs )
	{
		addWord(lexer->tree, pt, action, cs);
		return;
	}
	
	// fallback on (fast) regexp-like NFA-based semi-compiled parsing
	QNFA *nfa, *word, *end;
	
	word = sequence(w.constData(), w.length(), &end, cs);
	word->assertion |= WordStart;
	
	nfa = new QNFA;
	nfa->type = Match;
	nfa->assertion = WordEnd;
	nfa->actionid = action;
	
	end->out.next = nfa;
	
	//lexer->out.branch->append(word);
	addNFA(lexer, word);
}
Exemplo n.º 17
0
static void splitIntoWords( void ) {
    MSGSYM *m;
    WORD *w;
    WORDREF *r;
    WORDREF **a;
    char *p;

    for( m = messageSyms; m != NULL; m = m->next ) {
        p = m->lang_txt[LANG_English];
        a = &(m->words);
        for(;;) {
            if( p[0] && isspace( p[0] ) && isspace( p[1] ) ) {
                errorLocn( m->fname, m->line, "MSGSYM %s text has too many blanks '%s'\n",
                        m->name, p );
            }
            p = skipSpace( p );
            if( *p == '\0' ) break;
            p = skipNonSpace( word, p );
            w = addWord( m );
            r = malloc( sizeof( *r ) );
            r->word = w;
            r->next = NULL;
            *a = r;
            a = &(r->next);
        }
    }
}
Exemplo n.º 18
0
void AVIFileSink::completeOutputFile() {
  if (fHaveCompletedOutputFile || fOutFid == NULL) return;

  // Update various AVI 'size' fields to take account of the codec data that
  // we've now written to the file:
  unsigned maxBytesPerSecond = 0;
  unsigned numVideoFrames = 0;
  unsigned numAudioFrames = 0;

  //// Subsession-specific fields:
  MediaSubsessionIterator iter(fInputSession);
  MediaSubsession* subsession;
  while ((subsession = iter.next()) != NULL) {
    AVISubsessionIOState* ioState
      = (AVISubsessionIOState*)(subsession->miscPtr);
    if (ioState == NULL) continue;

    maxBytesPerSecond += ioState->fMaxBytesPerSecond;

    setWord(ioState->fSTRHFrameCountPosition, ioState->fNumFrames);
    if (ioState->fIsVideo) numVideoFrames = ioState->fNumFrames;
    else if (ioState->fIsAudio) numAudioFrames = ioState->fNumFrames;
  }

  //// Global fields:
  add4ByteString("idx1");
  addWord(fNumIndexRecords*4*4); // the size of all of the index records, which come next:
  for (AVIIndexRecord* indexRecord = fIndexRecordsHead; indexRecord != NULL; indexRecord = indexRecord->next()) {
    addWord(indexRecord->chunkId());
    addWord(indexRecord->flags());
    addWord(indexRecord->offset());
    addWord(indexRecord->size());
  }

  fRIFFSizeValue += fNumBytesWritten;
  setWord(fRIFFSizePosition, fRIFFSizeValue);

  setWord(fAVIHMaxBytesPerSecondPosition, maxBytesPerSecond);
  setWord(fAVIHFrameCountPosition,
	  numVideoFrames > 0 ? numVideoFrames : numAudioFrames);

  fMoviSizeValue += fNumBytesWritten;
  setWord(fMoviSizePosition, fMoviSizeValue);

  // We're done:
  fHaveCompletedOutputFile = True;
}
Exemplo n.º 19
0
/* Note that the usage of this function is very particular. It breaks strings into words through spaces. So don't do crazy things with spaces (such as several spaces in a row, or starting the string with a space). */
void dMessageSystem::addMessage(string msg)
{
  int last=0;
  string word;
  for(int i=0; i<msg.length(); i++)
  {
    if(msg[i] == ' ')
    {
      word = msg.substr(last, i-last);
      addWord(word);
      last = i+1;
    }
  }
  word = msg.substr(last, msg.length()-last);
  addWord(word);

}
Exemplo n.º 20
0
static void
parseName(const char *name, int16_t length) {
    int16_t start=0, limit, wordLength/*, prevStart=-1*/;
    Word *word;

    while(start<length) {
        /* skip any "noise" characters */
        limit=skipNoise(name, start, length);
        if(start<limit) {
            /*prevStart=-1;*/
            start=limit;
        }
        if(start==length) {
            break;
        }

        /* get a word and add it if it is longer than 1 */
        limit=getWord(name, start, length);
        wordLength=(int16_t)(limit-start);
        if(wordLength>1) {
            word=findWord(name+start, wordLength);
            if(word==NULL) {
                word=addWord(name+start, wordLength);
            }
            countWord(word);
        }

#if 0
        /*
         * if there was a word before this
         * (with no noise in between), then add the pair of words, too
         */
        if(prevStart!=-1) {
            wordLength=limit-prevStart;
            word=findWord(name+prevStart, wordLength);
            if(word==NULL) {
                word=addWord(name+prevStart, wordLength);
            }
            countWord(word);
        }
#endif

        /*prevStart=start;*/
        start=limit;
    }
}
Exemplo n.º 21
0
 arvore(vector<string> &dic){
   nodes = 0;
   limpar.clear();
   root = new node();
   for(auto &word : dic){
     addWord(root, word, 0);
   }
 }
Exemplo n.º 22
0
void Tester_68k::testExt() {
    u16 opcode;

    //MOVE.L #$12345678, D3
    //MOVE #$13, CCR
    //EXT.W D3
    setUp();
    opcode = 0x4800 | 2 << 6 | 3;
    addWord(opcode);
    addWord(0xffff);
    power();
    setRegD(3, 0x12345678);
    setCCR(0x13);
    process();
    check("ext.w D3");

    //MOVE.L #$12345600, D3
    //MOVE #$13, CCR
    //EXT.W D3
    setUp();
    opcode = 0x4800 | 2 << 6 | 3;
    addWord(opcode);
    addWord(0xffff);
    power();
    setRegD(3, 0x12345600);
    setCCR(0x13);
    process();
    check("ext.w D3 zero");

    //MOVE.L #$123456f0, D3
    //MOVE #$13, CCR
    //EXT.W D3
    setUp();
    opcode = 0x4800 | 2 << 6 | 3;
    addWord(opcode);
    addWord(0xffff);
    power();
    setRegD(3, 0x123456f0);
    setCCR(0x13);
    process();
    check("ext.w D3 negative");

    //MOVE.L #$1234f6f0, D3
    //MOVE #$13, CCR
    //EXT.L D3
    setUp();
    opcode = 0x4800 | 3 << 6 | 3;
    addWord(opcode);
    addWord(0xffff);
    power();
    setRegD(3, 0x1234f6f0);
    setCCR(0x13);
    process();
    check("ext.l D3");
}
Exemplo n.º 23
0
void Tester_68k::testRts() {
    u16 opcode;
    //MOVE.L    #$2000, A7
    //MOVE.L    #$c, $2000
    //RTS
    //NOP
    //NOP
    setUp();
    opcode = 0x4e75;
    addWord(opcode);
    addWord(0x4e71);
    addWord(0x4e71);
    power();
    setRegA(7, 0x2000);
    memoryblock.writeLong(0x2000, 0xc);
    process();
    check("RTS");
}
Exemplo n.º 24
0
void Tester_68k::testCmpi() {
    u16 opcode;

    //MOVE.L    #$fff2ffff, D1
    //MOVE      #$0, CCR
    //CMPI.W    #$ffff, D1
    setUp();
    opcode = 0xc00 | (1 << 6) | getEA(DR_DIRECT, 1);
    addWord(opcode);
    addWord(0xffff);
    addWord(0xffff);
    power();
    setRegD(1, 0xfff2ffff);
    process();
    check("CMPI.W #$ffff, D1");

    //MOVE.L    #$7fffffff, D1
    //MOVE      #$0, CCR
    //CMPI.L    #$80000000, D1
    setUp();
    opcode = 0xc00 | (2 << 6) | getEA(DR_DIRECT, 1);
    addWord(opcode);
    addWord(0x8000);
    addWord(0);
    addWord(0xffff);
    power();
    setRegD(1, 0x7fffffff);
    process();
    check("CMPI.L #$80000000, D1");

    //MOVE.L    #$8f, D1
    //MOVE      #$0, CCR
    //CMPI.B    #$90, D1
    setUp();
    opcode = 0xc00 | (0 << 6) | getEA(DR_DIRECT, 1);
    addWord(opcode);
    addWord(0x0090);
    addWord(0xffff);
    power();
    setRegD(1, 0x8f);
    process();
    check("CMPI.B #$90, D1");
}
Exemplo n.º 25
0
void MalcevSet::makeNormalClosure() {

  if(isNormal == yes) return;

  const BasicCommutators& BC = theCollector.commutators();
  int nilClass = BC.nilpotencyClass();

  int upper_i = BC.theFirstOfWeight(nilClass);

  for(int i = 1; i <= upper_i; i++) {

    if( ! theSet.bound( Generator(i) ) ) continue;
    PolyWord Wi = theSet.valueOf( Generator(i) );
    PolyWord WiInv = Wi.inverse();

    // trying generators of the group

    for(int j = 1; j <= BC.numberOfGenerators(); j++) {

      Generator g(j); 
      PolyWord comm = collect( Wi * Letter(g,-1) * WiInv * Letter(g,1) ); 

      addWord(comm);
    }

    // trying basis elements

    int upper_j = BC.theFirstOfWeight(nilClass - BC.weightOf(i) + 1);
    if(upper_j > i) upper_j = i;

    for(int j = 1; j < upper_j; j++) {

      if( ! theSet.bound( Generator(j) ) ) continue;
      PolyWord Wj = theSet.valueOf( Generator(j) );

      PolyWord comm = collect( Wi * Wj * WiInv * Wj.inverse() );

      addWord(comm);
    }
  }
  isBasis = true;
  isNormal = yes;
}
Exemplo n.º 26
0
int main(){
    const char name[] = "text.txt";
    FILE * file;
    file = fopen(name, "r");
    if(NULL == file)
        return 1;
    char c;
    int len = 0;
    char word[25] = "";
    text_t * text = text_new();
    sen_t * sen = sen_new();
    while((c = fgetc(file)) != EOF){
        //printf("%c", c);
        if(ispunct(c)){
            if(c == '.' || c == '!' || c == '?'){
                if(len == 0)
                    continue;
                addWord(sen, word_new(word));
                addSen(text, sen);
                sen = sen_new();
                memset(word, 0, 25);
                len = 0;
            }
            continue;
        }
        else if(isspace(c)){
            if(len == 0)
                continue;
            addWord(sen, word_new(word));
            memset(word, 0, 25);
            len = 0;
        }
        else{
            word[len] = c;
            len++;
        }
    }

    fclose(file);
    fprint(text);
    text_free(text);
    return 0;
}
Exemplo n.º 27
0
 void addWord(Node* node, const string &word, int idx, int id) {
     if (idx == (int)word.length()) {
         node->id = id;
     } else {
         int next = word[idx] - 'a';
         if (node->next[next] == nullptr) {
             node->next[next] = new Node();
         }
         addWord(node->next[next], word, idx + 1, id);
     }
 }
Exemplo n.º 28
0
SummNode::SummNode(const std::string& str, size_t offset, SummNode* parent) {
    c = str[offset];
    words=0;
    refs=0;
    this->parent=parent;

    //if leaf
    if(!addWord(str, ++offset)) {
         words=1;
    }
}
Exemplo n.º 29
0
bool XAP_Dictionary::load(void)
{
	UT_ASSERT(m_hashWords.size() == 0);

	if (!_openFile("r"))
		return false;

	if (!_parseUTF8())
		_abortFile();
	else
		_closeFile();

	m_bDirty = false;
//
// Hardwire in some words that should be in the English Language :-)
//
	addWord("AbiWord");
	addWord("AbiSource");
	return true;
}
Exemplo n.º 30
0
int main()
{
    char s1[MAXL + 6];
    char s2[MAXL + 6];
    int t1, t2;
    init();
    initNode(0);
    nodeNumber = 1;
    wordNumber = 0;
    memset(color, 0, sizeof(color));
    while(~scanf("%s%s", s1, s2))
    {
        t1 = addWord(0, s1);
        t2 = addWord(0, s2);
        ++ color[t1];
        ++ color[t2];
        combine(t1, t2);
    }
    bool connectivity = true;
    int oddNumber = 0;
    for(int i=0;i<wordNumber;++i)
    {
        if(find(i) != find(0))
        {
            connectivity = false;
        }
        if(color[i] & 1)
        {
            ++ oddNumber;
        }
    }
    if(!connectivity || oddNumber > 2)
    {
        printf("Impossible\n");
    }
    else
    {
        printf("Possible\n");
    }
    return 0;
}