package de.uniulm.mathematik.typo.hyphen; import java.lang.*; import java.util.*; public class HyphenationWordList implements WeightedHyphenator { private HashMap rules; private int minWeight; private int maxWeight; private int leftmin; private int rightmin; public HyphenationWordList() { rules = new HashMap(); minWeight = -1; maxWeight = -1; leftmin = 2; rightmin = 2; } public HyphenationWordList(int leftmin, int rightmin) { rules = new HashMap(); minWeight = -1; maxWeight = -1; this.leftmin = leftmin; this.rightmin = rightmin; } public int getLeftMin() { return leftmin; } public int getRightMin() { return rightmin; } public int getMinWeight() { return minWeight; } public int getMaxWeight() { return maxWeight; } public void add(String word, WeightedHyphenationRule rule) { assert(rule != null); rules.put(word.toLowerCase(), rule); for (WeightedHyphenationPoint hp: rule) { int weight = hp.getWeight(); if (minWeight == -1 || weight < minWeight) { minWeight = weight; } if (maxWeight == -1 || weight > maxWeight) { maxWeight = weight; } } } public WeightedHyphenationRule hyphenateWithWeights(String s) { return rules.get(s.toLowerCase()); } public int[] hyphenate(String s) { WeightedHyphenationRule rule = rules.get(s.toLowerCase()); if (rule == null) { return null; } int len = 0; for (WeightedHyphenationPoint hp: rule) { ++len; } int[] positions = new int[len]; int index = 0; for (WeightedHyphenationPoint hp: rule) { positions[index++] = hp.getPosition(); } return positions; } public int size() { return rules.size(); } }