示例#1
0
        public static List<string> ExtractWordsAndLines(this string text)
        {
            if (string.IsNullOrWhiteSpace(text)) return null;

            var words = new Regex(Settings.Default.WordRegex).Matches(text)
                                .Cast<Match>()
                                .Select(match => match.Value.CleanupPossibleDictionaryEntry())
                                .Where(sanitisedMatch => sanitisedMatch != null)
                                .ToList();

            var lines = text.Split('\n')
                            .Select(line => line.CleanupPossibleDictionaryEntry())
                            .Where(sanitisedMatch => sanitisedMatch != null)
                            .ToList();

            var extracts = words.Concat(lines).Distinct().ToList();

            return extracts.Any() ? extracts : null;
        }