I ran into this question earlier today:
Example Input: I ran into Joe and Jill and then we went shopping
Example Output: [TOP [S [S [NP [PRP I]] [VP [VBD ran] [PP [IN into] [NP [NNP Joe] [CC and] [NNP Jill]]]]] [CC and] [S [ADVP [RB then]] [NP [PRP we]] [VP [VBD went] [NP [NN shopping]]]]]]
I was about to suggest simply parsing the expected output (as it looks like an s-expression) into an object (in our case a tree) and then using simple LINQ methods to process it. However, to my surprise, I was unable to find a C# s-expression parser.
The only thing I could think of is using Clojure to parse it since it compiles to the clr, I'm not sure it's a good solution though.
By the way, I don't mind the answer to output of type dynamic
. Only answers I've found here were for deserializing into a specific schema.
To sum up my question: I need to deserialize s-expressions in C# (serialization would be nice for future readers of this question)
It looks like you need a data-structure of the form:
A serializer of the form
And a de-serializer of the form:
If haven't tested or even compiled this code, however, this is more or less how it could work.
I wrote an open source S-Expression parser that is available as S-Expression.NET. Since it uses OMeta# to generate the parser you can quickly play with it to add new features.