Daily Report 2012.10.30 刘宇翔

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace match0
{
    class Program
    {
        static public int match(string word,string keyword)
        {
            int matchDegree = -1;//word、keyword匹配级别
            string[] wordlist = word.Split(new char[] { ' ' },StringSplitOptions.RemoveEmptyEntries);
            int wlN = wordlist.Count();//word关键词数量
            

            //非模糊匹配,返回-1或3****************************************************************
            if (word.Length == 0 || keyword.Length == 0)//输入有空,返回-1
                return matchDegree;

            if (word == keyword)//word,keyword完全匹配,返回最高级3
            {
                matchDegree = 3;
                return matchDegree;
            }
            //**************************************************************************************

            //模糊匹配,返回0或1或2*****************************************************************暂未完全实现
            if (wlN == 1)//word只含一个关键词
            {

            }
            else //word含多个关键词
            {

            }
            //***************************************************************************************

            return matchDegree;//因错误等不明原因跳出,返回-1
        }

        static public int wordmatch(string w, string keyword)//单个关键词对keyword的模糊匹配,w为单个关键词
        {
            int wmatchDegree = 0;//w、keyword匹配级别
            List<int> wkDegree=new List<int>();
            string[] keywordlist = keyword.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            int klN = keywordlist.Count();//keyword关键词数量
            for (int i = 0; i < klN;i++ )
                wkDegree.Add(0);
            for (int j = 0; j < klN; j++)
            {
                wkDegree[j] = wkmatch(w, keywordlist[j]);
            }
            return wmatchDegree;
        }

        static public int wkmatch(string w, string k)//单个关键词对单个k的模糊匹配,k为keyword单个关键词
        {
            int wkDegree = 0;//w、k匹配级别
            int m, n;
            m = w.Length;
            n = k.Length;

            return wkDegree;
        }

        static int ChineseOrEnglish(string str)//中英文判断 暂未完全实现
        {
            int len = 0;
            byte[] b;

            for (int i = 0; i < str.Length; i++)
            {
                b = Encoding.Default.GetBytes(str.Substring(i, 1));
                if (b.Length > 1)
                    len += 2;
                else
                    len++;
            }
            return len;
        }


        static void Main(string[] args)//供测试用主函数提供各函数返回值
        {
            int a,b,c;
            string x = Console.ReadLine();
            string y = Console.ReadLine();
            a = match(x, y);
            b = ChineseOrEnglish(x);
            c = ChineseOrEnglish(y);
            Console.WriteLine(a);
            Console.WriteLine(b);
            Console.WriteLine(c);
            Console.WriteLine(x.Length);
            Console.WriteLine(y.Length);
        }
    }
}

主要实现了match算法的基本框架,match函数主要功能为判断word、keyword(都可能为由空格分隔的多个词)的匹配程度。

这是一个相对十分独立的模块,所以我先在一个单独的C#文件中编写。

几个难点还没有完全解决,汉字英文混杂问题、模糊匹配级别判断函数(与前一个有关)、函数对模糊程度的容忍程度的规定等。

基本判断过程都在上面的代码中。在汉字英文混杂问题解决后,算法会很快实现。

预计能在两天之内完成。

posted @ 2012-10-31 00:20  DOOM_buaascse  阅读(238)  评论(0编辑  收藏  举报