Пример #1
0
        private bool IsInNPDomain(DiscourseEntry P, DiscourseEntry N)
        {
            if (N.Node.Goal != "CNP")
            {
                return(false);
            }
            ParseNode Pnp = GetParentNP(P.Node);

            if (Pnp == null)
            {
                return(false);
            }
            if (Pnp == N.Node.Parent)
            {
                return(true);
            }
            ParseNode prp = GetParentPRP(Pnp, N.Node.Parent);

            if (prp == null)
            {
                return(false);
            }
            Pnp = GetParentNP(prp);
            if (Pnp == null)
            {
                return(false);
            }
            if (Pnp == N.Node.Parent)
            {
                return(true);
            }
            return(false);
        }
Пример #2
0
        private bool IsCondition3(DiscourseEntry P, DiscourseEntry N)
        {
            bool      isprp;
            ParseNode CurrP = GetNPorPRP(P.Node.Parent, out isprp);

            if (isprp)
            {
                CurrP = GetParentNP(CurrP);
            }
            if (((ParseNode)CurrP.Children[0]).Goal == "CNP")
            {
                return(false);
            }
            if (GetUpperHead(CurrP) == GetUpperHead(N.Node))
            {
                return(true);
            }
            ParseNode prp = GetPrep(CurrP);

            if (prp == null)
            {
                return(false);
            }
            ParseNode h1 = GetUpperHead(prp);

            return(h1 != null && h1 == GetUpperHead(N.Node));
        }
Пример #3
0
        internal void assigndiscoursedata()
        {
            foreach (ArrayList arr in DisClasses)
            {
                DiscourseEntry referredNounDE        = (DiscourseEntry)arr[0];
                ParseTree      ReferredNounParseTree = (ParseTree)ParseTrees[referredNounDE.TreeNum];
                string         word = GetWordString(ReferredNounParseTree, referredNounDE.Node);

                for (int i = 1; i < arr.Count; i++)
                {
                    DiscourseEntry de = (DiscourseEntry)arr[i];
                    ParseTree      p  = (ParseTree)ParseTrees[de.TreeNum];
                    if (p.ResolvedAnaphora.Count != p.Words.Count)
                    {
                        for (int j = 0; j < p.Words.Count; j++)
                        {
                            p.ResolvedAnaphora.Add(null);
                        }
                    }
                    p.ResolvedAnaphora[de.Node.Start] = word;
                    //ParseNode node= GetReferedNode(ReferredNounParseTree);
                    de.Node.ReferedAnaphoraNode = referredNounDE.Node;
                }
            }
        }
Пример #4
0
 private bool IsInNPDomain2(DiscourseEntry P, DiscourseEntry N)
 {
     if (P.Node.Goal != "PPJ" && P.Node.Goal != "REPC")
     {
         return(false);
     }
     return(IsContained(N.Node, P.Node.Parent));
 }
Пример #5
0
        private bool IsAdjunctDomain(DiscourseEntry P, DiscourseEntry N)
        {
            ParseNode prp = GetPrep(P.Node);

            if (prp == null)
            {
                return(false);
            }
            ParseNode h1 = GetUpperHead(prp);

            return(h1 != null && h1 == GetUpperHead(N.Node));
        }
Пример #6
0
        private bool IsRoleParallel(DiscourseEntry prn, DiscourseEntry de)
        {
            if (IsSBJ(prn.Node) && IsSBJ(de.Node))
            {
                return(true);
            }
            ParseNode obj   = null;
            ParseNode cmps  = null;
            bool      bopj1 = false;
            bool      bopj2 = false;
            bool      dobj1 = false;
            bool      dobj2 = false;
            bool      iobj1 = false;
            bool      iobj2 = false;

            if (IsOBJ(prn.Node, out obj, out cmps, out bopj1))
            {
                if (IsDirectOBJ(obj, cmps))
                {
                    dobj1 = true;
                }
                else
                {
                    iobj1 = true;
                }
            }
            if (IsOBJ(de.Node, out obj, out cmps, out bopj2))
            {
                if (IsDirectOBJ(obj, cmps))
                {
                    dobj2 = true;
                }
                else
                {
                    iobj2 = true;
                }
            }
            if (dobj1 && dobj2)
            {
                return(true);
            }
            if (iobj1 && iobj2)
            {
                return(true);
            }
            if (bopj1 && bopj2)
            {
                return(true);
            }
            return(false);
        }
Пример #7
0
 private bool IsCataphora(DiscourseEntry prn, DiscourseEntry de)
 {
     if (de.TreeNum > prn.TreeNum)
     {
         return(true);
     }
     else if (de.TreeNum < prn.TreeNum)
     {
         return(false);
     }
     else
     {
         return(de.Node.Start > prn.Node.Start);
     }
 }
Пример #8
0
        private void Form2_Load(object sender, System.EventArgs e)
        {
            #region Diaplay Discourse Results
            foreach (ArrayList arr in DisClasses)
            {
                foreach (DiscourseEntry de in arr)
                {
                    ParseTree p = (ParseTree)ParseTrees[de.TreeNum];

                    string str = GetWordString(p, de.Node) +
                                 " (" + ((int)(de.TreeNum + 1)).ToString() + "." + ((int)(de.Node.Start + 1)).ToString() + ")";

                    textBox1.Text += str + "\r\n";
                }
                textBox1.Text += "***************************************************\r\n";
            }
            textBox1.Select(0, 0);

            #endregion

            #region Assign Discourse Data

            foreach (ArrayList arr in DisClasses)
            {
                DiscourseEntry referredNounDE        = (DiscourseEntry)arr[0];
                ParseTree      ReferredNounParseTree = (ParseTree)ParseTrees[referredNounDE.TreeNum];
                string         word = GetWordString(ReferredNounParseTree, referredNounDE.Node);

                for (int i = 1; i < arr.Count; i++)
                {
                    DiscourseEntry de = (DiscourseEntry)arr[i];
                    ParseTree      p  = (ParseTree)ParseTrees[de.TreeNum];
                    if (p.ResolvedAnaphora.Count != p.Words.Count)
                    {
                        for (int j = 0; j < p.Words.Count; j++)
                        {
                            p.ResolvedAnaphora.Add(null);
                        }
                    }
                    p.ResolvedAnaphora[de.Node.Start] = word;
                    //ParseNode node= GetReferedNode(ReferredNounParseTree);
                    de.Node.ReferedAnaphoraNode = referredNounDE.Node;
                }
            }

            #endregion
        }
Пример #9
0
 private bool IsWrongSBJ(DiscourseEntry P, DiscourseEntry N)
 {
     if (N.Node.Parent.Goal == "NP" || N.Node.Parent.Goal == "NPC")
     {
         if (FoundSBJ(P.Node, N.Node.Parent))
         {
             return(true);
         }
     }
     if (P.Node.Parent.Goal == "NP" || P.Node.Parent.Goal == "NPC")
     {
         if (FoundSBJ(N.Node, P.Node.Parent))
         {
             return(true);
         }
     }
     return(false);
 }
Пример #10
0
        private bool IsCondition5(DiscourseEntry P, DiscourseEntry N)
        {
            if (P.Node.Goal != "REPC" && P.Node.Goal != "PPJ")
            {
                return(false);
            }
            if (GetUpperHead(P.Node.Parent) == GetUpperHead(N.Node))
            {
                return(true);
            }
            ParseNode prp = GetPrep(P.Node);

            if (prp == null)
            {
                return(false);
            }
            ParseNode h1 = GetUpperHead(prp);

            return(h1 != null && h1 == GetUpperHead(N.Node));
        }
Пример #11
0
 private bool IsMoreNear(DiscourseEntry prn, DiscourseEntry de1, DiscourseEntry de2)
 {
     if (prn.TreeNum >= de1.TreeNum && prn.TreeNum >= de2.TreeNum)
     {
         if (prn.TreeNum - de1.TreeNum < prn.TreeNum - de2.TreeNum)
         {
             return(true);
         }
         else if (prn.TreeNum - de1.TreeNum > prn.TreeNum - de2.TreeNum)
         {
             return(false);
         }
         else
         {
             return(de1.Node.Start > de2.Node.Start);
         }
     }
     else if (prn.TreeNum >= de1.TreeNum && prn.TreeNum < de2.TreeNum)
     {
         return(true);
     }
     else if (prn.TreeNum < de1.TreeNum && prn.TreeNum >= de2.TreeNum)
     {
         return(false);
     }
     else
     {
         if (prn.TreeNum - de1.TreeNum < prn.TreeNum - de2.TreeNum)
         {
             return(false);
         }
         else if (prn.TreeNum - de1.TreeNum > prn.TreeNum - de2.TreeNum)
         {
             return(true);
         }
         else
         {
             return(de1.Node.Start < de2.Node.Start);
         }
     }
 }
Пример #12
0
        private bool IsArgumentDomain(DiscourseEntry P, DiscourseEntry N)
        {
            ParseNode h1 = GetParentPRDorDS(P.Node);
            ParseNode h2 = GetParentPRDorDS(N.Node);

            if (h1 == h2)
            {
                return(true);
            }
            else if (h1 == null || h2 == null)
            {
                return(false);
            }
            else if (h1.Goal == "DS" && h1 == h2.Parent)
            {
                return(true);
            }
            else if (h2.Goal == "DS" && h2 == h1.Parent)
            {
                return(true);
            }
            return(false);
        }
Пример #13
0
        private bool IsCondition4(DiscourseEntry P, DiscourseEntry N)
        {
            if (N.Node.Goal == "PPJ" || N.Node.Goal == "REPC" || N.Node.Goal == "DEMP" ||
                N.Node.Goal == "NPP" || N.Node.Goal == "OPP" || N.Node.Goal == "RXPN" ||
                N.Node.Goal == "EACHO" || N.Node.Goal == "ONEAN")
            {
                return(false);
            }
            ParseNode head = GetDirectHead(P.Node);

            if (head == null)
            {
                return(false);
            }
            if (!IsContained(N.Node, head))
            {
                return(false);
            }
            if (N.Node.Goal == "CNP" && N.Node.Start < P.Node.Start)
            {
                return(false);
            }
            return(true);
        }
Пример #14
0
        private bool IsValidEntry(ParseTree ps, DiscourseEntry prn, DiscourseEntry de)
        {
            if (prn.Ag.Person != 0 && de.Ag.Person != 0 && de.Ag.Person != prn.Ag.Person)
            {
                return(false);
            }
            if (prn.Ag.Type != 0 && de.Ag.Type != 0 && de.Ag.Type != prn.Ag.Type)
            {
                return(false);
            }
            bool reflexive = prn.Node.Goal == "RXPN" || prn.Node.Goal == "REPC" ||
                             prn.Node.Goal == "EACHO" || prn.Node.Goal == "ONEAN";

            if (reflexive)
            {
                if (prn.TreeNum != de.TreeNum)
                {
                    return(false);
                }
                if (prn.Node.Parent == de.Node.Parent)
                {
                    return(false);
                }
                if (IsInNPDomain(prn, de))
                {
                    return(true);
                }
                if (IsArgumentDomain(prn, de))
                {
                    return(true);
                }
                if (IsAdjunctDomain(prn, de))
                {
                    return(true);
                }
                if (IsCondition5(prn, de))
                {
                    return(true);
                }
                if (IsCondition3(prn, de))
                {
                    return(true);
                }
                return(false);
            }
            else
            {
                if (prn.TreeNum != de.TreeNum)
                {
                    return(true);
                }
                if (prn.Node.Parent == de.Node.Parent)
                {
                    return(false);
                }
                if (IsInNPDomain(prn, de))
                {
                    return(false);
                }
                if (IsInNPDomain2(prn, de))
                {
                    return(false);
                }
                if (IsCondition4(prn, de))
                {
                    return(false);
                }
                if (IsArgumentDomain(prn, de))
                {
                    return(false);
                }
                if (IsAdjunctDomain(prn, de))
                {
                    return(false);
                }
                if (IsWrongSBJ(prn, de))
                {
                    return(false);
                }
                return(true);
            }
        }
Пример #15
0
        public void Begin(ArrayList ParseTrees)
        {
            EquivalenceClasses = new Hashtable();
            DistinctClasses    = new ArrayList();
            ArrayList PronounNPs = new ArrayList();
            ArrayList OtherNPs   = new ArrayList();
            int       tnum       = 0;

            foreach (ParseTree ps in ParseTrees)
            {
                Stack nodes = new Stack();
                nodes.Push(ps.Root);
                while (nodes.Count > 0)
                {
                    ParseNode pn = (ParseNode)nodes.Pop();
                    if (pn.Goal == "CMADJ" || pn.Goal == "CMADV")
                    {
                        continue;
                    }
                    if (pn.Goal == "NP" || pn.Goal == "NPC" || pn.Goal == "NPF")
                    {
                        ParseNode fch = (ParseNode)pn.Children[0];
                        if (fch.Goal == "DEMP" || fch.Goal == "NPP" || fch.Goal == "OPP" ||
                            fch.Goal == "RXPN" || fch.Goal == "EACHO" || fch.Goal == "ONEAN")
                        {
                            string p = GetWordString(ps, fch);
                            if (fch.Goal == "NPP" && p == "IT" && IsPleonasticPronoun(fch, ps))
                            {
                                continue;
                            }
                            Agreement g = new Agreement(p, p, true                          //New ,wsd
                                                        );
                            DiscourseEntry de = new DiscourseEntry();
                            de.Ag      = g;
                            de.Node    = fch;
                            de.Score   = 100 + GetScore(fch, ps);
                            de.TreeNum = tnum;
                            PronounNPs.Add(de);
                        }
                        else if (fch.Goal == "IDFP")
                        {
                            string    p = GetWordString(ps, fch);
                            Agreement g = new Agreement(p, p, true                          //New ,wsd
                                                        );
                            DiscourseEntry de = new DiscourseEntry();
                            de.Ag      = g;
                            de.Node    = fch;
                            de.Score   = 100 + GetScore(fch, ps);
                            de.TreeNum = tnum;
                            OtherNPs.Add(de);
                        }
                        else if (fch.Goal == "NP" || fch.Goal == "NPC")
                        {
                            continue;
                        }
                        else
                        {
                            foreach (ParseNode ch in pn.Children)
                            {
                                if (ch.Goal == "NN" || ch.Goal == "NNC")
                                {
                                    if (IsWrongReferent(ch, ps))
                                    {
                                        continue;
                                    }
                                    ParseNode term = (ParseNode)ch.Children[0];
                                    if (term.Goal == "ADVS")
                                    {
                                        term = (ParseNode)ch.Children[1];
                                    }
                                    string w = GetWordString(ps, term);
                                    //string p=((NodeSense)term.Senses[0]).Sense;
                                    string p = w + "#n#1";                  ////////Sevre Bug

                                    Agreement g = new Agreement(p, w, false //New ,wsd
                                                                );
                                    DiscourseEntry de = new DiscourseEntry();
                                    de.Ag      = g;
                                    de.Node    = ch;
                                    de.Score   = 100 + GetScore(ch, ps);
                                    de.TreeNum = tnum;
                                    OtherNPs.Add(de);
                                }
                            }
                        }
                        if (fch.Goal == "PPJ" || fch.Goal == "REPC")
                        {
                            string    p = GetWordString(ps, fch);
                            Agreement g = new Agreement(p, p, true                          //New ,wsd
                                                        );
                            DiscourseEntry de = new DiscourseEntry();
                            de.Ag      = g;
                            de.Node    = fch;
                            de.Score   = 100 + GetScore(fch, ps);
                            de.TreeNum = tnum;
                            PronounNPs.Add(de);
                        }
                        if (fch.Goal == "ARC")
                        {
                            fch = (ParseNode)pn.Children[1];
                        }
                        if (fch.Goal == "CNP")
                        {
                            string p = "";
                            if (fch.Senses != null)
                            {
                                p = ((NodeSense)fch.Senses[0]).Sense;
                            }
                            string w = GetWordString(ps, fch);
                            if (w.EndsWith("'s"))
                            {
                                w = w.Remove(w.Length - 2, 2);
                            }
                            if (w.EndsWith("s'"))
                            {
                                w = w.Remove(w.Length - 1, 1);
                            }
                            Agreement g = new Agreement(p, w, false                          //New ,wsd
                                                        );
                            DiscourseEntry de = new DiscourseEntry();
                            de.Ag      = g;
                            de.Node    = fch;
                            de.Score   = 100 + GetScore(fch, ps);
                            de.TreeNum = tnum;
                            OtherNPs.Add(de);
                        }
                    }
                    if (pn.Goal == "SBJ" || pn.Goal == "OBJ")
                    {
                        ParseNode fch = (ParseNode)pn.Children[0];
                        if (fch.Goal != "SSBJ" && fch.Goal != "SOBJ")
                        {
                            Agreement      g  = new Agreement(3, 0);
                            DiscourseEntry de = new DiscourseEntry();
                            de.Ag      = g;
                            de.Node    = pn;
                            de.Score   = 100 + GetScore(pn, ps);
                            de.TreeNum = tnum;
                            OtherNPs.Add(de);
                        }
                    }
                    if (pn.Children == null)
                    {
                        continue;
                    }
                    foreach (ParseNode n in pn.Children)
                    {
                        nodes.Push(n);
                    }
                }
                tnum++;
                // choose and move
                for (int i = 0; i < PronounNPs.Count; i++)
                {
                    DiscourseEntry PrnEntry   = (DiscourseEntry)PronounNPs[i];
                    ArrayList      ResEntries = (ArrayList)OtherNPs.Clone();
                    if (i > 0)
                    {
                        ResEntries.AddRange(PronounNPs.GetRange(0, i));
                    }
                    if (PronounNPs.Count > i + 1)
                    {
                        ResEntries.AddRange(PronounNPs.GetRange(i + 1, PronounNPs.Count - i - 1));
                    }
                    int            maxScore = -1000;
                    DiscourseEntry maxEntry = null;
                    foreach (DiscourseEntry de in ResEntries)
                    {
                        int currScore = de.Score;
                        if (IsCataphora(PrnEntry, de))
                        {
                            currScore -= 175;
                        }
                        if (IsRoleParallel(PrnEntry, de))
                        {
                            currScore += 35;
                        }
                        if (currScore >= maxScore && IsValidEntry(ps, PrnEntry, de))
                        {
                            if (currScore > maxScore || IsMoreNear(PrnEntry, de, maxEntry))
                            {
                                maxScore = currScore;
                                maxEntry = de;
                            }
                        }
                    }
                    if (maxEntry != null)
                    {
                        PrnEntry.Score += maxScore / 2;
                        // code to save results;
                        ArrayList items1 = (ArrayList)EquivalenceClasses[maxEntry];
                        ArrayList items2 = (ArrayList)EquivalenceClasses[PrnEntry];
                        if (items1 == null || items2 == null || items1 != items2)
                        {
                            ArrayList newitems = new ArrayList();
                            if (items1 != null)
                            {
                                DistinctClasses.Remove(items1);
                            }
                            else
                            {
                                items1 = new ArrayList();
                                items1.Add(maxEntry);
                            }
                            if (items2 != null)
                            {
                                DistinctClasses.Remove(items2);
                            }
                            else
                            {
                                items2 = new ArrayList();
                                items2.Add(PrnEntry);
                            }
                            foreach (DiscourseEntry di in items1)
                            {
                                items2.Remove(di);
                            }
                            newitems.AddRange(items1);
                            newitems.AddRange(items2);
                            DistinctClasses.Add(newitems);
                            foreach (DiscourseEntry di in newitems)
                            {
                                EquivalenceClasses[di] = newitems;
                            }
                        }
                        //
                        OtherNPs.Add(PrnEntry);
                        PronounNPs.RemoveAt(i);
                        i--;
                    }
                }
                //
                for (int i = OtherNPs.Count - 1; i >= 0; i--)
                {
                    DiscourseEntry de = (DiscourseEntry)OtherNPs[i];
                    de.Score /= 2;
                    if (de.Score <= 0 || tnum - de.TreeNum >= 4)
                    {
                        OtherNPs.RemoveAt(i);
                    }
                }
                foreach (DiscourseEntry de in PronounNPs)
                {
                    de.Score /= 2;
                }
            }
        }