⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 resultfilter.cs

📁 In the previous article, we presented an approach for capturing similarity between words that was co
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Windows.Forms;
using ServiceRanking;

namespace UDDI_Explorer
{

    class ResultFilter
    {

        class CompareItem : IComparer
        {
            public int Compare(object x, object y)
            {

                float descent = ((Data)y).Weight - ((Data)x).Weight;
                return Convert.ToInt32(descent * 100);
            }
        }

        class Data
        {
            public TreeNode Node;
            public float Weight;
        }

        public TreeNode[] Rank(TreeNodeCollection nodes, string query)
        {
            UDDIServiceList list = new UDDIServiceList();
            ArrayList descList = new ArrayList();
            foreach (TreeNode node in nodes)
            {
                UDDIService tag = node.Tag as UDDIService;

                if (tag != null && tag.Descriptions != string.Empty)
                {
                    descList.Add(tag.Descriptions + " " + node.Text);
                }
                else
                    descList.Add(node.Text);
            }

            descList.Add(query);

            string[] docs = (string[])descList.ToArray(typeof(string));
            TFIDFMeasure measure = new TFIDFMeasure(docs);
            ArrayList sortedList = new ArrayList();
            SyntacticSimilarity syntac = new SyntacticSimilarity();

            for (int i = 0; i < docs.Length - 1; i++)
            {
                Data data = new Data();
                data.Node = nodes[i];
                           
                float syntax = syntac.ComputeCombinedSimilarity ((string)docs[docs.Length - 1], docs[i]);
                float tf_idf = measure.GetSimilarity(i, docs.Length - 1);
                data.Weight = Math.Max (syntax , tf_idf) ;
                
                sortedList.Add(data);
            }

            if (sortedList.Count > 1)
            {
                CompareItem comparer = new CompareItem();
                sortedList.Sort(comparer);
            }

            TreeNode[] newOrder = new TreeNode[sortedList.Count];

            for (int i = 0; i < sortedList.Count; i++)
            {
                newOrder[i] = ((Data)sortedList[i]).Node;
            }


            return newOrder;
            
        }

        public ResultFilter()
        {
        }

    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -