Exemple #1
0
        public static ArrayList GetAllSenses(string word, string pos)
        {
            int senseCount = 0;

            Opt[]     relatednessTypes = null;
            ArrayList senses           = new ArrayList();

            MyWnLexicon.WSDWordInfo wordInfo = MyWnLexicon.Lexicon.FindWordInfo(word, true);
            Wnlib.PartsOfSpeech     POS      = Wnlib.PartsOfSpeech.Unknown;
            if (pos == "noun")
            {
                POS        = PartsOfSpeech.Noun;
                senseCount = wordInfo.senseCounts[1];
            }
            if (pos == "verb")
            {
                POS        = PartsOfSpeech.Verb;
                senseCount = wordInfo.senseCounts[2];
            }
            if (pos == "adj")
            {
                POS        = PartsOfSpeech.Adj;
                senseCount = wordInfo.senseCounts[3];
            }
            if (pos == "adv")
            {
                POS        = PartsOfSpeech.Adv;
                senseCount = wordInfo.senseCounts[4];
            }

            relatednessTypes = WordsMatching.Relatedness.GetRelatedness(POS);
            //senseCount = wordInfo.senseCounts[1];
            if (relatednessTypes == null)
            {
                return(null);
            }
            for (int i = 0; i < senseCount; i++)
            {
                string gloss = GetRelatednessGlosses(word, i + 1, relatednessTypes);
                senses.Add(gloss);
            }

            return(senses);
        }
Exemple #2
0
        private MyWordInfo[] Disambiguate(string[] words)
        {
            if (words.Length == 0)
            {
                return(null);
            }

            MyWordInfo[] wordInfos = new MyWordInfo [words.Length];

            for (int i = 0; i < words.Length; i++)
            {
                MyWnLexicon.WSDWordInfo wordInfo = MyWnLexicon.Lexicon.FindWordInfo(words[i], true);

                if (wordInfo.partOfSpeech != Wnlib.PartsOfSpeech.Unknown)
                {
                    if (wordInfo.text != string.Empty)
                    {
                        words[i] = wordInfo.text;
                    }

                    Wnlib.PartsOfSpeech[] posEnum = (Wnlib.PartsOfSpeech[])Enum.GetValues(typeof(Wnlib.PartsOfSpeech));

                    for (int j = 0; j < posEnum.Length; j++)
                    {
                        if (wordInfo.senseCounts[j] > 0) // get the first part of speech
                        {
                            wordInfos[i] = new MyWordInfo(words[i], posEnum[j]);
                            break;
                        }
                    }
                }
            }

            WordSenseDisambiguator wsd = new WordSenseDisambiguator();

            wordInfos = wsd.Disambiguate(wordInfos);

            return(wordInfos);
        }
Exemple #3
0
        private void Init_Relations()
        {
            Opt[] relatedness = null;
            for (int i = 0; i < _contextWords.Length; i++)
            {
                MyWnLexicon.WSDWordInfo wordInfo = MyWnLexicon.Lexicon.FindWordInfo(_contextWords[i].Word, true);

                if (wordInfo.partOfSpeech != Wnlib.PartsOfSpeech.Unknown)
                {
                    if (wordInfo.text != string.Empty)
                    {
                        _contextWords[i].Word = wordInfo.text;
                    }
                    Wnlib.PartsOfSpeech[] posEnum = (Wnlib.PartsOfSpeech[])Enum.GetValues(typeof(Wnlib.PartsOfSpeech));

                    bool stop       = false;
                    int  senseCount = 0;

                    for (int j = 1; j < posEnum.Length && !stop; j++)
                    {
                        Wnlib.PartsOfSpeech pos = posEnum[j];

                        if (wordInfo.senseCounts[j] > 0 && _contextWords[i].Pos == pos)
                        {
                            senseCount  = wordInfo.senseCounts[j];
                            relatedness = Relatedness.GetRelatedness(pos);
                            stop        = relatedness != null;
                            break;
                        }
                    }

                    if (stop)
                    {
                        string[][][] tmp = Relatedness.GetAllRelatednessData(_contextWords[i].Word, senseCount, relatedness);
                        _relCube[i] = tmp;
                    }
                }
            }
        }
        private ArrayList MMG_Scoring_Overlaps()//Greedy
        {
             ArrayList ArrScore = new ArrayList();

            int wordCount = _contextWords.Length;
            int[][][][] scoreCube;
            Init_ScoreCube(out scoreCube, wordCount);

            for (int i = 0; i < wordCount; i++)
                if (_relCube[i] != null)
                {
                    int iSenseCount = _relCube[i].Length;
                    int bestScoreOf_i = 0;

                    for (int iSense = 0; iSense < iSenseCount; iSense++)
                    {
                        int senseTotalScore = 0;
                        for (int j = 0; j < wordCount; j++)
                            if (i != j && InContext(i, j, CONTEXT_SIZE) && _relCube[j] != null)
                            {
                                int jSenseCount = _relCube[j].Length;

                                int bestScoreOf_j = 0;
                                for (int jSense = 0; jSense < jSenseCount; jSense++)
                                {
                                    int score = 0;
                                    if (scoreCube[i][iSense][j][jSense] != 0)
                                        score = scoreCube[i][iSense][j][jSense];
                                    else
                                        if (scoreCube[j][jSense][i][iSense] != 0)
                                            score = scoreCube[j][jSense][i][iSense];

                                    if (score == 0)
                                    {
                                        score = ScoringSensePair(_relCube[i][iSense], _relCube[j][jSense]);
                                        if (score > 0)
                                        {
                                            scoreCube[i][iSense][j][jSense] = score;
                                            scoreCube[j][jSense][i][iSense] = score;
                                        }
                                    }

                                    if (bestScoreOf_j < score)
                                        bestScoreOf_j = score;
                                }

                                if (bestScoreOf_j > THRESHOLD)
                                    senseTotalScore += bestScoreOf_j;
                            }

                        if (senseTotalScore > bestScoreOf_i)
                        {
                            bestScoreOf_i = senseTotalScore;
                            _bestSenses[i] = iSense;
                            
                        }
                    }

                    _overallScore += bestScoreOf_i;
                    ArrScore.Add(bestScoreOf_i);
                }


            for (int i = 0; i < wordCount; i++)
            {
                if (_bestSenses[i] == -1)
                {
                    MyWnLexicon.WSDWordInfo wordInfo = MyWnLexicon.Lexicon.FindWordInfo(_contextWords[i].Word, true);
                    if (wordInfo.partOfSpeech != Wnlib.PartsOfSpeech.Unknown && _contextWords[i].Pos != Wnlib.PartsOfSpeech.Unknown)
                    {
                        _bestSenses[i] = 0;
                    }
                }
            }
            return ArrScore;
        }