Java Code Examples for de.tudarmstadt.ukp.dkpro.core.api.metadata.type.DocumentMetaData#get()

The following examples show how to use de.tudarmstadt.ukp.dkpro.core.api.metadata.type.DocumentMetaData#get() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CasMergeSuiteTest.java    From webanno with Apache License 2.0 8 votes vote down vote up
private void writeAndAssertEquals(JCas curatorCas)
    throws Exception
{
    String targetFolder = "target/test-output/" + testContext.getClassName() + "/"
            + referenceFolder.getName();
    
    DocumentMetaData dmd = DocumentMetaData.get(curatorCas);
    dmd.setDocumentId("curator");
    runPipeline(curatorCas, createEngineDescription(WebannoTsv3XWriter.class,
            WebannoTsv3XWriter.PARAM_TARGET_LOCATION, targetFolder,
            WebannoTsv3XWriter.PARAM_OVERWRITE, true));
    
    File referenceFile = new File(referenceFolder, "curator.tsv");
    assumeTrue("No reference data available for this test.", referenceFile.exists());
    
    File actualFile = new File(targetFolder, "curator.tsv");
    
    String reference = FileUtils.readFileToString(referenceFile, "UTF-8");
    String actual = FileUtils.readFileToString(actualFile, "UTF-8");
    
    assertEquals(reference, actual);
}
 
Example 2
Source File: WebannoTsv1Reader.java    From webanno with Apache License 2.0 5 votes vote down vote up
public void convertToCas(JCas aJCas, InputStream aIs, String aEncoding)
    throws IOException

{
    StringBuilder text = new StringBuilder();
    Map<Integer, String> tokens = new HashMap<>();
    Map<Integer, String> pos = new HashMap<>();
    Map<Integer, String> lemma = new HashMap<>();
    Map<Integer, String> namedEntity = new HashMap<>();
    Map<Integer, String> dependencyFunction = new HashMap<>();
    Map<Integer, Integer> dependencyDependent = new HashMap<>();

    List<Integer> firstTokenInSentence = new ArrayList<>();

    DocumentMetaData documentMetadata = DocumentMetaData.get(aJCas);
    fileName = documentMetadata.getDocumentTitle();
    setAnnotations(aIs, aEncoding, text, tokens, pos, lemma, namedEntity, dependencyFunction,
            dependencyDependent, firstTokenInSentence);

    aJCas.setDocumentText(text.toString());

    Map<String, Token> tokensStored = new HashMap<>();

    createToken(aJCas, text, tokens, pos, lemma, tokensStored);

    createNamedEntity(namedEntity, aJCas, tokens, tokensStored);

    createDependency(aJCas, tokens, dependencyFunction, dependencyDependent, tokensStored);

    createSentence(aJCas, firstTokenInSentence, tokensStored);
}
 
Example 3
Source File: WebannoTsv2Reader.java    From webanno with Apache License 2.0 5 votes vote down vote up
public void convertToCas(JCas aJCas, InputStream aIs, String aEncoding)
    throws IOException

{
    StringBuilder text = new StringBuilder();
    DocumentMetaData documentMetadata = DocumentMetaData.get(aJCas);
    fileName = documentMetadata.getDocumentTitle();
    setAnnotations(aJCas, aIs, aEncoding, text);
    aJCas.setDocumentText(text.toString());
}
 
Example 4
Source File: WebannoTsv3Reader.java    From webanno with Apache License 2.0 5 votes vote down vote up
public void convertToCas(JCas aJCas, InputStream aIs, String aEncoding)
    throws IOException

{
    DocumentMetaData documentMetadata = DocumentMetaData.get(aJCas);
    fileName = documentMetadata.getDocumentTitle();
    // setLayerAndFeature(aJCas, aIs, aEncoding);

    setAnnotations(aJCas, aIs, aEncoding);
    aJCas.setDocumentText(coveredText.toString());
}
 
Example 5
Source File: TeiReaderTest.java    From webanno with Apache License 2.0 5 votes vote down vote up
@Test
 @Ignore("No TEI yet to opensource ")
public void testTeiReader()
    throws Exception
{
    CollectionReaderDescription reader = createReaderDescription(TeiReader.class,
            TeiReader.PARAM_LANGUAGE, "en", TeiReader.PARAM_SOURCE_LOCATION,
            "classpath:/local/", TeiReader.PARAM_PATTERNS, new String[] { "[+]*.xml" });

    String firstSentence = "70 I DAG.";

    for (JCas jcas : new JCasIterable(reader)) {
        DocumentMetaData meta = DocumentMetaData.get(jcas);
        String text = jcas.getDocumentText();
        System.out.printf("%s - %d%n", meta.getDocumentId(), text.length());
        System.out.println(jcas.getDocumentLanguage());

        assertEquals(2235, JCasUtil.select(jcas, Token.class).size());
        assertEquals(745, JCasUtil.select(jcas, POS.class).size());
        assertEquals(745, JCasUtil.select(jcas, Lemma.class).size());
        assertEquals(0, JCasUtil.select(jcas, NamedEntity.class).size());
        assertEquals(30, JCasUtil.select(jcas, Sentence.class).size());

        assertEquals(firstSentence, JCasUtil.select(jcas, Sentence.class).iterator().next()
                .getCoveredText());
    }

}
 
Example 6
Source File: ArgumentsToHTMLExporter.java    From argument-reasoning-comprehension-task with Apache License 2.0 4 votes vote down vote up
@Override
public void process(JCas aJCas)
        throws AnalysisEngineProcessException
{
    DocumentMetaData metaData = DocumentMetaData.get(aJCas);

    out.printf("<h1>%s</h1>\n<h2>%s</h2>\n", metaData.getDocumentId(),
            metaData.getDocumentTitle());

    // print paragraphs
    List<String> paragraphs = renderDocumentToHtmlParagraphs(aJCas);
    out.printf("<p>%s</p>", StringUtils.join(paragraphs, "<br/><br/>"));

    // implicit claim?
    for (Claim claim : JCasUtil.select(aJCas, Claim.class)) {
        if (ArgumentUnitUtils.isImplicit(claim)) {
            String claimText = claim.getStance();
            if (claimText == null) {
                claimText = ArgumentUnitUtils
                        .getProperty(claim, ArgumentUnitUtils.PROP_KEY_REPHRASED_CONTENT);
            }
            out.printf(
                    "<p><span class=\"component\">Implicit claim:</span> <span class=\"claim\">%s</span></p>",
                    claimText);
        }
    }

    // appeal to emotions
    for (ArgumentComponent component : JCasUtil.select(aJCas, ArgumentComponent.class)) {
        if (ArgumentUnitUtils
                .getProperty(component, ArgumentUnitUtils.PROP_KEY_IS_APPEAL_TO_EMOTION)
                != null) {
            out.printf(
                    "<p><span class=\"component\">Appeal to emotions:</span> <span class=\"appeal\">%s</span></p>",
                    component.getCoveredText());
        }
    }

    out.printf("<hr />");

}