OSDN Git Service
(root)
/
rec10
/
rec10-git.git
/ blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
history
|
raw
|
HEAD
use n-gram to search key schedule.
[rec10/rec10-git.git]
/
rec10
/
trunk
/
src
/
n_gram.py
1
#!/usr/bin/python
2
# coding: UTF-8
3
# Rec10 TS Recording Tools
4
# Copyright (C) 2009 Yukikaze
5
import zenhan
6
def bigram(str1,str2):
7
str1=zenhan.toHankaku(str1)
8
str2=zenhan.toHankaku(str2)
9
"""
10
bigramによる単語の近さを計算します。
11
"""
12
gram=[]
13
if len(str1)<2:
14
gram.append(str1)
15
else:
16
tmp=str1[0]
17
for x in str1[1:]:
18
gram.append(tmp+x)
19
tmp=x
20
point=0
21
for x in gram:
22
i=find_gram(x, str2)
23
if i>0:
24
i=90+10*i
25
else:
26
i=0
27
point=point+i
28
return point
29
def find_gram(gram,s):
30
"""
31
s中にあらわれるgramの数を調べる
32
"""
33
st=s
34
i=0
35
while st.find(gram)!=-1:
36
i=i+1
37
st=st[st.find(gram)+1:]
38
return i