<commit_before>using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using ConsoleTables.Core;
using Countersoft.Gemini.Api;
using Countersoft.Gemini.Commons.Dto;
using Gemini.Commander.Core;
using Gemini.Commander.Core.Extensions;
using Iveonik.Stemmers;
using Newtonsoft.Json;
using Format = ConsoleTables.Core.Format;

namespace Gemini.Commander.Commands
{
    [Command("show", "words", "all")]
    public class ShowWordsCommand : ServiceManagerCommand
    {
        public ShowWordsCommand(ServiceManager svc) : base(svc) { }

        public static string Trim(string e) => e.ToLower().Trim(',', ';', ':', '.', '-', '+', '\r', '\n');

        public static Func<string, string> Stem(bool stemmed) => e => stemmed ? new EnglishStemmer().Stem(e) : e;

        public static bool Allowed(string e)
        {
            var stopwords = (ConfigurationManager.AppSettings["stopwords"] ?? "").Split(' ');
            return !stopwords.Contains(e) && !string.IsNullOrWhiteSpace(e) && e.Length > 1;
        }

        public static string Clean(string e) => Regex.Replace(e.ToLower(), @"\s+", " ");

        public override void Execute(MainArgs args)
        {
            var take = args.Options.Take;
            var user = Svc.Item.WhoAmI();
            var items = Svc.LogsByUser(user, args);
            
            var words = items.SelectMany(e => EntryToWords(args, e))
                .GroupBy(m => m)
                .OrderByDescending(m => m.Count())
                .Select(m => new { m.Key, pct = (m.Count() * 100m / items.Count()) })
                .ToList();

            var table = new ConsoleTable("word", "percent");

            words
                .Select(x => new object[]
                {
                    x.Key,x.pct.ToString("F1")
                })
                .Take(take)
                .ToList()
                .ForEach(x => table.AddRow(x));

            table.Write(Format.MarkDown);
        }

        public static IEnumerable<string> EntryToWords(MainArgs args, IssueTimeTrackingDto e)
        {
            return e.Words()
                .Select(Clean)
                .Select(Trim)
                .Select(Stem(args.Options.Stemmed))
                .Where(Allowed)
                .Distinct();
        }
    }
}<commit_msg>cleanup show words command<commit_after>using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text.RegularExpressions;
using ConsoleTables.Core;
using Countersoft.Gemini.Api;
using Countersoft.Gemini.Commons.Dto;
using Gemini.Commander.Core;
using Gemini.Commander.Core.Extensions;
using Iveonik.Stemmers;
using Format = ConsoleTables.Core.Format;

namespace Gemini.Commander.Commands
{
    [Command("show", "words", "all")]
    public class ShowWordsCommand : ServiceManagerCommand
    {
        public ShowWordsCommand(ServiceManager svc) : base(svc) { }

        public static string Trim(string e) => e.ToLower().Trim(',', ';', ':', '.', '-', '+', '\r', '\n', '?', '!');

        public static Func<string, string> Stem(bool stemmed) => e => stemmed ? new EnglishStemmer().Stem(e) : e;

        public static bool Allowed(string e)
        {
            var stopwords = (ConfigurationManager.AppSettings["stopwords"] ?? "").Split(' ');
            return !stopwords.Contains(e) && !string.IsNullOrWhiteSpace(e) && e.Length > 1;
        }

        public static string Clean(string e) => Regex.Replace(e, @"\s+", " ");

        public override void Execute(MainArgs args)
        {
            var take = args.Options.Take;
            var user = Svc.Item.WhoAmI();
            var items = Svc.LogsByUser(user, args);

            var words = items.AllWords()
                .Select(Clean)
                .Select(Trim)
                .Select(Stem(args.Options.Stemmed))
                .Where(Allowed)
                .Distinct()
                .GroupBy(m => m)
                .OrderByDescending(m => m.Count())
                .Select(m => new { m.Key, pct = (m.Count() * 100m / items.Count()) })
                .ToList();

            var table = new ConsoleTable("word", "percent");

            words
                .Select(x => new object[]
                {
                    x.Key,x.pct.ToString("F1")
                })
                .Take(take)
                .ToList()
                .ForEach(x => table.AddRow(x));

            table.Write(Format.MarkDown);
        }
    }
}
{'fraction_non_alphanumeric': 0.13992042440318303, 'fraction_numerical': 0.0022104332449160036, 'mean_word_length': 1.9907468605419696, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5277430', 'n_tokens_mistral': 1379, 'n_tokens_neox': 1308, 'n_words': 274}