Exemplo n.º 1
0
 def test_match_6(self):
     matcher = KMP(
         "alksjflkasjflkasjfaslfjlasjflajsflajsflasjflasjflkasjflkasjflkasjflkjsaf"
     )
     self.assertTrue(
         matcher.match(
             "09012102412sdjadalksjflkasjflkasjfaslfjlasjflajsflajsflasjflasjflkasjflkasjflkasjflkjsafm,zxcoqwo90e12ne12e"
         ))
Exemplo n.º 2
0
def evaluateKMP():
	if (request.is_json):
		content = request.get_json()
		# construct string matcher
		pattern = content['spamkey']
		matcher = KMP(pattern)
		# get tweets based on search key
		tweets = api.search_tweets(content['searchkey'])
		# Evaluate tweets using matcher
		for tweet in tweets:
			tweet['is_spam'] = matcher.match(tweet['text'].lower())
			
		return json.dumps(tweets);
	else:
		return "Bad Request"
Exemplo n.º 3
0
 def test_match_7(self):
     matcher = KMP("SINGLES AROUND YOU")
     self.assertTrue(matcher.match("CHECK THIS OUT! SINGLES AROUND YOU!!"))
Exemplo n.º 4
0
 def test_border_1(self):
     matcher = KMP("AAAA")
     self.assertEqual(matcher.get_border_table(), [0, 1, 2, 3])
Exemplo n.º 5
0
 def test_match_5(self):
     matcher = KMP("checking it out")
     self.assertTrue(
         matcher.match("hello world! please consider checking it out!"))
Exemplo n.º 6
0
 def test_match_4(self):
     matcher = KMP("bcgl")
     self.assertFalse(matcher.match("abcbcgdbclgx"))
Exemplo n.º 7
0
 def test_match_3(self):
     matcher = KMP("bcgl")
     self.assertTrue(matcher.match("abcbcglx"))
Exemplo n.º 8
0
 def test_match_2(self):
     matcher = KMP("abcaby")
     self.assertTrue(matcher.match("abxabcabcaby"))
Exemplo n.º 9
0
 def test_match_1(self):
     matcher = KMP("abc")
     self.assertTrue(matcher.match("abcdef"))
Exemplo n.º 10
0
 def test_border_8(self):
     matcher = KMP("abcaby")
     self.assertEqual(matcher.get_border_table(), [0, 0, 0, 1, 2, 0])
Exemplo n.º 11
0
 def test_border_7(self):
     matcher = KMP("acacabacacabacacac")
     self.assertEqual(
         matcher.get_border_table(),
         [0, 0, 1, 2, 3, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 4])
Exemplo n.º 12
0
 def test_border_6(self):
     matcher = KMP("AABAABAAA")
     self.assertEqual(matcher.get_border_table(),
                      [0, 1, 0, 1, 2, 3, 4, 5, 2])
Exemplo n.º 13
0
 def test_border_4(self):
     matcher = KMP("AAACAAAAAC")
     self.assertEqual(matcher.get_border_table(),
                      [0, 1, 2, 0, 1, 2, 3, 3, 3, 4])
Exemplo n.º 14
0
 def test_border_2(self):
     matcher = KMP("ABCDE")
     self.assertEqual(matcher.get_border_table(), [0, 0, 0, 0, 0])