de.tudarmstadt.ukp.dkpro.core.RSTParseOutputReaderTest.java Source code

Java tutorial

Introduction

Here is the source code for de.tudarmstadt.ukp.dkpro.core.RSTParseOutputReaderTest.java

Source

/*
 * Copyright 2015
 * Ubiquitous Knowledge Processing (UKP) Lab
 * Technische Universitt Darmstadt
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package de.tudarmstadt.ukp.dkpro.core;

import de.tudarmstadt.ukp.dkpro.core.stanfordnlp.StanfordSegmenter;
import org.apache.commons.io.IOUtils;
import org.apache.uima.fit.factory.AnalysisEngineFactory;
import org.apache.uima.fit.factory.JCasFactory;
import org.apache.uima.fit.pipeline.SimplePipeline;
import org.apache.uima.jcas.JCas;
import org.junit.Test;

import java.io.InputStream;

/**
 * @author Ivan Habernal
 */
public class RSTParseOutputReaderTest {

    @Test
    public void testReadParseOutput() throws Exception {
        InputStream stream = this.getClass().getClassLoader().getResourceAsStream("parse1.txt");
        String s = IOUtils.toString(stream);

        RSTParseOutputReader reader = new RSTParseOutputReader();

        // mock jcas
        JCas jCas = JCasFactory.createJCas();

        InputStream textStream = this.getClass().getClassLoader().getResourceAsStream("roomfordebate1.txt");
        String text = IOUtils.toString(textStream);

        jCas.setDocumentText(text);
        jCas.setDocumentLanguage("en");

        // tokenize
        SimplePipeline.runPipeline(jCas, AnalysisEngineFactory.createEngineDescription(StanfordSegmenter.class));

        reader.readParseOutput(s, jCas);
    }

    @Test
    public void testProblem1() throws Exception {
        InputStream stream = this.getClass().getClassLoader().getResourceAsStream("problem1.txt");
        String s = IOUtils.toString(stream);

        RSTParseOutputReader reader = new RSTParseOutputReader();

        JCas jCas = JCasFactory.createJCas();
        jCas.setDocumentText("cannibaldave\n"
                + "Not particularly unusual among the people I know. I just had nothing in common with the people I went to school with. Why should I? The coincidence of age and living in the same area were all there was to go on. You could call that in itself a very narrow prospect. The friends I had were of all ages and from a variety of different localities. \n"
                + "A school doesn't need to be 'a nightmarish bully fest' to be a bane. All it needs to do is to fail to provide a totally unstimulating environment. Which mine did. It was boring, tedious, slow and frustrating. I learned nothing that I did not know before other than a handful of French verbs which have so far been of as much use as a chocolate fireguard. \n"
                + "Each to his own, as I said. If you really enjoyed school, good for you. But don't assume that one size fits everybody, because it doesn't. ");
        jCas.setDocumentLanguage("en");

        // tokenize
        SimplePipeline.runPipeline(jCas, AnalysisEngineFactory.createEngineDescription(StanfordSegmenter.class));

        reader.readParseOutput(s, jCas);
    }
}