private List <Decision> SetToAndAddUniversalDependency(int startIndex, int headIndex, List <WordNodePair> wordNodePairList, int finishIndex, ParseNodeDrawable parent)
        {
            var decisions = new List <Decision>();

            for (var i = startIndex; i <= finishIndex; i++)
            {
                if (i != headIndex)
                {
                    var    parentData = parent.GetData().GetName();
                    var    firstChild = parent.GetChild(0).GetData().GetName();
                    string secondChild = null, thirdChild = null;
                    if (parent.NumberOfChildren() > 1)
                    {
                        secondChild = parent.GetChild(1).GetData().GetName();
                    }
                    if (parent.NumberOfChildren() > 2)
                    {
                        thirdChild = parent.GetChild(2).GetData().GetName();
                    }
                    if (parent.NumberOfChildren() == 2 && parentData.Equals("S") && firstChild.Equals("NP"))
                    {
                        decisions.Add(new Decision(startIndex + decisions.Count, headIndex - i, "NSUBJ"));
                    }
                    else if (parent.NumberOfChildren() == 3 && parentData.Equals("S") && firstChild.Equals("NP") && secondChild.Equals("VP") && Word.IsPunctuation(thirdChild))
                    {
                        if (!wordNodePairList[i].GetWord().IsPunctuation())
                        {
                            decisions.Add(new Decision(startIndex + decisions.Count, headIndex - i, "NSUBJ"));
                        }
                        else
                        {
                            decisions.Add(new Decision(startIndex + decisions.Count, headIndex - i, "PUNCT"));
                        }
                    }
                    else
                    {
                        var dependent  = wordNodePairList[i].GetNode().GetData().GetName();
                        var head       = wordNodePairList[headIndex].GetNode().GetData().GetName();
                        var condition1 = wordNodePairList[i].GetNode().GetData().IsPunctuation();
                        var condition2 = wordNodePairList[headIndex].GetNode().GetData().IsPunctuation();
                        decisions.Add(new Decision(startIndex + decisions.Count, headIndex - i, FindData(dependent, head, condition1, condition2, wordNodePairList[i].GetWord(), wordNodePairList[headIndex].GetWord())));
                    }
                }
                else
                {
                    decisions.Add(new Decision(-1, 0, null));
                }
            }
            return(decisions);
        }
 private void NodeModify(ParseNodeDrawable parseNode)
 {
     _nodeModifier.Modifier(parseNode);
     for (var i = 0; i < parseNode.NumberOfChildren(); i++)
     {
         NodeModify((ParseNodeDrawable)parseNode.GetChild(i));
     }
 }
        protected bool IsLastWordOfVerbAsNoun(ParseNodeDrawable parseNode)
        {
            ParseNodeDrawable parent      = (ParseNodeDrawable)parseNode.GetParent();
            ParseNodeDrawable grandParent = (ParseNodeDrawable)parent.GetParent();

            if (parent.IsLastChild(parseNode) && parent.GetData().GetName().Equals("VP"))
            {
                if (grandParent != null && grandParent.GetData().GetName().Equals("NP") &&
                    grandParent.GetChild(0).Equals(parent) &&
                    grandParent.NumberOfChildren() == 2 && grandParent.GetChild(1).GetData().GetName().Equals("NP"))
                {
                    return(true);
                }
            }

            return(false);
        }
        private List <ParseNodeDrawable> FindNodes(ParseNodeDrawable node)
        {
            var list = new List <ParseNodeDrawable>();

            for (var i = 0; i < node.NumberOfChildren(); i++)
            {
                var child = (ParseNodeDrawable)node.GetChild(i);
                if (node.GetLayerInfo() == null)
                {
                    if (node.NumberOfChildren() == 1 && ((ParseNodeDrawable)node.GetChild(0)).GetLayerInfo() == null)
                    {
                        list.Add(node);
                    }
                    list.AddRange(FindNodes(child));
                }
            }
            return(list);
        }
Example #5
0
 private void CollectNodes(ParseNodeDrawable parseNode, List <ParseNodeDrawable> collected)
 {
     if (_condition == null || _condition.Satisfies(parseNode))
     {
         collected.Add(parseNode);
     }
     for (var i = 0; i < parseNode.NumberOfChildren(); i++)
     {
         CollectNodes((ParseNodeDrawable)parseNode.GetChild(i), collected);
     }
 }
 private bool ContainsChild(ParseNodeDrawable parent, ParseNodeDrawable child)
 {
     for (var i = 0; i < parent.NumberOfChildren(); i++)
     {
         if (GetParent((ParseNodeDrawable)parent.GetChild(i)).Equals(GetParent(child)))
         {
             return(true);
         }
     }
     return(false);
 }
        public List <Decision> MakeDecisions(int firstIndex, int lastIndex, List <WordNodePair> wordNodePairList, ParseNodeDrawable node, List <TreeEnsembleModel> models)
        {
            if (node.NumberOfChildren() == 3 && node.GetChild(1).GetData().GetName().Equals("CONJP"))
            {
                var decisions = new List <Decision>();
                decisions.Add(new Decision(-1, 0, null));
                decisions.Add(new Decision((lastIndex + firstIndex) / 2, lastIndex - ((lastIndex + firstIndex) / 2), "CC"));
                decisions.Add(new Decision(lastIndex, firstIndex - lastIndex, "CONJ"));
                return(decisions);
            }
            var headIndex = FindHeadIndex(firstIndex, lastIndex, wordNodePairList);

            return(SetToAndAddUniversalDependency(firstIndex, headIndex, wordNodePairList, lastIndex, node));
        }
Example #8
0
        private string ConvertToString(ParseNodeDrawable parseNode)
        {
            if (parseNode.IsLeaf())
            {
                return(_converter.LeafConverter(parseNode));
            }

            var st = "";

            for (var i = 0; i < parseNode.NumberOfChildren(); i++)
            {
                st += ConvertToString((ParseNodeDrawable)parseNode.GetChild(i));
            }

            return(st);
        }
Example #9
0
        public List <Decision> MakeDecisions(int firstIndex, int lastIndex, List <WordNodePair> wordNodePairList, ParseNodeDrawable node, List <TreeEnsembleModel> models)
        {
            var    testData = new List <Attribute.Attribute>(lastIndex + 1 - firstIndex);
            string classInfo;
            var    list      = new List <Tuple <int, int> >();
            var    decisions = new List <Decision>();

            for (var i = 0; i < lastIndex + 1 - firstIndex; i++)
            {
                testData.Add(new Attribute.DiscreteAttribute(wordNodePairList[firstIndex + i].GetWord().GetParse().GetPos()));
                testData.Add(new Attribute.DiscreteAttribute(wordNodePairList[firstIndex + i].GetWord().GetParse().GetRootPos()));
                testData.Add(new Attribute.DiscreteAttribute(wordNodePairList[firstIndex + i].GetWord().GetParse().ContainsTag(MorphologicalTag.ABLATIVE).ToString()));
                testData.Add(new Attribute.DiscreteAttribute(wordNodePairList[firstIndex + i].GetWord().GetParse().ContainsTag(MorphologicalTag.DATIVE).ToString()));
                testData.Add(new Attribute.DiscreteAttribute(wordNodePairList[firstIndex + i].GetWord().GetParse().ContainsTag(MorphologicalTag.GENITIVE).ToString()));
                testData.Add(new Attribute.DiscreteAttribute(wordNodePairList[firstIndex + i].GetWord().GetParse().ContainsTag(MorphologicalTag.NOMINATIVE).ToString()));
                testData.Add(new Attribute.DiscreteAttribute(wordNodePairList[firstIndex + i].GetWord().GetParse().ContainsTag(MorphologicalTag.ACCUSATIVE).ToString()));
                testData.Add(new Attribute.DiscreteAttribute(wordNodePairList[firstIndex + i].GetWord().GetParse().ContainsTag(MorphologicalTag.PROPERNOUN).ToString()));
            }
            switch (lastIndex + 1 - firstIndex)
            {
            case 2:
                classInfo = models[1].Predict(new Instance("", testData));
                list      = FindList(2, classInfo);
                break;

            case 3:
                classInfo = models[2].Predict(new Instance("", testData));
                list      = FindList(3, classInfo);
                break;

            case 4:
                classInfo = models[3].Predict(new Instance("", testData));
                list      = FindList(4, classInfo);
                break;

            case 5:
                classInfo = models[4].Predict(new Instance("", testData));
                list      = FindList(5, classInfo);
                break;

            case 6:
                classInfo = models[5].Predict(new Instance("", testData));
                list      = FindList(6, classInfo);
                break;

            case 7:
                classInfo = models[6].Predict(new Instance("", testData));
                list      = FindList(7, classInfo);
                break;

            default:
                break;
            }
            var headIndex = FindHeadIndex(list, firstIndex, lastIndex);

            for (var i = 0; i < list.Count; i++)
            {
                var fromWord   = wordNodePairList[firstIndex + list[i].Item1].GetWord();
                var toWord     = wordNodePairList[firstIndex + list[i].Item2].GetWord();
                var headWord   = wordNodePairList[headIndex].GetWord();
                var attributes = new List <Attribute.Attribute>(29);
                attributes.Add(new Attribute.DiscreteAttribute(fromWord.GetParse().GetPos()));
                attributes.Add(new Attribute.DiscreteAttribute(fromWord.GetParse().GetRootPos()));
                attributes.Add(new Attribute.DiscreteAttribute(fromWord.GetParse().ContainsTag(MorphologicalTag.ABLATIVE).ToString()));
                attributes.Add(new Attribute.DiscreteAttribute(fromWord.GetParse().ContainsTag(MorphologicalTag.DATIVE).ToString()));
                attributes.Add(new Attribute.DiscreteAttribute(fromWord.GetParse().ContainsTag(MorphologicalTag.GENITIVE).ToString()));
                attributes.Add(new Attribute.DiscreteAttribute(fromWord.GetParse().ContainsTag(MorphologicalTag.NOMINATIVE).ToString()));
                attributes.Add(new Attribute.DiscreteAttribute(fromWord.GetParse().ContainsTag(MorphologicalTag.ACCUSATIVE).ToString()));
                attributes.Add(new Attribute.DiscreteAttribute(fromWord.GetParse().ContainsTag(MorphologicalTag.PROPERNOUN).ToString()));
                attributes.Add(new Attribute.DiscreteAttribute(toWord.GetParse().GetPos()));
                attributes.Add(new Attribute.DiscreteAttribute(toWord.GetParse().GetRootPos()));
                attributes.Add(new Attribute.DiscreteAttribute(toWord.GetParse().ContainsTag(MorphologicalTag.ABLATIVE).ToString()));
                attributes.Add(new Attribute.DiscreteAttribute(toWord.GetParse().ContainsTag(MorphologicalTag.DATIVE).ToString()));
                attributes.Add(new Attribute.DiscreteAttribute(toWord.GetParse().ContainsTag(MorphologicalTag.GENITIVE).ToString()));
                attributes.Add(new Attribute.DiscreteAttribute(toWord.GetParse().ContainsTag(MorphologicalTag.NOMINATIVE).ToString()));
                attributes.Add(new Attribute.DiscreteAttribute(toWord.GetParse().ContainsTag(MorphologicalTag.ACCUSATIVE).ToString()));
                attributes.Add(new Attribute.DiscreteAttribute(toWord.GetParse().ContainsTag(MorphologicalTag.PROPERNOUN).ToString()));
                attributes.Add(new Attribute.DiscreteAttribute(headWord.GetParse().GetPos()));
                attributes.Add(new Attribute.DiscreteAttribute(headWord.GetParse().GetRootPos()));
                attributes.Add(new Attribute.DiscreteAttribute(headWord.GetParse().ContainsTag(MorphologicalTag.ABLATIVE).ToString()));
                attributes.Add(new Attribute.DiscreteAttribute(headWord.GetParse().ContainsTag(MorphologicalTag.DATIVE).ToString()));
                attributes.Add(new Attribute.DiscreteAttribute(headWord.GetParse().ContainsTag(MorphologicalTag.GENITIVE).ToString()));
                attributes.Add(new Attribute.DiscreteAttribute(headWord.GetParse().ContainsTag(MorphologicalTag.NOMINATIVE).ToString()));
                attributes.Add(new Attribute.DiscreteAttribute(headWord.GetParse().ContainsTag(MorphologicalTag.ACCUSATIVE).ToString()));
                attributes.Add(new Attribute.DiscreteAttribute(headWord.GetParse().ContainsTag(MorphologicalTag.PROPERNOUN).ToString()));
                if (fromWord.GetSemantic() == null || headWord.GetSemantic() == null)
                {
                    attributes.Add(new Attribute.DiscreteAttribute("null"));
                }
                else
                {
                    attributes.Add(new Attribute.DiscreteAttribute(fromWord.GetSemantic().Equals(headWord.GetSemantic()).ToString()));
                }
                attributes.Add(new Attribute.DiscreteAttribute(node.GetData().GetName()));
                var firstChild  = "null";
                var secondChild = "null";
                var thirdChild  = "null";
                if (node.NumberOfChildren() > 0)
                {
                    firstChild = node.GetChild(0).GetData().GetName();
                }
                if (node.NumberOfChildren() > 1)
                {
                    secondChild = node.GetChild(1).GetData().GetName();
                }
                if (node.NumberOfChildren() > 2)
                {
                    thirdChild = node.GetChild(2).GetData().GetName();
                }
                attributes.Add(new Attribute.DiscreteAttribute(firstChild));
                attributes.Add(new Attribute.DiscreteAttribute(secondChild));
                attributes.Add(new Attribute.DiscreteAttribute(thirdChild));
                decisions.Add(new Decision(firstIndex + list[i].Item1, list[i].Item2 - list[i].Item1, models[0].Predict(new Instance("", attributes))));
            }
            AddHeadToDecisions(decisions, headIndex);
            return(decisions);
        }