Split Korean text into sentences using heuristic algorithm

Related tags

Templates kss_dart
Overview

Korean Sentence Splitter

latest version BSD 3-Clause

Split Korean text into sentences using heuristic algorithm.

pub.dev link



example

1. Installation

dependencies:
  ...
  kss_dart:



2. Usage of splitSentences

 List<String> splitSentences(
        String text,
        {boolean useHeuristic = true,  
        boolean useQuotesBracketsProcessing = true, 
        int maxRecoverStep  = 5,
        int maxRecoverLength = 20000,
        int recoverStep = 0}
    ) 

2.1. Split sentences with heuristic algorithm.

  • splitSentences is the key method of Kss.
  • You can segment text to sentences with this method.
import 'package:kss_dart/kss_dart.dart';

Kss kss = Kss();
String text = "회사 동료 분들과 다녀왔는데 분위기도 좋고 음식도 맛있었어요 다만, 강남 토끼정이 강남 쉑쉑버거 골목길로 쭉 올라가야 하는데 다들 쉑쉑버거의 유혹에 넘어갈 뻔 했답니다 강남역 맛집 토끼정의 외부 모습.";
kss.splitSentences(text);
["회사 동료 분들과 다녀왔는데 분위기도 좋고 음식도 맛있었어요,"
 "다만, 강남 토끼정이 강남 쉑쉑버거 골목길로 쭉 올라가야 하는데 다들 쉑쉑버거의 유혹에 넘어갈 뻔 했답니다,"
 "강남역 맛집 토끼정의 외부 모습."]

2.2. Split sentences without heuristic algorithm.

  • If your articles follow the punctuation rules reratively well, we recommend to you set the useHeuristic = false. (default is true)
  • In these cases, Kss segments text depending only on punctuataion and you can segment text much more safely.
    • Formal articles (Wiki, News, Essay, ...) : recommend useHeuristic = false
    • Informal articles (SNS, Blogs, Messages, ...) : recommend useHeuristic = true
import 'package:kss_dart/kss_dart.dart';

Kss kss = Kss();
String text = "미리 예약을 할 수 있는 시스템으로 합리적인 가격에 여러 종류의 생선, 그리고 다양한 부위를 즐길 수 있기 때문이다. 계절에 따라 모둠회의 종류는 조금씩 달라지지만 자주 올려주는 참돔 마스까와는 특히 맛이 매우 좋다. 일반 모둠회도 좋지만 좀 더 특별한 맛을 즐기고 싶다면 특수 부위 모둠회를 추천한다 제철 생선 5~6가지 구성에 평소 접하지 못했던 부위까지 색다르게 즐길 수 있다.";
kss.splitSentences(text, useHeuristic : false);  
["미리 예약을 할 수 있는 시스템으로 합리적인 가격에 여러 종류의 생선, 그리고 다양한 부위를 즐길 수 있기 때문이다.", 
 "계절에 따라 모둠회의 종류는 조금씩 달라지지만 자주 올려주는 참돔 마스까와는 특히 맛이 매우 좋다.", 
 "제철 생선 5~6가지 구성에 평소 접하지 못했던 부위까지 색다르게 즐길 수 있다."]

2.3. Brackets and quotation marks processing

  • Kss provides a technique for not segmenting sentences enclosed in brackets (괄호) or quotation marks (따옴표).
import 'package:kss_dart/kss_dart.dart';

Kss kss = Kss();
String text = "그가 말했다. '거기는 가지 마세요. 위험하니까요. 알겠죠?' 그러자 그가 말했다. 알겠어요.";
kss.splitSentences(text)
        
["그가 말했다.","'거기는 가지 마세요. 위험하니까요. 알겠죠?' 그러자 그가 말했다.","알겠어요."]

2.3.1. Several options to optimize recursion

  • However, this can cause problem when brackets and quotation marks are misaligned, and it was a cronic problem of Kss 1.x (C++ version).
  • From Kss 2.xx, we provide quotes and brocket calibration feature to solve this problem, but it uses recursion and has very poor time complexity O(2^n).
  • So, we also provide several options to optimize recursion. You can save your precious time with these options.
    • The depth of the recursion can be modified through a parameter maxRecoverStep. (default is 5)
    • You can turn off calibration using the maxRecoverLength parameter. (default is 20,000)
import 'package:kss_dart/kss_dart.dart';

Kss kss = Kss();

Kss kss = new Kss();
String text = "VERY_LONG_TEXT";

splitSentences(text, useHeuristic : true, useQuotesBracketProcessing : true, maxRecoverStep : 5);
// you can adjust recursion depth using `maxRecoverStep` (default is 5)
splitSentences(text, useHeuristic : true, useQuotesBracketProcessing: true, maxRecoverStep : 5, maxRecoverLength : 20000);
// you can turn it off when you input very long text using `maxRecoverLength` (default is 20000)

2.3.2. Turn off brackets and quotation marks processing

  • You can also turn off brackets and quotation marks processing if you want.
  • Set useQuotesBracketsProcessing = false to turn it off.
import 'package:kss_dart/kss_dart.dart';

Kss kss = Kss();
String text = "그가 말했다. (거기는 가지 마세요. 위험하니까요. 알겠죠?) 그러자 그가 말했다. 알겠어요.";

kss.splitSentences(text);
['그가 말했다.','(거기는 가지 마세요. 위험하니까요. 알겠죠?) 그러자 그가 말했다.','알겠어요.']

kss.splitSentences(text, overlap : true, useHeuristic : false);
['그가 말했다.','(거기는 가지 마세요.','위험하니까요.','알겠죠?',') 그러자 그가 말했다.','알겠어요.']



3. Usage of splitChunks

 List<ChunkWithIndex> splitChunks(
        String text, 
        int maxLength ,
        {boolean overlap = false, 
        boolean useHeuristic = true, 
        boolean useQuotesBracketsProcessing =  true, 
        int maxRecoverStep = 5, 
        int maxRecoverLength = 20000 }
    ) 

3.1. Set maximum length of chunks via maxLength

  • splitChunks combine sentences into chunks of a maxlength or less.
  • You can set the maximum length of one chunk to maxLength.
import 'package:kss_dart/kss_dart.dart';

Kss kss = Kss();
String text = "NoSQL이라고 하는 말은 No 'English'라고 하는 말과 마찬가지다. 세상에는 영어 말고도 수많은 언어가 존재한다. MongoDB에서 사용하는 쿼리 언어와 CouchDB에서 사용하는 쿼리 언어는 서로 전혀 다르다. 그럼에도 이 두 쿼리 언어는 같은 NoSQL 카테고리에 속한다. 어쨌거나 SQL이 아니기 때문이다. 또한 NoSQL이 No RDBMS를 의미하지는 않는다. BerkleyDB같은 예외가 있기 때문이다. 그리고 No RDBMS가 NoSQL인 것도 아니다. SQL호환 레이어를 제공하는 KV-store라는 예외가 역시 존재한다. 물론 KV-store의 특징상 range query를 where절에 넣을 수 없으므로 완전한 SQL은 못 되고 SQL의 부분집합 정도를 제공한다.";
kss.splitChunks(text, 128);
[ChunkWithIndex(start = 0, text = "NoSQL이라고 하는 말은 No 'English'라고 하는 말과 마찬가지다. 세상에는 영어 말고도 수많은 언어가 존재한다. MongoDB에서 사용하는 쿼리 언어와 CouchDB에서 사용하는 쿼리 언어는 서로 전혀 다르다."),
 ChunkWithIndex(start = 124, text = "그럼에도 이 두 쿼리 언어는 같은 NoSQL 카테고리에 속한다. 어쨌거나 SQL이 아니기 때문이다. 또한 NoSQL이 No RDBMS를 의미하지는 않는다. BerkleyDB같은 예외가 있기 때문이다."),
 ChunkWithIndex(start = 236, text = "그리고 No RDBMS가 NoSQL인 것도 아니다. SQL호환 레이어를 제공하는 KV-store라는 예외가 역 시 존재한다."),
 ChunkWithIndex(start = 305, text = "물론 KV-store의 특징상 range query를 where절에 넣을 수 없으므로 완전한 SQL은 못 되고 SQL의 부분집합 정도를 제공한다.")]

3.2. Overlap sentences across chunks

  • If overlap is true, text will be chunked similar with sliding window.
  • Each chunk allows for duplicate sentences if you turn this feature on.
import 'package:kss_dart/kss_dart.dart';

Kss kss = Kss();
String text = "NoSQL이라고 하는 말은 No 'English'라고 하는 말과 마찬가지다. 세상에는 영어 말고도 수많은 언어가 존재한다. MongoDB에서 사용하는 쿼리 언어와 CouchDB에서 사용하는 쿼리 언어는 서로 전혀 다르다. 그럼에도 이 두 쿼리 언어는 같은 NoSQL 카테고리에 속한다. 어쨌거나 SQL이 아니기 때문이다. 또한 NoSQL이 No RDBMS를 의미하지는 않는다. BerkleyDB같은 예외가 있기 때문이다. 그리고 No RDBMS가 NoSQL인 것도 아니다. SQL호환 레이어를 제공하는 KV-store라는 예외가 역시 존재한다. 물론 KV-store의 특징상 range query를 where절에 넣을 수 없으므로 완전한 SQL은 못 되고 SQL의 부분집합 정도를 제공한다.";
kss.splitChunks(text, 128, overlap : false, useHeuristic : true); // text maxLength, overlap, useHeuristic,
[ChunkWithIndex(start = 0, text = "NoSQL이라고 하는 말은 No 'English'라고 하는 말과 마찬가지다. 세상에는 영어 말고도 수많은 언어가 존재한다. MongoDB에서 사용하는 쿼리 언어와 CouchDB에서 사용하는 쿼리 언어는 서로 전혀 다르다."),
 ChunkWithIndex(start = 43, text = "세상에는 영어 말고도 수많은 언어가 존재한다. MongoDB에서 사용하는 쿼리 언어와 CouchDB에서 사용하는 쿼리 언어는 서로 전혀 다르다. 그럼에도 이 두 쿼리 언어는 같은 NoSQL 카테고리에 속한다."),
 ChunkWithIndex(start = 69, text = "MongoDB에서 사용하는 쿼리 언어와 CouchDB에서 사용하는 쿼리 언어는 서로 전혀 다르다. 그럼 에도 이 두 쿼리 언어는 같은 NoSQL 카테고리에 속한다. 어쨌거나 SQL이 아니기 때문이다."),
 ChunkWithIndex(start = 124, text = "그럼에도 이 두 쿼리 언어는 같은 NoSQL 카테고리에 속한다. 어쨌거나 SQL이 아니기 때문이다. 또한 NoSQL이 No RDBMS를 의미하지는 않는다. BerkleyDB같은 예외가 있기 때문이다."),
 ChunkWithIndex(start = 180, text = "또한 NoSQL이 No RDBMS를 의미하지는 않는다. BerkleyDB같은 예외가 있기 때문이다. 그리고 No RDBMS가 NoSQL인 것도 아니다. SQL호환 레이어를 제공하는 KV-store라는 예외가 역시 존재한다."),
 ChunkWithIndex(start = 236, text = "그리고 No RDBMS가 NoSQL인 것도 아니다. SQL호환 레이어를 제공하는 KV-store라는 예외가 역 시 존재한다. 물론 KV-store의 특징상 range query를 where절에 넣을 수 없으므로 완전한 SQL은 못 되고 SQL의 부분집합 정도를 제공한다.")]

3.3. Use every options used in splitSentences

  • You can use the EVERY options used in splitSentences.
  • For example, if you want to turn off the processing about quotation marks, you can set useQuotesBracketsProcessing the same as split_sentences.
import 'package:kss_dart/kss_dart.dart';

Kss kss = Kss();
String text = "NoSQL이라고 하는 말은 No 'English'라고 하는 말과 마찬가지다. 세상에는 영어 말고도 수많은 언어가 존재한다. MongoDB에서 사용하는 쿼리 언어와 CouchDB에서 사용하는 쿼리 언어는 서로 전혀 다르다. 그럼에도 이 두 쿼리 언어는 같은 NoSQL 카테고리에 속한다. 어쨌거나 SQL이 아니기 때문이다. 또한 NoSQL이 No RDBMS를 의미하지는 않는다. BerkleyDB같은 예외가 있기 때문이다. 그리고 No RDBMS가 NoSQL인 것도 아니다. SQL호환 레이어를 제공하는 KV-store라는 예외가 역시 존재한다. 물론 KV-store의 특징상 range query를 where절에 넣을 수 없으므로 완전한 SQL은 못 되고 SQL의 부분집합 정도를 제공한다.";
splitChunks(text, 128, overlap : false, useHeuristic : true, useQuotesBracketsProcessing : false); // text maxLength, overlap, useHeuristic, useQuotesBracketsProcessing,



4. References

Kss is available in various programming languages.

You might also like...

Flutter Local Notifications - Learn how to implement local notifications into both Android and iOS using flutter_local_notifications plugin.

Flutter Local Notifications - Learn how to implement local notifications into both Android and iOS using flutter_local_notifications plugin.

Flutter Local Notifications Example Flutter Local Notifications - Learn how to implement local notifications into both Android and iOS using flutter_l

Nov 29, 2022

A Demo application📱 which stores User feedback from 💙Flutter application into Google Sheets🗎 using Google AppScript.

A Demo application📱  which stores User feedback from 💙Flutter application into Google Sheets🗎 using Google AppScript.

📱 Flutter 💙 to Google Sheets 📊 A Demo application which stores User feedback from Flutter application into Google Sheets using Google AppScript. Yo

Dec 28, 2022

A cross-platform flutter package to convert your links into rich beautiful previews.

A cross-platform flutter package to convert your links into rich beautiful previews.

Link Preview Generator A cross-platform flutter package to convert your links into rich beautiful previews. This package is inspired from Any Link Pre

Oct 21, 2022

Deep Dive Into Flutter

Deep Dive Into Flutter

Deep Dive Into Flutter This my more formalized version of a Rosetta Stone of Flutter Demos to encourage you to take a deep dive into flutter to master

Nov 2, 2022

Package your Flutter app into OS-specific bundles (.dmg, .exe, etc.) via Dart or the command line.

flutter_distributor Package your Flutter app into OS-specific bundles (.dmg, .exe, etc.) via Dart or the command line. The flutter_distributor source

Dec 24, 2022

A Flutter widget that forces the device rotates into the set of orientations the application interface can be displayed in.

A Flutter widget that forces the device rotates into the set of orientations the application interface can be displayed in. Features Force device keep

Nov 30, 2021

Flutter Control is complex library to maintain App and State management. Library merges multiple functionality under one hood. This approach helps to tidily bound separated logic into complex solution.

Flutter Control is complex library to maintain App and State management. Library merges multiple functionality under one hood. This approach helps to tidily bound separated logic into complex solution.

Flutter Control is complex library to maintain App and State management. Library merges multiple functionality under one hood. This approach helps to

Feb 23, 2022

All four are used to log into a Firebase backend.

All four are used to log into a Firebase backend.

Auth This library package works with four plugins: firebase_auth google_sign_in flutter_facebook_login flutter_twitter All four are used to log into a

Dec 14, 2022

A builder for extracting a package version into code

Include the version of your package in our source code. Add build_version to pubspec.yaml. Also make sure there is a version field. name: my_pkg versi

Dec 7, 2022
Owner
자유해결사
자유해결사
Flutter Split View and Drawer Navigation example

Flutter Split View and Drawer Navigation example This repo contains the source code for this tutorial: Responsive layouts in Flutter: Split View and D

Andrea Bizzotto 32 Nov 17, 2022
Split your bill among friends.

Bill-Split-App Split your bill among friends. Preview ?? split.mp4 Full Video ?? INSTAGRAM ⚙️ Built with Amazing Tools Flutter - Beautiful native apps

Flutter Queen 3 Oct 20, 2022
Masked text field - A flutter package for masked text field for formet your text and good UI

Masked Text Field Masked Text Field Features A package for masked text field for

Alok Dubey 7 Sep 4, 2022
Text analyzer that extracts tokens from text for use in full-text search queries and indexes.

Tokenize text, compute document readbility and compare terms in Natural Language Processing. THIS PACKAGE IS PRE-RELEASE, and SUBJECT TO DAILY BREAKIN

GM Consult Pty Ltd 5 Dec 12, 2022
Easy to use text widget for Flutter apps, which converts inlined urls into working, clickable links

LinkText Easy to use text widget for Flutter apps, which converts inlined URLs into clickable links. Allows custom styling. Usage LinkText widget does

Aleksander Woźniak 20 Nov 4, 2022
Tic Tac Toe game with single-player and multi-player options. Implemented minimax algorithm.

flutter_tic_tac_toe A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you star

null 0 Jan 1, 2022
The XOR Encryption algorithm is a effective and easy to implement method of symmetric encryption.

Symmetric XOR cipher library About XOR cipher XOR Encryption is an encryption method used to encrypt data and is hard to crack by brute-force method,

Plague Fox 7 Apr 20, 2022
An Instagram like text editor Flutter widget that helps you to change your text style.

TextEditor An instagram like text editor widget for flutter Show some ❤️ and star the repo to support the project Features Edit TextStyle object font

Mehdi Zarepour 68 Dec 16, 2022
Detectable text field - Flutter Text widgets with detection features

detectable_text_field Text widgets with detection features. You can detect hasht

null 0 Feb 2, 2022
A text field that displays text on different languages based on your selection.

translatable_text_field A text field that displays text on different languages based on your selection. Its basic idea is that you place this fields i

null 0 Mar 13, 2022