"Fossies" - the Fresh Open Source Software Archive

Member "cb2bib-2.0.1/src/c2b/wordPattern.cpp" (12 Feb 2021, 2120 Bytes) of package /linux/privat/cb2bib-2.0.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "wordPattern.cpp" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 2.0.0_vs_2.0.1.

    1 /***************************************************************************
    2  *   Copyright (C) 2004-2021 by Pere Constans
    3  *   constans@molspaces.com
    4  *   cb2Bib version 2.0.1. Licensed under the GNU GPL version 3.
    5  *   See the LICENSE file that comes with this distribution.
    6  ***************************************************************************/
    7 #include "wordPattern.h"
    8 
    9 #include "cb2bib_utilities.h"
   10 #include "triads.h"
   11 
   12 
   13 wordPattern::wordPattern() : compositePattern(), _type(AllWords) {}
   14 
   15 wordPattern::wordPattern(const QString& pattern, const Type type, const Qt::CaseSensitivity cs)
   16     : compositePattern(pattern, cs), _type(type)
   17 {
   18     setPattern(pattern, type, cs);
   19 }
   20 
   21 
   22 void wordPattern::setPattern(const QString& pattern, const Type type, const Qt::CaseSensitivity cs)
   23 {
   24     _string = pattern;
   25     _type = type;
   26     _case_sensitivity = cs;
   27     _is_multipattern = false;
   28     _matched_length = -1;
   29 
   30     const QStringList words(_string.split(c2bUtils::nonLetter, QString::SkipEmptyParts));
   31     _subpattern_count = words.count();
   32     if (_subpattern_count == 0)
   33         return;
   34 
   35     _ranks.clear();
   36     QStringList subpattern;
   37     QStringList substring;
   38     for (int i = 0; i < words.count(); ++i)
   39     {
   40         const QString& wi = words.at(i);
   41         const QString sp(escape(wi, _case_sensitivity));
   42         subpattern.append(sp);
   43         substring.append(wi);
   44         _ranks.append(triads::textFrequency(wi)); // Rank according expectation (arXiv:0705.0751, Eq. 6)
   45     }
   46     set_sort_index();
   47     if (_subpattern_count == 1)
   48         _regexp.setPattern(escape(_string, _case_sensitivity));
   49     else
   50         _regexp.setPattern(QString("(?:%1)").arg(subpattern.join("|")));
   51     _submatchers.resize(_subpattern_count);
   52     _subregexps.resize(_subpattern_count);
   53     _substrings.clear();
   54     for (int i = 0; i < _subpattern_count; ++i)
   55     {
   56         const int ii(_index.at(i));
   57         _submatchers[i] = txtmatcher(substring.at(ii), _case_sensitivity);
   58         _subregexps[i].setPattern(subpattern.at(ii));
   59         _substrings.append(substring.at(ii));
   60     }
   61     _is_multipattern = _subpattern_count > 1;
   62 }