Skip to content

Code from python to java #1301

@GonzaloCalandria

Description

@GonzaloCalandria

Hello guys, I'm trying to mimic this code from python into java but I can't find the way to do it properly.
The python code is the following:

annotators = 'tokenize,ssplit,pos,depparse,lemma,coref,openie,parse'
#setup corenlp server 
corenlp = StanfordCoreNLP('http://localhost', port=9000)
props={'annotators': annotators, 
        'pipelineLanguage': 'en',
        'outputFormat': 'json'}
annotated = corenlp.annotate('some sentence text', properties=props)

First of all, this is my code in java

public String annotate(String query) {
        query = lemmatize(query);
        Properties props = new Properties();
		props.setProperty("annotators", "tokenize,ssplit,pos,depparse,lemma,coref,openie,parse");
		props.setProperty("pipelineLanguage", "en");
		props.setProperty("outputFormat", "json");
        StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
        Annotation annotation = new Annotation(query);
        pipeline.annotate(annotation);
        return annotation.toString();
    }

This code, throws the following exception java.lang.IllegalArgumentException: annotator "coref" requires annotation "NamedEntityTagAnnotation". The usual requirements for this annotator are: tokenize,pos,lemma,ner,depparse when the new StanfordCoreNLP(props); is excecuted.

But besides this exception, I would like to understand how to get the same JSON format output in python from java. Is this possible?

Thanks in advance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions