示例#1
0
    //-------------私有方法------------------------

    /*
     * 生成比较结果的进程
     */
    private void processMarching()
    {
        List <TaskTransform> listTasks      = TaskManager.Instance.GetTasks();
        List <AudioPart>     listAudioParts = AudioEditManagercs.Instance.GetAudioPartsList();

        /*
         * 生成第一次比较结果
         */
        TaskTransform t  = null;
        AudioPart     a  = null;
        TaskResult    tr = null;
        float         matchRateThanTask      = 0;
        float         matchRateThanAudioPart = 0;

        float LOWER_MAIN_BODY_MARCH_RATE = 0.5f;
        int   startMarchIndex            = 0;
        int   stopMarchIndex             = 0;

        for (int i = 0; i < listTasks.Count; ++i)
        {
            t = listTasks[i];
            t.ListTaskResult.Clear();
            for (int z = 0; z < listAudioParts.Count; ++z)
            {
                a = listAudioParts[z];
                matchRateThanTask = ArrayUtil <string> .CaculateRegularSimilar(t.arrStrPingYing, a.textPingYinArr);      //StringUtil.CaculateStringSimilar(t.StrTaskWord, a.strText);// 解决复杂度

                matchRateThanAudioPart = ArrayUtil <string> .CaculateRegularSimilar(a.textPingYinArr, t.arrStrPingYing); //StringUtil.CaculateStringSimilar(a.strText, t.StrTaskWord);

                if (matchRateThanTask >= LOWER_MAIN_BODY_MARCH_RATE)
                {
                    tr           = new TaskResult();
                    tr.MarchRate = (matchRateThanTask + matchRateThanAudioPart) / 2.0f;
                    tr.ListAudioParts.Add(a);
                    t.ListTaskResult.Add(tr);

                    if (matchRateThanAudioPart > matchRateThanTask)
                    {
                        tr           = new TaskResult();
                        tr.MarchRate = (matchRateThanTask + matchRateThanAudioPart) / 2.0f - 0.1f;
                        int index = AudioEditManagercs.Instance.GetIndexByAudioPart(a);
                        if (index != -1)
                        {
                            for (int x = 0; x < 3; x++)
                            {
                                AudioPart apNow = AudioEditManagercs.Instance.GetAudioPartByIndex(index - 1 + x);
                                tr.ListAudioParts.Add(apNow);
                            }
                            t.ListTaskResult.Add(tr);
                        }
                    }
                }
            }
        }


        TaskManager.Instance.SaveTasksConfig();
    }
    /*
     * 比较两个拼音的相似度
     * 参数:
     * a:拼音a
     * b:拼音b
     * 返回
     * 相似度[0~1]
     */
    public static float CaculatePingYingSimilar(string a, string b)
    {
        float rate = 0;

        /*
         * 暂时以顺序散列相似度为标准计算
         */
        string[] arrA = GetStringArrayFromString(a);
        string[] arrB = GetStringArrayFromString(b);
        rate = ArrayUtil <string> .CaculateRegularSimilar(arrA, arrB);

        return(rate);
    }
    /*
     * 比较中文字符串a 与b 的相似程度
     * 参数:
     * a:主字符串
     * b:比较字符串
     * 返回
     * 相似度结果【0~1】
     */
    public static float CaculateStringSimilar(string a, string b)
    {
        float rate = 0;

        string chinaWordA = GetChinaWordFromString(a);
        string chinaWordB = GetChinaWordFromString(b);

        string[] pingYingA = GetPingYingArrayFromChinaString(chinaWordA);
        string[] pingYingB = GetPingYingArrayFromChinaString(chinaWordB);

        rate = ArrayUtil <string> .CaculateRegularSimilar(pingYingA, pingYingB);

        return(rate);
    }