#!/usr/bin/python
# coding: UTF-8
# Rec10 TS Recording Tools
# Copyright (C) 2009 Yukikaze
import zenhan
def bigram(str1,str2):
    str1=zenhan.toHankaku(str1)
    str2=zenhan.toHankaku(str2)
    str1=str1.replace(" ","")
    str2=str2.replace(" ","")
    """
    bigramによる単語の近さを計算します。
    """
    gram=[]
    if len(str1)<2:
        gram.append(str1)
    else:
        tmp=str1[0]
        for x in str1[1:]:
            gram.append(tmp+x)
            tmp=x
    point=0
    for x in gram:
        i=find_gram(x, str2)
        if i>0:
            i=90+10*i
        else:
            i=0
        point=point+i
    return point
def find_gram(gram,s):
    """
    s中にあらわれるgramの数を調べる
    """
    st=s
    i=0
    while st.find(gram)!=-1:
       i=i+1
       st=st[st.find(gram)+1:]
    return i