示例#1
0
 public static string GenerateAlias(string text)
 {
     text = TextManipulations.RemoveDiacritics(text);
     text = text.ToLowerInvariant();
     text = Regex.Replace(text, @"[^\w]+", "-", RegexOptions.Compiled);
     return(text.Trim('-'));
 }
 public DocumentSummaryProfile()
 {
     // Creates map to document summary
     // Doesn't need a reciprocal mapping, this is a one-way mapping
     this.CreateMap <data.Document, DocumentSummary>()
     .ForMember(m => m.SummaryText, o => o.MapFrom(src => TextManipulations.Summarize(src.Text)));
 }
示例#3
0
        public void CanStripLyricMarkerWhenSummarizing()
        {
            var text    = $"#{RandomValueGenerator.AlphaNumericTextWithSpaces(10, 20)}\n#{RandomValueGenerator.AlphaNumericTextWithSpaces(10, 20)}";
            var newText = TextManipulations.Summarize(text);

            Assert.IsFalse(newText.Contains('#'));
        }
示例#4
0
        public void CanShortenTextWithoutSpaces()
        {
            var limit   = 50;
            var newText = TextManipulations.ShortenText(RandomValueGenerator.AlphaNumericText(100, 200), limit);

            Assert.AreEqual(limit + EllipsisLength, newText.Length);
        }
示例#5
0
        public void CanStripSectionsWhenSummarizing()
        {
            var section = $"[{RandomValueGenerator.AlphaNumericText(10, 20)}]";
            var text    = $"{RandomValueGenerator.AlphaNumericTextWithSpaces(10, 20)}\n{section}";
            var newText = TextManipulations.Summarize(text);

            Assert.IsFalse(newText.Contains(section));
        }
示例#6
0
        public void CanShortenTextByNotTruncatingShortText()
        {
            var limit      = 50;
            var textLength = RandomValueGenerator.Integer(30, 40);
            var newText    = TextManipulations.ShortenText(RandomValueGenerator.AlphaNumericText(textLength), limit);

            Assert.AreEqual(textLength, newText.Length);
        }
示例#7
0
        public void CanStripAnnotationsWhenSummarizing()
        {
            var annotation = $"!{RandomValueGenerator.AlphaNumericTextWithSpaces(10, 20)}";
            var text       = $"{annotation}\n{RandomValueGenerator.AlphaNumericTextWithSpaces(10, 20)}";
            var newText    = TextManipulations.Summarize(text);

            Assert.IsFalse(newText.Contains('!'));
            Assert.IsFalse(newText.Contains(annotation.Substring(1)));
        }
示例#8
0
        public void CanStripChordsWhenSummarizing()
        {
            var chords  = $"@{RandomValueGenerator.AlphaNumericTextWithSpaces(10, 20)}";
            var text    = $"{chords}\n{RandomValueGenerator.AlphaNumericTextWithSpaces(10, 20)}";
            var newText = TextManipulations.Summarize(text);

            Assert.IsFalse(newText.Contains('@'));
            Assert.IsFalse(newText.Contains(chords.Substring(1)));
        }
示例#9
0
        public void CanShortenTextWithSpaces()
        {
            var limit         = 50;
            var spacePosition = RandomValueGenerator.Integer(100, 200);
            var text          = $"{RandomValueGenerator.AlphaNumericText(spacePosition)} {RandomValueGenerator.AlphaNumericText(100, 200)}";

            var newText = TextManipulations.ShortenText(text, limit);

            Assert.AreEqual(spacePosition + EllipsisLength, newText.Length);
        }
示例#10
0
        public void CanShortenTextWithNull()
        {
            var newText = TextManipulations.ShortenText(null, 50);

            Assert.IsNull(newText);
        }
示例#11
0
 public void CanCallShortenText()
 {
     TextManipulations.ShortenText(RandomValueGenerator.AlphaNumericText(100, 200), 50);
 }