Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 
 package eu.clarin.weblicht.wlfxb.lx.test;
 

Author(s):
Yana Panchenko
public class LexiconPosTagsTest extends AbstractLexiconTest {
    @Rule
    public TemporaryFolder testFolder = new TemporaryFolder();
    private static final String INPUT_FILE_WITHOUT_LAYER = "/data/lx-pos/lx-before.xml";
    private static final String INPUT_FILE_WITH_LAYER = "/data/lx-pos/lx-after.xml";
    private static final String EXPECTED_OUTPUT_FILE = "/data/lx-pos/output-expected.xml";
    private static final String OUTPUT_FILE = "output.xml";
    private static final EnumSet<LexiconLayerTaglayersToReadBeforePosTagging =
            EnumSet.of(.);
    private static final EnumSet<LexiconLayerTaglayersToReadAfterPosTagging =
            EnumSet.of(..);
    public static final Map<StringStringlemma2Pos = new HashMap<StringString>();
    static {
        .put("Peter""NE");
        .put("essen""VVFIN");
        .put("ein""ART");
        .put("Pizza""NE");
        .put(".""$.");
        .put("sie""PPER");
        .put("schmecken""VVFIN");
        .put("er""PPER");
    }
    @Test
    public void testRead() throws Exception {
        PosTagsLayer layer = lex.getPosTagsLayer();
        Assert.assertEquals(9, layer.size());
        Assert.assertEquals("NE"layer.getTag(0).getString());
        Assert.assertEquals(lex.getEntriesLayer().getEntry(0), layer.getEntry(layer.getTag(0)));
        Assert.assertEquals(lex.getEntriesLayer().getEntry(3), layer.getEntry(layer.getTag(3)));
        Assert.assertEquals(lex.getEntriesLayer().getEntry(3), layer.getEntry(layer.getTag(4)));
        Assert.assertArrayEquals(
                new PosTag[]{layer.getTag(3), layer.getTag(4)},
                layer.getTags(lex.getEntriesLayer().getEntry(3)));
    }
    @Test
    public void testReadWrite() throws Exception {
        String outfile = .getRoot() + . + ;
        ..println(lex);
        // create part of speech layer, it's empty at first
        PosTagsLayer tags = lex.createPosTagsLayer("STTS");
        for (int i = 0; i < lex.getEntriesLayer().size(); i++) {
            Entry lemma = lex.getEntriesLayer().getEntry(i);
            String posTag = tag(lemma.getString());
            // create and add part-of-speech tag to the tags layer
            tags.addTag(posTaglemma);
            if (i == 3) { // another tag option for this lemma
                posTag = "NN";
                tags.addTag(posTaglemma);
            }
        }
        // IMPORTANT close the streams!!!
        lex.close();
        ..println(lex);
        // compare output xml with expected xml
        assertEqualXml(outfile);
    }
    private String tag(String tokenString) {
        return .get(tokenString);
    }
New to GrepCode? Check out our FAQ X