<commit_before>using System.Linq;
using System.IO;
using System.Text.Json;
using System.Collections.Generic;
using System.Text.RegularExpressions;

using BibleBot.Lib;
using BibleBot.Backend.Models;

namespace BibleBot.Backend.Services
{
    public class ParsingService
    {
        private readonly VersionService _versionService;
        
        public ParsingService(VersionService versionService)
        {
            _versionService = versionService;
        }

        public System.Tuple<string, List<BookSearchResult>> GetBooksInString(Dictionary<string, List<string>> bookNames, List<string> defaultNames, string str)
        {
            List<BookSearchResult> results = new List<BookSearchResult>();

            foreach (var bookName in bookNames)
            {
                foreach (string item in bookName.Value)
                {
                    if (IsValueInString(str, item.ToLowerInvariant()))
                    {
                        str = str.Replace(item.ToLowerInvariant(), bookName.Key);
                    }
                }
            }

            var tokens = str.Split(" ");
            foreach (var bookName in defaultNames)
            {
                for (int i = 0; i < tokens.Length; i++)<commit_msg>Iterate parser twice to avoid collision with Ezra and numbered Esdras.<commit_after>using System.Linq;
using System.IO;
using System.Text.Json;
using System.Collections.Generic;
using System.Text.RegularExpressions;

using BibleBot.Lib;
using BibleBot.Backend.Models;

namespace BibleBot.Backend.Services
{
    public class ParsingService
    {
        private readonly VersionService _versionService;
        
        public ParsingService(VersionService versionService)
        {
            _versionService = versionService;
        }

        public System.Tuple<string, List<BookSearchResult>> GetBooksInString(Dictionary<string, List<string>> bookNames, List<string> defaultNames, string str)
        {
            List<BookSearchResult> results = new List<BookSearchResult>();

            // We want to iterate twice through the booknames
            // in order to skip Ezra in the first iteration,
            // otherwise 1/2/3 Esdras will collide with Ezra.
            for (int i = 1; i < 2; i++) {
                foreach (var bookName in bookNames)
                {
                    foreach (string item in bookName.Value)
                    {
                        if (IsValueInString(str, item.ToLowerInvariant()))
                        {
                            if (!(i == 1 && bookName.Key == "ezra"))
                            {
                                str = str.Replace(item.ToLowerInvariant(), bookName.Key);
                            }
                        }
                    }
                }
            }

            var tokens = str.Split(" ");
            foreach (var bookName in defaultNames)
            {
                for (int i = 0; i < tokens.Length; i++)
{'fraction_non_alphanumeric': 0.08352901710835291, 'fraction_numerical': 0.0026836632002683663, 'mean_word_length': 1.6864864864864866, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '970821', 'n_tokens_mistral': 749, 'n_tokens_neox': 717, 'n_words': 191}