<commit_before>﻿using System.Collections.Generic;
using System.Linq;
using PhotoStoryToBloomConverter.BloomModel.BloomHtmlModel;
using System.IO;

namespace PhotoStoryToBloomConverter.BloomModel
{
    //Comparable to a collection of the bloom 'data' divs
    public class BloomBookData
    {
        public string LanguagesOfBook;
        public string StyleNumberSequence;
        public string LicenseUrl;
        public string LicenseImage;
        public string Title;
        public string[] ContentLanguages;

        public string CoverNarrationPath;
        public string CoverBackgroundAudioPath;
        public double CoverBackgroundAudioVolume;

        //All localized variables are expected to have similar indexes 
        //to their languages location in ContentLanguages
        public string[] LocalizedBookTitle;
        public string[] LocalizedSmallCoverCredits;
        public string[] LocalizedOriginalContributions;
        public string[] LocalizedFunding;
        public List<string> LocalizedOriginalAcknowledgments;
        public string[] LocalizedInsideFrontCover;
        public string[] LocalizedInsideBackCover;
        public string[] LocalizedOutsideBackCover;
        public string[] LocalizedLicenseDescription;

        public List<List<Dictionary<string, string>>> LocalizedNarrationList;

        public static BloomBookData DefaultBloomBookData(string title)
        {
            return new BloomBookData
            {
                Title = title,
                LanguagesOfBook = "English",
                StyleNumberSequence = "0",
                LicenseUrl = "",
                LicenseImage = "",
                ContentLanguages = new [] { "en" },
                LocalizedBookTitle = new [] { "" },
                LocalizedSmallCoverCredits = new[] { "" },
                LocalizedOriginalContributions = new[] { "" },
                LocalizedFunding = new[] { "" },
                LocalizedOriginalAcknowledgments = new List<string>(),
                LocalizedInsideFrontCover = new[] { "" },
                LocalizedInsideBackCover = new[] { "" },
                LocalizedOutsideBackCover = new[] { "" },
                LocalizedLicenseDescription = new[] { "" },
            };
        }

        public Div ConvertToHtml()
        {
            var dataDiv = new Div
            {
                Id = "bloomDataDiv",
                Divs = new List<Div>
                {
                    new Div { DataBook = "styleNumberSequence", Lang = "*", SimpleText = StyleNumberSequence},
                    new Div { DataBook = "languagesOfBook", Lang = "*", SimpleText = LanguagesOfBook},
                    new Div { DataBook = "licenseUrl", Lang = "*", SimpleText = LicenseUrl},
                }
            };
            if (CoverBackgroundAudioPath != null)
            {
                dataDiv.Divs.Add(new Div { DataBook = "initialBackgroundAudio", Lang = "*", SimpleText = Path.GetFileNameWithoutExtension(CoverBackgroundAudioPath) });
                dataDiv.Divs.Add(new Div { DataBook = "initialBackgroundAudioVolume", Lang = "*", SimpleText = CoverBackgroundAudioVolume.ToString() });
            }
            dataDiv.Divs.AddRange(ContentLanguages.Select((lang, index) => new Div { DataBook = string.Format("contentLanguage{0}", index+1), Lang = "*", SimpleText = lang }).ToArray());
            dataDiv.Divs.AddRange(LocalizedBookTitle.Select((lang, index) => new Div { DataBook = "bookTitle", Lang = ContentLanguages[index], FormattedText = new Paragraph { Span = new Span { Id = Path.GetFileNameWithoutExtension(CoverNarrationPath), Class = "audio-sentence", RecordingMD5 = "undefined", ContentText = Title } } }).ToArray());
            dataDiv.Divs.AddRange(LocalizedSmallCoverCredits.Select((credits, index) => new Div { DataBook = "smallCoverCredits", Lang = ContentLanguages[index], FormattedText = new Paragraph { Text = credits } }).ToArray());
            dataDiv.Divs.AddRange(LocalizedOriginalContributions.Select((contributions, index) => new Div { DataBook = "originalContributions", Lang = ContentLanguages[index], FormattedText = new Paragraph { Text = contributions } }).ToArray());
            dataDiv.Divs.AddRange(LocalizedOriginalAcknowledgments.Select((acknowledgments, index) => new Div { DataBook = "originalAcknowledgments", Lang = ContentLanguages[index], FormattedText = new Paragraph { Text = acknowledgments } }).ToArray());
            dataDiv.Divs.AddRange(LocalizedFunding.Select((funding, index) => new Div { DataBook = "funding", Lang = ContentLanguages[index], FormattedText = new Paragraph { Text = funding } }).ToArray());
            dataDiv.Divs.AddRange(LocalizedInsideFrontCover.Select((insideFrontCover, index) => new Div { DataBook = "insideFrontCover", Lang = ContentLanguages[index], FormattedText = new Paragraph { Text = insideFrontCover } }).ToArray());
            dataDiv.Divs.AddRange(LocalizedInsideBackCover.Select((insideBackCover, index) => new Div { DataBook = "insideBackCover", Lang = ContentLanguages[index], FormattedText = new Paragraph { Text = insideBackCover } }).ToArray());
            dataDiv.Divs.AddRange(LocalizedOutsideBackCover.Select((outsideBackCover, index) => new Div { DataBook = "outsideBackCover", Lang = ContentLanguages[index], FormattedText = new Paragraph { Text = outsideBackCover } }).ToArray());
            dataDiv.Divs.AddRange(LocalizedLicenseDescription.Select((licenseDescription, index) => new Div { DataBook = "licenseDescription", Lang = ContentLanguages[index], FormattedText = new Paragraph { Text = licenseDescription } }).ToArray());
            return dataDiv;
        }
    }
}<commit_msg>Re-formatted background audio to be of form audio/filename.ext<commit_after>﻿using System.Collections.Generic;
using System.Linq;
using PhotoStoryToBloomConverter.BloomModel.BloomHtmlModel;
using System.IO;

namespace PhotoStoryToBloomConverter.BloomModel
{
    //Comparable to a collection of the bloom 'data' divs
    public class BloomBookData
    {
        public string LanguagesOfBook;
        public string StyleNumberSequence;
        public string LicenseUrl;
        public string LicenseImage;
        public string Title;
        public string[] ContentLanguages;

        public string CoverNarrationPath;
        public string CoverBackgroundAudioPath;
        public double CoverBackgroundAudioVolume;

        //All localized variables are expected to have similar indexes 
        //to their languages location in ContentLanguages
        public string[] LocalizedBookTitle;
        public string[] LocalizedSmallCoverCredits;
        public string[] LocalizedOriginalContributions;
        public string[] LocalizedFunding;
        public List<string> LocalizedOriginalAcknowledgments;
        public string[] LocalizedInsideFrontCover;
        public string[] LocalizedInsideBackCover;
        public string[] LocalizedOutsideBackCover;
        public string[] LocalizedLicenseDescription;

        public List<List<Dictionary<string, string>>> LocalizedNarrationList;

        public static BloomBookData DefaultBloomBookData(string title)
        {
            return new BloomBookData
            {
                Title = title,
                LanguagesOfBook = "English",
                StyleNumberSequence = "0",
                LicenseUrl = "",
                LicenseImage = "",
                ContentLanguages = new [] { "en" },
                LocalizedBookTitle = new [] { "" },
                LocalizedSmallCoverCredits = new[] { "" },
                LocalizedOriginalContributions = new[] { "" },
                LocalizedFunding = new[] { "" },
                LocalizedOriginalAcknowledgments = new List<string>(),
                LocalizedInsideFrontCover = new[] { "" },
                LocalizedInsideBackCover = new[] { "" },
                LocalizedOutsideBackCover = new[] { "" },
                LocalizedLicenseDescription = new[] { "" },
            };
        }

        public Div ConvertToHtml()
        {
            var dataDiv = new Div
            {
                Id = "bloomDataDiv",
                Divs = new List<Div>
                {
                    new Div { DataBook = "styleNumberSequence", Lang = "*", SimpleText = StyleNumberSequence},
                    new Div { DataBook = "languagesOfBook", Lang = "*", SimpleText = LanguagesOfBook},
                    new Div { DataBook = "licenseUrl", Lang = "*", SimpleText = LicenseUrl},
                }
            };
            if (CoverBackgroundAudioPath != null)
            {
                dataDiv.Divs.Add(new Div { DataBook = "initialBackgroundAudio", Lang = "*", SimpleText = GetBackgroundAudio() });
                dataDiv.Divs.Add(new Div { DataBook = "initialBackgroundAudioVolume", Lang = "*", SimpleText = CoverBackgroundAudioVolume.ToString() });
            }
            dataDiv.Divs.AddRange(ContentLanguages.Select((lang, index) => new Div { DataBook = string.Format("contentLanguage{0}", index+1), Lang = "*", SimpleText = lang }).ToArray());
            dataDiv.Divs.AddRange(LocalizedBookTitle.Select((lang, index) => new Div { DataBook = "bookTitle", Lang = ContentLanguages[index], FormattedText = new Paragraph { Span = new Span { Id = Path.GetFileNameWithoutExtension(CoverNarrationPath), Class = "audio-sentence", RecordingMD5 = "undefined", ContentText = Title } } }).ToArray());
            dataDiv.Divs.AddRange(LocalizedSmallCoverCredits.Select((credits, index) => new Div { DataBook = "smallCoverCredits", Lang = ContentLanguages[index], FormattedText = new Paragraph { Text = credits } }).ToArray());
            dataDiv.Divs.AddRange(LocalizedOriginalContributions.Select((contributions, index) => new Div { DataBook = "originalContributions", Lang = ContentLanguages[index], FormattedText = new Paragraph { Text = contributions } }).ToArray());
            dataDiv.Divs.AddRange(LocalizedOriginalAcknowledgments.Select((acknowledgments, index) => new Div { DataBook = "originalAcknowledgments", Lang = ContentLanguages[index], FormattedText = new Paragraph { Text = acknowledgments } }).ToArray());
            dataDiv.Divs.AddRange(LocalizedFunding.Select((funding, index) => new Div { DataBook = "funding", Lang = ContentLanguages[index], FormattedText = new Paragraph { Text = funding } }).ToArray());
            dataDiv.Divs.AddRange(LocalizedInsideFrontCover.Select((insideFrontCover, index) => new Div { DataBook = "insideFrontCover", Lang = ContentLanguages[index], FormattedText = new Paragraph { Text = insideFrontCover } }).ToArray());
            dataDiv.Divs.AddRange(LocalizedInsideBackCover.Select((insideBackCover, index) => new Div { DataBook = "insideBackCover", Lang = ContentLanguages[index], FormattedText = new Paragraph { Text = insideBackCover } }).ToArray());
            dataDiv.Divs.AddRange(LocalizedOutsideBackCover.Select((outsideBackCover, index) => new Div { DataBook = "outsideBackCover", Lang = ContentLanguages[index], FormattedText = new Paragraph { Text = outsideBackCover } }).ToArray());
            dataDiv.Divs.AddRange(LocalizedLicenseDescription.Select((licenseDescription, index) => new Div { DataBook = "licenseDescription", Lang = ContentLanguages[index], FormattedText = new Paragraph { Text = licenseDescription } }).ToArray());
            return dataDiv;
        }

        public string GetBackgroundAudio()
        {
            if (!string.IsNullOrWhiteSpace(CoverBackgroundAudioPath))
                return Path.Combine(BloomAudio.kAudioDirectory, CoverBackgroundAudioPath);
            return null;
        }
    }
}
{'fraction_non_alphanumeric': 0.1052676954909906, 'fraction_numerical': 0.000689714630571601, 'mean_word_length': 2.8978494623655915, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 35, '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': '1212725', 'n_tokens_mistral': 3009, 'n_tokens_neox': 2798, 'n_words': 679}