N-Gram in Python

I used python-ngram

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import ngram

text = u'AIUEO'
index = ngram.NGram(N=2)
for term in index.ngrams(index.pad(text)):
    print term

result

$ python sample.py 
$Ah
Ai
Say
up
Eo
O$

There are many other functions, so you should read the tutorials linked above. It seems that you can also search

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import ngram

G = ngram.NGram(['joe','joseph','jon','john','sally'])
print G.search("joseph")
$ python sample.py
[('joseph', 1.0), ('joe', 0.18181818181818182), ('jon', 0.18181818181818182), ('john', 0.16666666666666666)]

Recommended Posts

N-Gram in Python
N-gram in python
Quadtree in Python --2
Python in optimization
CURL in python
Metaprogramming in Python
Python 3.3 in Anaconda
Geocoding in python
SendKeys in Python
Meta-analysis in Python
Unittest in python
Epoch in Python
Discord in Python
Sudoku in Python
DCI in Python
quicksort in python
nCr in python
Programming in python
Plink in Python
Constant in python
Lifegame in Python.
FizzBuzz in Python
Sqlite in python
StepAIC in Python
LINE-Bot [0] in Python
Csv in python
Disassemble in Python
Reflection in Python
Constant in python
nCr in Python.
format in python
Scons in Python3
Puyo Puyo in python
python in virtualenv
PPAP in Python
Quad-tree in Python
Reflection in Python
Chemistry in Python
Hashable in python
DirectLiNGAM in Python
LiNGAM in Python
Flatten in python
flatten in python
Module to generate word N-gram in Python
Sorted list in Python
Clustering text in Python
Daily AtCoder # 2 in Python
Implement Enigma in python
Daily AtCoder # 6 in Python
Daily AtCoder # 18 in Python
Edit fonts in Python
Singleton pattern in Python
File operations in Python
Read DXF in python
Daily AtCoder # 53 in Python
Key input in Python
Use config.ini in Python
Daily AtCoder # 33 in Python
Solve ABC168D in Python
Logistic distribution in Python
LU decomposition in Python