// Path: src/de/unitrier/daalft/pali/cache/CachedDictionaryLookup.java
// public class CachedDictionaryLookup {
// 
// 	private Cache<JObject[]> cache;
// 	private LexiconAdapter lexiconAdapter;
// 	private HashSet<String> invalid;
// 	
// 	public CachedDictionaryLookup(String domain, int port, String user, String pw, int maxCacheSize, int maxCacheDurationInSeconds) throws Exception {
// 		invalid = new HashSet<>();
// 		cache = new Cache<JObject[]>(maxCacheSize, maxCacheDurationInSeconds);
// 		lexiconAdapter = new LexiconAdapter(domain, port, user, pw);
// 	}
// 		
// 	public boolean lemmaExists(String lemma) {
// 		return (cache.get(lemma, false) != null);
// 	}
// 
// 	public JObject[] getLemmata (String lemma) throws Exception {
// 		if (invalid.contains(lemma))
// 			return null;
// 		JObject[] lemmata = cache.get(lemma, false);
// 		if (lemmata != null) {
// 			return lemmata;
// 		}
// 		lemmata = lexiconAdapter.getLemmaEntriesAsJObjectArray(lemma);
// 		if (lemmata == null) {
// 			invalid.add(lemma);
// 			return null;
// 		}
// 		cache.put(lemma, lemmata);
// 		return lemmata;
// 	}
// }


import de.unitrier.daalft.pali.cache.CachedDictionaryLookup;

package de.unitrier.daalft.pali.morphology.compound;


/**
 * Class responsible for splitting Pali compound words,
 * using the dictionary as knowledge source
 * @author s2daalft
 *
 */
public class CompoundSplitter {

	/**
	 * Set the minimum postfix length
	 * <p>
	 * This value will be used to determine whether
	 * a split produced a word that is too short and hence
	 * invalid.
	 */
	private int minimumPostfixLength = 3;
	/**
	 * Dictionary lookup utility to check for existence of word in dictionary
	 */
	private CachedDictionaryLookup dictionaryLookup;

	/**
	 * Constructor
	 * @throws Exception 
	 */
	public CompoundSplitter(String domain, int port, String user, String pw, int maxCacheSize, int maxCacheDurationInSeconds) throws Exception {
		dictionaryLookup = new CachedDictionaryLookup(domain, port, user, pw, maxCacheSize, maxCacheDurationInSeconds);
	}

	/**
	 * Split a compound word
	 * <p>
	 * If the word exists in the dictionary,
	 * the word itself is returned <b>unless</b>
	 * the flag <code>force</code> is specified.
	 * In that case the word is split even if it
	 * occurs in the dictionary.
	 * <br/><br/>
	 * If the word cannot be split, <code>null</code>
	 * is returned
	 * @param lemma lemma of compound to split
	 * @param force flag indicating whether to split regardless of dictionary occurrence
	 * @return split compound or word itself or <code>null</code>
	 * @throws Exception
	 */
	public String[] split(String lemma, boolean force) throws Exception {
		if (lemma==null || lemma.isEmpty())
			return null;

// Path: src/de/unitrier/daalft/pali/cache/CachedDictionaryLookup.java
// public class CachedDictionaryLookup {
// 
// 	private Cache<JObject[]> cache;
// 	private LexiconAdapter lexiconAdapter;
// 	private HashSet<String> invalid;
// 	
// 	public CachedDictionaryLookup(String domain, int port, String user, String pw, int maxCacheSize, int maxCacheDurationInSeconds) throws Exception {
// 		invalid = new HashSet<>();
// 		cache = new Cache<JObject[]>(maxCacheSize, maxCacheDurationInSeconds);
// 		lexiconAdapter = new LexiconAdapter(domain, port, user, pw);
// 	}
// 		
// 	public boolean lemmaExists(String lemma) {
// 		return (cache.get(lemma, false) != null);
// 	}
// 
// 	public JObject[] getLemmata (String lemma) throws Exception {
// 		if (invalid.contains(lemma))
// 			return null;
// 		JObject[] lemmata = cache.get(lemma, false);
// 		if (lemmata != null) {
// 			return lemmata;
// 		}
// 		lemmata = lexiconAdapter.getLemmaEntriesAsJObjectArray(lemma);
// 		if (lemmata == null) {
// 			invalid.add(lemma);
// 			return null;
// 		}
// 		cache.put(lemma, lemmata);
// 		return lemmata;
// 	}
// }


// Path: src/de/unitrier/daalft/pali/morphology/compound/CompoundSplitter.java
import de.unitrier.daalft.pali.cache.CachedDictionaryLookup;

package de.unitrier.daalft.pali.morphology.compound;


/**
 * Class responsible for splitting Pali compound words,
 * using the dictionary as knowledge source
 * @author s2daalft
 *
 */
public class CompoundSplitter {

	/**
	 * Set the minimum postfix length
	 * <p>
	 * This value will be used to determine whether
	 * a split produced a word that is too short and hence
	 * invalid.
	 */
	private int minimumPostfixLength = 3;
	/**
	 * Dictionary lookup utility to check for existence of word in dictionary
	 */
	private CachedDictionaryLookup dictionaryLookup;

	/**
	 * Constructor
	 * @throws Exception 
	 */
	public CompoundSplitter(String domain, int port, String user, String pw, int maxCacheSize, int maxCacheDurationInSeconds) throws Exception {
		dictionaryLookup = new CachedDictionaryLookup(domain, port, user, pw, maxCacheSize, maxCacheDurationInSeconds);
	}

	/**
	 * Split a compound word
	 * <p>
	 * If the word exists in the dictionary,
	 * the word itself is returned <b>unless</b>
	 * the flag <code>force</code> is specified.
	 * In that case the word is split even if it
	 * occurs in the dictionary.
	 * <br/><br/>
	 * If the word cannot be split, <code>null</code>
	 * is returned
	 * @param lemma lemma of compound to split
	 * @param force flag indicating whether to split regardless of dictionary occurrence
	 * @return split compound or word itself or <code>null</code>
	 * @throws Exception
	 */
	public String[] split(String lemma, boolean force) throws Exception {
		if (lemma==null || lemma.isEmpty())
			return null;

		boolean exists = dictionaryLookup.lemmaExists(lemma);
