-
Notifications
You must be signed in to change notification settings - Fork 5
/
SuffixCollection.cpp
155 lines (130 loc) · 3.76 KB
/
SuffixCollection.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#include "SuffixCollection.h"
#include "Lexicon.h"
#include <QDebug>
#include <QJsonArray>
class CLexicon;
CSuffixCollection::CSuffixCollection(CLexicon* lexicon)
{
m_suffix_map = QMap<QString, CSuffix*>();
m_Lexicon = lexicon;
}
CSuffixCollection::~CSuffixCollection() {
}
void CSuffixCollection::clear(){
foreach (CSuffix* suffix, m_suffix_list){
//delete suffix;
}
m_suffix_map.clear();
m_suffix_list.clear();
}
CSuffix* CSuffixCollection::operator ^=(const QString& suffix)
{
return this->find_or_fail ( suffix );
}
CSuffix* CSuffixCollection::find_or_fail(const QString& suffix)
{
QMap<QString,CSuffix*>::iterator suffix_iter = m_suffix_map.find(suffix);
//map_string_to_suffix_iter suffix_iter = m_SuffixMap.find(suffix);
if (suffix_iter == m_suffix_map.end()){
return NULL;
} else{
return suffix_iter.value();
}
}
CSuffix* CSuffixCollection::find_or_add(const QString& suffix)
{ CSuffix* pSuffix;
if (! m_suffix_map.contains(suffix)){
CSuffix* pSuffix = new CSuffix(suffix);
m_suffix_map.insert(suffix, pSuffix);
m_suffix_list.append(pSuffix);
//pSuffix->increment_count(1);
return pSuffix;
}
pSuffix = m_suffix_map.value(suffix);
//pSuffix->increment_count();
return pSuffix;
}
CSuffix* CSuffixCollection::operator << (const QString& suffix)
{
return this->find_or_add(suffix);
}
QList<CSuffix*> CSuffixCollection::get_suffixes(){
return m_suffix_list;
}
bool count_compare_suffixes(CSuffix* pSuff1, CSuffix* pSuff2){
if (pSuff1->get_sig_count() > pSuff2->get_sig_count()) return true;
return false;
}
void CSuffixCollection::sort_by_count()
{
m_suffix_list.clear();
QMapIterator<QString, CSuffix*> suffix_iter (m_suffix_map);
while (suffix_iter.hasNext()){
suffix_iter.next();
m_suffix_list.append(suffix_iter.value());
}
std::sort(m_suffix_list.begin(), m_suffix_list.end(), count_compare_suffixes);
}
CPrefixCollection::CPrefixCollection(CLexicon* lexicon)
{
m_PrefixMap = QMap<QString, CPrefix*>();
m_Lexicon = lexicon;
}
CPrefixCollection::~CPrefixCollection() {
}
void CPrefixCollection::clear(){
m_PrefixMap.clear();
m_prefix_list.clear();
}
/*CPrefix* CPrefixCollection::operator ^=(const QString& prefix)
{ return this->find_or_fail ( prefix );
}
*/
CPrefix* CPrefixCollection::find_or_fail(const QString& prefix)
{ if (m_PrefixMap.contains(prefix)){
return m_PrefixMap[prefix];
}
return NULL;
}
CPrefix* CPrefixCollection::find_or_add(const QString& prefix)
{ if (m_PrefixMap.contains(prefix)){
return m_PrefixMap[prefix];
}
CPrefix* pPrefix = new CPrefix(prefix);
m_PrefixMap.insert(prefix, pPrefix);
m_prefix_list.append(pPrefix);
return pPrefix;
}
/*
CPrefix* CPrefixCollection::operator << (const QString& prefix)
{
return this->find_or_add(prefix);
qDebug() << 124;
}
*/
/*
void CPrefixCollection::get_set_of_prefixes(QSet<QString> *p_string_set){
p_string_set->fromList(m_PrefixMap.uniqueKeys());
}
*/
void CPrefixCollection::get_prefixes(QList<QString>* pList)
{ QMapIterator<QString,CPrefix*> iter (m_PrefixMap);
while (iter.hasNext()){
iter.next();
pList->append(iter.value()->get_key());
}
}
bool count_compare_prefixes(CPrefix* pPrefix1, CPrefix* pPrefix2){
if (pPrefix1->get_sig_count() > pPrefix2->get_sig_count()) return true;
return false;
}
void CPrefixCollection::sort_by_count()
{
m_prefix_list.clear();
QMapIterator<QString, CPrefix*> prefix_iter (m_PrefixMap);
while (prefix_iter.hasNext()){
prefix_iter.next();
m_prefix_list.append(prefix_iter.value());
}
std::sort(m_prefix_list.begin(), m_prefix_list.end(), count_compare_prefixes);
}