ABB.Swum.AbbreviationExpander.Expand C# (CSharp) Метод

Expand() публичный Метод

Expands the given abbreviation (short form) to its long form. Potential long forms are found by searching the program texts relevent to the short form.
public Expand ( string shortForm, System.Xml.Linq.XElement methodXml, string methodComment, string classComment ) : string[]
shortForm string The abbreviation to expand.
methodXml System.Xml.Linq.XElement An XElement corresponding to the srcML of the method where the shortForm is located.
methodComment string The summary comments for the method where the short form is located.
classComment string The summary comments for the class that the short form is located within.
Результат string[]
        public string[] Expand(string shortForm, XElement methodXml, string methodComment, string classComment)
        {
            //according to Emily, patterns should be applied in order: acronym, prefix, dropped letter, combination word
            string[] longForms;
            longForms = ExpandToMultipleWords(shortForm, MultiWordPattern.Acronym, methodXml, methodComment, classComment);
            Console.WriteLine("{1} matches from Acronym pattern: {0}", string.Join(", ", longForms), longForms.Length);

            longForms = ExpandToSingleWord(shortForm, SingleWordPattern.Prefix, methodXml, methodComment, classComment);
            Console.WriteLine("{1} matches from Prefix pattern: {0}", string.Join(", ", longForms), longForms.Length);

            longForms = ExpandToSingleWord(shortForm, SingleWordPattern.DroppedLetter, methodXml, methodComment, classComment);
            Console.WriteLine("{1} matches from Dropped Letter pattern: {0}", string.Join(", ", longForms), longForms.Length);

            longForms = ExpandToMultipleWords(shortForm, MultiWordPattern.CombinationWord, methodXml, methodComment, classComment);
            Console.WriteLine("{1} matches from Combination Word pattern: {0}", string.Join(", ", longForms), longForms.Length);

            return new string[1];
        }
    }

Usage Example

Пример #1
0
        public override void Execute()
        {
            SrcMLFile testFile = new SrcMLFile(this.File);
            XElement firstFile = testFile.FileUnits.First();

            //get all the functions
            var containers = new System.Collections.ObjectModel.Collection<XName>() { SRC.Function, SRC.Constructor, SRC.Destructor };
            var funcs = from func in firstFile.Descendants()
                        where containers.Any(c => c == func.Name)
                        select func;

            Dictionary<XElement, string> functionComments = new Dictionary<XElement, string>();


            //grab the comment block for each function
            foreach (var func in funcs)
            {
                StringBuilder functionComment = new StringBuilder();

                var prevElements = func.ElementsBeforeSelf().Reverse();
                foreach (var element in prevElements)
                {
                    if (element.Name == SRC.Comment)
                    {
                        //add comment to beginning of comment block
                        functionComment.Insert(0, element.Value + System.Environment.NewLine);
                    }
                    else
                    {
                        //found something besides a comment
                        break;
                    }
                }

                functionComments[func] = functionComment.ToString();
            }

            AbbreviationExpander ae = new AbbreviationExpander();
            ae.Expand(Word, functionComments.First().Key, functionComments.First().Value, "");

            //string patternRegex;
            //string shortForm = Word;
            //StringBuilder sb = new StringBuilder(@"\b");
            //for (int i = 0; i < shortForm.Length - 1; i++)
            //{
            //    sb.AppendFormat(@"{0}\w+\s+", shortForm[i]);
            //}
            //sb.AppendFormat(@"{0}\w+\b", shortForm[shortForm.Length - 1]);
            //patternRegex = sb.ToString();

            //Console.WriteLine("Acronym regex: {0}", patternRegex);

            //string methodComment = functionComments.First().Value;
            //Match m = Regex.Match(methodComment, string.Format("({0})", patternRegex), RegexOptions.IgnoreCase);
            //if (m.Success)
            //{
            //    Console.WriteLine("Found match: {0}", m.Groups[1].Value);
            //}
        }