2
$\begingroup$

I feel this should be relatively straightforward, if I run the code:

TextStructure["I read the book he wrote.", "DependencyStrings"]

I get as string:

    {"(read, 2)((nsubj, (I, 1)), (dobj, (book, 4)((det, (the, 3)), 
(rcmod, (wrote, 6)((nsubj, (he, 5)))))))"}

I want to convert this into a nested list I can index.

Thanks in advance.

$\endgroup$
  • 1
    $\begingroup$ What version are you running? On V12 I get {"(read, 2)((nsubj, (I, 1)), (dobj, (book, 4)((det, (the, 3)), (rcmod, (wrote, 6)((nsubj, (he, 5)))))))"} $\endgroup$ – Rohit Namjoshi Feb 13 at 21:34
  • $\begingroup$ Looks like lazy unfinished functionality $\endgroup$ – M.R. Feb 16 at 19:38
4
$\begingroup$
str = TextStructure["I read the book he wrote.", "DependencyStrings"];

{"(read, 2)((nsubj, (I, 1)), (dobj, (book, 4)((det, (the, 3)), (rcmod, (wrote, 6)((nsubj, (he, 5)))))))"}

ToExpression @ 
   StringReplace["{" <> str[[1]] <> "}", {")(" -> "}, {", "(" -> "{", ")" -> "}"}] 

{{read, 2}, {{nsubj, {I, 1}}, {dobj, {book, 4}, {{det, {the, 3}}, {rcmod, {wrote, 6}, {{nsubj, {he, 5}}}}}}}}

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.