public static StringTuple fromList(List<String> list) { List<String> items = new LinkedList<String>(list); String repr = joinList(" ", items); return new StringTuple(repr, items); }
public StringTuple remove(int index) throws IndexOutOfBoundsException{ if( index < 0 || index >= items.size()) throw new IndexOutOfBoundsException(); List<String> copy = stringToItems(repr); copy.remove(index); String modifiedRepr = joinList(" ", copy); return new StringTuple(modifiedRepr, copy); }
public StringTuple insert(int index, String value) throws IndexOutOfBoundsException{ if( index < 0 || index >= items.size()) throw new IndexOutOfBoundsException(); List<String> copy = stringToItems(repr); copy.add(index, value); String modifiedRepr = joinList(" ", copy); return new StringTuple(modifiedRepr, copy); }
public StringTuple modify(int index, ModifierFn fn) throws IndexOutOfBoundsException{ if( index < 0 || index >= items.size()) throw new IndexOutOfBoundsException(); List<String> copy = stringToItems(repr); copy.set(index, fn.modify(items.get(index))); String modifiedRepr = joinList(" ", copy); return new StringTuple(modifiedRepr, copy); }
@Override public List<Rule> annotate(List<String> tokens) { String phrase = StringTuple.joinList(" ", tokens); return Collections.singletonList( new Rule(SYMBOL, StringTuple.fromList(tokens), SemanticUtils.valueFn(phrase))); }
@Test void joinList(){ List<String> items = Arrays.asList("a", "bb", "ccc", "12"); assertEquals("a bb ccc 12", StringTuple.joinList(" ", items)); } }