public bool Satisfies(ParseNodeDrawable parseNode)
        {
            if (parseNode.NumberOfChildren() > 0)
            {
                return(parseNode.GetData().ToString().Equals(_symbol));
            }

            return(false);
        }
예제 #2
0
 public void Modifier(ParseNodeDrawable parseNode)
 {
     if (parseNode.IsLeaf())
     {
         string name = parseNode.GetData().GetName();
         parseNode.ClearLayers();
         parseNode.GetLayerInfo().SetLayerData(ViewLayerType.ENGLISH_WORD, name);
         parseNode.ClearData();
     }
 }
        protected bool IsLastWordOfNounPhrase(ParseNodeDrawable parseNode)
        {
            var parent      = (ParseNodeDrawable)parseNode.GetParent();
            var grandParent = (ParseNodeDrawable)parent.GetParent();
            var next        = (ParseNodeDrawable)parseNode.NextSibling();
            var previous    = (ParseNodeDrawable)parseNode.PreviousSibling();

            if (parent.IsLastChild(parseNode))
            {
                if (previous != null && previous.GetData().GetName().StartsWith("J") && previous.LastChild().IsLeaf())
                {
                    string word = ((ParseNodeDrawable)previous.LastChild()).GetLayerData(ViewLayerType.TURKISH_WORD);
                    if (word != null && txtDictionary.GetWord(word) != null &&
                        ((TxtWord)txtDictionary.GetWord(word)).IsNominal())
                    {
                        return(true);
                    }
                }

                if (previous != null && previous.GetData().GetName().StartsWith("N"))
                {
                    return(true);
                }

                if (grandParent != null && grandParent.IsLastChild(parent) && grandParent.NumberOfChildren() == 2)
                {
                    ParseNodeDrawable parentPrevious = (ParseNodeDrawable)parent.PreviousSibling();
                    if (parentPrevious.GetData().GetName().Equals("PP") &&
                        parentPrevious.LastChild().GetData().GetName().Equals("IN"))
                    {
                        ParseNodeDrawable inNode = (ParseNodeDrawable)parentPrevious.LastChild().LastChild();
                        if (inNode != null && inNode.GetLayerData(ViewLayerType.ENGLISH_WORD) != null &&
                            inNode.GetLayerData(ViewLayerType.ENGLISH_WORD).Equals("of"))
                        {
                            return(true);
                        }

                        return(false);
                    }

                    return(false);
                }

                return(false);
            }

            if (next != null && previous != null)
            {
                return(!(next.GetData().GetName().StartsWith("N")) && previous.GetData().GetName().StartsWith("N"));
            }

            return(false);
        }
        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);
        }
        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);
        }
예제 #6
0
 public bool Satisfies(ParseNodeDrawable parseNode)
 {
     return(parseNode.NumberOfChildren() > 0 && parseNode.GetData().IsVp());
 }
예제 #7
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);
        }