void NaiveBayesianClassifier::changeWordCount(const QString &category, const QString &word, int change)
{
    long idxsearch=-1;
    c4_Row findrow;
    c4_StringProp match("word");
    
    const char* test = word;
    match(findrow) = test;
    c4_IntProp count("count");

    c4_View cat = getCategory(category);

    idxsearch = cat.Find(findrow,idxsearch+1);

    if (idxsearch>=0) {
        long int zero = 0;
        count(cat[idxsearch]) = std::max(zero, count(cat[idxsearch]) + change);
    } 
    else 
    {
        c4_StringProp newWord("word");
        c4_IntProp newCount("count");
        c4_Row newRow;
        QString temp = QString(word);
        newWord(newRow)=temp;
        newCount(newRow)=1;
        cat.Add(newRow);
    }
}
예제 #2
0
 int bfs(string beginWord, string endWord, unordered_set<string> wordList)
 {
 	queue<pair<string,int> > q;
 	q.push(make_pair(beginWord,1));
 	unordered_set<string> visited;
 	visited.insert(beginWord);
 	bool found = false;
 	while(!q.empty())
 	{
 		pair<string,int> cur = q.front();
 		q.pop();
 		string word = cur.first;
 		int len = word.size();
 		for (int i = 0; i < len; ++i)
 		{
 			string newWord(word);
 			for(int j = 0; j < 26;++j)
 			{
 				newWord[i] = 'a' + j;
 				if(newWord == endWord)
 				{
 					found = true;
 					return cur.second+1;
 				}
 				if(wordList.count(newWord) > 0 && visited.count(newWord) == 0)
 				{
 					visited.insert(newWord);
 					q.push(make_pair(newWord,cur.second+1));
 				}
 			}
 		}
 	}
 	if(found == false)
 		return 0;
 }
int testInsertBST(BST *tree, int isVerbose) {
    printf("TESTCASE: INSERTION\n");
    // Print the tree
    if (isVerbose == TRUE) {
        printf("PRE-INSERTION - TREE OVERVIEW\n");
        inOrderPrintBST(tree);
    }
    
    // Create test word
    WORD *insertionTestWord = newWord(TEST_WORD, newWordLocation(1, 1, 1));
    
    if (isVerbose == TRUE) {
        printf("INSERTION - TEST WORD\n");
        printWord(insertionTestWord, 15, maxPageDigit, maxLineDigit);
    }
    
    // Run the insert function
    insertBST(tree, insertionTestWord);
    
    // Print the tree
    if (isVerbose == TRUE) {
        printf("POST-INSERTION - TREE OVERVIEW\n");
        inOrderPrintBST(tree);
    }
    
    if (searchBST(tree, TEST_WORD) != NULL) {
        return SUCCESS;
    }
    return FAILED;
}
예제 #4
0
Item*
Bchart::
add_item2(int b, const Term* trm, int wInt, ECString wrdstr)
{
  //cerr << "AI " << b << " " << *trm << " " << wInt << endl;
  Item* ans = NULL;
  Wrd* wrd = NULL;
  bool wasthere;
  ans = addtochart(trm);
  newWord(wrdstr, wInt, ans);
  return ans;
}
예제 #5
0
Item*
Bchart::
add_item(int b, const Term* trm, int wInt )
{
  //cerr << "AI " << b << " " << *trm << " " << wInt << endl;
  Item* ans = NULL;
  Wrd* wrd = NULL;
  bool wasthere;
  if(!trm->terminal_p()) return in_chart(b,trm,wasthere);
  if(wInt < 0) return in_chart(b,trm, wasthere);
  ans = addtochart(trm);
  newWord(intToW(wInt), wInt,ans);
  return ans;
}
예제 #6
0
void scoreWord() {
  static int letterValue[26] = {13,3,2,1,4,2,4,1,8,5,1,3,1,1,3,10,1,1,1,4,4,8,4,10};
  int i;

  if (!isaWord())
    return;

  for(i=0; i <= currentLetter; i++) {
    fprintf(stderr, "adding %i to score\n", letterValue[currentWord[i] - 97]);
    score += letterValue[currentWord[i] - 97];
  } /* for */
  newWord();


} /* scoreWord */
예제 #7
0
NS_IMETHODIMP 
mozSpellChecker::Replace(const nsAString &aOldWord, const nsAString &aNewWord, bool aAllOccurrences)
{
  if(!mConverter)
    return NS_ERROR_NULL_POINTER;

  nsAutoString newWord(aNewWord); // sigh

  if(aAllOccurrences){
    int32_t selOffset;
    int32_t startBlock,currentBlock,currOffset;
    int32_t begin,end;
    bool done;
    nsresult result;
    nsAutoString str;

    // find out where we are
    result = SetupDoc(&selOffset);
    if(NS_FAILED(result))
      return result;
    result = GetCurrentBlockIndex(mTsDoc,&startBlock);
    if(NS_FAILED(result))
      return result;

    //start at the beginning
    result = mTsDoc->FirstBlock();
    currOffset=0;
    currentBlock = 0;
    while( NS_SUCCEEDED(mTsDoc->IsDone(&done)) && !done )
      {
        result = mTsDoc->GetCurrentTextBlock(&str);
        do{
          result = mConverter->FindNextWord(str.get(),str.Length(),currOffset,&begin,&end);
          if(NS_SUCCEEDED(result)&&(begin != -1)){
            if (aOldWord.Equals(Substring(str, begin, end-begin))) {
              // if we are before the current selection point but in the same block
              // move the selection point forwards
              if((currentBlock == startBlock)&&(begin < selOffset)){
                selOffset +=
                  int32_t(aNewWord.Length()) - int32_t(aOldWord.Length());
                if(selOffset < begin) selOffset=begin;
              }
              mTsDoc->SetSelection(begin, end-begin);
              mTsDoc->InsertText(&newWord);
              mTsDoc->GetCurrentTextBlock(&str);
              end += (aNewWord.Length() - aOldWord.Length());  // recursion was cute in GEB, not here.
            }
          }
          currOffset = end;
        }while(currOffset != -1);
        mTsDoc->NextBlock();
        currentBlock++;
        currOffset=0;          
      }

    // We are done replacing.  Put the selection point back where we found  it (or equivalent);
    result = mTsDoc->FirstBlock();
    currentBlock = 0;
    while(( NS_SUCCEEDED(mTsDoc->IsDone(&done)) && !done ) &&(currentBlock < startBlock)){
      mTsDoc->NextBlock();
    }

//After we have moved to the block where the first occurrence of replace was done, put the 
//selection to the next word following it. In case there is no word following it i.e if it happens
//to be the last word in that block, then move to the next block and put the selection to the 
//first word in that block, otherwise when the Setupdoc() is called, it queries the LastSelectedBlock()
//and the selection offset of the last occurrence of the replaced word is taken instead of the first 
//occurrence and things get messed up as reported in the bug 244969

    if( NS_SUCCEEDED(mTsDoc->IsDone(&done)) && !done ){
      nsString str;                                
      result = mTsDoc->GetCurrentTextBlock(&str);  
      result = mConverter->FindNextWord(str.get(),str.Length(),selOffset,&begin,&end);
            if(end == -1)
             {
                mTsDoc->NextBlock();
                selOffset=0;
                result = mTsDoc->GetCurrentTextBlock(&str); 
                result = mConverter->FindNextWord(str.get(),str.Length(),selOffset,&begin,&end);
                mTsDoc->SetSelection(begin, 0);
             }
         else
                mTsDoc->SetSelection(begin, 0);
    }
 }
  else{
    mTsDoc->InsertText(&newWord);
  }
  return NS_OK;
}
예제 #8
0
Job* Parser::parseLine (void) {
	job = new Job();
	currState = PARSCMD;
	int i, length, curr;
	int rflag;
	
	// Limpa o buffer de entrada para evitar loop infinito
	strcpy(line, "\0");
	std::cin.clear();
	
	std::cin.getline (line, MAX_LENGTH);
	
	i = 0;
	while (i < length && line[i] == ' ')	i++;
	length = strlen(line+i);
	// Checa se a linha nao estava em branco
	if (length == 0) {
		job->addFlag (shooSH_NOP);
		return job;
	} else {
		while (line[--length] == ' '); // pega os espacos do fim
		length++;
		if (strcmp (line+i, "exit") == 0) { //builtin
			job->addFlag (shooSH_EXIT);
			return job;
		}
	}
	if ((line+i)[length-1] == '&')
		job->setCommand (std::string (line+i, length-1));
	else
		job->setCommand (std::string (line+i, length));
		
	while (currState != PARSSUCCESS && currState != PARSFAIL) {
		if (currState == PARSCMD) {
			newProcess();
			newWord();
			rflag = 0;
			// pega espacos
			while (i < length && line[i] == ' ')	i++;
			// esperava um comando, mas nao veio nada (usado para pipe)
			if (i == length) {
				currState = PARSFAIL;
			} else {
				// le ate encontrar um espaco
				while (i < length && line[i] != ' ')	cmdList[cmdListSize][currChar++] = line[i++];
				currState = PARSNEXT;
			}
			endWord();
		} else if (currState == PARSNEXT) {
			// le espaco
			while (i < length && line[i] == ' ')	i++;
	
			if (i == length) { //chegou ao fim da linha
				currState = PARSSUCCESS;
				endProcess();
			} else {
				// procura token
				switch (line[i]) {
					case '<':
						i++;
						currState = PARSRIN;
						break;
					case '>':
						i++;
						currState = PARSROUT;
						break;
					case '2': //pode ser argumento ou redirecionamento de erro
						i++;
						currState = PARSTWO;
						break;
					case '|':
						i++;
						job->addFlag (shooSH_PIPE);
						endProcess();
						currState = PARSCMD;
						break;
					case '&':
						i++;
						job->addFlag (shooSH_BG);
						endProcess();
						currState = PARSSUCCESS;
						break;
					default:
						currState = PARSPARAM;
				}
			}
		} else if (currState == PARSPARAM) {
			newWord();
			while (i < length && line[i] != ' ' && line[i] != '\"' && line[i] != '\'')	cmdList[cmdListSize][currChar++] = line[i++];
			if (line[i] == '\"') {
				i++;
				while (i < length && line[i] != '\"')	cmdList[cmdListSize][currChar++] = line[i++];
				if (i == length) {
					endWord();
					currState = PARSFAIL;
				} else {
					i++;
					endWord();
					currState = PARSNEXT;
				}
			} else if (line[i] == '\'') {
				i++;
				while (i < length && line[i] != '\'')	cmdList[cmdListSize][currChar++] = line[i++];
				if (i == length) {
					endWord();
					currState = PARSFAIL;
				} else {
					i++;
					endWord();
					currState = PARSNEXT;
				}
			} else {
				endWord();
				currState = PARSNEXT;
			}
		} else if (currState == PARSTWO) {
			if (line[i] == '>') {
				i++;
				endWord();
				currState = PARSRERR;
			} else {
				i--;
				currState = PARSPARAM;
			}
			endWord();
		} else if (currState == PARSRERR) {
			if (line[i] == '>') { // append
				i++;
				rflag = REDERRA;
			} else { // trunc
				rflag = REDERRT;
			}
			currState = PARSFILENAME;
		} else if (currState == PARSRIN) {
			rflag = REDIN;
			currState = PARSFILENAME;
		} else if (currState == PARSROUT) {
			if (line[i] == '>') { // append
				i++;
				rflag = REDOUTA;
			} else { // trunc
				rflag = REDOUTT;
			}
			currState = PARSFILENAME;
		} else if (currState == PARSFILENAME) {
			while (i < length && line[i] == ' ')	i++;
			if (i == length)	currState = PARSFAIL;
			else {
				curr = 0;
				if (line[i] == '"') { // le nomes como "file name"
					i++;
					while (i < length && line[i] != '"')	filename[curr++] = line[i++];
					if (i == length)	currState = PARSFAIL;
					else	i++;
				} else if (line[i] == '\'') { // le nomes do tipo 'file name'
					i++;
					while (i < length && line[i] != '\'')	filename[curr++] = line[i++];
					if (i == length)	currState = PARSFAIL;
					else	i++;
				} else { // le nomes do tipo filename
					while (i < length && line[i] != ' ')	filename[curr++] = line[i++];
				}
				filename[curr] = '\0';
				job->setProcessFile (filename, rflag);
				currState = PARSNEXT;
			}
		}
	}
	if (currState == PARSFAIL)	job->addFlag (shooSH_FAIL);
	return job;
}
예제 #9
0
//-----------------------------------------------------------------
// format the textbox contents. 
void mgTextScan::scan(
  unsigned int &posn)            // starting position
{
  // parse buffer and format text
  m_clipped = false;  

  // set state to default
  m_page->getDefaultFormat(m_justify, m_leftMargin, m_rightMargin, m_indent, m_wrap);
  m_page->getDefaultFont(m_fontFace, m_fontSize, m_fontItalic, m_fontBold, m_color);
  m_baseFontSize = m_fontSize;
  newFont();

  // temporaries for when we return values to defaults
  mgString face;
  short left, right, indent, size;
  BOOL wrap, italic, bold;
  DWORD color;
  mgTextAlign justify;

  unsigned int count = 0;
  BOOL endBuffer = false;
  while (!m_clipped && !endBuffer)
  {
    mgFormatCmd cmd = m_buffer->readCommand(posn);
    switch (cmd)
    {
      case mgJustifyCmd: 
      {
        m_justify = m_buffer->readJustify(posn);
        if (m_justify == mgTextAlignHDefault)
          m_page->getDefaultFormat(m_justify, left, right, indent, wrap);
        break;
      }
        
      case mgLeftMarginCmd: 
      {
        short value = m_buffer->readLeftMargin(posn);
        if (value == MGDEFAULTSHORT)
          m_page->getDefaultFormat(justify, m_leftMargin, right, indent, wrap);
        else m_leftMargin = (m_page->getUnits()*value)/100;
        newMargins();
        break;
      }

      case mgRightMarginCmd: 
      {
        short value = m_buffer->readRightMargin(posn);
        if (value == MGDEFAULTSHORT)
          m_page->getDefaultFormat(justify, left, m_rightMargin, indent, wrap);
        else m_rightMargin = (m_page->getUnits()*value)/100;
        newMargins();
        break;
      }

      case mgIndentCmd:
      {
        short value = m_buffer->readIndent(posn);
        if (value == MGDEFAULTSHORT)
          m_page->getDefaultFormat(justify, left, right, m_indent, wrap);
        else m_indent = (m_page->getUnits() * value)/100;
        newMargins();
        break;
      }

      case mgWrapCmd: 
      {
        mgBooleanAttr value = m_buffer->readWrap(posn);
        if (value == mgDefaultBoolean)
          m_page->getDefaultFormat(justify, left, right, indent, m_wrap);
        else m_wrap = value == mgTrue;
        break;
      }

      case mgFontFaceCmd: 
        m_buffer->readFontFace(posn, m_fontFace);
        if (m_fontFace.equals("default"))
          m_page->getDefaultFont(m_fontFace, size, italic, bold, color);
        newFont();
        break;
  
      case mgFontSizeCmd: 
      {
        short value = m_buffer->readFontSize(posn);
        if (value == MGDEFAULTSHORT)
          m_page->getDefaultFont(face, m_fontSize, italic, bold, color);
        else m_fontSize = (m_baseFontSize * value)/100;
        newFont();
        break;
      }
  
      case mgFontItalicCmd: 
      {
        mgBooleanAttr value = m_buffer->readFontItalic(posn);
        if (value == mgDefaultBoolean)
          m_page->getDefaultFont(face, size, m_fontItalic, bold, color);
        else m_fontItalic = value == mgTrue;
        newFont();
        break;
      }
  
      case mgFontBoldCmd: 
      {
        mgBooleanAttr value = m_buffer->readFontBold(posn);
        if (value == mgDefaultBoolean)
          m_page->getDefaultFont(face, size, italic, m_fontBold, color);
        else m_fontBold = value == mgTrue;
        newFont();
        break;
      }
  
      case mgColorCmd:
        m_color = m_buffer->readColor(posn);
        if (m_color == MGDEFAULTCOLOR)
          m_page->getDefaultFont(face, size, italic, bold, m_color);
        break;
        
      case mgAnchorCmd:
//        m_anchor = (mgAnchorDesc*) m_buffer->readPtr(posn);
        break;
          
      case mgSpaceCmd: 
        newWord();
        addSpace(m_buffer->readSpace(posn));
        break;

      case mgTabCmd: 
      {
        newWord();
        short value = m_buffer->readTab(posn);
        value = (m_page->getUnits() * value)/100;
        addTab(value);
        break;
      }

      case mgTextCmd:
      {
        int textLen;
        const char* text;
        m_buffer->readText(posn, textLen, text);

        if (!m_wrap)
          addFrag(false, text, textLen);
        else
        {
          // writeText has converted whitespace to blanks and removed
          // duplicate blanks.  However, a single word may be broken into 
          // multiple fragments due to tags within the word.
          // ex: <b>T</b>est
          while (textLen > 0)
          {
            int c = 0xFF & text[0];
            BOOL isBlank = isspace(c) != 0;
            if (isBlank)
            {
              newWord();
              text++;
              textLen--;
            }
            // count characters of next word
            int len = 0;
            while (len < textLen)
            {
              c = 0xFF & text[len];
              if (!isspace(c))
                len++;
              else break;
            }

            addFrag(isBlank, text, len);

            text += len;
            textLen -= len;
          }
        }
        break;
      }

      case mgChildCmd:
      {
        // read child info 
        const void* child;
        mgTextAlign halign;
        mgTextAlign valign;
        m_buffer->readChild(posn, child, halign, valign);

        newWord();  // breaks the current word
        addChild(child, halign, valign);
        break;
      } 

      case mgBreakCmd: 
      {
        int height = m_buffer->readBreak(posn);
        newWord();  // breaks the current word
        newLine(height);
        break;
      }

      case mgClearCmd: 
      {
        mgTextAlign clear = m_buffer->readClear(posn);
        clearMargins(clear);
        break;
      }

      case mgTargetCmd:
        addTarget((int*) m_buffer->readTarget(posn));
        break;

      case mgDoneCmd:
        newWord();  // breaks the current word
        done();   // end of input
        endBuffer = true;
        break;
    } 
  } 
}
예제 #10
0
void
FieldWriter::newWord(vespalib::stringref word)
{
    newWord(_wordNum + 1, word);
}