-1
私はstsonford-nlp出力をjsonにパイプ処理しようとしています。私はシンプルなjsonで試して、すべてうまく動作します。私はjson toStringはまだメモリ値を返します
public static void main(String[] args) throws IOException {
JsonObjectBuilder parserJSONObj = stanfordNLPParser(processedQuestion);
System.out.println(parserJSONObj.toString());
}
public static JsonObjectBuilder stanfordNLPParser (String processedQuestion)throws IOException {
Properties props = new Properties();
props.setProperty("annotators", "tokenize, ssplit, pos, lemma, ner, parse, sentiment");
StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
JsonObjectBuilder parserJSONObj = Json.createObjectBuilder();
Annotation annotation = pipeline.process(processedQuestion);
List<CoreMap> sentences = annotation.get(CoreAnnotations.SentencesAnnotation.class);
for (CoreMap sentence : sentences) {
for (CoreMap quesGentokens : sentence.get(TokensAnnotation.class)) {
String quesGenToken = quesGentokens.toString();
String quesGenPOS = quesGentokens.get(PartOfSpeechAnnotation.class);
parserJSONObj.add(quesGenToken, Json.createArrayBuilder()
.add(Json.createObjectBuilder()
.add("POS", quesGenPOS)));
parserJSONObj.build();
System.out.println(parserJSONObj.toString());
}
}
return parserJSONObj;
}
出力の下に示すようにjavax.jsonを使用しようとすると:
[email protected]
私は今、この上のいくつかの質問を持っている:
- さえのtoStringを追加するだけのメモリ位置を示してい。
- は戻り値の型です.JsonObjectBuilderの戻り値の型です(これを考慮して、Jsonでのさらなる操作を考慮してください)。
私はあなたがこのメソッドからJsonObject
を返すべきだと思いますおかげ
ビルダーが作成したJSONオブジェクトではなく、ビルダーを印刷しています。 –