我怎么能将凌乱的Stanford Core NLP字符串对象转换为JSON

时间:2014-11-16 22:30:07

标签: ruby json casting stanford-nlp

Ruby Stanford Core NLP gem返回凌乱的对象。

示例1:

 => "[produced nsubjpass:[lbs amod:[many advmod:how] prep:[of pobj:CO2]] auxpass:is prep:[from pcomp:[burning dobj:[gallons num:12 prep:[of pobj:gas]]]]]"

示例2:

 -> produced-VBN (root)
   -> lbs-NNS (nsubjpass)
     -> many-JJ (amod)
       -> how-WRB (advmod)
     -> of-IN (prep)
       -> CO2-NN (pobj)
   -> is-VBZ (auxpass)
   -> from-IN (prep)
     -> burning-VBG (pcomp)
       -> gallons-NNS (dobj)
         -> 12-CD (num)
         -> of-IN (prep)
           -> gas-NN (pobj)

示例3:

  @sentence.to_s
=> "-> produced-VBN (root)\n  -> lbs-NNS (nsubjpass)\n    -> many-JJ (amod)\n      -> how-WRB (advmod)\n    -> of-IN (prep)\n      -> CO2-NN (pobj)\n  -> is-VBZ (auxpass)\n  -> from-IN (prep)\n    -> burning-VBG (pcomp)\n      -> gallons-NNS (dobj)\n        -> 12-CD (num)\n        -> of-IN (prep)\n          -> gas-NN (pobj)\n"

如何使用Ruby将任何这些对象转换为JSON?

1 个答案:

答案 0 :(得分:0)

请参阅following excerpt了解如何迭代结果并构建相应的树。我将它留作练习,将生成的树转换为JSON格式。

请注意,您也可以跳过并直接使用Treat来检索已解析的句子树。