diff --git a/src/main/java/com/hankcs/hanlp/dictionary/nt/OrganizationDictionary.java b/src/main/java/com/hankcs/hanlp/dictionary/nt/OrganizationDictionary.java index 5e0ebccbd..4f85176f4 100644 --- a/src/main/java/com/hankcs/hanlp/dictionary/nt/OrganizationDictionary.java +++ b/src/main/java/com/hankcs/hanlp/dictionary/nt/OrganizationDictionary.java @@ -3756,7 +3756,7 @@ public static void parsePattern(List ntList, List vertexList, final public void hit(int begin, int end, String keyword) { StringBuilder sbName = new StringBuilder(); - for (int i = begin; i <= end; ++i) + for (int i = begin; i < end; ++i) { sbName.append(wordArray[i].realWord); } diff --git a/src/test/java/com/hankcs/test/seg/TestSegment.java b/src/test/java/com/hankcs/test/seg/TestSegment.java index 42f751866..434f30d4d 100644 --- a/src/test/java/com/hankcs/test/seg/TestSegment.java +++ b/src/test/java/com/hankcs/test/seg/TestSegment.java @@ -140,7 +140,7 @@ public void testIssue2() throws Exception public void testIssue3() throws Exception { - assertEquals(CharType.CT_DELIMITER, CharType.get('*'));; + assertEquals(CharType.CT_DELIMITER, CharType.get('*')); System.out.println(HanLP.segment("300g*2")); System.out.println(HanLP.segment("300g*2")); System.out.println(HanLP.segment("鱼300克*2/组")); @@ -169,8 +169,7 @@ public void testSpeedOfSecondViterbi() throws Exception String text = "王总和小丽结婚了"; Segment segment = new ViterbiSegment().enableAllNamedEntityRecognize(false) .enableNameRecognize(false) // 人名识别需要二次维特比,比较慢 - .enableCustomDictionary(false) - ; + .enableCustomDictionary(false); System.out.println(segment.seg(text)); long start = System.currentTimeMillis(); int pressure = 1000000; @@ -178,7 +177,7 @@ public void testSpeedOfSecondViterbi() throws Exception { segment.seg(text); } - double costTime = (System.currentTimeMillis() - start) / (double)1000; + double costTime = (System.currentTimeMillis() - start) / (double) 1000; System.out.printf("分词速度:%.2f字每秒", text.length() * pressure / costTime); } @@ -243,13 +242,13 @@ public void testMultiThreading() throws Exception text = sbBigText.toString(); long start = System.currentTimeMillis(); List termList1 = segment.seg(text); - double costTime = (System.currentTimeMillis() - start) / (double)1000; + double costTime = (System.currentTimeMillis() - start) / (double) 1000; System.out.printf("单线程分词速度:%.2f字每秒\n", text.length() / costTime); segment.enableMultithreading(4); start = System.currentTimeMillis(); List termList2 = segment.seg(text); - costTime = (System.currentTimeMillis() - start) / (double)1000; + costTime = (System.currentTimeMillis() - start) / (double) 1000; System.out.printf("四线程分词速度:%.2f字每秒\n", text.length() / costTime); assertEquals(termList1.size(), termList2.size()); @@ -323,7 +322,7 @@ public void testIssue71() throws Exception public void testIssue193() throws Exception { - String[] testCase = new String[] { + String[] testCase = new String[]{ "以每台约200元的价格送到苹果售后维修中心换新机(苹果的保修基本是免费换新机)", "可能以2500~2800元的价格回收", "3700个益农信息社打通服务“最后一公里”", @@ -336,7 +335,8 @@ public void testIssue193() throws Exception "则应从排名第八的投标人开始依次递补三名投标人" }; Segment segment = HanLP.newSegment().enableOrganizationRecognize(true).enableNumberQuantifierRecognize(true); - for (String sentence : testCase) { + for (String sentence : testCase) + { List termList = segment.seg(sentence); System.out.println(termList); } @@ -388,4 +388,15 @@ public void testIssue343() throws Exception Segment segment = HanLP.newSegment().enableIndexMode(true); System.out.println(segment.seg("1酷我音乐2酷我音乐3酷我4酷我音乐6酷7酷我音乐")); } + + public void testIssue358() throws Exception + { + HanLP.Config.enableDebug(); + String text = "受约束,需要遵守心理学会所定的道德原则,所需要时须说明该实验与所能得到的知识的关系"; + + Segment segment = StandardTokenizer.SEGMENT.enableAllNamedEntityRecognize(false).enableCustomDictionary(false) + .enableOrganizationRecognize(true); + + System.out.println(segment.seg(text)); + } }