Skip to content

Commit 18e5c7a

Browse files
committed
修复 convertToPinyinList fix #1634
1 parent 88d3eb0 commit 18e5c7a

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/main/java/com/hankcs/hanlp/dictionary/py/PinyinDictionary.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,10 @@ protected static List<Pinyin> segLongest(char[] charArray, AhoCorasickDoubleArra
187187
public void hit(int begin, int end, Pinyin[] value)
188188
{
189189
int length = end - begin;
190+
if (length == 1 && value.length > 1)
191+
{
192+
value = new Pinyin[]{value[0]};
193+
}
190194
if (length > lengths[begin])
191195
{
192196
wordNet[begin] = value;

src/test/java/com/hankcs/hanlp/HanLPTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,9 @@ public void testDicUpdate()
1616
{
1717
System.out.println(HanLP.segment("大数据是一个新词汇!"));
1818
}
19+
20+
public void testConvertToPinyinList()
21+
{
22+
System.out.println(HanLP.convertToPinyinString("你好", " ", false));
23+
}
1924
}

0 commit comments

Comments
 (0)