<commit_before>﻿using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using Buzzbox_Common;

namespace Buzzbox.Encoders
{
    public class scfdivineFormatEncoder : IEncoderInterface
    {
        public string EncodeCard(Card card)
        {
            string output;

            switch (card.Type)
            {
                case "SPELL":
                    output = EncodeSpell(card);
                    break;

                case "WEAPON":
                    output = EncodeWeapon(card);
                    break;

                case "MINION":
                default:
                    output = EncodeMinion(card);
                    break;
            }

            return output;
        }

        private string EncodeMinion(Card card)
        {
            var encodedClass = EncodeCardClass(card.PlayerClass);
            var encodedRace = EncodeCardRace(card.Race);
            var encodedType = EncodeCardType(card.Type);
            var encodedRarity = EncodeCardRarity(card.Rarity);
            var encodedText = EncodeCardText(card.Text);

            var encodedCard = string.Format("{0} @ {1} | {2} | {3} | {4} | {5} | {6}/{7} || {8} &",
                card.Name,
                encodedClass,
                encodedRace,
                encodedType,
                encodedRarity,
                card.Cost,
                card.Attack,
                card.Health,
                encodedText);

            return encodedCard;
        }

        private string EncodeSpell(Card card)
        {
            var encodedClass = EncodeCardClass(card.PlayerClass);
            var encodedType = EncodeCardType(card.Type);
            var encodedRarity = EncodeCardRarity(card.Rarity);
            var encodedText = EncodeCardText(card.Text);

            var encodedCard = string.Format("{0} @ {1} | {2} | {3} | {4} || {5} &",
                card.Name,
                encodedClass,                
                encodedType,
                encodedRarity,
                card.Cost,
                encodedText);

            return encodedCard;
        }

        private string EncodeCardText(string cardText)
        {
            if (string.IsNullOrWhiteSpace(cardText))
            {
                return "";
            }

            var output = cardText.RemoveMarkup();

            //Also strip newlines.
            output = Regex.Replace(output, @"\r\n?|\n", "");

            //Get rid of : as well, it'll be put back in ( for 90 of cases ) at decode when keywords are put back in
            output = output.Replace(":", string.Empty);

            //Replace keywords with shorter symbols.
            foreach (KeyValuePair<string, string> replacement in Collections.KeywordReplacements)
            {
                output = output.Replace(replacement.Key, replacement.Value);
            }

            return output;
        }


        private string EncodeCardRace(string race)
        {
            if (string.IsNullOrWhiteSpace(race))
            {
                return "";
            }

            return race.CapitalizeOnlyFirstLetter();
        }

        private string EncodeCardClass(string cardClass)
        {
            if (string.IsNullOrWhiteSpace(cardClass))
            {
                return "Neutral";
            }

            return cardClass.CapitalizeOnlyFirstLetter();
        }

        private string EncodeCardType(string type)
        {
            if (string.IsNullOrWhiteSpace(type))
            {
                return "";
            }

            return type.CapitalizeOnlyFirstLetter();
        }

        private string EncodeCardRarity(string rarity)
        {
            if (string.IsNullOrWhiteSpace(rarity))
                return "";

            if (rarity == "FREE")
            {
                rarity = "COMMON";
            }

            return rarity[0].ToString();
        }

        private string EncodeWeapon(Card card)
        {
            return "";
        }
    }
}<commit_msg>Added EncodeWeapon to scfdivine encoder.<commit_after>﻿using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using Buzzbox_Common;

namespace Buzzbox.Encoders
{
    public class scfdivineFormatEncoder : IEncoderInterface
    {
        public string EncodeCard(Card card)
        {
            string output;

            switch (card.Type)
            {
                case "SPELL":
                    output = EncodeSpell(card);
                    break;

                case "WEAPON":
                    output = EncodeWeapon(card);
                    break;

                case "MINION":
                default:
                    output = EncodeMinion(card);
                    break;
            }

            return output;
        }

        private string EncodeMinion(Card card)
        {
            var encodedClass = EncodeCardClass(card.PlayerClass);
            var encodedRace = EncodeCardRace(card.Race);
            var encodedType = EncodeCardType(card.Type);
            var encodedRarity = EncodeCardRarity(card.Rarity);
            var encodedText = EncodeCardText(card.Text);

            var encodedCard = string.Format("{0} @ {1} | {2} | {3} | {4} | {5} | {6}/{7} || {8} &",
                card.Name,
                encodedClass,
                encodedRace,
                encodedType,
                encodedRarity,
                card.Cost,
                card.Attack,
                card.Health,
                encodedText);

            return encodedCard;
        }

        private string EncodeWeapon(Card card)
        {
            var encodedClass = EncodeCardClass(card.PlayerClass);            
            var encodedType = EncodeCardType(card.Type);
            var encodedRarity = EncodeCardRarity(card.Rarity);
            var encodedText = EncodeCardText(card.Text);

            var encodedCard = string.Format("{0} @ {1} | {2} | {3} | {4} | {5}/{6} || {7} &",
                card.Name,
                encodedClass,
                encodedType,
                encodedRarity,
                card.Cost,
                card.Attack,
                card.Durability,
                encodedText);

            return encodedCard;
        }

        private string EncodeSpell(Card card)
        {
            var encodedClass = EncodeCardClass(card.PlayerClass);
            var encodedType = EncodeCardType(card.Type);
            var encodedRarity = EncodeCardRarity(card.Rarity);
            var encodedText = EncodeCardText(card.Text);

            var encodedCard = string.Format("{0} @ {1} | {2} | {3} | {4} || {5} &",
                card.Name,
                encodedClass,                
                encodedType,
                encodedRarity,
                card.Cost,
                encodedText);

            return encodedCard;
        }

        private string EncodeCardText(string cardText)
        {
            if (string.IsNullOrWhiteSpace(cardText))
            {
                return "";
            }

            var output = cardText.RemoveMarkup();

            //Also strip newlines.
            output = Regex.Replace(output, @"\r\n?|\n", "");

            //Get rid of : as well, it'll be put back in ( for 90 of cases ) at decode when keywords are put back in
            output = output.Replace(":", string.Empty);

            //Replace keywords with shorter symbols.
            foreach (KeyValuePair<string, string> replacement in Collections.KeywordReplacements)
            {
                output = output.Replace(replacement.Key, replacement.Value);
            }

            return output;
        }


        private string EncodeCardRace(string race)
        {
            if (string.IsNullOrWhiteSpace(race))
            {
                return "";
            }

            return race.CapitalizeOnlyFirstLetter();
        }

        private string EncodeCardClass(string cardClass)
        {
            if (string.IsNullOrWhiteSpace(cardClass))
            {
                return "Neutral";
            }

            return cardClass.CapitalizeOnlyFirstLetter();
        }

        private string EncodeCardType(string type)
        {
            if (string.IsNullOrWhiteSpace(type))
            {
                return "";
            }

            return type.CapitalizeOnlyFirstLetter();
        }

        private string EncodeCardRarity(string rarity)
        {
            if (string.IsNullOrWhiteSpace(rarity))
                return "";

            if (rarity == "FREE")
            {
                rarity = "COMMON";
            }

            return rarity[0].ToString();
        }

    }
}
{'fraction_non_alphanumeric': 0.08960202438463308, 'fraction_numerical': 0.005060961582700713, 'mean_word_length': 1.321142552055526, 'pattern_counts': {'":': 8, '<': 5, '<?xml version=': 0, '>': 5, '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': '3394976', 'n_tokens_mistral': 2296, 'n_tokens_neox': 2159, 'n_words': 466}