@Test public void testEncodeNoNames() { NameSample nameSample = new NameSample("Once upon a time.".split(" "), new Span[] {}, true); String[] expected = new String[] {OTHER, OTHER, OTHER, OTHER}; String[] acutal = codec.encode(nameSample.getNames(), nameSample.getSentence().length); Assert.assertArrayEquals("Only 'Other' is expected.", expected, acutal); }
@Override public String[] encode(Span[] names, int length) { String[] outcomes = new String[length]; Arrays.fill(outcomes, BilouCodec.OTHER); for (Span name : names) { if (name.length() > 1) { if (name.getType() == null) { outcomes[name.getStart()] = "default" + "-" + BilouCodec.START; } else { outcomes[name.getStart()] = name.getType() + "-" + BilouCodec.START; } for (int i = name.getStart() + 1; i < name.getEnd() - 1; i++) { if (name.getType() == null) { outcomes[i] = "default" + "-" + BilouCodec.CONTINUE; } else { outcomes[i] = name.getType() + "-" + BilouCodec.CONTINUE; } } if (name.getType() == null) { outcomes[name.getEnd() - 1] = "default" + "-" + BilouCodec.LAST; } else { outcomes[name.getEnd() - 1] = name.getType() + "-" + BilouCodec.LAST; } } else { if (name.getType() == null) { outcomes[name.getEnd() - 1] = "default" + "-" + BilouCodec.UNIT; } else { outcomes[name.getEnd() - 1] = name.getType() + "-" + BilouCodec.UNIT; } } } return outcomes; }
BilouCodec implements SequenceCodec<String> { @Override public String[] encode(Span[] names, int length) { String[] outcomes = new String[length]; Arrays.fill(outcomes, BilouCodec.OTHER); for (Span name : names) { if (name.length() > 1) { if (name.getType() == null) { outcomes[name.getStart()] = "default" + "-" + BilouCodec.START; } else { outcomes[name.getStart()] = name.getType() + "-" + BilouCodec.START; } for (int i = name.getStart() + 1; i < name.getEnd() - 1; i++) { if (name.getType() == null) { outcomes[i] = "default" + "-" + BilouCodec.CONTINUE; } else { outcomes[i] = name.getType() + "-" + BilouCodec.CONTINUE; } } if (name.getType() == null) { outcomes[name.getEnd() - 1] = "default" + "-" + BilouCodec.LAST; } else { outcomes[name.getEnd() - 1] = name.getType() + "-" + BilouCodec.LAST; } } else { if (name.getType() == null) { outcomes[name.getEnd() - 1] = "default" + "-" + BilouCodec.UNIT; } else { outcomes[name.getEnd() - 1] = name.getType() + "-" + BilouCodec.UNIT; } } } return outcomes; } }
BilouCodec implements SequenceCodec<String> { @Override public String[] encode(Span[] names, int length) { String[] outcomes = new String[length]; Arrays.fill(outcomes, BilouCodec.OTHER); for (Span name : names) { if (name.length() > 1) { if (name.getType() == null) { outcomes[name.getStart()] = "default" + "-" + BilouCodec.START; } else { outcomes[name.getStart()] = name.getType() + "-" + BilouCodec.START; } for (int i = name.getStart() + 1; i < name.getEnd() - 1; i++) { if (name.getType() == null) { outcomes[i] = "default" + "-" + BilouCodec.CONTINUE; } else { outcomes[i] = name.getType() + "-" + BilouCodec.CONTINUE; } } if (name.getType() == null) { outcomes[name.getEnd() - 1] = "default" + "-" + BilouCodec.LAST; } else { outcomes[name.getEnd() - 1] = name.getType() + "-" + BilouCodec.LAST; } } else { if (name.getType() == null) { outcomes[name.getEnd() - 1] = "default" + "-" + BilouCodec.UNIT; } else { outcomes[name.getEnd() - 1] = name.getType() + "-" + BilouCodec.UNIT; } } } return outcomes; }  }
BilouCodec implements SequenceCodec<String> { @Override public String[] encode(Span[] names, int length) { String[] outcomes = new String[length]; Arrays.fill(outcomes, BilouCodec.OTHER); for (Span name : names) { if (name.length() > 1) { if (name.getType() == null) { outcomes[name.getStart()] = "default" + "-" + BilouCodec.START; } else { outcomes[name.getStart()] = name.getType() + "-" + BilouCodec.START; } for (int i = name.getStart() + 1; i < name.getEnd() - 1; i++) { if (name.getType() == null) { outcomes[i] = "default" + "-" + BilouCodec.CONTINUE; } else { outcomes[i] = name.getType() + "-" + BilouCodec.CONTINUE; } } if (name.getType() == null) { outcomes[name.getEnd() - 1] = "default" + "-" + BilouCodec.LAST; } else { outcomes[name.getEnd() - 1] = name.getType() + "-" + BilouCodec.LAST; } } else { if (name.getType() == null) { outcomes[name.getEnd() - 1] = "default" + "-" + BilouCodec.UNIT; } else { outcomes[name.getEnd() - 1] = name.getType() + "-" + BilouCodec.UNIT; } } } return outcomes; }  @Override Span[] decode(List<String> c); @Override String[] encode(Span[] names, int length); @Override SequenceValidator<String> createSequenceValidator(); @Override boolean areOutcomesCompatible(String[] outcomes); }
BilouCodec implements SequenceCodec<String> { @Override public String[] encode(Span[] names, int length) { String[] outcomes = new String[length]; Arrays.fill(outcomes, BilouCodec.OTHER); for (Span name : names) { if (name.length() > 1) { if (name.getType() == null) { outcomes[name.getStart()] = "default" + "-" + BilouCodec.START; } else { outcomes[name.getStart()] = name.getType() + "-" + BilouCodec.START; } for (int i = name.getStart() + 1; i < name.getEnd() - 1; i++) { if (name.getType() == null) { outcomes[i] = "default" + "-" + BilouCodec.CONTINUE; } else { outcomes[i] = name.getType() + "-" + BilouCodec.CONTINUE; } } if (name.getType() == null) { outcomes[name.getEnd() - 1] = "default" + "-" + BilouCodec.LAST; } else { outcomes[name.getEnd() - 1] = name.getType() + "-" + BilouCodec.LAST; } } else { if (name.getType() == null) { outcomes[name.getEnd() - 1] = "default" + "-" + BilouCodec.UNIT; } else { outcomes[name.getEnd() - 1] = name.getType() + "-" + BilouCodec.UNIT; } } } return outcomes; }  @Override Span[] decode(List<String> c); @Override String[] encode(Span[] names, int length); @Override SequenceValidator<String> createSequenceValidator(); @Override boolean areOutcomesCompatible(String[] outcomes); static final String START; static final String CONTINUE; static final String LAST; static final String UNIT; static final String OTHER; }