Beispiel #1
0
def doKMP():
    data = request.form['hasil']
    data = json.JSONDecoder().decode(data)
    pattern = KMP(data['spam_indicator'])
    search_type = data['search_type']
    tweets = dict()
    if (search_type == "1"):
        username = data['username']
        count = data['count']
        tweets = api.search_timeline(username, count)
    else:
        region = data['region']
        count = data['count']
        tweets = api.search_region(region, count)

    is_spam = []
    for tweet in tweets['full_text']:
        is_spam.append(pattern.is_match(tweet))

    tweets['is_spam'] = is_spam

    return json.dumps(tweets)
Beispiel #2
0
def match(word, algo, filename):
    sentL = ConvertText(filename)
    word = word.lower()
    awalan = re.split('\n', sentL[0])
    judul = awalan[0]
    waktufile = awalan[2]
    del sentL[0]
    sentL.insert(0, awalan[4])
    sentL.insert(0, judul)
    # print(awalan[4])
    hasil = []
    if (algo == "Regex"):
        for s in sentL:
            # print(s)
            t = s
            awal = REexact(word, s)
            res = []
            if (awal != -1):
                waktu = REWaktu(s)
                if (waktu == "None"):
                    waktu = waktufile
                else:
                    s = re.sub(waktu, "", s)
                jumlah = REjumlah(awal, word, s)

                res.append("Jumlah    :" + jumlah)
                res.append("Waktu     :" + waktu)
                res.append(t + "(" + filename + ")")
                hasil.append(res)
        return (hasil)
    elif (algo == "KMP"):
        for s in sentL:
            # print(s)
            t = s
            awal = KMP(s, word)
            res = []
            if (awal != -1):
                waktu = REWaktu(s)
                if (waktu == "None"):
                    waktu = waktufile
                else:
                    s = re.sub(waktu, "", s)
                jumlah = REjumlah(awal, word, s)

                res.append("Jumlah    :" + jumlah)
                res.append("Waktu     :" + waktu)
                res.append(t + "(" + filename + ")")
                hasil.append(res)
        return (hasil)
    elif (algo == "BM"):
        for s in sentL:
            # print(s)
            t = s
            awal = (BM(s, word))
            res = []
            if (awal != -1):
                waktu = REWaktu(s)
                if (waktu == "None"):
                    waktu = waktufile
                else:
                    s = re.sub(waktu, "", s)
                jumlah = REjumlah(awal, word, s)

                res.append("Jumlah    :" + jumlah)
                res.append("Waktu     :" + waktu)
                res.append(t + "(" + filename + ")")
                hasil.append(res)
        return (hasil)
Beispiel #3
0
fileName = 'book.txt'

#reader.readFile("Paragraphs/para0.txt")
#reader.readFile("Paragraphs/para1.txt") 
#reader.readFile("Paragraphs/para2.txt") 
#"of"
#pattern = reader.readFile("Paragraphs/para2.txt")
pattern = "his"
# Get content's file
s = reader.readFile(fileName)

#print("	==> Text :: %s" %s)
print("	==> Pattern :: %s" %pattern)
print("	==> Pattern Length :: %d" %len(pattern))

#Bruteforce Algorithm
Bruteforce.bruteForce(s, pattern)

#Sunday Algorithm
Sunday.sunday(s, pattern)

#KMP Algorithm
KMP.KMP(s, pattern)

#FSM Algorithm
FSM.FSM(s, pattern)

#Rabin-Karp Algorithm
RabinKarp.rabinKarp(s, pattern)