package at.medunigraz.imi.abbres.resolver;

import java.util.NavigableSet;
import java.util.TreeSet;

import at.medunigraz.imi.abbres.model.Abbreviation;
import at.medunigraz.imi.abbres.model.NGramMapFactory;
import at.medunigraz.imi.abbres.model.mapper.Mapper;
import at.medunigraz.imi.abbres.model.mapper.SingleMapper;
import at.medunigraz.imi.abbres.model.matcher.LeftBigramMatcher;
import at.medunigraz.imi.abbres.model.matcher.Matcher;
import at.medunigraz.imi.abbres.model.matcher.RightBigramMatcher;
import at.medunigraz.imi.abbres.model.matcher.UnigramMatcher;
import at.medunigraz.imi.abbres.model.policy.FuzzyPolicy;
import at.medunigraz.imi.abbres.model.policy.Policy;
import at.medunigraz.imi.abbres.model.policy.StrictPolicy;
import at.medunigraz.imi.abbres.model.reducer.FuzzyBigramWithFallbackReducer;

public class DefaultResolver implements Resolver {

	public DefaultResolver() {
		NGramMapFactory.warm();
	}

	@Override
	public String resolve(Abbreviation abbreviation) {
		Matcher unigram = new UnigramMatcher(abbreviation);
		Matcher leftBigram = new LeftBigramMatcher(abbreviation);
		Matcher rightBigram = new RightBigramMatcher(abbreviation);
		
		Policy strict = new StrictPolicy();

		Mapper strictUnigram = new SingleMapper(unigram, strict);
		Mapper strictLeftBigram = new SingleMapper(leftBigram, strict);
		Mapper strictRightBigram = new SingleMapper(rightBigram, strict);
		
		Policy fuzzy = new FuzzyPolicy();

		Mapper fuzzyUnigram = new SingleMapper(unigram, fuzzy);
		Mapper fuzzyLeftBigram = new SingleMapper(leftBigram, fuzzy);
		Mapper fuzzyRightBigram = new SingleMapper(rightBigram, fuzzy);

		NavigableSet<Mapper> set = new TreeSet<>();
		set.add(strictUnigram);
		set.add(strictLeftBigram);
		set.add(strictRightBigram);
		set.add(fuzzyUnigram);
		set.add(fuzzyLeftBigram);
		set.add(fuzzyRightBigram);

		return new FuzzyBigramWithFallbackReducer().reduce(set);
	}
}

@@ -1193,33 +1193,32 @@
 StrictPolicy();%0A
-%0A
 %09%09Mapper strictU
@@ -1207,24 +1207,30 @@
 ;%0A%09%09Mapper s
+ingleS
 trictUnigram
@@ -1273,24 +1273,30 @@
 ;%0A%09%09Mapper s
+ingleS
 trictLeftBig
@@ -1349,16 +1349,22 @@
 Mapper s
+ingleS
 trictRig
@@ -1452,17 +1452,16 @@
 licy();%0A
-%0A
 %09%09Mapper
@@ -1457,25 +1457,31 @@
 );%0A%09%09Mapper 
-f
+singleF
 uzzyUnigram 
@@ -1521,25 +1521,31 @@
 );%0A%09%09Mapper 
-f
+singleF
 uzzyLeftBigr
@@ -1595,17 +1595,23 @@
 %09Mapper 
-f
+singleF
 uzzyRigh
@@ -1712,24 +1712,30 @@
 %0A%09%09set.add(s
+ingleS
 trictUnigram
@@ -1744,24 +1744,30 @@
 %0A%09%09set.add(s
+ingleS
 trictLeftBig
@@ -1783,16 +1783,22 @@
 et.add(s
+ingleS
 trictRig
@@ -1814,25 +1814,31 @@
 ;%0A%09%09set.add(
-f
+singleF
 uzzyUnigram)
@@ -1845,25 +1845,31 @@
 ;%0A%09%09set.add(
-f
+singleF
 uzzyLeftBigr
@@ -1883,17 +1883,23 @@
 set.add(
-f
+singleF
 uzzyRigh

Refactor variables to prepare addition of DoubleMapper