Parser for Constituency Tree (Linguistics Analysis API)

别来无恙 提交于 2019-12-13 18:13:43

问题


I'm using Microsofts Linguistics API. I'm trying to extract specific tokens from the returned tree. I dont see any type of parser for traversing through the tree in any documentation...

One approach I considered was to use the Stanford NLP parser but It seems a little overkill for what I need.

Is there an existing parser that I could use?

here is sample data that is returned. for example what can I use to extract "NNP" (Tom)

[{
"analyzerId": "4FA79AF1-F22C-408D-98BB-B7D7AEEF7F04", 
"result": [ ["NNP",",","NNP","."], ["WRB","VBP","PRP","NN","."] ]  },

{
"analyzerId": "22A6B758-420F-4745-8A3C-46835A67C0D2", 
"result":["(TOP (S (NNP Hi) (, ,) (NNP Tom) (. !)))","(TOP (SBARQ (WHADVP (WRB How)) (SQ (VP (VBP are)) (NP (PRP you)) (NN today) (. ?))))"]  }]

回答1:


Find my parser-to-tree (and roundtripping) source code at:

https://github.com/BSalita/Woundify/blob/master/WoundifyShared/ParseHelpers.cs

ParseHelpers is a file from the Woundify project. One of the functions of the project is to demonstrate the calling and consumption of APIs from all leading AI services providers (Microsoft, Google, HPE, IBM, Wit, Hound, etc.).

I've edited in a usage fragment from command.cs file:

foreach (Newtonsoft.Json.Linq.JToken s in arrayOfResults)
{
    ConstituencyTreeNode root = ParseHelpers.ConstituencyTreeFromText(s.ToString());
    text = ParseHelpers.TextFromConstituencyTree(root); // roundtrip
    if (text != s.ToString()) // original and roundtrip must compare equal
        throw new FormatException();
    string words = ParseHelpers.WordsFromConstituencyTree(root);
    string[] printLines = ParseHelpers.FormatConstituencyTree(root);
    foreach (string p in printLines)
        Console.WriteLine(p);
}


来源:https://stackoverflow.com/questions/41518425/parser-for-constituency-tree-linguistics-analysis-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!