Skip to content

Instantly share code, notes, and snippets.

@Saren-Arterius
Last active January 3, 2016 06:21
Show Gist options
  • Save Saren-Arterius/fbc2a25ff40df7b929bf to your computer and use it in GitHub Desktop.
Save Saren-Arterius/fbc2a25ff40df7b929bf to your computer and use it in GitHub Desktop.
聲優廚終結者
#!/usr/bin/env python3
from pybrain.datasets import SupervisedDataSet
from pybrain.structure import TanhLayer
from pybrain.supervised.trainers import BackpropTrainer
from pybrain.tools.shortcuts import buildNetwork
from pyquery import PyQuery as pq
from os.path import exists
import urllib.request
import pickle
GOOD_DATA = [["曼迪邀請聲優川澄綾子來台舉行簽名會", """Saber ~~~~~
BJ4!!!"""],
["代購之中的轉賣除", """在露天上看到有個人的帳號是 a09********
至少下標了4個代購簽名資格 這樣試想轉賣嗎=_="""],
["無標題", """居然阿!!XDDD
原本覺得很熱不想去了阿"""],
["《Fate/Grand Order》",
"魔槍を操る、王者の気質を備えた女性。有能な師でもあり、数多くの弟子を戦士や魔術師に育てあげた。人の身で神域に踏み入った罰か、人としてカウントされない呪いを受けている。"],
["無標題", "諸君我昨天夢到能登了,好開心。"],
["對不起", "無內文"],
["能登かわいいよ能登", "能登生日快樂喔"],
["帥哥", "帥哥"],
["可以讓鹿島太太當版娘嗎?", "可以讓鹿島太太當版娘嗎?"],
["無標題", "看我的降狗十八掌 第一掌 (啪!狗狗:幹你娘咧! 你是欠咬逆!"],
["無標題", "這偽娘的蛋蛋 好大!"],
["無標題", "幹得好~"]
]
BAD_DATA = [["幹林娘 悠木 碧 根多少 監 督 上 床 幹 鮑 魚", """幹林娘 悠木 碧 根多少 監 督 上 床 幹 鮑 魚
幹林娘 悠木 碧 根多少 監 督 上 床 幹 鮑 魚
幹林娘 悠木 碧 根多少 監 督 上 床 幹 鮑 魚
幹林娘 悠木 碧 根多少 監 督 上 床 幹 鮑 魚
幹林娘 悠木 碧 根多少 監 督 上 床 幹 鮑 魚
幹林娘 悠木 碧 根多少 監 督 上 床 幹 鮑 魚
幹林娘 悠木 碧 根多少 監 督 上 床 幹 鮑 魚
幹林娘 悠木 碧 根多少 監 督 上 床 幹 鮑 魚"""], ["幹林娘 早見大嬸根多少 監 督 上 床 幹 鮑 魚", """幹林娘 早見大嬸根多少 監 督 上 床 幹 鮑 魚
幹林娘 早見大嬸根多少 監 督 上 床 幹 鮑 魚
幹林娘 早見大嬸根多少 監 督 上 床 幹 鮑 魚
幹林娘 早見大嬸根多少 監 督 上 床 幹 鮑 魚
幹林娘 早見大嬸根多少 監 督 上 床 幹 鮑 魚
幹林娘 早見大嬸根多少 監 督 上 床 幹 鮑 魚
幹林娘 早見大嬸根多少 監 督 上 床 幹 鮑 魚
幹林娘 早見大嬸根多少 監 督 上 床 幹 鮑 魚"""], ["幹拎娘 小澤亞理根多少 監 督 上 床 幹 鮑 魚", """幹拎娘 小澤亞理根多少 監 督 上 床 幹 鮑 魚
幹拎娘 小澤亞理根多少 監 督 上 床 幹 鮑 魚
幹拎娘 小澤亞理根多少 監 督 上 床 幹 鮑 魚
幹拎娘 小澤亞理根多少 監 督 上 床 幹 鮑 魚
幹拎娘 小澤亞理根多少 監 督 上 床 幹 鮑 魚
幹拎娘 小澤亞理根多少 監 督 上 床 幹 鮑 魚
幹拎娘 小澤亞理根多少 監 督 上 床 幹 鮑 魚"""], ["幹拎娘 早見大嬸根多少 監 督 上 床 幹 鮑 魚", """幹拎娘 早見大嬸根多少 監 督 上 床 幹 鮑 魚
幹拎娘 早見大嬸根多少 監 督 上 床 幹 鮑 魚
幹拎娘 早見大嬸根多少 監 督 上 床 幹 鮑 魚
幹拎娘 早見大嬸根多少 監 督 上 床 幹 鮑 魚
幹拎娘 早見大嬸根多少 監 督 上 床 幹 鮑 魚
幹拎娘 早見大嬸根多少 監 督 上 床 幹 鮑 魚
幹拎娘 早見大嬸根多少 監 督 上 床 幹 鮑 魚
幹拎娘 早見大嬸根多少 監 督 上 床 幹 鮑 魚
幹拎娘 早見大嬸根多少 監 督 上 床 幹 鮑 魚
幹拎娘 早見大嬸根多少 監 督 上 床 幹 鮑 魚"""], ["幹拎娘 淵上舞根多少 監 督 上 床 幹 鮑 魚", """幹拎娘 淵上舞根多少 監 督 上 床 幹 鮑 魚
幹拎娘 淵上舞根多少 監 督 上 床 幹 鮑 魚
幹拎娘 淵上舞根多少 監 督 上 床 幹 鮑 魚
幹拎娘 淵上舞根多少 監 督 上 床 幹 鮑 魚
幹拎娘 淵上舞根多少 監 督 上 床 幹 鮑 魚
幹拎娘 淵上舞根多少 監 督 上 床 幹 鮑 魚
幹拎娘 淵上舞根多少 監 督 上 床 幹 鮑 魚
幹拎娘 淵上舞根多少 監 督 上 床 幹 鮑 魚"""], ["幹你娘 內田真禮根多少 監 督 上 床 幹 鮑 魚", """幹你娘 內田真禮根多少 監 督 上 床 幹 鮑 魚
幹你娘 內田真禮根多少 監 督 上 床 幹 鮑 魚
幹你娘 內田真禮根多少 監 督 上 床 幹 鮑 魚
幹你娘 內田真禮根多少 監 督 上 床 幹 鮑 魚
幹你娘 內田真禮根多少 監 督 上 床 幹 鮑 魚
幹你娘 內田真禮根多少 監 督 上 床 幹 鮑 魚
幹你娘 內田真禮根多少 監 督 上 床 幹 鮑 魚
幹你娘 內田真禮根多少 監 督 上 床 幹 鮑 魚
幹你娘 內田真禮根多少 監 督 上 床 幹 鮑 魚"""], ["幹拎娘 早見大嬸根多少 監 督 上 床 幹 鮑 魚", """幹拎娘 早見大嬸根多少 監 督 上 床 幹 鮑 魚
幹拎娘 早見大嬸根多少 監 督 上 床 幹 鮑 魚
幹拎娘 早見大嬸根多少 監 督 上 床 幹 鮑 魚
幹拎娘 早見大嬸根多少 監 督 上 床 幹 鮑 魚
幹拎娘 早見大嬸根多少 監 督 上 床 幹 鮑 魚
幹拎娘 早見大嬸根多少 監 督 上 床 幹 鮑 魚
幹拎娘 早見大嬸根多少 監 督 上 床 幹 鮑 魚
幹拎娘 早見大嬸根多少 監 督 上 床 幹 鮑 魚
幹拎娘 早見大嬸根多少 監 督 上 床 幹 鮑 魚"""], ["幹拎娘 早見大嬸根多少 監 督 上 床 幹 鮑 魚", """幹拎娘 早見大嬸根多少 監 督 上 床 幹 鮑 魚
幹拎娘 早見大嬸根多少 監 督 上 床 幹 鮑 魚
幹拎娘 早見大嬸根多少 監 督 上 床 幹 鮑 魚
幹拎娘 早見大嬸根多少 監 督 上 床 幹 鮑 魚
幹拎娘 早見大嬸根多少 監 督 上 床 幹 鮑 魚
幹拎娘 早見大嬸根多少 監 督 上 床 幹 鮑 魚
幹拎娘 早見大嬸根多少 監 督 上 床 幹 鮑 魚
幹拎娘 早見大嬸根多少 監 督 上 床 幹 鮑 魚"""], ["幹你娘 小岩井大嬸根多少監督 上 床 幹過他的 臭 鮑 魚", """幹你娘 小岩井大嬸根多少監督 上 床 幹過他的 臭 鮑 魚
幹你娘 小岩井大嬸根多少監督 上 床 幹過他的 臭 鮑 魚
幹你娘 小岩井大嬸根多少監督 上 床 幹過他的 臭 鮑 魚
幹你娘 小岩井大嬸根多少監督 上 床 幹過他的 臭 鮑 魚
幹你娘 小岩井大嬸根多少監督 上 床 幹過他的 臭 鮑 魚
幹你娘 小岩井大嬸根多少監督 上 床 幹過他的 臭 鮑 魚
幹你娘 小岩井大嬸根多少監督 上 床 幹過他的 臭 鮑 魚"""], ["糙機掰 種田大嬸跟多少音響監督 上 床 幹過他的臭鮑魚了", """糙機掰 種田大嬸跟多少音響監督 上 床 幹過他的臭鮑魚了
糙機掰 種田大嬸跟多少音響監督 上 床 幹過他的臭鮑魚了
糙機掰 種田大嬸跟多少音響監督 上 床 幹過他的臭鮑魚了"""]]
BAD_STRINGS = ["幹", "娘", "上床", "鮑魚", "監督", "你娘", "臭", "多少", "機掰", "糙"]
opener = urllib.request.build_opener()
opener.addheaders = [('User-agent', 'Mozilla/5.0')]
def extract_features(data):
composite = data[0] + data[1]
feature = [0 if not data[1] or not data[0] else data[1].count(data[0]) / len(data[1])]
for s in BAD_STRINGS:
feature.append(composite.replace(" ", "").replace("\n", "").count(s) / len(composite))
return feature
BASE_URL = "http://www.minorin.com/fps/"
PAGE_PATH = "{0}.htm"
if __name__ == "__main__":
if exists("network.dat"):
net = pickle.load(open("network.dat", "rb"))
else:
good_features = [extract_features(data) for data in GOOD_DATA]
bad_features = [extract_features(data) for data in BAD_DATA]
net = buildNetwork(len(good_features[0]), len(good_features[0]), 1, hiddenclass=TanhLayer)
data_set = SupervisedDataSet(len(good_features[0]), 1)
for f in good_features:
data_set.appendLinked(f, (0,))
for f in bad_features:
data_set.appendLinked(f, (1,))
t = BackpropTrainer(net, learningrate=0.01, momentum=0.1, verbose=True)
t.trainOnDataset(data_set, 500)
pickle.dump(net, open("network.dat", "wb"))
spam_ids = []
for page in range(10):
print("============Page {0}============".format(page))
url = BASE_URL + ("" if page == 0 else PAGE_PATH.format(page))
html = opener.open(url).read()
for selector in [".threadpost", ".reply"]:
for thread in pq(html)(selector):
title = pq(thread)(".title").text()
temp = pq(pq(thread)(".quote").html().replace("<br/>", "\n"))
temp(".pushpost").text("")
article = temp.text()
features = extract_features([title, article])
result = net.activate(extract_features([title, article]))
if result[0] >= 0.4:
print("============SPAM============")
spam_ids.append(int(pq(thread).find("input").attr("name")))
print("Title: ", title)
print("Article: ",
article[:50].replace("\n", " ") + "..." if len(article) > 50 else article.replace("\n", ""))
print("Features: ", features)
print(result, "\n")
spam_ids.sort()
print("Spam IDs:", spam_ids)
@qcheni77
Copy link

qcheni77 commented Jan 3, 2016

您好,請問使用這個可以屏蔽K島的spam嗎?具體使用方法是?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment