Exemplo n.º 1
0
void SpellCheckerCore::replaceWordsInCurrentEditor(const WordList &wordsToReplace, const QString &replacementWord)
{
    if(wordsToReplace.count() == 0) {
        Q_ASSERT(wordsToReplace.count() != 0);
        return;
    }
    if(d->currentEditor == NULL) {
        Q_ASSERT(d->currentEditor != NULL);
        return;
    }
    TextEditor::TextEditorWidget* editorWidget = qobject_cast<TextEditor::TextEditorWidget*>(d->currentEditor->widget());
    if(editorWidget == NULL) {
        Q_ASSERT(editorWidget != NULL);
        return;
    }

    QTextCursor cursor = editorWidget->textCursor();
    /* Iterate the words and replace all one by one */
    foreach(const Word& wordToReplace, wordsToReplace) {
        editorWidget->gotoLine(wordToReplace.lineNumber, wordToReplace.columnNumber - 1);
        int wordStartPos = editorWidget->textCursor().position();
        editorWidget->gotoLine(wordToReplace.lineNumber, wordToReplace.columnNumber + wordToReplace.length - 1);
        int wordEndPos = editorWidget->textCursor().position();

        cursor.beginEditBlock();
        cursor.setPosition(wordStartPos);
        cursor.setPosition(wordEndPos, QTextCursor::KeepAnchor);
        cursor.removeSelectedText();
        cursor.insertText(replacementWord);
        cursor.endEditBlock();
    }
void SpellCheckerCore::giveSuggestionsForWordUnderCursor()
{
  if( d->currentEditor.isNull() == true ) {
    return;
  }
  Word word;
  WordList wordsToReplace;
  bool wordMistake = isWordUnderCursorMistake( word );
  if( wordMistake == false ) {
    return;
  }

  getAllOccurrencesOfWord( word, wordsToReplace );

  SuggestionsDialog dialog( word.text, word.suggestions, wordsToReplace.count() );
  SuggestionsDialog::ReturnCode code = static_cast<SuggestionsDialog::ReturnCode>( dialog.exec() );
  switch( code ) {
    case SuggestionsDialog::Rejected:
      /* Cancel and exit */
      return;
    case SuggestionsDialog::Accepted:
      /* Clear the list and only add the one to replace */
      wordsToReplace.clear();
      wordsToReplace.append( word );
      break;
    case SuggestionsDialog::AcceptAll:
      /* Do nothing since the list of words is already valid */
      break;
  }

  QString replacement = dialog.replacementWord();
  replaceWordsInCurrentEditor( wordsToReplace, replacement );
}
Exemplo n.º 3
0
static void ColouriseWord(StyleContext& sc, WordList& keywords, WordList& keywords2, WordList& keywords3, bool& apostropheStartsAttribute) {
    apostropheStartsAttribute = true;
    sc.SetState(SCE_SPICE_IDENTIFIER);
    std::string word;
    while (!sc.atLineEnd && !IsSeparatorOrDelimiterCharacter(sc.ch)) {
        word += static_cast<char>(tolower(sc.ch));
        sc.Forward();
    }
    if (keywords.InList(word.c_str())) {
        sc.ChangeState(SCE_SPICE_KEYWORD);
        if (word != "all") {
            apostropheStartsAttribute = false;
        }
    }
    else if (keywords2.InList(word.c_str())) {
        sc.ChangeState(SCE_SPICE_KEYWORD2);
        if (word != "all") {
            apostropheStartsAttribute = false;
        }
    }
    else if (keywords3.InList(word.c_str())) {
        sc.ChangeState(SCE_SPICE_KEYWORD3);
        if (word != "all") {
            apostropheStartsAttribute = false;
        }
    }
    sc.SetState(SCE_SPICE_DEFAULT);
}
Exemplo n.º 4
0
DictViewInstance::WordList *DictViewInstance::WordSuggestion(FarStringW &word)
{
  WordList *wl = new WordList();
  _current_color = -1;
  _current_word = word;
  DecisionTable::action_inst_t act_inst = logic.Execute();
  Action *action = static_cast<Action *>(act_inst->client_context);
  far_assert(action);
  FarString suggestion_order = action->suggestions;
  if (suggestion_order.IsEmpty()) 
    for (int i = 0; i<DictCount(); i++)
      suggestion_order += GetDict(i)->dict + ';';
  if (suggestion_order.IsEmpty())
    return wl;
  FarStringTokenizer dicts(suggestion_order, ';');
  for (int i = 0; i < DictCount() && dicts.HasNext(); i++) 
  {
    const FarString &dict(dicts.NextToken());
    for (int j = 0; j < DictCount(); j++)
      if (GetDict(j)->dict == dict) {
        far_assert(spell_factory);
        SpellInstance *dict_inst = spell_factory->GetDictInstance(dict);
        far_assert(dict_inst);
        wl->Add(dict_inst->Suggest(word));
      }
  }
  return wl;
}
Exemplo n.º 5
0
bool SpellCheckerCore::isWordUnderCursorMistake(Word& word) const
{
    if(d->currentEditor.isNull() == true) {
        return false;
    }

    unsigned int column = d->currentEditor->currentColumn();
    unsigned int line = d->currentEditor->currentLine();
    QString currentFileName = d->currentEditor->document()->filePath().toString();
    WordList wl;
    wl = d->spellingMistakesModel->mistakesForFile(currentFileName);
    if(wl.isEmpty() == true) {
        return false;
    }
    WordList::ConstIterator iter = wl.constBegin();
    while(iter != wl.constEnd()) {
        const Word& currentWord = iter.value();
        if((currentWord.lineNumber == line)
                && ((currentWord.columnNumber <= column)
                    && (currentWord.columnNumber + currentWord.length) >= column)) {
            word = currentWord;
            return true;
        }
        ++iter;
    }
    return false;
}
Exemplo n.º 6
0
QString RandomNameProvider::generateRandomName()
{
    static WordList words;

    return  words.at(std::abs(iscore::random_id_generator::getRandomId() % (words.size() - 1))) +
            QString::number(std::abs(iscore::random_id_generator::getRandomId() % 99)) +
            words.at(std::abs(iscore::random_id_generator::getRandomId() % (words.size() - 1))) +
            QString::number(std::abs(iscore::random_id_generator::getRandomId() % 99));
}
Exemplo n.º 7
0
const WordList layprop::ViewProperties::getAllLayers(void)
{
	//drawprop._layset
	WordList listLayers;
	laySetList::const_iterator it;
	for(  it = _drawprop._layset.begin(); it != _drawprop._layset.end(); ++it)
	{
		listLayers.push_back((*it).first);
	}
	return listLayers;
}
Exemplo n.º 8
0
int SCI_METHOD LexerBase::WordListSet(int n, const char *wl) {
	if (n < numWordLists) {
		WordList wlNew;
		wlNew.Set(wl);
		if (*keyWordLists[n] != wlNew) {
			keyWordLists[n]->Set(wl);
			return 0;
		}
	}
	return -1;
}
Exemplo n.º 9
0
void laydata::tdtlibrary::collect_usedlays(WordList& laylist) const
{
   for (cellList::const_iterator CC = _cells.begin(); CC != _cells.end(); CC++)
   {
      CC->second->collect_usedlays(NULL, false,laylist);
   }
   laylist.sort();
   laylist.unique();
   if ( (0 < laylist.size()) && (0 == laylist.front()) )
      laylist.pop_front();
}
Exemplo n.º 10
0
int main(int argc, char *argv[])
{
        WordList wordlist;
	if (argc == 2) {
		wordlist.read_lyrics(argv[1],false);
        	wordlist.search();
	}
	else {
		cout << "Usage: songsearch database.txt\n";
	}
        return 0;
}
void SpellCheckerCore::updateContextMenu()
{
  if( d->contextMenuHolderCommands.isEmpty() == true ) {
    /* Populate the internal vector with the holder actions to speed up the process
     * of updating the context menu when requested again. */
    QVector<const char*> holderActionIds { Constants::ACTION_HOLDER1_ID, Constants::ACTION_HOLDER2_ID, Constants::ACTION_HOLDER3_ID, Constants::ACTION_HOLDER4_ID, Constants::ACTION_HOLDER5_ID };
    /* Iterate the commands and */
    for( int count = 0; count < holderActionIds.size(); ++count ) {
      Core::Command* cmd = Core::ActionManager::command( holderActionIds[count] );
      d->contextMenuHolderCommands.push_back( cmd );
    }
  }

  Word word;
  bool isMistake = isWordUnderCursorMistake( word );
  /* Do nothing if the context menu is not a mistake.
   * The context menu will in this case already be disabled so there
   * is no need to update it. */
  if( isMistake == false ) {
    return;
  }
  QStringList list = word.suggestions;
  /* Iterate the commands and */
  for( Core::Command* cmd: qAsConst( d->contextMenuHolderCommands ) ) {
    Q_ASSERT( cmd != nullptr );
    if( list.size() > 0 ) {
      /* Disconnect the previous connection made, otherwise it will also trigger */
      cmd->action()->disconnect();
      /* Set the text on the action for the word to use*/
      QString replacementWord = list.takeFirst();
      cmd->action()->setText( replacementWord );
      /* Show the action */
      cmd->action()->setVisible( true );
      /* Connect to lambda function to call to replace the words if the
       * action is triggered. */
      connect( cmd->action(), &QAction::triggered, this, [this, word, replacementWord]() {
        WordList wordsToReplace;
        if( d->settings->replaceAllFromRightClick == true ) {
          this->getAllOccurrencesOfWord( word, wordsToReplace );
        } else {
          wordsToReplace.append( word );
        }
        this->replaceWordsInCurrentEditor( wordsToReplace, replacementWord );
      } );
    } else {
      /* Hide the action since there are less than 5 suggestions for the word. */
      cmd->action()->setVisible( false );
    }
  }
}
Exemplo n.º 12
0
int tellstdfunc::stdREPORTLAY::execute() {
   bool recursive = getBoolValue();
   std::string cellname = getStringValue();
   WordList ull;
   DATC->lockDB();
      bool success = DATC->TEDLIB()->collect_usedlays(cellname, recursive, ull);
   DATC->unlockDB();
   telldata::ttlist* tllull = DEBUG_NEW telldata::ttlist(telldata::tn_int);
   if (success) {
      ull.sort();ull.unique();
      std::ostringstream ost;
      ost << "used layers: {";
      for(WordList::const_iterator CL = ull.begin() ; CL != ull.end();CL++ )
         ost << " " << *CL << " ";
      ost << "}";
      tell_log(console::MT_INFO, ost.str());

      for(WordList::const_iterator CL = ull.begin() ; CL != ull.end();CL++ )
         tllull->add(DEBUG_NEW telldata::ttint(*CL));
      ull.clear();
   }
   else {
      std::string news = "cell \"";
      news += cellname; news += "\" doesn't exists";
      tell_log(console::MT_ERROR,news);
   }
   OPstack.push(tllull);
   return EXEC_NEXT;
}
void HighlightStateBuilder::build(StringListLangElem *elem,
        HighlightState *state) {
    const string &name = elem->getName();

    StringDefs *alternatives = elem->getAlternatives();
    WordList wordList;

    bool doubleQuoted = false, nonDoubleQuoted = false, buildAsWordList = true;

    for (StringDefs::const_iterator it = alternatives->begin(); it
            != alternatives->end(); ++it) {
        const string &rep = (*it)->toString();

        // double quoted strings generate WordListRules, otherwise simple ListRules

        // we don't allow double quoted strings mixed with non double quoted
        if (((*it)->isDoubleQuoted() && nonDoubleQuoted)
                || (!(*it)->isDoubleQuoted() && doubleQuoted)) {
            throw HighlightBuilderException(
                    "cannot mix double quoted and non double quoted", elem);
        }

        doubleQuoted = (*it)->isDoubleQuoted();
        nonDoubleQuoted = !(*it)->isDoubleQuoted();

        wordList.push_back(rep);

        // now check whether we must build a word list rule (word boundary) or an
        // ordinary list; as soon as we find something that is not to be isolated
        // we set buildAsWordList as false
        if (buildAsWordList && (!doubleQuoted || !is_to_isolate(rep))) {
            buildAsWordList = false;
        }
    }

    HighlightRulePtr rule;

    if (buildAsWordList)
        rule = HighlightRulePtr(highlightRuleFactory->createWordListRule(name,
                wordList, elem->isCaseSensitive()));
    else
        rule = HighlightRulePtr(highlightRuleFactory->createListRule(name,
                wordList, elem->isCaseSensitive()));

    rule->setAdditionalInfo(elem->toStringParserInfo());

    state->addRule(rule);

    setExitLevel(elem, rule.get());
}
Exemplo n.º 14
0
void HalfDictionary::read( std::istream& is )
{
  clear();

  while (!is.eof())
  {
    WordList ph;
    Hunglish::read(ph,is);

    if (ph.empty())
      continue;

    push_back(ph);
  }
}
Exemplo n.º 15
0
void FrequencyMap::remove( const WordList& wordList )
{
  for ( int j=0; j<wordList.size(); ++j )
  {
    remove(wordList[j]);
  }
}
Exemplo n.º 16
0
void FrequencyMap::build( const WordList& wordList )
{
  for ( int j=0; j<wordList.size(); ++j )
  {
    add(wordList[j]);
  }
}
Exemplo n.º 17
0
/**
 * This function detects keywords which are able to have a body. Note that it
 * uses the Fold Containers word description, not the containers description. It
 * only works when the style at that particular position is set on Containers
 * or Flow (number 3 or 4).
 *
 * \param  keywordslist The list of keywords that are scanned, they should only
 *         contain the start keywords, not the end keywords
 * \param  The actual keyword
 * \return 1 if it is a folding start-keyword, -1 if it is a folding end-keyword
 *         0 otherwise
 */
static inline int IsFoldingContainer(WordList &keywordslist, char * keyword) {
    if(
        strlen(keyword) > 3 &&
        keyword[0] == 'e' && keyword[1] == 'n' && keyword[2] == 'd') {
        if (keywordslist.InList(keyword + 3)) {
            return -1;
        }

    } else {
        if(keywordslist.InList(keyword)) {
            return 1;
        }
    }

    return 0;
}
Exemplo n.º 18
0
static void ColouriseLabel(StyleContext& sc, WordList& keywords, bool& apostropheStartsAttribute) {
	apostropheStartsAttribute = false;

	sc.SetState(SCE_ADA_LABEL);

	// Skip "<<"
	sc.Forward();
	sc.Forward();

	std::string identifier;

	while (!sc.atLineEnd && !IsSeparatorOrDelimiterCharacter(sc.ch)) {
		identifier += static_cast<char>(tolower(sc.ch));
		sc.Forward();
	}

	// Skip ">>"
	if (sc.Match('>', '>')) {
		sc.Forward();
		sc.Forward();
	} else {
		sc.ChangeState(SCE_ADA_ILLEGAL);
	}

	// If the name is an invalid identifier or a keyword, then make it invalid label
	if (!IsValidIdentifier(identifier) || keywords.InList(identifier.c_str())) {
		sc.ChangeState(SCE_ADA_ILLEGAL);
	}

	sc.SetState(SCE_ADA_DEFAULT);

}
Exemplo n.º 19
0
static int classifyWordBullant(unsigned int start, unsigned int end, WordList &keywords, Accessor &styler) {
  char s[100];
  s[0] = '\0';
  for (unsigned int i = 0; i < end - start + 1 && i < 30; i++) {
    s[i] = static_cast<char>(tolower(styler[start + i]));
    s[i + 1] = '\0';
  }
  int lev= 0;
  char chAttr = SCE_C_IDENTIFIER;
  if (isdigit(s[0]) || (s[0] == '.')){
    chAttr = SCE_C_NUMBER;
  }
  else {
    if (keywords.InList(s)) {
      chAttr = SCE_C_WORD;
      if (strcmp(s, "end") == 0)
        lev = -1;
      else if (strcmp(s, "method") == 0 ||
        strcmp(s, "case") == 0 ||
        strcmp(s, "class") == 0 ||
        strcmp(s, "debug") == 0 ||
        strcmp(s, "test") == 0 ||
        strcmp(s, "if") == 0 ||
        strcmp(s, "lock") == 0 ||
        strcmp(s, "transaction") == 0 ||
        strcmp(s, "trap") == 0 ||
        strcmp(s, "until") == 0 ||
        strcmp(s, "while") == 0)
        lev = 1;
    }
  }
  styler.ColourTo(end, chAttr);
  return lev;
}
Exemplo n.º 20
0
void SpellCheckerCore::replaceWordUnderCursorFirstSuggestion() {
    Word word;
    /* Get the word under the cursor. */
    bool wordMistake = isWordUnderCursorMistake(word);
    if(wordMistake == false) {
        Q_ASSERT(wordMistake);
        return;
    }
    if(word.suggestions.isEmpty() == true) {
        /* Word does not have any suggestions */
        return;
    }
    WordList words;
    words.append(word);
    replaceWordsInCurrentEditor(words, word.suggestions.first());
}
Exemplo n.º 21
0
/**
 * Given a wordset create UYiV yields crossing them and return the best one
 * @param ws set of words
 * @return best UYiV
 */
shared_ptr<UYiV> Dencoder::getBestUYiV(unordered_set< shared_ptr<Word> > * ws) const
{


  shared_ptr<Sequence> seq = getSeq();
  shared_ptr<Word> u;
  shared_ptr<Word> v;
  list <std::pair<int,int> > * wordPosPairs;
  WordList* y;

  shared_ptr<UYiV> newUYV;
  shared_ptr<UYiV> best = NULL;

  for(unordered_set< shared_ptr<Word> >::iterator it1 = ws->begin(); it1!= ws->end(); ++it1)
  {
    u = *it1;
    for(unordered_set< shared_ptr<Word> >::iterator it2 = ws->begin(); it2!= ws->end(); ++it2)
    {
      v = *it2;

      //wordPosPairs could be NULL
      wordPosPairs = seq->wordPosPairList(u,v);
      if(wordPosPairs == NULL || wordPosPairs->size()>=2)
      {
        y = seq->obtainWordsInside(wordPosPairs, u->getSize());
        newUYV = make_shared<UYiV>(u, v, y, wordPosPairs);

        if(!(wordPosPairs == NULL || y->getSize() == 0))
        {
          if(score(best)<=score(newUYV))
          {
            // cout << "Score best: " << score(best) << endl;
            best = newUYV;
            // cout << "Score New: " << score(newUYV) << endl;
          }
        }  
      }
      else
      {
        delete wordPosPairs;
      }
      // it = ls.erase(it);
    }
  }
  return best;
}
Exemplo n.º 22
0
void SpellCheckerCore::addMisspelledWords(const QString &fileName, const WordList &words)
{
    d->spellingMistakesModel->insertSpellingMistakes(fileName, words, d->filesInStartupProject.contains(fileName));
    if(d->currentFilePath == fileName) {
        d->mistakesModel->setCurrentSpellingMistakes(words);
    }

    /* Only apply the underlines to the current file. This is done so that if the
     * whole project is scanned, it does not add selections to pages that might
     * potentially never be opened. This can especially be a problem in large
     * projects.
     */
    if(d->currentFilePath != fileName) {
        return;
    }
    TextEditor::BaseTextEditor* baseEditor = qobject_cast<TextEditor::BaseTextEditor*>(d->currentEditor);
    if(baseEditor == NULL) {
        return;
    }
    TextEditor::TextEditorWidget* editorWidget = baseEditor->editorWidget();
    if(editorWidget == NULL) {
        return;
    }
    QList<QTextEdit::ExtraSelection> selections;
    foreach(const Word& word, words.values()) {
        QTextCursor cursor(editorWidget->document());
        /* Walk to the correct position using the line and column number since the
         * absolute position is not available and I do not know of a way to get/
         * calculate the absolute position from that information.
         *
         * One would think that the position from the CppDocumentParser::tokenizeWords()
         * function can be used if stored in the Word, but it is not the correct position. */
        cursor.setPosition(0);
        cursor.movePosition(QTextCursor::Down, QTextCursor::MoveAnchor, word.lineNumber - 1);
        cursor.movePosition(QTextCursor::Right, QTextCursor::MoveAnchor, word.columnNumber - 1);
        cursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor, word.length);

        /* Get the current format from the cursor, this is to make sure that the text font
         * and color stays the same, we just want to underline the mistake. */
        QTextCharFormat format = cursor.charFormat();
        format.setFontUnderline(true);
        format.setUnderlineColor(QColor(Qt::red));
        format.setUnderlineStyle(QTextCharFormat::WaveUnderline);
        format.setToolTip(word.suggestions.isEmpty() ? QLatin1String("Incorrect spelling")
                                                     : QString(QLatin1String("Incorrect spelling, did you mean '%1' ?")).arg(word.suggestions.first()));
        QTextEdit::ExtraSelection selection;
        selection.cursor = cursor;
        selection.format = format;
        selections.append(selection);
    }
    editorWidget->setExtraSelections(Core::Id(SpellChecker::Constants::SPELLCHECK_MISTAKE_ID), selections);

    /* The model updated, check if the word under the cursor is now a mistake
     * and notify the rest of the checker with this information. */
    Word word;
    bool wordIsMisspelled = isWordUnderCursorMistake(word);
    emit wordUnderCursorMistake(wordIsMisspelled, word);
}
Exemplo n.º 23
0
int main (int argc, char* argv[]) {
  if(argc == 1) {
    cout << "Please select a file." << endl;
  }
  else {
      //Open File
      ifstream fileInput  (argv[1]);
      
      if(!fileInput.is_open()) {
        cout << "Unable to open " << argv[1] << endl;
      }
      else {
        cout << argv[1] << " opened." << endl;
        string word;
        WordList wordList;
        while(fileInput >> word) {
          if( word[word.size()-1] == ',' ||
              word[word.size()-1] == '!' ||
              word[word.size()-1] == '.' ||
              word[word.size()-1] == ';' ||
              word[word.size()-1] == ':' ||
              word[word.size()-1] == '?' ||
              word[word.size()-1] == '-' ||
              word[word.size()-1] == '"' ||
              word[word.size()-1] == '+') 
          {
            word.erase(word.size()-1);
          }
          wordList.addWord(word);
          //cout << word << endl;
            
        }
        
        wordList.sortList();
        wordList.printList();

        // Close File
        fileInput.close();
      }
  }
  
  return 0;
}
Exemplo n.º 24
0
/**
 * Given the current best Yield and a word, try to find a Yield with the suffix
 * and prefix of this word that's better than the current one.
 * @param best current best yield
 * @param mr   word
 */
void Dencoder::getUVFromMaximalRepeat(shared_ptr<UYiV> &best, shared_ptr<Word> mr)
{
  shared_ptr<Word> u;
  shared_ptr<Word> v;
  shared_ptr<Sequence> seq = getSeq();
  int size = mr->getSize();

  shared_ptr<UYiV> newUYV;
  WordList* y;
  list <std::pair<int,int> > * wordPosPairs;

  for(int i = 1; i<size; ++i)
  {
    u = seq->createSubWord(mr, 0, i);
    for(int j = i; j<size; ++j)
    {
      v = seq->createSubWord(mr, j, size);
      wordPosPairs = seq->wordPosPairList(u,v);

        clock_t t;
  t = clock();

      y = seq->obtainWordsInside(wordPosPairs, u->getSize());
  t = clock() - t;
  printf("obtainWordsInside: It took me %ld clicks (%f seconds).\n",t,((float)t)/CLOCKS_PER_SEC);
      newUYV = make_shared<UYiV>(u, v, y, wordPosPairs);

      if(!(wordPosPairs == NULL || y->getSize() == 0))
      {
        if(score(best)<score(newUYV))
        {
          // cout << "Score best: " << score(best) << endl;
          best = newUYV;
          // cout << "Score New: " << score(newUYV) << endl;
        }

      }      

    }
    // cout << "Score primer palabra: " << score(best) << endl;
  }
}
Exemplo n.º 25
0
void LexerMake::PropertyUpdateNotification(void *, int PropOffset)
{
  switch (PropOffset)
  {
    case PROP_OFFSET(LexerMake, functionStrings):
      if (functionStrings.empty())
        functionStrings = defaultFunctionStrings;
      functions.Set(functionStrings.c_str());
      break;
    case PROP_OFFSET(LexerMake, directiveStrings):
      if (directiveStrings.empty())
        directiveStrings = defaultDirectiveStrings;
      directives.Set(directiveStrings.c_str());
      break;
    case PROP_OFFSET(LexerMake, nmakeDirectiveStrings):
      if (nmakeDirectiveStrings.empty())
        nmakeDirectiveStrings = defaultNmakeDirectiveStrings;
      nmakeDirectives.Set(nmakeDirectiveStrings.c_str());
      break;
  }
}
Exemplo n.º 26
0
void FrequencyMap::highPassFilter( WordList& allowedWords, double ratio ) const
{
  allowedWords.clear();

  FrequencyMap::ReFrequencyMap reFrequencyMap;
  reverseMap(reFrequencyMap);

  FrequencyMap::ReFrequencyMap::reverse_iterator rit;

  int totalItemNum = total();

  int localItemNum(0);
  for ( rit=reFrequencyMap.rbegin(); rit!=reFrequencyMap.rend(); ++rit )
  {
    localItemNum += rit->first;
    if ( ((double)localItemNum)/totalItemNum > ratio )
      break;

    allowedWords.push_back(rit->second);
  }
}
Exemplo n.º 27
0
//********************************************************
void WordsEdit::merge_file()
{

  WordList w = WordList();
  Q3FileDialog *f = new Q3FileDialog(0,"Open",true);  
  const char *filters[] = {"words.tok","*.tok","All files (*)",NULL};
  
  f->setFilters(filters);
  f->setCaption("Open");
  f->setMode(Q3FileDialog::ExistingFile);
  f->setDir(game->dir.c_str());
  if ( f->exec() == QDialog::Accepted ) {
    if ( !f->selectedFile().isEmpty() ){
      int ret = w.read((char *)f->selectedFile().latin1());
      if(ret)return ;
      wordlist->merge(w);
      update_all();
    }
  }
  
}
Exemplo n.º 28
0
/**
 * Calculate score of a given UYiV. The score is based on the formulas written in the inform.
 * @param  uyv
 * @return score
 */
double Dencoder::score(shared_ptr<UYiV> uyv) const
{
  if (uyv == NULL) return -1;

  WordList* y = uyv->getYList();
  //if the yList is NULL return score 0
  
  assert(y != NULL);
  if (y == NULL) return 0;
  // if (y->getSize() == 0) return -1;

  int p, q, k, l, pipes, I, encoding, total;
  p = uyv->getWordsPosPairs()->size();
  //This is the complete encoding... And I just to count the encoding of the new uyv...
  encoding = 0;
  q = y->getWordVec().size();
  k = uyv->getU()->getSize();
  l = uyv->getV()->getSize();
  pipes = (q-1) ;
  I = 1;


  // the terms with the + are our gains, the - our penalties

  // total = - getProdElectionSize() + p*k + p*l + y->sumWordsLengthWithoutRepeats() - y->sumWordsLengthWithRepeats() - p - 1 - k - l - 1 - 1 - (q - 1);
  total =  p*k + p*l + y->sumWordsLengthWithRepeats() -
                          y->sumWordsLengthWithoutRepeats() - 
                          encoding - 
                          p - 1 - k - l - 1 - I - pipes ;
  assert(y->sumWordsLengthWithRepeats()>=y->sumWordsLengthWithoutRepeats());

  return total;
}
Exemplo n.º 29
0
void IoHandler::loadWordFile(string wordFile, WordList &wordList)
{
	ifstream inputFile;

	inputFile.open(wordFile);

	if (inputFile.fail())
	{
		cout << "단어 파일을 찾지 못했습니다.";
		return;
	}

	string wordName;
	string partOfSpeech;
	string meaning;

	int wordCount = 0;

	string temp;

	while (!inputFile.eof())
	{
		inputFile >> wordName;

		while (wordName.at(wordName.size() - 1) != ']')		//단어에 공백이 있는경우
		{
			inputFile >> temp;
			wordName = wordName + " " + temp;
		}

		inputFile >> partOfSpeech;

		while (partOfSpeech.at(partOfSpeech.size() - 1) != ']')		//품사에 공백이 있는경우
		{
			inputFile >> temp;
			partOfSpeech = partOfSpeech + " " + temp;
		}

		//inputFile >> space;			//구분자인 빈칸을 없애기위해

		getline(inputFile, meaning, '\n');	//의미부분은 공백이 많고 길기 때문에 getline사용


		wordName = wordName.substr(1, wordName.size() - 2);

		Word word(wordName, partOfSpeech, meaning);

		wordList.insertWord(word);
	}

	inputFile.close();
}
Exemplo n.º 30
0
void LayerMapGds::getList(wxString exp, WordList& data)
{
   wxRegEx number_tmpl(wxT("[[:digit:]]*"));
   wxRegEx separ_tmpl(wxT("[\\,\\-]{1,1}"));
   unsigned long conversion;
   bool last_was_separator = true;
   char separator = ',';
   VERIFY(number_tmpl.IsValid());
   VERIFY(separ_tmpl.IsValid());

   do
   {
      if (last_was_separator)
      {
         number_tmpl.Matches(exp);
         number_tmpl.GetMatch(exp).ToULong(&conversion);
         number_tmpl.ReplaceFirst(&exp,wxT(""));
         if (',' == separator)
            data.push_back((word)conversion);
         else
         {
            for (word numi = data.back() + 1; numi <= conversion; numi++)
               data.push_back(numi);
         }
      }
      else
      {
         separ_tmpl.Matches(exp);
         if      (wxT("-") == separ_tmpl.GetMatch(exp))
            separator = '-';
         else if (wxT(",") == separ_tmpl.GetMatch(exp))
            separator = ',';
         else assert(false);
         separ_tmpl.ReplaceFirst(&exp,wxT(""));
      }
      last_was_separator = !last_was_separator;
   } while (!exp.IsEmpty());

}