예제 #1
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));
}
예제 #2
0
void FrequencyMap::remove( const WordList& wordList )
{
  for ( int j=0; j<wordList.size(); ++j )
  {
    remove(wordList[j]);
  }
}
예제 #3
0
void FrequencyMap::build( const WordList& wordList )
{
  for ( int j=0; j<wordList.size(); ++j )
  {
    add(wordList[j]);
  }
}
예제 #4
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();
}
예제 #5
0
void filterSentences( SentenceList& sentenceList, const WordList& words )
{
  std::set<Word> wordSet;
  int i;
  for ( i=0; i<words.size(); ++i )
  {
    wordSet.insert(words[i]);
  }

  for ( i=0; i<sentenceList.size(); ++i )
  {
    WordList& wordList = sentenceList[i].words;

    for ( int j=0; j<wordList.size(); ++j )
    {
      if ( wordSet.find(wordList[j]) == wordSet.end() )
      {
        wordList.erase(wordList.begin()+j);
        --j;
      }
    }
  }
}
예제 #6
0
void SpellCheckProcessor::process(QFutureInterface<WordList> &future)
{
#ifdef BENCH_TIME
    QElapsedTimer timer;
    timer.start();
#endif /* BENCH_TIME */
    WordListConstIter misspelledIter;
    WordListConstIter prevMisspelledIter;
    Word misspelledWord;
    WordList misspelledWords;
    WordList words = d_wordList;
    WordListConstIter wordIter = words.constBegin();
    bool spellingMistake;
    future.setProgressRange(0, words.count() + 1);
    while(wordIter != d_wordList.constEnd()) {
        /* Get the word at the current iterator position.
         * After this is done, move the iterator to the next position and
         * increment the progress value. This is done so that one can call
         * 'continue' anywhere after this in the loop without having to worry
         * about advancing the iterator since this will already be done and
         * correct for the next iteration. */
        misspelledWord = (*wordIter);
        ++wordIter;
        future.setProgressValue(future.progressValue() + 1);
        /* Check if the future was cancelled */
        if(future.isCanceled() == true) {
            return;
        }
        spellingMistake = d_spellChecker->isSpellingMistake(misspelledWord.text);
        /* Check to see if the char after the word is a period. If it is,
         * add the period to the word an see if it passes the checker. */
        if((spellingMistake == true)
                && (misspelledWord.charAfter == QLatin1Char('.'))) {
            /* Recheck the word with the period added */
            spellingMistake = d_spellChecker->isSpellingMistake(misspelledWord.text + QLatin1Char('.'));
        }

        if(spellingMistake == true) {
            /* The word is a spelling mistake, check if the word was a mistake
             * the previous time that this file was processed. If it was the
             * suggestions can be reused without having to get the suggestions
             * through the spell checker since this is slow compared to the rest
             * of the processing. */
            prevMisspelledIter = d_previousMistakes.find(misspelledWord.text);
            if(prevMisspelledIter != d_previousMistakes.constEnd()) {
                misspelledWord.suggestions = (*prevMisspelledIter).suggestions;
                misspelledWords.append(misspelledWord);
                continue;
            }
            /* The word was not in the previous iteration, search for the word
             * in the list of words that were already checked in this iteration
             * and identified as spelling mistakes. If there are words that are
             * repeated and misspelled, this can reduce the time to process
             * the file since the time to get suggestions is rather slow.
             * If there are no repeating mistakes then this might add unneeded
             * overhead. */
            misspelledIter = misspelledWords.find(misspelledWord.text);
            if(misspelledIter != misspelledWords.constEnd()) {
                misspelledWord.suggestions = (*misspelledIter).suggestions;
                /* Add the word to the local list of misspelled words. */
                misspelledWords.append(misspelledWord);
                continue;
            }
            /* At this point the word is a mistake for the first time. It was neither
             * a mistake in the previous pass of the file nor did the word occur previously
             * in this file, use the spell checker to get the suggestions for the word. */
            d_spellChecker->getSuggestionsForWord(misspelledWord.text, misspelledWord.suggestions);
            /* Add the word to the local list of misspelled words. */
            misspelledWords.append(misspelledWord);
        }
    }
#ifdef BENCH_TIME
    qDebug() << "File: " << d_fileName
             << "\n  - time : " << timer.elapsed()
             << "\n  - count: " << misspelledWords.size();
#endif /* BENCH_TIME */
    future.reportResult(misspelledWords);
}
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 == nullptr ) {
    return;
  }
  TextEditor::TextEditorWidget* editorWidget = baseEditor->editorWidget();
  if( editorWidget == nullptr ) {
    return;
  }
  QTextDocument* document = editorWidget->document();
  if( document == nullptr ) {
    return;
  }
  QList<QTextEdit::ExtraSelection> selections;
  selections.reserve( words.size() );
  const WordList::ConstIterator wordsEnd = words.constEnd();
  for( WordList::ConstIterator wordIter = words.constBegin(); wordIter != wordsEnd; ++wordIter ) {
    const Word& word = wordIter.value();
    /* Get the QTextBlock for the line that the misspelled word is on.
     * The QTextDocument manages lines as blocks (in most cases).
     * The lineNumber of the misspelled word is 1 based (seen in the editor)
     * but the blocks on the QTextDocument are 0 based, thus minus one
     * from the line number to get the correct line.
     * If the block is valid, and the word is not longer than the number of
     * characters in the block (which should normally not be the case)
     * then the cursor is moved to the correct column, and the word is
     * underlined.
     * Again the Columns on the misspelled word is 1 based but
     * the blocks and cursor are 0 based. */
    const QTextBlock& block = document->findBlockByNumber( int32_t( word.lineNumber ) - 1 );
    if( ( block.isValid() == false )
        || ( uint32_t( block.length() ) < ( word.columnNumber - 1 + uint32_t( word.length ) ) ) ) {
      continue;
    }

    QTextCursor cursor( block );
    cursor.setPosition( cursor.position() + int32_t( 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 );
    static const QColor underLineColor = QColor( Qt::red );
    format.setUnderlineColor( underLineColor );
    format.setUnderlineStyle( QTextCharFormat::WaveUnderline );
    format.setToolTip( word.suggestions.isEmpty()
                       ? QStringLiteral( "Incorrect spelling" )
                       : QStringLiteral( "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 );
}
예제 #8
0
bool LayerMapGds::parseLayTypeString(wxString exp, word tdtLay)
{
   wxString lay_exp, type_exp;
   if (!separateQuickLists(exp, lay_exp, type_exp)) return false;


   WordList llst;
   // get the listed layers
   getList(  lay_exp , llst);

   if (NULL != _alist)
   {// GDS to TDT conversion
      // ... for every listed layer
      for ( WordList::const_iterator CL = llst.begin(); CL != llst.end(); CL++ )
      {
         // if the layer is listed among the GDS used layers
         if ( _alist->end() != _alist->find(*CL) )
         {
            if (wxT('*') == type_exp)
            { // for all data types
            // get all GDS data types for the current layer and copy them
            // to the map
               for ( WordList::const_iterator CT = (*_alist)[*CL].begin(); CT != (*_alist)[*CL].end(); CT++)
                  _theMap[*CL].insert(std::make_pair(*CT, tdtLay));
            }
            else
            {// for particular (listed) data type
               WordList dtlst;
               getList( type_exp , dtlst);
               for ( WordList::const_iterator CT = dtlst.begin(); CT != dtlst.end(); CT++)
                  _theMap[*CL].insert(std::make_pair(*CT, tdtLay));
            }
         }
         // else ignore the mapped GDS layer
      }
   }
   else
   {// TDT to GDS conversion
      if (1 < llst.size())
      {
         wxString wxmsg;
         wxmsg << wxT("Can't export to multiple layers. Expression \"")
               << lay_exp << wxT("\"")
               << wxT(" is coerced to a single layer ")
               << llst.front();
         std::string msg(wxmsg.mb_str(wxConvUTF8));
         tell_log(console::MT_ERROR,msg);
      }
      if (wxT('*') == type_exp)
      { // for all data types - same as data type = 0
         _theMap[tdtLay].insert(std::make_pair(0, llst.front()));
      }
      else
      {// for particular (listed) data type
         WordList dtlst;
         getList( type_exp , dtlst);
         if (1 < dtlst.size())
         {
            wxString wxmsg;
            wxmsg << wxT("Can't export to multiple types. Expression \"")
                  << type_exp << wxT("\"")
                  << wxT(" for layer ") << tdtLay
                  << wxT(" is coerced to a single data type ")
                  << dtlst.front();
            std::string msg(wxmsg.mb_str(wxConvUTF8));
            tell_log(console::MT_ERROR,msg);
         }
         _theMap[tdtLay].insert(std::make_pair(dtlst.front(), llst.front()));
      }
   }

   return true;
}