forked from Daniel-Moraes1/Quote-Quest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuote.cpp
More file actions
94 lines (76 loc) · 2.24 KB
/
Quote.cpp
File metadata and controls
94 lines (76 loc) · 2.24 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
#include "Quote.h"
#include <string>
#include <iostream>
Quote::Quote()
{
this->sentimentVal = 0;
this->length = 0;
this->quote = "";
this->category = "";
this->author = "";
this->index = 0;
}
Quote::Quote(float sentimentVal, int length, std::string quote, std::string category, std::string author, int index)
{
this->sentimentVal = sentimentVal;
this->length = length;
this->quote = quote;
this->category = category;
this->author = author;
this->index = index;
}
float Quote::getSentimentVal()
{
return this->sentimentVal;
}
int Quote::getLength()
{
return this->length;
}
std::string Quote::getQuote()
{
return this->quote;
}
std::string Quote::getCategory()
{
return this->category;
}
std::string Quote::getAuthor()
{
return this->author;
}
int Quote::getIndex() {
return this->index;
}
float Quote::calculateSimilarity(Quote *q2) {
//If the quotes are the same, similarity is 0 (perfect)
if (q2 == this)
return 0.0;
float similarity = 0.0;
// Sentiment value
similarity += std::max(this->getSentimentVal(), q2->getSentimentVal()) - std::min(this->getSentimentVal(), q2->getSentimentVal());
//Category
if (this->getCategory() != q2->getCategory()) {
similarity += 0.0075; // Must be low enough to jump between categories if sentiments are close enough
}
//Length
float l1(this->getLength()); float l2(q2->getLength());
float length_reduction_factor = 50.0; // Chosen to ensure similarity is not too heavily impacted by length
similarity += ((std::max(l1, l2) - std::min(l1, l2))/(std::max(l1, l2)*length_reduction_factor));
return similarity;
}
/* OUTPUT FORMAT (all strings)
* [0] QUOTE
* [1] AUTHOR
* [2] CATEGORY: (one of) love, life, inspirational, philosophy, humor, god, truth, wisdom, happiness, hope, hate
* [3] SENTIMENT (-1, 1)
* [4] LENGTH (in characters)
*/
std::vector<std::string> Quote::getQuoteAttributes() {
std::vector<std::string> output = {this->getQuote(),
this->getAuthor(),
this->getCategory(),
std::to_string(this->getSentimentVal()),
std::to_string(this->getLength())};
return output;
}