<commit_before>package com.rabidgremlin.mutters.slots;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

import org.apache.commons.lang3.StringUtils;

import com.rabidgremlin.mutters.core.Context;
import com.rabidgremlin.mutters.core.Slot;
import com.rabidgremlin.mutters.core.SlotMatch;

public class FuzzySlot implements Slot
{
    
	private String name;
	private double tolerance;
	private List<String> options = new ArrayList<String>();

	public FuzzySlot(String name, String[] options, double tolerance)
	{
		this.name = name;
		this.options = Arrays.asList(options);
		this.tolerance = tolerance;
	}
	
	public FuzzySlot(String name, String[] options)
	{
		this(name,options,0.99);
	}
	

	@Override
	public SlotMatch match(String token, Context context)
	{
		double bestMatchScore = 0;
		String bestMatch = null;
		
		for(String option:options)
		{
			double score = StringUtils.getJaroWinklerDistance(token,option);
			if (score > bestMatchScore)
			{
				bestMatchScore = score;
				bestMatch = option;
			}			
		}
		
		if (bestMatchScore > tolerance && bestMatch != null)
		{
			return new SlotMatch(this, token, bestMatch);
		}
		else
		{
			return null;	
		}
	}

	public String getName()
	{
		return name;
	}

	@Override<commit_msg>Made fuzzy matching no be case sensitive.<commit_after>package com.rabidgremlin.mutters.slots;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

import org.apache.commons.lang3.StringUtils;

import com.rabidgremlin.mutters.core.Context;
import com.rabidgremlin.mutters.core.Slot;
import com.rabidgremlin.mutters.core.SlotMatch;

// TODO needs to be optimised
public class FuzzySlot implements Slot
{
    
	private String name;
	private double tolerance;
	private List<String> options = new ArrayList<String>();

	public FuzzySlot(String name, String[] options, double tolerance)
	{
		this.name = name;
		this.options = Arrays.asList(options);
		this.tolerance = tolerance;
	}
	
	public FuzzySlot(String name, String[] options)
	{
		this(name,options,0.98);
	}
	

	@Override
	public SlotMatch match(String token, Context context)
	{
		String lowerToken = token.toLowerCase();
		double bestMatchScore = 0;
		String bestMatch = null;
		
		for(String option:options)
		{
			double score = StringUtils.getJaroWinklerDistance(lowerToken,option.toLowerCase());
			if (score > bestMatchScore)
			{
				bestMatchScore = score;
				bestMatch = option;
			}			
		}
		
		if (bestMatchScore > tolerance && bestMatch != null)
		{
			return new SlotMatch(this, token, bestMatch);
		}
		else
		{
			return null;	
		}
	}

	public String getName()
	{
		return name;
	}

	@Override
{'fraction_non_alphanumeric': 0.10435103244837758, 'fraction_numerical': 0.003687315634218289, 'mean_word_length': 3.968864468864469, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, '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': '7318928', 'n_tokens_mistral': 1006, 'n_tokens_neox': 891, 'n_words': 207}