Skip to content

Commit 492bc11

Browse files
committed
自动通过空格来划分分词段落 issues leizongmin#8
1 parent f4785e5 commit 492bc11

2 files changed

Lines changed: 3 additions & 1 deletion

File tree

‎lib/Segment.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ Segment.prototype.doSegment = function (text) {
160160
var ret = [];
161161

162162
// 将文本按照换行符分割成多段,并逐一分词
163-
text.replace(/\r?\n(\r?\n)*/, '\n').split(/\r?\n/).forEach(function (section) {
163+
text.replace(/\r/g, '\n').split(/(\n|\s)+/).forEach(function (section) {
164164
var section = section.trim();
165165
if (section.length < 1) return;
166166
// ======================================

‎test/test_segment.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ describe('ChsNameTokenizer', function () {
9191
['中国', '两艘', '海监船', '赴', '钓鱼岛', '宣示', '主权']);
9292
equal('中日关系因钓鱼岛问题面临严峻局面',
9393
['中日关系', '因', '钓鱼岛', '问题', '面临', '严峻', '局面']);
94+
equal('一一', ['一一']);
95+
equal('一 一', ['一', '一']);
9496
});
9597

9698
});

0 commit comments

Comments
 (0)