public static NameSample createPredSample() { return createSimpleNameSample(false); } }
@Test public void testEquals() { Assert.assertFalse(createGoldSample() == createGoldSample()); Assert.assertTrue(createGoldSample().equals(createGoldSample())); Assert.assertFalse(createGoldSample().equals(createPredSample())); Assert.assertFalse(createPredSample().equals(new Object())); }
@Test public void testNameSampleSerDe() throws IOException { NameSample nameSample = createGoldSample(); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(byteArrayOutputStream); out.writeObject(nameSample); out.flush(); byte[] bytes = byteArrayOutputStream.toByteArray(); ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes); ObjectInput objectInput = new ObjectInputStream(byteArrayInputStream); NameSample deSerializedNameSample = null; try { deSerializedNameSample = (NameSample) objectInput.readObject(); } catch (ClassNotFoundException e) { // do nothing } Assert.assertNotNull(deSerializedNameSample); Assert.assertArrayEquals(nameSample.getSentence(), deSerializedNameSample.getSentence()); Assert.assertArrayEquals(nameSample.getNames(), deSerializedNameSample.getNames()); Assert.assertArrayEquals(nameSample.getAdditionalContext(), deSerializedNameSample.getAdditionalContext()); }
public static NameSample createGoldSample() { return createSimpleNameSample(true); }
/** * Checks if could create a NameSample without NameTypes, generate the * string representation and validate it. */ @Test public void testNoTypesToString() { String nameSampleStr = createSimpleNameSample(false).toString(); Assert.assertEquals("<START> U . S . <END> President <START> Barack Obama <END>" + " is considering " + "sending additional American forces to <START> Afghanistan <END> .", nameSampleStr); }
/** * Checks if could create a NameSample with NameTypes, generate the * string representation and validate it. */ @Test public void testWithTypesToString() throws Exception { String nameSampleStr = createSimpleNameSample(true).toString(); Assert.assertEquals("<START:Location> U . S . <END> President <START:Person>" + " Barack Obama <END> " + "is considering sending additional American forces to <START:Location> Afghanistan <END> .", nameSampleStr); NameSample parsedSample = NameSample.parse("<START:Location> U . S . <END> " + "President <START:Person> Barack Obama <END> is considering sending " + "additional American forces to <START:Location> Afghanistan <END> .", false); Assert.assertEquals(createSimpleNameSample(true), parsedSample); }