예제 #1
0
def test_add_pre_analyzed_word():
    kiwi = Kiwi()
    ores = kiwi.tokenize("팅겼어")

    try:
        kiwi.add_pre_analyzed_word("팅겼어", [("팅기", "VV"), "었/EP", "어/EF"])
        raise AssertionError("expected to raise `ValueError`")
    except ValueError:
        pass
    except:
        raise AssertionError("expected to raise `ValueError`")

    kiwi.add_user_word("팅기", "VV", orig_word="튕기")
    kiwi.add_pre_analyzed_word("팅겼어", [("팅기", "VV", 0, 2), ("었", "EP", 1, 2),
                                       ("어", "EF", 2, 3)])

    res = kiwi.tokenize("팅겼어...")

    assert res[0].form == "팅기" and res[0].tag == "VV" and res[
        0].start == 0 and res[0].end == 2
    assert res[1].form == "었" and res[1].tag == "EP" and res[
        1].start == 1 and res[1].end == 2
    assert res[2].form == "어" and res[2].tag == "EF" and res[
        2].start == 2 and res[2].end == 3
    assert res[3].form == "..." and res[3].tag == "SF" and res[
        3].start == 3 and res[3].end == 6
예제 #2
0
def test_bug_33():
    kiwi = Kiwi()
    kiwi.add_user_word('김갑갑', 'NNP')
    print(kiwi.analyze("김갑갑 김갑갑 김갑갑"))
예제 #3
0
        try:
            return next(self.iter)
        except StopIteration:
            return None

    def write(self, sent_id, res):
        print('Analyzed %dth row' % sent_id)
        self.output.write(' '.join(map(lambda x:x[0]+'/'+x[1], res[0][0])) + '\n')

    def __del__(self):
        self.input.close()
        self.output.close()

kiwi = Kiwi()
kiwi.load_user_dictionary(r'./server_project/test/userDict.txt')
kiwi.add_user_word('iXVDR', 'NNP', 3.0)

kiwi.prepare()
# handle = IOHandler(r'./server_project/test/input.txt', r'./server_project/test/result.txt')
# kiwi.analyze(handle.read, handle.write)


result = kiwi.analyze('강남에서 먹었던 오늘의 스파게티는 맛있었다.', 1)
for i in result:
    print(i)


class ReaderExam:
    def __init__(self, filePath):
        self.file = open(filePath, encoding='UTF8')