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

namespace Wox.Infrastructure
{
    /// <summary>
    /// refer to https://github.com/mattyork/fuzzy
    /// </summary>
    public class FuzzyMatcher
    {
        private string query;
        private MatchOption opt;

        private FuzzyMatcher(string query, MatchOption opt)
        {
            this.query = query.Trim();
            this.opt = opt;
        }

        public static FuzzyMatcher Create(string query)
        {
            return new FuzzyMatcher(query, new MatchOption());
        }

        public static FuzzyMatcher Create(string query, MatchOption opt)
        {
            return new FuzzyMatcher(query, opt);
        }

        public MatchResult Evaluate(string str)
        {
            var len = str.Length;
            var compareString = opt.IgnoreCase ? str.ToLower() : str;
            var pattern = opt.IgnoreCase ? query.ToLower() : query;

            var sb = new StringBuilder(str.Length + (query.Length * (opt.Prefix.Length + opt.Suffix.Length)));
            var patternIdx = 0;
            var firstMatchIndex = -1;
            var lastMatchIndex = 0;
            char ch;<commit_msg>fix #256<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace Wox.Infrastructure
{
    /// <summary>
    /// refer to https://github.com/mattyork/fuzzy
    /// </summary>
    public class FuzzyMatcher
    {
        private string query;
        private MatchOption opt;

        private FuzzyMatcher(string query, MatchOption opt)
        {
            this.query = query.Trim();
            this.opt = opt;
        }

        public static FuzzyMatcher Create(string query)
        {
            return new FuzzyMatcher(query, new MatchOption());
        }

        public static FuzzyMatcher Create(string query, MatchOption opt)
        {
            return new FuzzyMatcher(query, opt);
        }

        public MatchResult Evaluate(string str)
        {
            if (string.IsNullOrEmpty(str) || string.IsNullOrEmpty(query)) return new MatchResult() { Success = false };

            var len = str.Length;
            var compareString = opt.IgnoreCase ? str.ToLower() : str;
            var pattern = opt.IgnoreCase ? query.ToLower() : query;

            var sb = new StringBuilder(str.Length + (query.Length * (opt.Prefix.Length + opt.Suffix.Length)));
            var patternIdx = 0;
            var firstMatchIndex = -1;
            var lastMatchIndex = 0;
            char ch;
{'fraction_non_alphanumeric': 0.09668924003009782, 'fraction_numerical': 0.003386004514672686, 'mean_word_length': 1.9977452085682075, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 2, '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': '4991546', 'n_tokens_mistral': 731, 'n_tokens_neox': 698, 'n_words': 190}