package fr.doap.dicofr;

import java.io.*;
import java.util.*;

public class POSTagger {
	
	static public Set<POSTag> word(String aS) {
		if (sPOSTagger == null) {
			sPOSTagger = new POSTagger();
			sPOSTagger.init();
		}
		return sPOSTagger.mTags.get(aS);
	}
	
	static protected POSTagger sPOSTagger;
	
	protected void init() {
		try (InputStream lIS = POSTagger.class.getResourceAsStream("/dict.txt")) {
			BufferedReader lISR = new BufferedReader(new InputStreamReader(lIS));
//			BufferedReader lISR = new BufferedReader(new InputStreamReader(lIS, "Windows-1252"));
			lISR.lines().forEach(aS -> {
				String[] lS = aS.split("\\t");
				String[] lType = lS[2].split(" ");
				POSTag lPT = new POSTag();
				lPT.mLemma = lS[1];
				lPT.mType = lType[0];
				lPT.mInfos = lS[2];
				add(lS[0], lPT);
			});
		} catch (IOException aE) {
			throw new RuntimeException(aE);
		}
	}
	
	protected void add(String aS, POSTag aPT) {
		Set<POSTag> lS = mTags.get(aS);
		if (lS == null) {
			lS = new HashSet<>();
			mTags.put(aS, lS);
		}
		lS.add(aPT);
	}
	
	Map<String, Set<POSTag>>	mTags = new HashMap<>();
}