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;
 import org.junit.Rule;
 import java.io.File;

Author(s):
Yana Panchenko
 
 
     @Rule
     public TemporaryFolder testFolder = new TemporaryFolder();
 
     private static final String INPUT_FILE_WITHOUT_PARSING = "/data/tc-dparsing/tcf-before.xml";
     private static final String INPUT_FILE_WITH_PARSING = "/data/tc-dparsing/tcf-after.xml";
     private static final String EXPECTED_OUTPUT_FILE = "/data/tc-dparsing/output-expected.xml";
     private static final String OUTPUT_FILE = "output.xml";
     private static final EnumSet<TextCorpusLayerTaglayersToReadBeforeParsing =
             EnumSet.of(..);
     private static final EnumSet<TextCorpusLayerTaglayersToReadAfterParsing =
 
     @Test
     public void testRead() throws Exception {
         DependencyParsingLayer layer = tc.getDependencyParsingLayer();
         Assert.assertEquals("Tiger"layer.getTagset());
         Assert.assertEquals(truelayer.hasEmptyTokens());
         Assert.assertEquals(falselayer.hasMultipleGovernors());
         Assert.assertEquals(2, layer.size());
         Assert.assertEquals(4, layer.getParse(0).getDependencies().length);
         Assert.assertEquals("SUBJ"layer.getParse(0).getDependencies()[1].getFunction());
         Assert.assertEquals(tc.getTokensLayer().getToken(1), layer.getDependentTokens(layer.getParse(0).getDependencies()[0])[0]);
         Assert.assertEquals(""layer.getGovernorTokens(layer.getParse(1).getDependencies()[0])[0].getString());
     }
 
     @Test
     public void testReadWrite() throws Exception {
         String outfile = .getRoot() + . + ;
         ..println(tc);
         SentencesLayer sentences = tc.getSentencesLayer();
         DependencyParsingLayer parses = tc.createDependencyParsingLayer("Tiger"falsetrue);
         for (int i = 0; i < sentences.size(); i++) {
             Token[] sentenceTokens = sentences.getTokens(sentences.getSentence(i));
             // creates test parse for the test tokens
             List<Dependencydeps = parse(sentenceTokensparses);
             parses.addParse(deps);
         }
         tc.close();
         ..println(tc);
         // compare output xml with expected xml
         assertEqualXml(outfile);
     }
 
     private List<Dependencyparse(Token[] sentenceTokensDependencyParsingLayer parses) {
         if (sentenceTokens[0].getString().equals("Peter")) {
             return parseFirstTestSentence(sentenceTokensparses);
         } else {
             return parseSecondTestSentence(sentenceTokensparses);
         }
     }
 
     private List<DependencyparseSecondTestSentence(Token[] sentenceTokens,
             DependencyParsingLayer parses) {
 
 //	   <parse>
 //	   <dependency func="ROOT" depIDs="t7" govIDs="et_0"/>
 //	    <dependency func="SUBJ" depIDs="t6" govIDs="t7"/>
 //	    <dependency func="OBJ" depIDs="t8" govIDs="t7"/>
 //	    <emptytoks>
 //	          <emptytok ID="et_0"></emptytok>
 //	        </emptytoks>
 //	   </parse>
 
         List<Dependencydeps = new ArrayList<Dependency>();
         Token emptyToken = parses.createEmptyToken("");
         Dependency d1 = parses.createDependency("ROOT"sentenceTokens[1], emptyToken);
         Dependency d2 = parses.createDependency("SUBJ"sentenceTokens[0], sentenceTokens[1]);
         Dependency d3 = parses.createDependency("OBJ"sentenceTokens[3], sentenceTokens[1]);
         deps.add(d1);
         deps.add(d2);
         deps.add(d3);
         return deps;
 
     }
    private List<DependencyparseFirstTestSentence(Token[] sentenceTokens,
            DependencyParsingLayer parses) {
//		<parse>
//	    <dependency depIDs="t2" func="ROOT"/>
//	    <dependency func="SUBJ" depIDs="t1" govIDs="t2"/>
//	    <dependency func="SPEC" depIDs="t3" govIDs="t4"/>
//	    <dependency func="OBJ" depIDs="t4" govIDs="t2"/>
//	   </parse>
        List<Dependencydeps = new ArrayList<Dependency>();
        Dependency d1 = parses.createDependency("ROOT"sentenceTokens[1]);
        Dependency d2 = parses.createDependency("SUBJ"sentenceTokens[0], sentenceTokens[1]);
        Dependency d3 = parses.createDependency("SPEC"sentenceTokens[2], sentenceTokens[3]);
        Dependency d4 = parses.createDependency("OBJ"sentenceTokens[3], sentenceTokens[1]);
        deps.add(d1);
        deps.add(d2);
        deps.add(d3);
        deps.add(d4);
        return deps;
    }
New to GrepCode? Check out our FAQ X