コード例 #1
0
        void Cluster_Clicked(object sender, int featureIndex)
        {
            // sort the documents by membership in the specified cluster
            SortedDictionary <float, List <DownloadResult> > sorter = new SortedDictionary <float, List <DownloadResult> >();

            for (int i = 0; i < _weightMatrix.ShapeY; i++)
            {
                float                 weight = _weightMatrix[featureIndex, i];
                DownloadResult        result = _resultList[i];
                List <DownloadResult> list;
                if (!sorter.TryGetValue(weight, out list))
                {
                    sorter.Add(weight, list = new List <DownloadResult>());
                }
                list.Add(result);
            }

            List <DownloadResult> sortedList = new List <DownloadResult>();

            foreach (KeyValuePair <float, List <DownloadResult> > item in sorter)
            {
                item.Value.Reverse();
                foreach (DownloadResult result in item.Value)
                {
                    sortedList.Add(result);
                }
            }
            sortedList.Reverse();
            _ShowResults(sortedList);
        }
コード例 #2
0
        private void _ParseSearchResults(string xml)
        {
            bool        shouldUpdate = false;
            XmlDocument doc          = new XmlDocument();

            doc.LoadXml(xml);
            int docIndex            = 0;
            DocumentTermModel model = new DocumentTermModel();

            foreach (XmlNode node in doc.SelectNodes("/data/result"))
            {
                XmlAttribute titleAtt = node.Attributes["title"];
                XmlAttribute hrefAtt  = node.Attributes["disp"];
                XmlAttribute urlAtt   = node.Attributes["url"];
                XmlAttribute textAtt  = node.Attributes["text"];
                if (titleAtt != null && hrefAtt != null && textAtt != null)
                {
                    string title = titleAtt.Value, href = hrefAtt.Value, text = textAtt.Value, url = urlAtt.Value;
                    if (!String.IsNullOrEmpty(title) && !String.IsNullOrEmpty(href) && !String.IsNullOrEmpty(url))
                    {
                        DownloadResult             result = new DownloadResult(title, href, url, text, docIndex++);
                        DocumentTermModel.Document d      = model.AddDocument(result);
                        foreach (XmlNode catNode in node.SelectNodes("t"))
                        {
                            string tagText = catNode.Attributes["text"].Value;
                            uint   count   = 1;
                            if (catNode.Attributes["c"] != null)
                            {
                                count = Convert.ToUInt32(catNode.Attributes["c"].Value);
                            }
                            if (!String.IsNullOrEmpty(tagText))
                            {
                                model.AddTerm(d, tagText, count);
                            }
                        }
                        _resultList.Add(result);
                        shouldUpdate = true;
                    }
                }
            }
            if (shouldUpdate)
            {
                Dispatcher.Invoke((SimpleDelegate) delegate() {
                    _UpdateUI(model);
                });
            }
        }
コード例 #3
0
        private void _ParseDelicousXml(string xml)
        {
            bool        shouldUpdate = false;
            XmlDocument doc          = new XmlDocument();

            doc.LoadXml(xml);
            DocumentTermModel model = new DocumentTermModel();
            int docIndex            = 0;

            foreach (XmlNode node in doc.SelectNodes("/rss/channel/item"))
            {
                XmlElement titleAtt = node["title"];
                XmlElement hrefAtt  = node["link"];
                if (titleAtt != null && hrefAtt != null)
                {
                    string title = titleAtt.InnerText, href = hrefAtt.InnerText;
                    if (!String.IsNullOrEmpty(title) && !String.IsNullOrEmpty(href))
                    {
                        DownloadResult             result = new DownloadResult(title, href, docIndex++);
                        DocumentTermModel.Document d      = model.AddDocument(result);
                        foreach (XmlNode catNode in node.SelectNodes("category"))
                        {
                            string text = catNode.InnerText;
                            if (!String.IsNullOrEmpty(text))
                            {
                                model.AddTerm(d, text, 1);
                            }
                        }
                        _resultList.Add(result);
                        shouldUpdate = true;
                    }
                }
            }
            if (shouldUpdate)
            {
                Dispatcher.Invoke((SimpleDelegate) delegate() {
                    _UpdateUI(model);
                });
            }
        }