3
$\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$
2
  • 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$ Commented Feb 13, 2020 at 21:34
  • $\begingroup$ Looks like lazy unfinished functionality $\endgroup$
    – M.R.
    Commented Feb 16, 2020 at 19:38

1 Answer 1

5
$\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 and acknowledge you have read our privacy policy.

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