@Test public void testEncodeAdjacentSpans() { String[] sentence = "something PersonA PersonA PersonB Something".split(" "); Span[] span = new Span[] { new Span(1,3, A_TYPE), new Span(3, 4, A_TYPE) }; NameSample nameSample = new NameSample(sentence, span, true); String[] expected = new String[] {OTHER, A_START, A_CONTINUE, A_START, OTHER}; String[] actual = codec.encode(nameSample.getNames(), nameSample.getSentence().length); Assert.assertArrayEquals(expected, actual); }
public String[] encode(Span[] names, int length) { String[] outcomes = new String[length]; for (int i = 0; i < outcomes.length; i++) { outcomes[i] = BioCodec.OTHER; } for (Span name : names) { if (name.getType() == null) { outcomes[name.getStart()] = "default" + "-" + BioCodec.START; } else { outcomes[name.getStart()] = name.getType() + "-" + BioCodec.START; } for (int i = name.getStart() + 1; i < name.getEnd(); i++) { if (name.getType() == null) { outcomes[i] = "default" + "-" + BioCodec.CONTINUE; } else { outcomes[i] = name.getType() + "-" + BioCodec.CONTINUE; } } } return outcomes; }
BioCodec implements SequenceCodec<String> { public String[] encode(Span[] names, int length) { String[] outcomes = new String[length]; for (int i = 0; i < outcomes.length; i++) { outcomes[i] = BioCodec.OTHER; } for (Span name : names) { if (name.getType() == null) { outcomes[name.getStart()] = "default" + "-" + BioCodec.START; } else { outcomes[name.getStart()] = name.getType() + "-" + BioCodec.START; } for (int i = name.getStart() + 1; i < name.getEnd(); i++) { if (name.getType() == null) { outcomes[i] = "default" + "-" + BioCodec.CONTINUE; } else { outcomes[i] = name.getType() + "-" + BioCodec.CONTINUE; } } } return outcomes; } }
BioCodec implements SequenceCodec<String> { public String[] encode(Span[] names, int length) { String[] outcomes = new String[length]; for (int i = 0; i < outcomes.length; i++) { outcomes[i] = BioCodec.OTHER; } for (Span name : names) { if (name.getType() == null) { outcomes[name.getStart()] = "default" + "-" + BioCodec.START; } else { outcomes[name.getStart()] = name.getType() + "-" + BioCodec.START; } for (int i = name.getStart() + 1; i < name.getEnd(); i++) { if (name.getType() == null) { outcomes[i] = "default" + "-" + BioCodec.CONTINUE; } else { outcomes[i] = name.getType() + "-" + BioCodec.CONTINUE; } } } return outcomes; }  }
BioCodec implements SequenceCodec<String> { public String[] encode(Span[] names, int length) { String[] outcomes = new String[length]; for (int i = 0; i < outcomes.length; i++) { outcomes[i] = BioCodec.OTHER; } for (Span name : names) { if (name.getType() == null) { outcomes[name.getStart()] = "default" + "-" + BioCodec.START; } else { outcomes[name.getStart()] = name.getType() + "-" + BioCodec.START; } for (int i = name.getStart() + 1; i < name.getEnd(); i++) { if (name.getType() == null) { outcomes[i] = "default" + "-" + BioCodec.CONTINUE; } else { outcomes[i] = name.getType() + "-" + BioCodec.CONTINUE; } } } return outcomes; }  Span[] decode(List<String> c); String[] encode(Span[] names, int length); NameFinderSequenceValidator createSequenceValidator(); @Override boolean areOutcomesCompatible(String[] outcomes); }
BioCodec implements SequenceCodec<String> { public String[] encode(Span[] names, int length) { String[] outcomes = new String[length]; for (int i = 0; i < outcomes.length; i++) { outcomes[i] = BioCodec.OTHER; } for (Span name : names) { if (name.getType() == null) { outcomes[name.getStart()] = "default" + "-" + BioCodec.START; } else { outcomes[name.getStart()] = name.getType() + "-" + BioCodec.START; } for (int i = name.getStart() + 1; i < name.getEnd(); i++) { if (name.getType() == null) { outcomes[i] = "default" + "-" + BioCodec.CONTINUE; } else { outcomes[i] = name.getType() + "-" + BioCodec.CONTINUE; } } } return outcomes; }  Span[] decode(List<String> c); String[] encode(Span[] names, int length); NameFinderSequenceValidator createSequenceValidator(); @Override boolean areOutcomesCompatible(String[] outcomes); static final String START; static final String CONTINUE; static final String OTHER; }