Skip to content

Instantly share code, notes, and snippets.

@ryerh
Created October 29, 2020 16:09
Show Gist options
  • Save ryerh/6f1e78996090c7b6008c5a9b8a11cc45 to your computer and use it in GitHub Desktop.
Save ryerh/6f1e78996090c7b6008c5a9b8a11cc45 to your computer and use it in GitHub Desktop.
private void buttonSyntacParse_Click(object sender, EventArgs e)
{
//依存句法分析
var dictMode = new Dictionary<string, int>{
{"web模型", 0},
{"query模型", 1}
};
var options = new Dictionary<string, object>{
{"mode", dictMode[comboBoxSyntacParse.Text.ToString()]}};
var result = client.DepParser(textBoxLexiAnaly.Text, options);
var items = result["items"];
var root = items.First(p => (int)p["head"] == 0);
this.insertTreeNode(root);
this.buildTree(root, items);
}
private void buildTree(JToken root, JToken items)
{
var children = items.Where(p => p["head"].ToString() == root["id"].ToString()).ToList();
foreach (var item in children)
{
this.insertTreeNode(item);
this.buildTree(item, items);
}
}
private void insertTreeNode(JToken item)
{
var text = item["word"] + "(" + DEPRELTABLE[item["deprel"].ToString()] + ")";
var parents = this.treeViewSyntacParse.Nodes.Find(item["head"].ToString(), true);
if (parents.Count() == 0)
this.treeViewSyntacParse.Nodes.Add(item["id"].ToString(), text);
else
parents[0].Nodes.Add(item["id"].ToString(), text);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment