-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathnote.cpp
More file actions
191 lines (159 loc) · 3.95 KB
/
note.cpp
File metadata and controls
191 lines (159 loc) · 3.95 KB
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#include "note.h"
#include <QFile>
#include <QTextStream>
#include <QMessageBox>
#include <QDebug>
Note::Note(){
text = "";
editedText = "";
fileName = "";
filepath = "";
}
Note::Note(QString filename)
{
filepath = filename;
QFile file(filename);
editedText = "";
// Check if file didnt open in read only
if(!file.open(QIODevice::ReadOnly)){
QMessageBox::information(0, "error", file.errorString());
}
QTextStream in(&file);
// loop through text file
while(!in.atEnd()){
QString line = in.readLine();
text += line + "\n";
}
file.close();
//remove articles and symbols that arent needed
removeSymbols();
//initialize sentence vector
findSentences();
}
QString Note::getText(){
return text;
}
QString Note::getEditedText(){
return editedText;
}
void Note::findSentences(){
QString currentWord = "";
QString currentSentence = "";
QVector<QString> wordSentence;
for(int i = 0; i < editedText.size(); i++){
if(editedText.at(i) == ' '){
if(!isArticle(currentWord) && !currentWord.isEmpty()){
wordSentence.append(currentWord);
}
currentWord = "";
}else{
currentWord += editedText.at(i);
}
if(isPunctuation(editedText.at(i)) && !isTitle(currentWord)){
//take of punctuation before adding word
currentWord.truncate(currentWord.size()-1);
//resolved last word not being added
wordSentence.append(currentWord);
//add punctuation to sentence
currentSentence += editedText.at(i);
words.append(wordSentence);
wordSentence.clear();
sentences.append(currentSentence);
currentSentence = "";
currentWord = "";
}else{
currentSentence += editedText.at(i);
}
}
}
void Note::removeSymbols(){
for(int i = 0; i < text.size(); i++){
if(!isSymbol(text.at(i))){
//not a symbol
//add to edited text
editedText += text.at(i);
}
}
}
void Note::setFilePath(QString name){
filepath = name;
}
bool Note::isArticle(QString article){
QString articles[3] = {
"the","a","an",
};
for(int i = 0; i < 3;i++){
if(article.toLower() == articles[i])
return true;
}
return false;
}
bool Note::isSymbol(QChar symbol){
//take care fo exceptions first
if(isPunctuation(symbol))
return false;
if(symbol == '%' || symbol == '@' || symbol == '$' || symbol == ' ' || symbol == '\'')
return false;
else if(symbol >= 48 && symbol <= 57)//its a number in this case
return false;
else if(!(symbol >= 65 && symbol <= 90) //not uppercase letter
&& !(symbol >= 97 && symbol <= 122))//not lower case letter
{
return true;
}
return false;
}
bool Note::isTitle(QString word){
QString titles[4] = {
"mr","ms","dr","ex",
};
for(int i = 0; i < 4; i++){
if(word.toLower() == titles[i])
return true;
}
return false;
}
bool Note::isPunctuation(QChar p){
char punct[3] = {
'.','?','!'
};
for(int i = 0; i < 3; i++){
if(p == punct[i])
return true;
}
return false;
}
QVector<QString> Note::getOriginalSentences(){
return sentences;
}
QVector<QVector<QString>> Note::getEditedSentences(){
return words;
}
void Note::addChange(Change* change)
{
this->changeLog.append(change);
}
QVector<Change*> Note::getChangeLog()
{
return changeLog;
}
void Note::clearChangeLog()
{
changeLog.clear();
}
void Note::setFileName(QString name){
fileName = name;
}
QString Note::getFileName(){
return fileName;
}
QString Note::getFilePath(){
return filepath;
}
void Note::editNote(QString txt)
{
text = txt;
}
void Note::setOriginalSentence(QVector<QString> ori){
this->sentences = ori;
}