konlpy Package

jvm Module

konlpy.jvm.init_jvm(jvmpath=None)

Initializes the Java virtual machine (JVM).

Parameters:jvmpath – The path of the JVM. If left empty, inferred by jpype.getDefaultJVMPath().

utils Module

class konlpy.utils.UnicodePrinter(indent=1, width=80, depth=None, stream=None)

Bases: pprint.PrettyPrinter

format(object, context, maxlevels, level)

Overrided method to enable Unicode pretty print.

konlpy.utils.char2hex(c)

Converts a unicode character to hex.

>>> char2hex(u'음')
'0xc74c'
konlpy.utils.concat(phrase)

Concatenates lines into a unified string.

konlpy.utils.concordance(phrase, text, show=False)

Find concordances of a phrase in a text.

The farmost left numbers are indices, that indicate the location of the phrase in the text (by means of tokens). The following string, is part of the text surrounding the phrase for the given index.

Parameters:
  • phrase – Phrase to search in the document.
  • text – Target document.
  • show – If True, shows locations of the phrase on the console.
>>> from konlpy.corpus import kolaw
>>> from konlpy.tag import Mecab
>>> from konlpy import utils
>>> constitution = kolaw.open('constitution.txt').read()
>>> idx = utils.concordance(u'대한민국', constitution, show=True)
0       대한민국헌법 유구한 역사와
9       대한국민은 3·1운동으로 건립된 대한민국임시정부의 법통과 불의에
98      총강 제1조 ① 대한민국은 민주공화국이다. ②대한민국의
100     ① 대한민국은 민주공화국이다. ②대한민국의 주권은 국민에게
110     나온다. 제2조 ① 대한민국의 국민이 되는
126     의무를 진다. 제3조 대한민국의 영토는 한반도와
133     부속도서로 한다. 제4조 대한민국은 통일을 지향하며,
147     추진한다. 제5조 ① 대한민국은 국제평화의 유지에
787     군무원이 아닌 국민은 대한민국의 영역안에서는 중대한
1836    파견 또는 외국군대의 대한민국 영역안에서의 주류에
3620    경제 제119조 ① 대한민국의 경제질서는 개인과
>>> idx
[0, 9, 98, 100, 110, 126, 133, 147, 787, 1836, 3620]
konlpy.utils.hex2char(h)

Converts a hex character to unicode.

>>> print hex2char('c74c')

>>> print hex2char('0xc74c')

konlpy.utils.load_txt(filename)

Text file loader.

konlpy.utils.partition(list_, indices)

Partitions a list to several parts using indices.

Parameters:
  • list – The target list.
  • indices – Indices to partition the target list.
konlpy.utils.pprint(obj)

Unicode pretty printer.

>>> import pprint, konlpy
>>> pprint.pprint([u"Print", u"유니코드", u"easily"])
[u'Print', u'\uc720\ub2c8\ucf54\ub4dc', u'easily']
>>> konlpy.utils.pprint([u"Print", u"유니코드", u"easily"])
['Print', '유니코드', 'easily']
konlpy.utils.preprocess(phrase)

Preprocesses a phrase in the following steps:.

konlpy.utils.select(phrase)

Replaces some ambiguous punctuation marks to simpler ones.

Fork me on GitHub

Table Of Contents

Related Topics