NCBI C++ ToolKit
Word_substitution.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: Word_substitution.cpp 65282 2014-11-18 19:13:59Z bollin $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Author: .......
27  *
28  * File Description:
29  * .......
30  *
31  * Remark:
32  * This code was originally generated by application DATATOOL
33  * using the following specifications:
34  * 'macro.asn'.
35  */
36 
37 // standard includes
38 #include <ncbi_pch.hpp>
39 
40 // generated includes
42 
43 // generated classes
44 
46 
47 BEGIN_objects_SCOPE // namespace ncbi::objects::
48 
49 // constructor
51 {
52  SetWord(word);
53  SetSynonyms().push_back(synonym);
54 }
55 
56 
57 // destructor
59 {
60 }
61 
62 
64 {
65  if (ch == 0 || !isalpha(ch)) {
66  return true;
67  } else {
68  return false;
69  }
70 }
71 
72 
73 // this function looks for portions of the text that can be skipped because it
74 // begins with a word to ignore or one of its synonyms.
75 // note that more than one item could match, all should be tried
76 vector<size_t> CWord_substitution :: GetMatchLens(const string& text, const string& pattern, char prev_char) const
77 {
78  vector<size_t> match_lens;
79  size_t len;
80 
81  if (!IsSetWord()) {
82  // doesn't make sense
83  } else if (!NStr::StartsWith(pattern, GetWord(), GetCase_sensitive() ? NStr::eCase : NStr::eNocase)) {
84  // no match
85  } else if (IsSetSynonyms()) {
87  len = (*syn).length();
89  && (!IsSetWhole_word()
90  || (IsWordBoundary(prev_char) && IsWordBoundary(text.c_str()[len])))) {
91  // text matches synonym
92  match_lens.push_back(len);
93  }
94  }
95  } else {
96  // word is optional, but don't skip it if it's already in the text
98  match_lens.push_back(0);
99  }
100  }
101  return match_lens;
102 }
103 
104 
105 END_objects_SCOPE // namespace ncbi::objects::
106 
108 
109 /* Original file checksum: lines: 57, chars: 1744, CRC32: 9a0806fb */
User-defined methods of the data storage class.
CWord_substitution_Base –.
static bool IsWordBoundary(char ch)
vector< size_t > GetMatchLens(const string &text, const string &pattern, char prev_char) const
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
static bool StartsWith(const CTempString str, const CTempString start, ECase use_case=eCase)
Check if a string starts with a specified prefix value.
Definition: ncbistr.hpp:5412
@ eNocase
Case insensitive compare.
Definition: ncbistr.hpp:1206
@ eCase
Case sensitive compare.
Definition: ncbistr.hpp:1205
const TWord & GetWord(void) const
Get the Word member data.
bool IsSetSynonyms(void) const
Check if a value has been assigned to Synonyms data member.
const TSynonyms & GetSynonyms(void) const
Get the Synonyms member data.
TSynonyms & SetSynonyms(void)
Assign a value to Synonyms data member.
bool IsSetWhole_word(void) const
Check if a value has been assigned to Whole_word data member.
TWord & SetWord(void)
Assign a value to Word data member.
bool IsSetWord(void) const
Check if a value has been assigned to Word data member.
TCase_sensitive GetCase_sensitive(void) const
Get the Case_sensitive member data.
int len
static void text(MDB_val *v)
Definition: mdb_dump.c:62
int isalpha(Uchar c)
Definition: ncbictype.hpp:61
Modified on Wed Apr 24 14:10:02 2024 by modify_doxy.py rev. 669887