The Ruby Stanford Core NLP gem returns messy objects.
Example 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]]]]]"
Example 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)
Example 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"
How could I convert any of those objects into something like JSON using Ruby?
See the following excerpt for how to iterate the results and build the corresponding tree. I'll leave it as an exercise to convert the resulting tree into JSON format.
Note you could also skip ahead and use Treat directly to retrieve the parsed tree of the sentence.