Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  
  package eu.clarin.weblicht.wlfxb.tc.test;
  
 import java.util.List;
 import org.junit.Test;

Author(s):
Yana Panchenko
 
 
     private static final String INPUT_FILE_WITHOUT_LAYER = "/data/tc-morph/tcf-before.xml";
     private static final String INPUT_FILE_WITH_LAYER = "/data/tc-morph/tcf-after.xml";
     private static final String EXPECTED_OUTPUT_FILE = "/data/tc-morph/output-expected.xml";
     private static final String OUTPUT_FILE = "/tmp/output.xml";
             EnumSet.of(.);
             EnumSet.of(..);
 
     @Test
     public void testRead() throws Exception {
         MorphologyLayer layer = tc.getMorphologyLayer();
         Assert.assertEquals(truelayer.hasCharoffsets());
         Assert.assertEquals(truelayer.hasSegmentation());
         Assert.assertEquals(tc.getTokensLayer().getToken(3), layer.getTokens(layer.getAnalysis(0))[0]);
         Assert.assertEquals(truelayer.getAnalysis(0).getFeatures()[0].isTerminal());
         Assert.assertEquals("cat"layer.getAnalysis(0).getFeatures()[0].getName());
         Assert.assertEquals("noun"layer.getAnalysis(0).getFeatures()[0].getValue());
         Assert.assertEquals(falselayer.getAnalysis(0).getFeatures()[4].isTerminal());
         Assert.assertEquals("test"layer.getAnalysis(0).getFeatures()[4].getName());
         Assert.assertEquals("noun"layer.getAnalysis(0).getFeatures()[4].getSubfeatures()[0].getValue());
         Assert.assertEquals(1, layer.size());
     }
 
     @Test
     public void testReadWrite() throws Exception {
         ..println(tc);
         MorphologyLayer morphology = tc.createMorphologyLayer(truetrue);
         for (int i = 0; i < tc.getTokensLayer().size(); i++) {
             Token token = tc.getTokensLayer().getToken(i);
             // create morphology annotation for the test token (for the 4th token)
             if (i == 3) {
                 addAnalysis(tokenmorphology);
             }
         }
         tc.close();
         ..println(tc);
         // compare output xml with expected xml
     }
 
     private void addAnalysis(Token tokenMorphologyLayer morphology) {
 
         List<Featurefeatures = new ArrayList<Feature>();
 //		<fs>
 //        <f name="cat">noun</f>
 //        <f name="case">acc</f>
 //        <f name="gender">fem</f>
 //        <f name="number">singular</f>
 //        <f name="test">
 //        	<fs>
 //	          <f name="cat">noun</f>
 //	          <f name="case">acc</f>
 //	          <f name="gender">fem</f>
 //	          <f name="number">singular</f>
 //	          <f name="number">singular</f>
 //      	</fs>
 //        </f>
 //      </fs>
         Feature feature1 = morphology.createFeature("cat""noun");
         features.add(feature1);
         Feature feature2 = morphology.createFeature("case""acc");
         features.add(feature2);
         Feature feature3 = morphology.createFeature("gender""fem");
         features.add(feature3);
         Feature feature4 = morphology.createFeature("number""singular");
         features.add(feature4);
 
         List<Featuresubfeatures5 = new ArrayList<Feature>();
         Feature feature5_1 = morphology.createFeature("cat""noun");
         subfeatures5.add(feature5_1);
         Feature feature5_2 = morphology.createFeature("case""acc");
         subfeatures5.add(feature5_2);
         Feature feature5_3 = morphology.createFeature("gender""fem");
         subfeatures5.add(feature5_3);
         Feature feature5_4 = morphology.createFeature("number""singular");
         subfeatures5.add(feature5_4);
        Feature feature5_5 = morphology.createFeature("number""singular");
        subfeatures5.add(feature5_5);
        Feature feature5 = morphology.createFeature("test"subfeatures5);
        features.add(feature5);
        List<MorphologySegmentsegments = new ArrayList<MorphologySegment>();
//		<segment cat="noun" start="0" end="9">
//        <segment type="stem" cat="noun" func="comp" start="0" end="4">Käse</segment>
//        <segment type="stem" cat="noun" func="base" start="4" end="9">Pizza</segment>
//      </segment>
        List<MorphologySegmentsubsegments1 = new ArrayList<MorphologySegment>();
        MorphologySegment s1_1 = morphology.createSegment("stem""noun""comp", 0, 4, "Käse");
        subsegments1.add(s1_1);
        MorphologySegment s1_2 = morphology.createSegment("stem""noun""base", 4, 9, "Pizza");
        subsegments1.add(s1_2);
        MorphologySegment s1 = morphology.createSegment(null"noun"null, 0, 9, subsegments1);
        segments.add(s1);
        morphology.addAnalysis(tokenfeaturessegments);
    }
New to GrepCode? Check out our FAQ X