Skip to content

Commit

Permalink
Fix for g++ and python 3
Browse files Browse the repository at this point in the history
  • Loading branch information
vchahun committed Jul 3, 2012
1 parent 68d723d commit 0121f57
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 84 deletions.
11 changes: 6 additions & 5 deletions examples/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@

LM = os.path.join(os.path.dirname(__file__), 'mini.klm')
model = kenlm.LanguageModel(LM)
print '%d-gram model' % model.order
print('{0}-gram model'.format(model.order))

sentence = u'language modeling is fun .'
print sentence, model.score(sentence)
sentence = 'language modeling is fun .'
print(sentence)
print(model.score(sentence))

# Check that total full score = direct score
def score(s):
Expand All @@ -17,9 +18,9 @@ def score(s):
# Show scores and n-gram matches
words = ['<s>'] + sentence.split() + ['</s>']
for i, (prob, length) in enumerate(model.full_scores(sentence)):
print prob, length, ':', ' '.join(words[i+2-length:i+2])
print('{0} {1} : {2}'.format(prob, length, ' '.join(words[i+2-length:i+2])))

# Find out-of-vocabulary words
for w in words:
if not w in model:
print '"%s" is an OOV' % w
print('"{0}" is an OOV'.format(w))
Loading

0 comments on commit 0121f57

Please sign in to comment.