Esempio n. 1
0
        //看看本type是否在参考字典中存在:
        public void Compare(Dictionary <string, CSharpType_t> other)
        {
            CompareResult.Clear();

            //首先查找TypeWithNS完整的匹配的class,直接返回...
            CSharpType_t eg = null;

            other.TryGetValue(this.TypeName, out eg);
            if (eg != null && this.TypeWithNS == eg.TypeWithNS)
            {
                CSharpTypeCompareResult_t res = Compare(eg);
                if (res.percent > 80)
                {
                    CompareResult.Insert(res);
                    return;
                }
            }
            //忽略.成员数太小的Type
            if (this.Members.Count < 2)
            {
                return;
            }
            //遍历参考
            foreach (var p in other)
            {
                //比较类型名字:
                if (CSharpType_t.CONFIG_Type_LevenshteinDistance)
                {
                    if (this.TypeName.Length > 4)
                    {
                        double Similarity;
                        int    Distance = CCLevenshtein.LevenshteinDistance(TypeName, p.Value.TypeName, out Similarity, false);
                        if (Similarity > 0.5)
                        {
                            CSharpTypeCompareResult_t n = new CSharpTypeCompareResult_t();
                            n.percent = (int)(Similarity * 1000);
                            n.refType = p.Value;
                            CompareNSResult.Insert(n);
                        }
                    }
                }

                //比较字典中的每个type,计算相似度:
                if (p.Value.Members.Count > 1)
                {
                    CSharpTypeCompareResult_t res = Compare(p.Value);
                    if (res.percent > 15)
                    {
                        CompareResult.Insert(res);
                    }
                }
            }
        }
Esempio n. 2
0
        //zTODO: 如果匹配一致?包括完美一致?
        //使用词语近似性算法:LevenshteinDistance
        public MemberCompareResult_t Compare(CSharpMember_t src)
        {
            if (Members.Count == 0)
            {
                return(null);
            }

            MemberCompareResult_t mcr = new MemberCompareResult_t(src);

            Int32  Distance;
            Double Similarity;

            for (int i = 0; i < Members.Count; ++i)
            {
                if (UseSign[i] == true)
                {
                    continue;
                }

                if (Members[i].Name == src.Name)
                {
                    this.UseSign[i] = true;

                    mcr.Distance   = 0;
                    mcr.Similarity = 1;
                    mcr.dst        = Members[i];
                    return(mcr);
                }

                //忽略太短的词语
                if (CONFIG_Member_LevenshteinDistance)
                {
                    if (src.Name.Length > 4)
                    {
                        Distance = CCLevenshtein.LevenshteinDistance(Members[i].Name, src.Name, out Similarity, false);
                        if (Similarity > mcr.Similarity)
                        {
                            mcr.Distance   = Distance;
                            mcr.Similarity = Similarity;
                            mcr.dst        = Members[i];
                        }
                    }
                }
            }
            return(mcr);
        }