mirror of
http://aero2k.de/t/repos/urlbot-native.git
synced 2017-09-06 15:25:38 +02:00
testing str_sim() for (title, lev_url)
This commit is contained in:
@@ -1,8 +1,9 @@
|
|||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
def str_sim(a, b):
|
def str_sim(a, b, do_print=False):
|
||||||
a = a.lower()
|
a = a.lower()
|
||||||
b = b.lower()
|
b = b.lower()
|
||||||
|
|
||||||
@@ -17,6 +18,7 @@ def str_sim(a, b):
|
|||||||
if a_parts[i] == b_parts[j]:
|
if a_parts[i] == b_parts[j]:
|
||||||
out[i][j] += 1
|
out[i][j] += 1
|
||||||
|
|
||||||
|
if do_print:
|
||||||
i = 0
|
i = 0
|
||||||
for j in range(0, len(b_parts)):
|
for j in range(0, len(b_parts)):
|
||||||
print(' |'*i + ' '*2 + '.- ' + b_parts[j])
|
print(' |'*i + ' '*2 + '.- ' + b_parts[j])
|
||||||
@@ -38,10 +40,11 @@ def sum_array(array):
|
|||||||
return _sum
|
return _sum
|
||||||
|
|
||||||
def wrapper_print(a, b, comment=''):
|
def wrapper_print(a, b, comment=''):
|
||||||
ret = str_sim(a, b)
|
ret = str_sim(a, b, do_print=True)
|
||||||
if '' != comment: comment = ' ^ ' + comment
|
if '' != comment: comment = ' ^ ' + comment
|
||||||
print('[%2dx%2d::%2d]%s' %(len(ret), len(ret[0]), sum_array(ret), comment))
|
print('[%2dx%2d::%2d]%s' %(len(ret), len(ret[0]), sum_array(ret), comment))
|
||||||
|
|
||||||
|
if '__main__' == __name__:
|
||||||
pairs = (
|
pairs = (
|
||||||
(
|
(
|
||||||
'http://de.wikipedia.org/wiki/Monte_Kali_%28Heringen%29',
|
'http://de.wikipedia.org/wiki/Monte_Kali_%28Heringen%29',
|
||||||
|
|||||||
11
urlbot.py
11
urlbot.py
@@ -5,6 +5,7 @@ import sys, os, stat, re, time, pickle, random
|
|||||||
import urllib.request, urllib.parse, urllib.error, html.parser
|
import urllib.request, urllib.parse, urllib.error, html.parser
|
||||||
from local_config import conf, set_conf
|
from local_config import conf, set_conf
|
||||||
from common import *
|
from common import *
|
||||||
|
from strsim import str_sim
|
||||||
|
|
||||||
# rate limiting to 5 messages per 10 minutes
|
# rate limiting to 5 messages per 10 minutes
|
||||||
hist_ts = []
|
hist_ts = []
|
||||||
@@ -145,7 +146,15 @@ def extract_url(data):
|
|||||||
conf_save(obj)
|
conf_save(obj)
|
||||||
|
|
||||||
lev_str = 'lev=%d/%d:%d ' %(lev_res, len(title), len(lev_url))
|
lev_str = 'lev=%d/%d:%d ' %(lev_res, len(title), len(lev_url))
|
||||||
message = lev_str + 'Title: %s: %s' %(title, r)
|
|
||||||
|
sim = str_sim(title, lev_url)
|
||||||
|
sim_len_title = len(sim)
|
||||||
|
sim_len_url = len(sim[0])
|
||||||
|
sim_sum = sum([sum(a) for a in sim])
|
||||||
|
|
||||||
|
sim_str = 'sim=%d/%d:%d ' %(sim_sum, sim_len_title, sim_len_url)
|
||||||
|
|
||||||
|
message = lev_str + sim_str + 'Title: %s: %s' %(title, r)
|
||||||
elif 1 == status:
|
elif 1 == status:
|
||||||
if conf('image_preview'):
|
if conf('image_preview'):
|
||||||
# of course it's fake, but it looks interesting at least
|
# of course it's fake, but it looks interesting at least
|
||||||
|
|||||||
Reference in New Issue
Block a user