libscid 0.1.0
Chess applications made easy.
Loading...
Searching...
No Matches
spelling.h
1/*
2# Copyright (C) 2015 Fulvio Benini
3
4* This file is part of Scid (Shane's Chess Information Database).
5*
6* Scid is free software: you can redistribute it and/or modify
7* it under the terms of the GNU General Public License as published by
8* the Free Software Foundation.
9*
10* Scid is distributed in the hope that it will be useful,
11* but WITHOUT ANY WARRANTY; without even the implied warranty of
12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13* GNU General Public License for more details.
14*
15* You should have received a copy of the GNU General Public License
16* along with Scid. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19#ifndef SCID_SPELLING_SPELLING_H
20#define SCID_SPELLING_SPELLING_H
21
22#include "scid/database/namebase.h"
23#include "scid/core/date.h"
24#include <deque>
25#include <memory>
26#include <string>
27#include <vector>
28#include <utility>
29
30/*
31* A "spelling" file contains the correct names for players, events, sites and rounds.
32* Optionally it can provide further informations for players like elo, birthdate, etc..
33* See the header of spelling.ssp for a more detailed description of the format.
34*/
35
36namespace scid::spelling {
37
53 typedef std::vector< std::pair<std::string,std::string> > Cont;
54 Cont prefix_;
55 Cont infix_ ;
56 Cont suffix_;
57
58public:
65 size_t normalize(std::string* name) const;
66
75 scid::core::errorT addPrefix(const char* s);
76 scid::core::errorT addInfix (const char* s);
77 scid::core::errorT addSuffix(const char* s);
78
79private:
80 scid::core::errorT add(Cont& v, const char* s);
81};
82
83
90class PlayerElo {
91 std::vector< std::pair<uint16_t, scid::core::ratingT> > elo_;
92
93public:
94 void addEloData(const char* str);
95
96 scid::core::ratingT getElo (scid::core::dateT date) const;
97
98#ifdef SCID_SPELLING_VALIDATE
99 std::string isValid() const;
100#endif
101};
102
103
115 const char* comment_;
116 std::vector<const char*> bio_;
117
118 friend class SpellingLoader;
119 friend class SpellChecker;
120
121public:
122 PlayerInfo(const char* s) : comment_(s) {}
123 const char* getTitle() const;
124 std::string getLastCountry() const;
125 scid::core::dateT getBirthdate() const;
126 scid::core::dateT getDeathdate() const;
127 scid::core::ratingT getPeakRating() const;
128 const char* getComment() const;
129};
130
131
139 struct Idx {
140 std::string alias;
141 int32_t idx;
142
143 Idx();
144 Idx(const std::string& a, int32_t i);
145 bool operator<(const Idx& b) const;
146 bool operator<(const std::string& b) const;
147 };
148 typedef std::vector<Idx>::const_iterator IdxIt;
149
150 NameNormalizer general_[scid::database::NUM_NAME_TYPES];
151 std::string excludeChars_[scid::database::NUM_NAME_TYPES];
152 std::vector<Idx> idx_[scid::database::NUM_NAME_TYPES];
153 std::vector<const char*> names_[scid::database::NUM_NAME_TYPES];
154 std::vector<PlayerInfo> pInfo_;
155 std::vector<PlayerElo> pElo_;
156 std::deque<std::string> strings_;
157
158 friend class SpellingLoader;
159
160public:
169 static std::pair<scid::core::errorT, std::unique_ptr<SpellChecker>> create(
170 const char* filename, const scid::database::Progress& progress);
171
184 std::vector<const char*> find(const scid::database::nameT& nt, const char* name, scid::core::uint nMaxRes = 10) const;
185
186 const NameNormalizer& getGeneralCorrections(const scid::database::nameT& nt) const;
187
200 const PlayerInfo* getPlayerInfo(const char* name,
201 std::vector<const char*>* bio = 0) const;
202
203 const PlayerElo* getPlayerElo(const char* name) const;
204
205 bool hasEloData() const;
206
207 size_t numCorrectNames(const scid::database::nameT& nt) const;
208
209private:
210 SpellChecker() = default;
211 SpellChecker(const SpellChecker&) = delete;
212 SpellChecker& operator=(const SpellChecker&) = delete;
213
214 scid::core::errorT read(const char* filename, const scid::database::Progress& progress);
215
216 const char* storeString(const char* s);
217
218 std::string normalizeAndTransform(const scid::database::nameT& nt, const char* s) const;
219
220 std::pair<IdxIt, IdxIt> idxFind(const scid::database::nameT& nt, const char* prefix) const;
221
222 std::pair<IdxIt, IdxIt> idxFindPlayer(const char* prefix) const;
223
224 IdxIt idxFindPlayerUnambiguous(const char* name) const;
225
226 class SpellingValidate;
227
228};
229
230
231} // namespace scid::spelling
232
233#endif
Definition misc.h:66
class NameNormalizer - apply general corrections to a name
Definition spelling.h:52
scid::core::errorT addPrefix(const char *s)
add*fix() - add a general correction
class PlayerElo - elo ratings of a player
Definition spelling.h:90
class PlayerInfo - player informations
Definition spelling.h:114
class SpellChecker - name spelling
Definition spelling.h:138
static std::pair< scid::core::errorT, std::unique_ptr< SpellChecker > > create(const char *filename, const scid::database::Progress &progress)
create() - Create a new SpellChecker object