private static <NodeT extends ConstituentNode<NodeT, ?>> ImmutableMap<Symbol, HeadRule<NodeT>> headRulesFromResources(final CharSource charSource) throws IOException { final ImmutableMap.Builder<Symbol, HeadRule<NodeT>> ret = ImmutableMap.builder(); for (final Map.Entry<Symbol, HeadRule<NodeT>> e : FluentIterable.from(charSource.readLines()) .transform(StringUtils.Trim) .filter(Predicates.not(StringUtils.startsWith("#"))) .filter(Predicates.not(StringUtils.isEmpty())) .transform(PatternMatchHeadRule.<NodeT>fromHeadRuleFileLine())) { ret.put(e.getKey(), e.getValue()); } return ret.build(); }
private static final ImmutableSet<ImmutableSet<Integer>> parseClustering(String s) { final ImmutableSet.Builder<ImmutableSet<Integer>> ret = ImmutableSet.builder(); // strip parens for (final String inParens : StringUtils.onSpaces().split(s)) { final String withinParens = inParens.substring(1, inParens.length() - 1); final ImmutableSet.Builder<Integer> cluster = ImmutableSet.builder(); for (final String number : StringUtils.onCommas().split(withinParens)) { // strip parens before parsing cluster.add(Integer.parseInt(number)); } ret.add(cluster.build()); } return ret.build(); }