    001    package calhoun.analysis.crf.io;
    002
    003    import java.util.Collection;
    004
    005    import calhoun.util.Assert;
    006
    007    /** an input sequence where the elements of the sequence are string characters. */
    008    public class InputSequenceCharacter implements InputSequence<Character> {
    009            String str;
    010
    011            /** default constructor */
    012            public InputSequenceCharacter() { }
    013
    014            /** creates an input sequence using data from this string
    015             * @param a string containing characters of the input sequence */
    016            public InputSequenceCharacter(String a) {
    017                    str = a;
    018            }
    019
    020            /** returns the input sequence as a string
    021             * @return a string of the characters */
    022            public String getString() {
    023                    return str;
    024            }
    025
    026            public Character getX(int ix) {
    027                    return str.charAt(ix);
    028            }
    029
    030            public int length() {
    031                    return str == null ? 0 : str.length();
    032            }
    033
    034            public InputSequence<?> getComponent(String name) {
    035                    throw new UnsupportedOperationException();
    036            }
    037
    038            public Collection<String> listComponents() {
    039                    throw new UnsupportedOperationException();
    040            }
    041
    042            public InputSequence<Character> subSequence(int start, int end) {
    043                    Assert.a(start >= 1);
    044                    Assert.a(end <= this.length());
    045                    Assert.a(start <= end);
    046
    047                    InputSequenceCharacter S = new InputSequenceCharacter(str.substring(start-1,end));
    048
    049                    return S;
    050            }
    051
    052            @Override
    053            public String toString() {
    054                    return str.substring(0, Math.min(str.length(), 15));
    055            }
    056    }