GetWordPosition() 공개 메소드

public GetWordPosition ( ) : int
리턴 int
예제 #1
0
    private void CollectEdges(SolarixGrammarEngineNET.SyntaxTreeNode node, Dictionary <int, int> node2parent, Dictionary <int, string> node2word)
    {
        node2word.Add(node.GetWordPosition(), node.GetWord());

        for (int i = 0; i < node.leafs.Count; ++i)
        {
            SolarixGrammarEngineNET.SyntaxTreeNode child = node.leafs[i];
            node2parent.Add(child.GetWordPosition(), node.GetWordPosition());

            CollectEdges(child, node2parent, node2word);
        }
    }
    private void SetLabel(SolarixGrammarEngineNET.SyntaxTreeNode node, string label, bool recursive)
    {
        if (recursive)
        {
            List <int> indeces = new List <int>();
            CollectSubtreeNodeIndeces(node, indeces);

            int k = 0;
            foreach (int index in indeces.OrderBy(z => z))
            {
                if (k == 0)
                {
                    labels[index + 1].Insert(0, label);
                }
                else
                {
                    labels[index + 1].Insert(0, label);
                }

                k++;
            }
        }
        else
        {
            int index = node.GetWordPosition();
            labels[index + 1].Insert(0, label);
        }

        return;
    }
예제 #3
0
    public bool ProcessSample(SampleData sample, bool train_sample, bool test_sample)
    {
        if (wrt_train == null)
        {
            wrt_train = new System.IO.StreamWriter("syntax_neuro_train.txt");
            wrt_test  = new System.IO.StreamWriter("syntax_neuro_test.txt");
        }

        System.IO.StreamWriter wrt = train_sample ? wrt_train : wrt_test;

        if (sample.syntax_tree.Count == 3)
        {
            SolarixGrammarEngineNET.SyntaxTreeNode root = sample.syntax_tree[1];

            Dictionary <int, int>    node2parent = new Dictionary <int, int>();
            Dictionary <int, string> node2word   = new Dictionary <int, string>();

            node2parent.Add(root.GetWordPosition(), -1);

            CollectEdges(root, node2parent, node2word);

            foreach (int index in node2word.Select(z => z.Key).OrderBy(z => z))
            {
                wrt.WriteLine("{0}\t{1}\t{2}", index, node2word[index], node2parent[index]);
            }

            wrt.WriteLine("");
        }

        return(true);
    }
예제 #4
0
    static void GetChunkNodes(SolarixGrammarEngineNET.SyntaxTreeNode node,
                              int chunk_index,
                              Dictionary <int /*word_index*/, int /*chunk_index*/> labels)
    {
        labels[node.GetWordPosition()] = chunk_index;

        for (int i = 0; i < node.leafs.Count; ++i)
        {
            GetChunkNodes(node.leafs[i], chunk_index, labels);
        }
    }
    private void CollectSubtreeNodeIndeces(SolarixGrammarEngineNET.SyntaxTreeNode node, List <int> word_index)
    {
        if (node.GetWord() == ".")
        {
            return;
        }

        word_index.Add(node.GetWordPosition());

        for (int ileaf = 0; ileaf < node.leafs.Count; ++ileaf)
        {
            SolarixGrammarEngineNET.SyntaxTreeNode leaf = node.leafs[ileaf];
            CollectSubtreeNodeIndeces(leaf, word_index);
        }

        return;
    }
예제 #6
0
    void TraverseEdges(SolarixGrammarEngineNET.SyntaxTreeNode token)
    {
        foreach (SolarixGrammarEngineNET.SyntaxTreeNode leaf in token.leafs)
        {
            int distance = System.Math.Abs(leaf.GetWordPosition() - token.GetWordPosition());
            if (edge_len2count.ContainsKey(distance))
            {
                edge_len2count[distance] = edge_len2count[distance] + 1;
            }
            else
            {
                edge_len2count.Add(distance, 1);
            }

            TraverseEdges(leaf);
        }
    }