Esempio n. 1
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);
                });
            }
        }
Esempio n. 2
0
        private void _UpdateUI(DocumentTermModel model)
        {
            progressBar.Visibility  = Visibility.Collapsed;
            browserFrame.Visibility = Visibility.Visible;

            NNMFMatrix termDocument = model.GetNormalised();

            termDocument.Factorise(FEATURE_COUNT, out _weightMatrix, out _featureMatrix);

            // calculate the maximum weight across all documents
            _topWeight = 0;
            for (int i = 0; i < _weightMatrix.ShapeX; i++)
            {
                for (int j = 0; j < _weightMatrix.ShapeY; j++)
                {
                    float val = _weightMatrix[i, j];
                    if (val > _topWeight)
                    {
                        _topWeight = val;
                    }
                }
            }

            // build the list of clusters
            for (int i = 0; i < FEATURE_COUNT; i++)
            {
                StringBuilder sb       = new StringBuilder();
                List <int>    wordList = _RankFeatureWordList(_featureMatrix, i);
                foreach (int index in wordList)
                {
                    string word = model.GetTerm(index);
                    if (sb.Length > 0)
                    {
                        sb.Append(", ");
                    }
                    sb.Append(word);
                }
                Cluster cluster = new Cluster(sb.ToString(), _colourList[i % 7], i);
                cluster.Clicked += new Cluster.ClickedDelegate(Cluster_Clicked);
                tagCloudContainer.Children.Add(cluster);
            }

            _ShowResults(_resultList);
        }
Esempio n. 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);
                });
            }
        }