public bool AnnotateWikiPost(HtmlAgilityPack.XmlDocument xmlDoc)
        {
            try
            {
                var eventDataNode = xmlDoc.DocumentNode.SelectSingleNode("//ns1:eventData");
                var wikiNode = eventDataNode.SelectSingleNode("./r2:wikiSensor");

                string subject = GetNodeInnerText(wikiNode, "./r2:title", "");
                string body = GetNodeInnerText(wikiNode, "./r2:rawText", "");

                // annotate the text
                AddNewLines(eventDataNode, 8);
                HtmlNode keuiNode = xmlDoc.CreateElement("s1:keui");
                eventDataNode.AppendChild(keuiNode);

                AddAnnotatedData(keuiNode, subject, "s1:titleAnnotated", "s1:titleConcepts", "s1:titleReferences", 9);
                AddAnnotatedData(keuiNode, body, "s1:rawTextAnnotated", "s1:rawTextConcepts", "s1:rawTextReferences", 9);
            }
            catch (Exception ex)
            {
                AddEvent("Exception while annotating new wiki post: " + ex.Message);
            }
            return false;
        }
        public bool AnnotateIssueUpdate(HtmlAgilityPack.XmlDocument xmlDoc)
        {
            try {
                var eventDataNode = xmlDoc.DocumentNode.SelectSingleNode("//ns1:eventData");
                var kesiNode = eventDataNode.SelectSingleNode("./s:kesi");

                // add the keui section
                AddNewLines(eventDataNode, 8);
                HtmlNode keuiNode = xmlDoc.CreateElement("s1:keui");
                eventDataNode.AppendChild(keuiNode);

                // annotate all the comments
                var commentNodes = kesiNode.SelectNodes("./s:issueComment");
                int commentCount = commentNodes != null ? commentNodes.Count : 0;
                for (int commentN = 0; commentN < commentCount; commentN++) {
                    string comment = GetNodeInnerText(kesiNode, string.Format("./s:issueComment[{0}]/s:commentText", commentN + 1), "");
                    HtmlNode commentTextNode = xmlDoc.CreateElement("s1:issueComment");
                    AddNewLines(keuiNode, 9);
                    keuiNode.AppendChild(commentTextNode);
                    AddAnnotatedData(commentTextNode, comment, "s1:commentTextAnnotated", "s1:commentTextConcepts", "s1:commentTextReferences", 10);
                }
                return true;
            }
            catch (Exception ex) {
                AddEvent("Exception while annotating new bug post: " + ex.Message);
                GenLib.Log.LogService.LogException("Exception while annotating new bug post.", ex);
            }
            return false;
        }
        public bool AnnotateTextToAnnotate(HtmlAgilityPack.XmlDocument xmlDoc)
        {
            try
            {
                var eventDataNode = xmlDoc.DocumentNode.SelectSingleNode("//ns1:eventData");
                var textNode = eventDataNode.SelectSingleNode("./s1:generalText");
                string source = GetNodeInnerText(textNode, "./s1:source", "");
                string text = GetNodeInnerText(textNode, "./s1:text", "");

                // annotate the text and publish it
                Dictionary<string, double> conceptToWeight = new Dictionary<string, double>();
                HashSet<string> references = new HashSet<string>();
                string annotatedBody = AnnotateText(text, conceptToWeight, references);

                AddNewLines(eventDataNode, 8);
                HtmlNode keuiNode = xmlDoc.CreateElement("s1:keui");
                eventDataNode.AppendChild(keuiNode);

                AddAnnotatedData(keuiNode, text, "s1:textAnnotated", "s1:textConcepts", "s1:textReferences", 9);

                return true;
            }
            catch (Exception ex)
            {
                AddEvent("Exception while annotating text to annotate: " + ex.Message);
                GenLib.Log.LogService.LogException("Exception while annotating text to annotate.", ex);
            }
            return false;
        }
        public bool AnnotateIssueNew(HtmlAgilityPack.XmlDocument xmlDoc)
        {
            try {
                var eventDataNode = xmlDoc.DocumentNode.SelectSingleNode("//ns1:eventData");
                var kesiNode = eventDataNode.SelectSingleNode("./s:kesi");

                // add the keui section
                AddNewLines(eventDataNode, 8);
                HtmlNode keuiNode = xmlDoc.CreateElement("s1:keui");
                eventDataNode.AppendChild(keuiNode);

                // annotate the bug summary
                string description = GetNodeInnerText(kesiNode, "./s:issueDescription", "");
                AddAnnotatedData(keuiNode, description, "s1:issueDescriptionAnnotated", "s1:issueDescriptionConcepts", "s1:issueDescriptionReferences", 9);

                // annotate the bug description
                HtmlNode commentTextNode = xmlDoc.CreateElement("s1:issueComment");
                AddNewLines(keuiNode, 9);
                keuiNode.AppendChild(commentTextNode);
                string comment = GetNodeInnerText(kesiNode, "./s:issueComment/s:commentText", "");
                AddAnnotatedData(commentTextNode, comment, "s1:commentTextAnnotated", "s1:commentTextConcepts", "s1:commentTextReferences", 9);
                return true;
            }
            catch (Exception ex) {
                AddEvent("Exception while annotating IssueNew: " + ex.Message);
                GenLib.Log.LogService.LogException("Exception while annotating IssueNew.", ex);
            }
            return false;
        }
        //public bool AnnotateIssueUpdate(HtmlAgilityPack.XmlDocument xmlDoc)
        //{
        //    try
        //    {
        //        var eventDataNode = xmlDoc.DocumentNode.SelectSingleNode("//ns1:eventData");
        //        var kesiNode = eventDataNode.SelectSingleNode("./s:issue");
        //        string comment = GetNodeInnerText(kesiNode, "./s:issueComment/s:commentText", null);
        //        if (comment == null)
        //            return false;
        //        // annotate the text
        //        AddNewLines(eventDataNode, 8);
        //        HtmlNode keuiNode = xmlDoc.CreateElement("s1:keui");
        //        eventDataNode.AppendChild(keuiNode);
        //        AddAnnotatedData(keuiNode, comment, "s1:commentTextAnnotated", "s1:commentTextConcepts", "s1:commentTextReferences", 9);
        //        return true;
        //    }
        //    catch (Exception ex)
        //    {
        //        AddEvent("Exception while annotating new bug comment: " + ex.Message);
        //        GenLib.Log.LogService.LogException("Exception while annotating new bug comment.", ex);
        //    }
        //    return false;
        //}
        public bool AnnotateForumPost(HtmlAgilityPack.XmlDocument xmlDoc)
        {
            try
            {
                var eventDataNode = xmlDoc.DocumentNode.SelectSingleNode("//ns1:eventData");
                var forumNode = eventDataNode.SelectSingleNode("./r:forumSensor");

                string subject = GetNodeInnerText(forumNode, "./r:subject", "");
                string body = GetNodeInnerText(forumNode, "./r:body", "");

                // annotate the text
                AddNewLines(eventDataNode, 8);
                HtmlNode keuiNode = xmlDoc.CreateElement("s1:keui");
                eventDataNode.AppendChild(keuiNode);

                AddAnnotatedData(keuiNode, body, "s1:bodyAnnotated", "s1:bodyConcepts", "s1:bodyReferences", 9);
                AddAnnotatedData(keuiNode, subject, "s1:subjectAnnotated", "s1:subjectConcepts", "s1:subjectReferences", 9);

                return true;			// return OuterHtml not InnerHtml, otherwise we don't get the newlines printed correctly
            }
            catch (Exception ex)
            {
                AddEvent("Exception while annotating new forum post: " + ex.Message);
                GenLib.Log.LogService.LogException("Exception while annotating new forum post.", ex);
            }
            return false;
        }
        public bool AnnotateEmail(HtmlAgilityPack.XmlDocument xmlDoc)
        {
            try
            {
                var eventDataNode = xmlDoc.DocumentNode.SelectSingleNode("//ns1:eventData");
                var mlNode = eventDataNode.SelectSingleNode("./r1:mlsensor");

                string subject = GetNodeInnerText(mlNode, "./r1:subject", "");
                string body = GetNodeInnerText(mlNode, "./r1:content", "");

                // annotate the text
                AddNewLines(eventDataNode, 8);
                HtmlNode keuiNode = xmlDoc.CreateElement("s1:keui");
                eventDataNode.AppendChild(keuiNode);

                AddAnnotatedData(keuiNode, subject, "s1:subjectAnnotated", "s1:subjectConcepts", "s1:subjectReferences", 9);
                AddAnnotatedData(keuiNode, body, "s1:contentAnnotated", "s1:contentConcepts", "s1:contentReferences", 9);

                return true;
            }
            catch (Exception ex)
            {
                AddEvent("Exception while annotating email: " + ex.Message);
                GenLib.Log.LogService.LogException("Exception while annotating email.", ex);
            }
            return false;
        }
        public bool AnnotateCommit(HtmlAgilityPack.XmlDocument xmlDoc)
        {
            try
            {
                var eventDataNode = xmlDoc.DocumentNode.SelectSingleNode("//ns1:eventData");
                var kesiNode = eventDataNode.SelectSingleNode("./s:kesi");

                string comment = GetNodeInnerText(kesiNode, "./s:commitMessageLog", "");

                // annotate the text
                AddNewLines(eventDataNode, 8);
                HtmlNode keuiNode = xmlDoc.CreateElement("s1:keui");
                eventDataNode.AppendChild(keuiNode);

                AddAnnotatedData(keuiNode, comment, "s1:commitMessageLogAnnotated", "s1:commitMessageLogConcepts", "s1:commitMessageLogReferences", 9);
            }
            catch (Exception ex)
            {
                AddEvent("Exception while annotating source code: " + ex.Message);
                GenLib.Log.LogService.LogException("Exception while annotating source code.", ex);
            }
            return false;
        }
Ejemplo n.º 8
0
        private void AppendNewWord(ref HtmlAgilityPack.HtmlDocument newDoc, string word, WordMatcher matcher, StatisticsDataSet.HighlightStatisticsRow statisticsRow = null)
        {
            HighlightWord matchedWord = null;
            if (matcher.Match(word, out matchedWord))
            {
                HtmlNode span = newDoc.CreateElement("span");
                span.SetAttributeValue("style", matchedWord.Style);
                span.InnerHtml = word;
                newDoc.DocumentNode.ChildNodes.Append(span);

                //if (statisticsRow != null)
                //{
                //    frmStatistics.HighlightStaticsticIncrease(statisticsRow, matchedWord);
                //}
            }
            else
            {
                AppendSimpleWord(ref newDoc, word);
            }
        }