This repository has been archived by the owner on Jan 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Scala2.txt
223 lines (179 loc) · 7.68 KB
/
Scala2.txt
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
import scala.language.postfixOps
import scala.collection.mutable.ArrayBuffer
trait IWebResource {
var _url : String;
var _searchTerm : String;
var _content : String
}
trait TrafficFocusedEvaluator {
var thousandRate : Int = 5;
def EstimateWorth(website: Website) : Double = {
return website._trafficPerMonth/1000 * thousandRate;
}
}
trait SiteMetricsFocusedEvaluator {
var _specialCountries : ArrayBuffer[String] = ArrayBuffer("USA", "Germany", "United Kingdom", "Canada", "Spain");
def EstimateWorth(website: Website) : Double = {
var worth : Double = 0;
if (website._age > 5) {
worth += 1000 * website._age
} else {
worth += 200 * website._age
}
for (country <- _specialCountries) {
if (country == website._location) {
worth += 5000l
}
}
return worth;
}
}
trait OldRanker {
var _blackList : ArrayBuffer[String] = ArrayBuffer("Drugs", "Alcohol", "Guns", "Violence", "Pornography", "Gambling", "Casino");
def DetermineTopic(resourceContent : String) : String = {
var titleStart = resourceContent.indexOf("<title>");
var titleEnd = resourceContent.indexOf("</title>");
var topic : String = "";
if (titleStart == -1 || titleEnd == -1) {
return "undefinedTopic"
} else {
return resourceContent.substring(titleStart + 7, titleEnd);
}
}
def GetAlgorithmDescription() : String = {
return "Old 90s algorithm";
}
def IsSpammy(topic : String, webResource : IWebResource) : Boolean = {
for(word <- _blackList) {
if ((webResource._url.toLowerCase() contains word.toLowerCase()) || (webResource._content.toLowerCase() contains word.toLowerCase()) || (topic.toLowerCase() contains word.toLowerCase()) ) {
return true
}
}
return false;
}
}
trait NewRanker {
var _blackList : ArrayBuffer[String] = ArrayBuffer("Drugs", "Alcohol", "Guns", "Violence", "Pornography", "Gambling", "Casino");
def DetermineTopic(resourceContent : String) : String = {
var titleStart = resourceContent.indexOf("<h1>");
var titleEnd = resourceContent.indexOf("</h1>");
var topic : String = "";
if (titleStart == -1 || titleEnd == -1) {
return "undefinedTopic"
} else {
return resourceContent.substring(titleStart + 4, titleEnd);
}
}
def GetAlgorithmDescription() : String = {
return "The new Panda SERP algorithm";
}
def IsSpammy(topic : String, webResource : IWebResource) : Boolean = {
var words = webResource._content.split(' ');
var totalLength = words.length;
var counter : Int = 0;
var rate : Double = 0.00;
println("Total words: " + totalLength);
for(e<-words) {
if (topic contains e) {
counter += 1;
rate = (counter.toDouble / totalLength).toDouble;
if (rate > 0.05) {
println("Detected topic frequency rate is " + rate + " it is a spammy rate!!");
return true
}
}
}
rate = (counter.toDouble / totalLength).toDouble;
println("Detected topic frequency rate is " + rate + " it is a normal rate");
return false;
}
}
abstract class Video (url: String, searchTerm: String, title: String, views: Int) extends IWebResource {
var _url : String = url;
var _searchTerm : String = searchTerm;
var _title : String = title;
var _views : Int = views;
var _content : String = "";
var _deleted : Boolean = false;
def ToBeSuspended() : Boolean = {
println("Checking video using " + GetAlgorithmDescription());
if (IsSpammy(_title, this)) {
println("Content does not match title, video will be removed");
_deleted = true;
return true;
} else {
println("Content does match title, video will not be removed");
_deleted = false;
return false;
}
}
protected def GetAlgorithmDescription() : String
protected def IsSpammy(topic: String, webResource : IWebResource) : Boolean
}
abstract class Website (url: String, age: Int, location: String, currentPosition: Int, searchTerm: String, trafficPerMonth: Int) extends IWebResource {
var _premiumCriteria : Int = 5000;
var _url : String = url;
var _age : Int = age;
var _location : String = location;
var _currentPosition: Int = currentPosition;
var _searchTerm : String = searchTerm;
var _trafficPerMonth : Int = trafficPerMonth;
var _isPremium : Boolean = false;
var _content : String = "";
def CheckForPremiumStatus() : Boolean = {
var value : Double = EstimateWorth(this);
println("Estimated website value: " + value);
if (value > _premiumCriteria) {
println("Site applicable to premium");
_isPremium = true;
return _isPremium;
} else {
println("Site not applicable to premium");
_isPremium = false;
return _isPremium;
}
}
def RecalculateSERP() : Int = {
var websiteTopic : String = getWebsiteTopic();
if (!isWebSpammy(websiteTopic)) {
alterRanking(true);
} else {
alterRanking(false);
}
return _currentPosition;
}
private def isWebSpammy(topic: String) : Boolean = {
var isSpammy : Boolean = IsSpammy(topic, this);
println("Website is condidered spammy?" + isSpammy);
return isSpammy;
}
private def alterRanking(up: Boolean) : Unit = {
println("Previous rank: " + _currentPosition);
if (up) {
if (_currentPosition > 1) {
_currentPosition -= 1;
println("Website went up after checking with" + GetAlgorithmDescription());
}
} else {
_currentPosition+=1;
println("Website went down after checking with" + GetAlgorithmDescription());
}
}
private def getWebsiteTopic() : String = {
var topic : String = DetermineTopic(_content);
println("Website topic is: " + topic);
return topic;
}
protected def DetermineTopic(resourceContent: String) : String
protected def GetAlgorithmDescription() : String
protected def IsSpammy(topic: String, webResource : IWebResource) : Boolean
protected def EstimateWorth(website : Website) : Double
}
var website : Website = new Website("https://casino.com", 5, "USA", 1, "best casino", 500000) with OldRanker with TrafficFocusedEvaluator
//var website : Website = new Website("https://casino.com", 5, "USA", 1, "best casino", 500000) with NewRanker with SiteMetricsFocusedEvaluator
website._content = "<!DOCTYPE html><html><head><meta charset='utf-8' /<meta http-equiv='X-UA-Compatible' content='IE=edge'><title>Some casino website</title><meta name='viewport' content='width=device-width, initial-scale=1'><link rel='stylesheet' type='text/css' media='screen' href='main.css' /><script src='main.js'></script></head><body><h1>Casino</h1><p>Lorem ipsum dolor sit Casino amet consectetur adipisicing elit. Temporibus repellendus dicta, dolores voluptates assumenda suscipit possimus. Veritatis impedit blanditiis vel! Officiis, explicabo eveniet quas nemo aliquid impedit incidunt maiores soluta.Quam vero culpa ipsum iste consequuntur magni obcaecati praesentium id </p></body></html>"
website.RecalculateSERP();
website.CheckForPremiumStatus();
var video : Video = new Video("https://www.youtube.com/watch?v=szk1wnalFRQ", "cernobylio avarija", "Praeities Atgarsiai: Cernobylio avarija", 4750) with NewRanker
video._content = "Pasakojimas apie Cernobyli ir šalia jo avarija esanti apleista miesta Pripete. Laidos FaceBook: https://www.facebook.com/praeitiesatg... Autoriaus FaceBook: https://www.facebook.com/andriuspl/ Instagram: https://www.instagram.com/praeities_a... Internetine svetaine: http://praeitiesatgarsiai.lt"
video.ToBeSuspended();