コード例 #1
0
        public void TestParseQuantityFromIKAnalyzer()
        {
            ParseResultCollection prc = ParseChineseQuantity("1500名常用的数量和人名的匹配超过22万个");

            Assert.AreEqual(4, prc.Count);
            TestUtility.AssertParseResult(prc[0], "1500", 0, POSType.A_M);
            TestUtility.AssertParseResult(prc[1], "名", 4, POSType.A_Q);
            TestUtility.AssertParseResult(prc[2], "22万", 18, POSType.A_M);
            TestUtility.AssertParseResult(prc[3], "个", 21, POSType.A_Q);

            prc = ParseChineseQuantity("这个月我们家用了一百五十三度电");
            Assert.AreEqual(2, prc.Count);
            TestUtility.AssertParseResult(prc[0], "一百五十三", 8, POSType.A_M);
            TestUtility.AssertParseResult(prc[1], "度", 13, POSType.A_Q);

            prc = ParseChineseQuantity("欢迎使用阿江统计2.01版");
            Assert.AreEqual(2, prc.Count);
            TestUtility.AssertParseResult(prc[0], "2.01", 8, POSType.A_M);
            TestUtility.AssertParseResult(prc[1], "版", 12, POSType.A_Q);

            prc = ParseChineseQuantity("千年等一回");
            Assert.AreEqual(2, prc.Count);
            TestUtility.AssertParseResult(prc[0], "一", 3, POSType.A_M);
            TestUtility.AssertParseResult(prc[1], "回", 4, POSType.A_Q);

            prc = ParseChineseQuantity("关羽真是一员猛将");
            Assert.AreEqual(2, prc.Count);
            TestUtility.AssertParseResult(prc[0], "一", 4, POSType.A_M);
            TestUtility.AssertParseResult(prc[1], "员", 5, POSType.A_Q);

            prc = ParseChineseQuantity("为了这三世姻缘");
            Assert.AreEqual(2, prc.Count);
            TestUtility.AssertParseResult(prc[0], "三", 3, POSType.A_M);
            TestUtility.AssertParseResult(prc[1], "世", 4, POSType.A_Q);

            prc = ParseChineseQuantity("鲁智深一拳打死郑关西,最后还踹了他一脚");
            Assert.AreEqual(4, prc.Count);
            TestUtility.AssertParseResult(prc[0], "一", 3, POSType.A_M);
            TestUtility.AssertParseResult(prc[1], "拳", 4, POSType.A_Q);
            TestUtility.AssertParseResult(prc[2], "一", 17, POSType.A_M);
            TestUtility.AssertParseResult(prc[3], "脚", 18, POSType.A_Q);

            prc = ParseChineseQuantity("他家有15亩农田");
            Assert.AreEqual(2, prc.Count);
            TestUtility.AssertParseResult(prc[0], "15", 3, POSType.A_M);
            TestUtility.AssertParseResult(prc[1], "亩", 5, POSType.A_Q);

            prc = ParseChineseQuantity("这个文件总共有15.3兆");
            Assert.AreEqual(2, prc.Count);
            TestUtility.AssertParseResult(prc[0], "15.3", 7, POSType.A_M);
            TestUtility.AssertParseResult(prc[1], "兆", 11, POSType.A_Q);

            prc = ParseChineseQuantity("一元钱能干吗");
            Assert.AreEqual(2, prc.Count);
            TestUtility.AssertParseResult(prc[0], "一", 0, POSType.A_M);
            TestUtility.AssertParseResult(prc[1], "元", 1, POSType.A_Q);


            prc = ParseChineseQuantity("经历了两届奥运会");
            Assert.AreEqual(2, prc.Count);
            TestUtility.AssertParseResult(prc[0], "两", 3, POSType.A_M);
            TestUtility.AssertParseResult(prc[1], "届", 4, POSType.A_Q);
        }