/// <summary>
            /// Get a random word weighted to occur after a specified first word.
            /// </summary>
            /// <param name="firstWord">The word before the word being queried for.</param>
            /// <param name="secondWordPOS">The part of speech of the word being queried for.</param>
            /// <returns>A word most likely to occur after the specified first word.</returns>
            public Word GetRandomSecondWord(Word firstWord, PartOfSpeech secondWordPOS)
            {
                CachedBigramList bigramList   = BigramDictionary.Instance.GetBigramListByPOS(firstWord.PoS, secondWordPOS);
                CachedBigramList listToSearch = bigramList;

                if (bigramList.entries.Any(e => e.First.Equals(firstWord)))
                {
                    List <BigramEntry> entriesWithWord = bigramList.entries.Where(e => e.First.Equals(firstWord)).ToList();
                    int frequency = (int)entriesWithWord.Sum(e => e.Frequency);
                    listToSearch = new CachedBigramList()
                    {
                        entries = entriesWithWord, totalFrequency = frequency
                    };
                }
                BigramEntry randomEntry = GetWeightedRandomEntryFromList(listToSearch.entries, listToSearch.totalFrequency);
                Word        randomWord  = null;

                if (randomEntry == null)
                {
                    randomWord = wordDictLookup.GetRandomWordByPOS(secondWordPOS);
                }
                else
                {
                    randomWord = randomEntry.Second;
                }
                return(randomWord);
            }
Пример #2
0
        private void ValidateSenseWithAnalysis(ILexSense sense, WfiGloss wfiGloss, int hvoSbWordPos, bool fMatchMainPossibility, IMoStemAllomorph allomorph)
        {
            WfiAnalysis wfiAnalysis = wfiGloss.Owner as WfiAnalysis;

            CompareTss(sense.Gloss.GetAlternativeTss(Cache.DefaultAnalWs),
                       wfiGloss.Form.GetAlternativeTss(Cache.DefaultAnalWs));

            // make sure the morph is linked to the lexicon sense, msa, and part of speech.
            IWfiMorphBundle morphBundle = wfiAnalysis.MorphBundlesOS[0];

            Assert.AreEqual(sense.Hvo, morphBundle.SenseRAHvo);
            Assert.AreEqual(sense.MorphoSyntaxAnalysisRAHvo, morphBundle.MsaRAHvo);
            if (!fMatchMainPossibility)
            {
                // expect exact possibility
                Assert.AreEqual(hvoSbWordPos, (sense.MorphoSyntaxAnalysisRA as MoStemMsa).PartOfSpeechRAHvo);
            }
            else
            {
                IPartOfSpeech posTarget = PartOfSpeech.CreateFromDBObject(Cache, hvoSbWordPos);
                Assert.AreEqual(posTarget.MainPossibility.Hvo, (sense.MorphoSyntaxAnalysisRA as MoStemMsa).PartOfSpeechRA.MainPossibility.Hvo);
            }
            Assert.AreEqual(allomorph.Hvo, morphBundle.MorphRAHvo);
            Assert.AreEqual(hvoSbWordPos, wfiAnalysis.CategoryRAHvo);
        }
Пример #3
0
        public string QueryPartOfSpeech(PartOfSpeech prtSpeech)
        {
            string partOfSpeech = "";

            return(partOfSpeech = string.Join(", ", words.Where(item => item.WordType == prtSpeech)
                                              .Select(item => item.Word.ToString())));
        }
Пример #4
0
        public bool OnPromoteReversalSubPOS(object cmd)
        {
            Slice slice = m_dataEntryForm.CurrentSlice;

            Debug.Assert(slice != null, "No slice was current");
            if (slice != null)
            {
                FdoCache       cache       = m_dataEntryForm.Cache;
                ICmPossibility sliceObj    = slice.Object as ICmPossibility;
                int            hvoNewOwner = cache.GetOwnerOfObject(sliceObj.OwnerHVO);
                switch (cache.GetClassOfObject(hvoNewOwner))
                {
                default:
                    throw new ArgumentException("Illegal class.");

                case PartOfSpeech.kclsidPartOfSpeech:
                {
                    IPartOfSpeech pos = PartOfSpeech.CreateFromDBObject(cache, hvoNewOwner);
                    pos.SubPossibilitiesOS.Append(sliceObj);
                    break;
                }

                case CmPossibilityList.kclsidCmPossibilityList:
                {
                    ICmPossibilityList posList = CmPossibilityList.CreateFromDBObject(cache, hvoNewOwner);
                    posList.PossibilitiesOS.Append(sliceObj);
                    break;
                }
                }
            }
            return(true);
        }
Пример #5
0
        public bool OnMoveReversalPOS(object cmd)
        {
            FdoCache cache = Cache;
            ObjectLabelCollection labels = new ObjectLabelCollection();

            foreach (IPartOfSpeech pos in MergeOrMoveCandidates)
            {
                labels.Add(ObjectLabel.CreateObjectLabelOnly(cache, pos.Hvo, "ShortNameTSS", "best analysis"));
            }
            using (SimpleListChooser dlg = new SimpleListChooser(cache, null, labels, 0,
                                                                 LexEdStrings.ksCategoryToMoveTo, null))
            {
                if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    IPartOfSpeech currentPOS = POS;
                    IPartOfSpeech newOwner   = PartOfSpeech.CreateFromDBObject(cache, dlg.ChosenOne.Hvo);
                    cache.BeginUndoTask(LexEdStrings.ksUndoMoveRevCategory,
                                        LexEdStrings.ksRedoMoveRevCategory);
                    ICmObject newOwningObj = newOwner.MoveIfNeeded(currentPOS);
                    newOwner.SubPossibilitiesOS.Append(currentPOS);
                    cache.EndUndoTask();
                    // Note: PropChanged should happen on the old owner and the new in the 'Add" method call.
                    // Have to jump to a main PartOfSpeech, as RecordClerk doesn't know anything about subcategories.
                    m_mediator.BroadcastMessageUntilHandled("JumpToRecord", newOwner.MainPossibility.Hvo);
                }
            }

            return(true);
        }
Пример #6
0
        void MakePart(IWord word, ISourceLine location, PartOfSpeech part, string description,
                      Func <OldParserWord, Action <Context, ISourceLine, byte> > getSetter, ref byte next, bool onlyNumberedInV3 = false)
        {
            var result = (OldParserWord)word;

            if ((result.PartOfSpeech & part) != 0)
            {
                return;
            }

            byte value;

            if (!onlyNumberedInV3 || ctx.ZEnvironment.ZVersion == 3)
            {
                if (next == 0)
                {
                    throw new InterpreterError(
                              InterpreterMessages.Too_Many_0_Only_1_Allowed_In_This_Vocab_Format,
                              description,
                              255);
                }

                value = next--;
            }
            else
            {
                value = 0;
            }

            getSetter(result)(ctx, location, value);
        }
Пример #7
0
        public void OverviewFor(string t, string p, ref bool b, ref SearchSet obj, ArrayList list)
        {
            PartOfSpeech pos         = Wnlib.PartOfSpeech.of(p);
            SearchSet    ss          = Wnlib.WNDB.is_defined(t, pos);
            MorphStr     ms          = new Wnlib.MorphStr(t, pos);
            bool         checkmorphs = false;

            hasmatch = false;                         //TODO: if this isn't reset then morphs aren't checked on subsequent searches - check for side effects of resetting this manually

            checkmorphs = AddSearchFor(t, pos, list); // do a search
            string m;

            if (checkmorphs)
            {
                WN.hasmatch = true;
            }

            if (!hasmatch)
            {
                // loop through morphs (if there are any)
                while ((m = ms.next()) != null)
                {
                    if (m != t)
                    {
                        ss = ss + WNDB.is_defined(m, pos);
                        AddSearchFor(m, pos, list);
                    }
                }
            }
            b   = ss.NonEmpty;
            obj = ss;
        }
Пример #8
0
        /// <summary>
        /// Use if PartOfSpeech is known
        /// </summary>
        /// <param name="word">word to lookup</param>
        /// <param name="pos">PartOfSpeech</param>
        /// <returns>Winlib.Search</returns>
        public static Search GetWordNetInfo(string word, PartOfSpeech pos)
        {
            SearchType ser = new SearchType(false, "OVERVIEW");
            Search     s   = new Search(word, true, pos, ser, 0);

            return(s);
        }
            public CachedWordList GetCachedWordByPOSList(PartOfSpeech pos)
            {
                CachedWordList list = null;

                _cachedWordByPOSLists.TryGetValue(pos, out list);
                return(list);
            }
Пример #10
0
        public Morpheme ConvertToMorpheme(List <string> morphemeJsonArray)
        {
            string       kanji        = "";
            string       katakana     = "";
            PartOfSpeech partOfSpeech = PartOfSpeech.NotRecognized;

            foreach (string str in morphemeJsonArray)
            {
                if (katakanaRecognitionService.IsSentenceWrittenInKatakana(str))
                {
                    katakana = str;
                }
                else
                {
                    PartOfSpeech partOfSpeechDetected = partOfSpeechDetectionService.DetectPartOfSpeech(str);
                    if (partOfSpeechDetected != PartOfSpeech.NotRecognized)
                    {
                        partOfSpeech = partOfSpeechDetected;
                    }
                    else
                    {
                        kanji = str;
                    }
                }
            }

            return(new Morpheme(kanji, katakana, partOfSpeech));
        }
        private string SegmentPOSFormat(string line)
        {
            var    split = line.Split(' ');
            string res   = "";

            for (int i = 0; i < split.Length; ++i)
            {
                if (split[i] == "")
                {
                    continue;
                }

                var slopeSplit = split[i].Split('/');
                Debug.Assert(slopeSplit.Length == 2);
                Debug.Assert(POSTable.ContainsKey(slopeSplit[1]));

                PartOfSpeech pos = POSTable[slopeSplit[1]].POS;
                if (pos == PartOfSpeech.Other)
                {
                    throw new Exception("Contain other.");
                }

                int posIndex = Convert.ToInt32(pos);

                res += slopeSplit[0] + "/" + Convert.ToString(posIndex);
                if (i != split.Length - 1)
                {
                    res += " ";
                }
            }

            return(res);
        }
Пример #12
0
        public static int GetSynsetIndex(string word, PartsOfSpeech pos)
        {
            word = word.ToLower();
            //word=RemoveBadChars (word);
            Index index = Wnlib.Index.lookup(word, PartOfSpeech.of(pos));

            if (index == null)
            {
                MorphStr morphs = new MorphStr(word, PartOfSpeech.of(pos));
                string   morph  = "";
                while ((morph = morphs.next()) != null)
                {
                    index = Index.lookup(morph, PartOfSpeech.of(pos));
                    if (index != null)
                    {
                        break;
                    }
                }
            }

            if (index == null)
            {
                return(-1);
            }
            else
            {
                return(0);
            }
        }
Пример #13
0
        public bool HasHoloMero(PointerType p, Search search)
        {
            PointerType pbase;

            if (p.Mnemonic == "HMERONYM")
            {
                pbase = PointerType.Of("HASMEMBERPTR");
            }
            else
            {
                pbase = PointerType.Of("ISMEMBERPTR");
            }

            if (offs != null)
            {
                for (int i = 0; i < offs.Length; i++)
                {
                    SynonymSet s = new SynonymSet(offs[i], PartOfSpeech.Of("noun"), "", search, 0, netData);

                    if (s.Has(pbase) || s.Has(pbase + 1) || s.Has(pbase + 2))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Пример #14
0
        public MyWordInfo[] FindSynonyms(ref MyWordInfo pos, bool includeMorphs)
        {
            pos.Word = pos.Word.ToLower();
            Index index = Index.lookup(pos.Word, PartOfSpeech.of(pos.Pos));

            if (index == null)
            {
                if (!includeMorphs)
                {
                    return(null);
                }

                var    morphs = new MorphStr(pos.Word, PartOfSpeech.of(pos.Pos));
                string morph  = "";
                while ((morph = morphs.next()) != null)
                {
                    index    = Index.lookup(morph, PartOfSpeech.of(pos.Pos));
                    pos.Word = morph;
                    if (index != null)
                    {
                        break;
                    }
                }
            }


            return(index == null ? null : LookupCandidates(index, pos));
        }
Пример #15
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="partOfSpeech"></param>
 /// <param name="translation"></param>
 /// <param name="sourceText"></param>
 /// <param name="sorces"></param>
 public OptionalTranslation(PartOfSpeech partOfSpeech, string translation, string sourceText, List <Synonym> sorces)
 {
     this.PartOfSpeech   = partOfSpeech;
     this.Translation    = translation;
     this.SourceText     = sourceText;
     this.SourceSynonyms = sorces;
 }
Пример #16
0
        // extracted from Exceptions class 
        private static IEnumerable<string> GetExceptions(string word, PartOfSpeech pos, WordNetContext context)
        {
            if (_exceptCache == null)
            {
                var watch = new System.Diagnostics.Stopwatch();
                watch.Start();

                _exceptCache = context.Excepts
                    .Include(e => e.Lemma)
                    .GroupBy(e => e.Value, e => e.Lemma)
                    .ToDictionary(grp => grp.Key, grp => grp.Select(l => new DictException { Exception = l.Value, Poses = l.Poses }).ToList());

                watch.Stop();
                Console.WriteLine($"GetExceptions time: {watch.ElapsedMilliseconds} ms");
            }

            List<DictException> excepts;
            if (_exceptCache.TryGetValue(word, out excepts))
            { 
                return excepts.Where(e => e.Poses.Contains(pos.symbol))
                    .Select(e => e.Exception);
            }
            
            return Enumerable.Empty<string>();
        }
Пример #17
0
        public static bool HasPartOfSpeech <TEnum>(TEnum enumValue, PartOfSpeech partOfSpeech)
        {
            Type t = enumValue.GetType();

            return(t.GetField(Enum.GetName(t, enumValue)).GetCustomAttributes(typeof(PosAndSymbolAttribute), false).OfType <PosAndSymbolAttribute>()
                   .Any(a => a.PartOfSpeech == partOfSpeech));
        }
Пример #18
0
 public void reopen(PartOfSpeech p)
 {
     _indexFps[p.key].Dispose();
     _indexFps[p.key] = GetStreamReader(IndexFile(p));
     _dataFps[p.key].Dispose();
     _dataFps[p.key] = GetStreamReader(DataFile(p));
 }
Пример #19
0
        /// <summary>
        /// Trace meronyms.
        /// </summary>
        /// <param name="pbase"></param>
        /// <param name="fpos"></param>
        /// <param name="depth"></param>
        private void TraceInherit(PointerType pbase, PartOfSpeech fpos, int depth)
        {
            for (int i = 0; i < ptrs.Length; i++)
            {
                Pointer pt = ptrs[i];
                if (pt.ptp.Ident == HYPERPTR && (pt.sce == 0 || pt.sce == whichword))
                {
                    Spaces("TRACEI", depth);
                    SynonymSet cursyn = new SynonymSet(pt.off, pt.pos, this, netData);
                    search.WordsFrom(cursyn);
                    cursyn.Str("=> ", "\n", 1, 0, 0, 1);
                    // TDMS 6 Oct 2005 - build hierarchical results
                    // TODO: verify this
                    if (senses == null)
                    {
                        senses = new List <SynonymSet>();
                    }

                    cursyn.thisptr = pt;  // TDMS 17 Nov 2005 - add this pointer type
                    // TODO: This is adding senses incorrectly
                    senses.Add(cursyn);

                    cursyn.TracePtrs(pbase, PartOfSpeech.Of("noun"), depth);
                    cursyn.TracePtrs(pbase + 1, PartOfSpeech.Of("noun"), depth);
                    cursyn.TracePtrs(pbase + 2, PartOfSpeech.Of("noun"), depth);

                    if (depth > 0)
                    {
                        depth = Depthcheck(depth);
                        cursyn.TraceInherit(pbase, cursyn.pos, depth + 1);
                    }
                }
            }
            search.Trunc();
        }
        /// <summary>
        /// Given a (potentially) owning object, and the flid in which is does/will own
        /// the feature structure, find the relevant POS.
        /// </summary>
        /// <param name="cobj"></param>
        /// <param name="owningFlid"></param>
        /// <returns></returns>
        private IPartOfSpeech GetPosFromCmObjectAndFlid(ICmObject cobj, int owningFlid)
        {
            IPartOfSpeech pos = null;

            switch (cobj.ClassID)
            {
            case MoInflAffMsa.kclsidMoInflAffMsa:
                IMoInflAffMsa infl = cobj as IMoInflAffMsa;
                if (infl != null)
                {
                    pos = infl.PartOfSpeechRA;
                }
                break;

            case MoDerivAffMsa.kclsidMoDerivAffMsa:
                IMoDerivAffMsa deriv = cobj as IMoDerivAffMsa;
                if (deriv != null)
                {
                    if (owningFlid == (int)MoDerivAffMsa.MoDerivAffMsaTags.kflidFromMsFeatures)
                    {
                        pos = deriv.FromPartOfSpeechRA;
                    }
                    else if (owningFlid == (int)MoDerivAffMsa.MoDerivAffMsaTags.kflidToMsFeatures)
                    {
                        pos = deriv.ToPartOfSpeechRA;
                    }
                }
                break;

            case MoStemMsa.kclsidMoStemMsa:
                IMoStemMsa stem = cobj as IMoStemMsa;
                if (stem != null)
                {
                    pos = stem.PartOfSpeechRA;
                }
                break;

            case MoStemName.kclsidMoStemName:
                IMoStemName sn = cobj as IMoStemName;
                pos = PartOfSpeech.CreateFromDBObject(sn.Cache, sn.OwnerHVO);
                break;

            case MoAffixAllomorph.kclsidMoAffixAllomorph:
                // get entry of the allomorph and then get the msa of first sense and return its (from) POS
                ILexEntry entry = LexEntry.CreateFromDBObject(m_cache, cobj.OwnerHVO);
                if (entry == null)
                {
                    return(pos);
                }
                ILexSense sense = entry.SensesOS.FirstItem;
                if (sense == null)
                {
                    return(pos);
                }
                IMoMorphSynAnalysis msa = sense.MorphoSyntaxAnalysisRA;
                pos = GetPosFromCmObjectAndFlid(msa, (int)MoDerivAffMsa.MoDerivAffMsaTags.kflidFromMsFeatures);
                break;
            }
            return(pos);
        }
        public static string ToFullString(this PartOfSpeech pos)
        {
            switch (pos)
            {
            case PartOfSpeech.Unknown:      return(PrgResources.POFFullUnknown);

            case PartOfSpeech.Noun:         return(PrgResources.POFFullNoun);

            case PartOfSpeech.Pronoun:      return(PrgResources.POFFullPronoun);

            case PartOfSpeech.Verb:         return(PrgResources.POFFullVerb);

            case PartOfSpeech.Adjective:    return(PrgResources.POFFullAdjective);

            case PartOfSpeech.Adverb:       return(PrgResources.POFFullAdverb);

            case PartOfSpeech.Preposition:  return(PrgResources.POFFullPreposition);

            case PartOfSpeech.Conjunction:  return(PrgResources.POFFullConjunction);

            case PartOfSpeech.Interjection: return(PrgResources.POFFullInterjection);

            default:
                return(pos.ToString());
            }
        }
        public static string ToShortString(this PartOfSpeech pos)
        {
            switch (pos)
            {
            case PartOfSpeech.Unknown:      return(PrgResources.POFShortUnknown);

            case PartOfSpeech.Noun:         return(PrgResources.POFShortNoun);

            case PartOfSpeech.Pronoun:      return(PrgResources.POFShortPronoun);

            case PartOfSpeech.Verb:         return(PrgResources.POFShortVerb);

            case PartOfSpeech.Adjective:    return(PrgResources.POFShortAdjective);

            case PartOfSpeech.Adverb:       return(PrgResources.POFShortAdverb);

            case PartOfSpeech.Preposition:  return(PrgResources.POFShortPreposition);

            case PartOfSpeech.Conjunction:  return(PrgResources.POFShortConjunction);

            case PartOfSpeech.Interjection: return(PrgResources.POFShortInterjection);

            default:
                return(pos.ToString());
            }
        }
 public Attack(string n, string a, PartOfSpeech pos, int l)
 {
     name         = n;
     animation    = a;
     partOfSpeech = pos;
     level        = l;
 }
Пример #24
0
 public Word(Guid id, PartOfSpeech partOfSpeech, CEFR cefr, ResourceId?pictureId)
 {
     Id           = id;
     PartOfSpeech = partOfSpeech;
     Cefr         = cefr;
     PictureId    = pictureId;
 }
Пример #25
0
        public void AddInterpretation(PartOfSpeech partOfSpeech, string interpretation)
        {
            if (Interpretations == null)
                throw new HangerdException("Interpretations has not been loaded.");

            Interpretations.Add(new WordInterpretation(partOfSpeech, interpretation, Interpretations.Count));
        }
Пример #26
0
        // TDMS 16 July 2006 - removed this method.
        // Method removed because if called externally
        // WNDBPart was not correctly constructed.
        // Calling is_defined(string searchstr,PartOfSpeech fpos)
        // correctly constructs WNDBPart.

        /*
         *                      private static SearchSet is_defined(string word,string p)
         *                      {
         *                              Console.WriteLine("is_defined string, string");
         *                              return is_defined(word,PartOfSpeech.of(p));
         *                      }
         */

        /// <summary>
        /// Determines if a word is defined in the WordNet database and returns
        /// all possible searches of the word.
        /// </summary>
        /// <example> This sample displays a message stating whether the
        /// word "car" exists as the part of speech "noun".
        /// <code>
        /// Wnlib.WNCommon.path = "C:\Program Files\WordNet\2.1\dict\"
        /// Dim wrd As String = "car"
        /// Dim POS As String = "noun"
        /// Dim b As Boolean = Wnlib.WNDB.is_defined(wrd, Wnlib.PartOfSpeech.of(POS)).NonEmpty.ToString
        ///
        /// If b Then
        ///     MessageBox.Show("The word " &amp; wrd &amp; " exists as a " &amp; POS &amp; ".")
        /// Else
        ///     MessageBox.Show("The word " &amp; wrd &amp; " does not exist as a " &amp; POS &amp; ".")
        /// End If
        /// </code>
        /// </example>
        /// <param name="searchstr">The word to search for</param>
        /// <param name="fpos">Part of Speech (noun, verb, adjective, adverb)</param>
        /// <returns>A SearchSet or null if the word does not exist in the dictionary</returns>
        // public SearchSet is_defined(string searchstr, PartOfSpeech fpos)
        // {
        //     Indexes ixs = new Indexes(searchstr, fpos, this);
        //     int i;
        //     int CLASS = 22; /* - */
        //     int LASTTYPE = CLASS;

        //     Search s = new Search(searchstr, fpos, new SearchType(false, "FREQ"), 0, this);
        //     SearchSet retval = new SearchSet();
        //     foreach (Index index in ixs)
        //     {
        //         retval = retval + "SIMPTR" + "FREQ" + "SYNS" + "WNGREP" + "OVERVIEW"; // added WNGREP - TDMS
        //         for (i = 0; i < index.ptruse.Length; i++)
        //         {
        //             PointerType pt = index.ptruse[i];
        //             //			retval=retval+pt;

        //             // WN2.1 - TDMS
        //             if (pt.ident <= LASTTYPE)
        //             {
        //                 retval = retval + pt;
        //             }
        //             else if (pt.mnemonic == "INSTANCE")
        //             {
        //                 retval = retval + "HYPERPTR";
        //             }
        //             else if (pt.mnemonic == "INSTANCES")
        //             {
        //                 retval = retval + "HYPOPTR";
        //             }

        //             // WN2.1 - TDMS
        //             if (pt.mnemonic == "SIMPTR")
        //             {
        //                 retval = retval + "ANTPTR";
        //             }

        //             if (fpos.name == "noun")
        //             {
        //                 /* set generic HOLONYM and/or MERONYM bit if necessary */
        //                 if (pt >= "ISMEMBERPTR" && pt <= "ISPARTPTR")
        //                     retval = retval + "HOLONYM";
        //                 else if (pt >= "HASMEMBERPTR" && pt <= "HASPARTPTR")
        //                     retval = retval + "MERONYM";
        //             }
        //             // WN2.1 - TDMS					else if (fpos.name=="adj" && pt.mnemonic=="SIMPTR")
        //             //						retval=retval+"ANTPTR";
        //         }

        //         if (fpos.name == "noun")
        //         {
        //             retval = retval + "RELATIVES";
        //             if (index.HasHoloMero("HMERONYM", s))
        //                 retval = retval + "HMERONYM";
        //             if (index.HasHoloMero("HHOLONYM", s))
        //                 retval = retval + "HHOLONYM";
        //             if (retval["HYPERPTR"])
        //                 retval = retval + "COORDS";
        //         }
        //         else if (fpos.name == "verb")
        //             retval = retval + "RELATIVES" + "FRAMES"; // added frames - TDMS
        //     }
        //     return retval;
        // }

        internal List <string> wngrep(string wordPassed, PartOfSpeech pos)
        {
            var          r  = new List <string>();
            StreamReader fp = index(pos);

            fp.BaseStream.Position = 0;
            fp.DiscardBufferedData();
            string word = wordPassed.Replace(" ", "_");
            string line;

            while ((line = fp.ReadLine()) != null)
            {
                int lineLen = line.IndexOf(' ');
                line = line.Substring(0, lineLen);
                try
                {
                    if (line.IndexOf(word) >= 0)
                    {
                        r.Add(line.Replace("_", " "));
                    }
                }
                catch
                {
                }
            }
            return(r);
        }
Пример #27
0
        // Summary:
        //     Retrieves words from dictionary by word syllables schema and part of speech type.
        //
        // Parameters:
        //   syllablesSchema:
        //     The syllables schema of the word to be retrieved.
        //   type:
        //     PartOfSpeech object representing the type of word.
        // Returns:
        //     The list of Word objects.
        public List <Word> GetWords(string syllablesSchema, PartOfSpeech type)
        {
            string      query        = "select id, word, syllables, type from Dictionary where syllables = @syllablesSchema and type = @type";
            List <Word> matchedWords = new List <Word>();

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                connection.Open();
                using (SqlCommand command = new SqlCommand(query, connection))
                {
                    command.Parameters.Add(new SqlParameter("@syllablesSchema", syllablesSchema));
                    command.Parameters.Add(new SqlParameter("@type", type.ToString()));

                    SqlDataReader reader = command.ExecuteReader();
                    while (reader.Read())
                    {
                        int    id        = reader.GetInt32(0);
                        string word      = reader.GetString(1);
                        string syllables = reader.GetString(2);
                        string type1     = reader.GetString(3);

                        PartOfSpeech partOfSpeech;
                        if (Enum.TryParse(type1, out partOfSpeech))
                        {
                            matchedWords.Add(new Word {
                                Id = id, Value = word, Syllables = syllables, PartOfSpeech = partOfSpeech
                            });
                        }
                    }
                }
            }

            return(matchedWords);
        }
Пример #28
0
 private void Initialize()
 {
     if (!_isInitialized)
     {
         if (tags != null && tags.Any())
         {
             _partsOfSpeech = PartOfSpeech.Unknown;
             foreach (var tag in tags)
             {
                 if (tag.StartsWith("pron:"))
                 {
                     _pron = tag.Substring(5).Split(' ');
                 }
                 else if (tag.StartsWith("f:"))
                 {
                     _freq = Convert.ToInt32(tag.Substring(2));
                 }
                 else
                 {
                     _partsOfSpeech |= API.PARTS_OF_SPEECH_DICT[tag];
                 }
             }
         }
         _isInitialized = true;
     }
 }
Пример #29
0
        internal void SetTokenTag(int tokenIndex, int spanIndex, PartOfSpeech tag)
        {
            var tmp = TokensData[spanIndex][tokenIndex];

            tmp.Tag = tag;
            TokensData[spanIndex][tokenIndex] = tmp;
        }
Пример #30
0
        public void AddWrongLookup(PartOfSpeech pos, string form, string lemma, List <string> predictedLemma)
        {
            switch (pos)
            {
            case PartOfSpeech.Noun:
                this.WrongNouns.Add(new LookupItem()
                {
                    Form = form, Lemma = lemma, PredictedLemma = predictedLemma
                });
                break;

            case PartOfSpeech.Verb:
                this.WrongVerbs.Add(new LookupItem()
                {
                    Form = form, Lemma = lemma, PredictedLemma = predictedLemma
                });
                break;

            case PartOfSpeech.Adjective:
                this.WrongAdjectives.Add(new LookupItem()
                {
                    Form = form, Lemma = lemma, PredictedLemma = predictedLemma
                });
                break;
            }
        }
Пример #31
0
        public void OverviewFor(string t, string p, ref bool b, ref SearchSet obj, ArrayList list)
        {
            PartOfSpeech pos         = Wnlib.PartOfSpeech.of(p);
            SearchSet    ss          = Wnlib.WNDB.is_defined(t, pos);
            MorphStr     ms          = new Wnlib.MorphStr(t, pos);
            bool         checkmorphs = false;

            checkmorphs = AddSearchFor(t, pos, list);             // do a search
            string m;

            if (checkmorphs)
            {
                WN.hasmatch = true;
            }

            if (!hasmatch)
            {
                // loop through morphs (if there are any)
                while ((m = ms.next()) != null)
                {
                    if (m != t)
                    {
                        ss = ss + WNDB.is_defined(m, pos);
                        AddSearchFor(m, pos, list);
                    }
                }
            }
            b   = ss.NonEmpty;
            obj = ss;
        }
Пример #32
0
 public DictionaryDataEntry(int id, string kanji, string kana, List<string> english, PartOfSpeech partOfSpeech)
 {
     ID = id;
     Kanji = kanji;
     Kana = kana;
     English = english;
     PartOfSpeech = partOfSpeech;
 }
Пример #33
0
        public WordInterpretation(PartOfSpeech partOfSpeech, string interpretation, int order = 0)
        {
            if (!Enum.IsDefined(typeof(PartOfSpeech), partOfSpeech))
                throw new HangerdException("未知词性");

            if (string.IsNullOrWhiteSpace(interpretation))
                throw new HangerdException("释义内容不可为空");

            PartOfSpeech = partOfSpeech;
            Interpretation = interpretation;
            Order = order;
        }
        public string GetDefinitionSourceName(PartOfSpeech part)
        {
            if (part == WordNetAccess.PartOfSpeech.Noun)
                return NounDefinitionSourceName;
            else if (part == WordNetAccess.PartOfSpeech.Verb)
                return VerbDefinitionSourceName;
            else if (part == WordNetAccess.PartOfSpeech.Adj)
                return AdjDefinitionSourceName;
            else if (part == WordNetAccess.PartOfSpeech.Adv)
                return AdvDefinitionSourceName;

            return null;
        }
 public void AddMissingLookup(PartOfSpeech pos, String form, String lemma, List<String> predictedLemma)
 {
     switch (pos)
     {
         case PartOfSpeech.Noun:
             this.MissedNouns.Add(new LookupItem() { Form = form, Lemma = lemma, PredictedLemma = predictedLemma });
             break;
         case PartOfSpeech.Verb:
             this.MissedVerbs.Add(new LookupItem() { Form = form, Lemma = lemma, PredictedLemma = predictedLemma });
             break;
         case PartOfSpeech.Adjective:
             this.MissedAdjectives.Add(new LookupItem() { Form = form, Lemma = lemma, PredictedLemma = predictedLemma });
             break;
     }
 }
        public List<string> GetExactSynonyms(string word, PartOfSpeech part)
        {
            long[] indices;

            IDataSource<string, long[]> indexSource = plugenv.GetDataSource<string, long[]>(GetIndexSourceName(part));
            if (indexSource == null || !indexSource.TryGetValue(word, out indices) || indices.Length != 1)
                return null; // missing or ambiguous

            WordNetDefinition definition;

            IDataSource<long, WordNetDefinition> definitionSource = plugenv.GetDataSource<long, WordNetDefinition>(GetDefinitionSourceName(part));
            if (definitionSource == null || !definitionSource.TryGetValue(indices[0], out definition))
                return null; // missing

            return definition.Words;
        }
Пример #37
0
        private void findSP(List<int> allResultIds, PartOfSpeech PartOfSpeech, ObjectType type, List<int> excludeIds)
        {
            // из всех текущих id выбираем такие, которые являются заданным типом СЧР
            List<int> idsToAnalyze = new List<int>();
            foreach (var resultId in allResultIds)
            {
                if (_sentence.WordList.Exists(x => x.Id == resultId && x.PartOfSpeech.Value == PartOfSpeech.Value))
                    idsToAnalyze.Add(resultId);
            }

            foreach (var wordId in idsToAnalyze)
            {
                //ищем дочернее слово для СЧР
                List<SentenceWord> childWords = _sentence.WordList.FindAll(x => x.DOM == wordId && !excludeIds.Contains(x.Id));

                foreach (var childWord in childWords)
                {
                    // найдем в текущих результатах такой элемент, id которого либо равен исследуемому, либо в его ServiceParts присутствует исследуемый id - чтобы знать куда добавлять инфу
                    var resultItem = Result.Items.Find(x => x.Id == wordId);
                    if (resultItem == null)
                    {
                        foreach (var i in Result.Items)
                        {
                            if (i.ServiceParts.Concat(i.AddedWordsCase1).Concat(i.AddedWordsCase2).ToList().Exists(x => x.Id == wordId))
                                resultItem = i;
                        }
                    }

                    if (resultItem != null)
                    {
                        // если дочернего слова нет в списке предварительных элеметнов, то добавляем его вместо текущего элемента, присоединяя к нему СЧР с заданным типом СЧР
                        if (!allResultIds.Exists(x => x == childWord.Id))
                        {
                            Stage3ResultElement itemToAdd = new Stage3ResultElement();
                            itemToAdd.IsRestoredFromServicePart = true;
                            itemToAdd.CopyFromSourceWord(childWord);
                            itemToAdd.ObjectType = type;
                            List<SentenceWord> itemAddWords = itemToAdd.ServiceParts.Concat(itemToAdd.AddedWordsCase1).Concat(itemToAdd.AddedWordsCase2).ToList();
                            if (itemAddWords.Find(x => x.Id == wordId) == null)
                                itemToAdd.AddedWordsCase2.Add(_sentence.WordList.Find(x => x.Id == wordId));

                            itemAddWords = itemToAdd.ServiceParts.Concat(itemToAdd.AddedWordsCase1).Concat(itemToAdd.AddedWordsCase2).ToList();
                            if (itemAddWords.Find(x => x.Id == wordId) == null)
                                itemToAdd.AddedWordsCase2.Add(_sentence.WordList.Find(x => x.Id == resultItem.Id));

                            Result.Items.Remove(resultItem);

                            Result.Items.Add(itemToAdd);
                        }
                        // а если такое слово есть, то берем его и объединяем с СЧР, с заданным типом
                        else
                        {
                            List<SentenceWord> resultAddWords = resultItem.ServiceParts.Concat(resultItem.AddedWordsCase1).Concat(resultItem.AddedWordsCase2).ToList();

                            if (resultAddWords.Find(x => x.Id == wordId) == null && resultItem.Id != wordId)
                                resultItem.AddedWordsCase2.Add(_sentence.WordList.Find(x => x.Id == wordId));
                            Result.Items.RemoveAll(x => x.Id == wordId);
                        }
                    }
                    else
                        Debug.WriteLine("IPPI MainParts 583: resultItem == null, sentence " + allResultIds.ToString());

                    allResultIds = getAllMainPartsIds(type);
                }
            }
        }
        public string GetIndexSourceName(PartOfSpeech part)
        {
            if (part == WordNetAccess.PartOfSpeech.Noun)
                return NounIndexSourceName;
            else if (part == WordNetAccess.PartOfSpeech.Verb)
                return VerbIndexSourceName;
            else if (part == WordNetAccess.PartOfSpeech.Adj)
                return AdjIndexSourceName;
            else if (part == WordNetAccess.PartOfSpeech.Adv)
                return AdvIndexSourceName;

            return null;
        }
Пример #39
0
		public void InflectionClassInCompoundStemMsasIsRelevant()
		{
			IMoExoCompound compound = Cache.ServiceLocator.GetInstance<IMoExoCompoundFactory>().Create();
			Cache.LangProject.MorphologicalDataOA.CompoundRulesOS.Add(compound);
			IMoStemMsaFactory factStemMsa = Cache.ServiceLocator.GetInstance<IMoStemMsaFactory>();
			IMoStemMsa msaLeft = factStemMsa.Create();
			compound.LeftMsaOA = msaLeft;
			IMoStemMsa msaRight = factStemMsa.Create();
			compound.RightMsaOA = msaRight;
			IMoStemMsa msaTo = factStemMsa.Create();
			compound.ToMsaOA = msaTo;
			var propsToMonitor = new HashSet<Tuple<int, int>>();
			Assert.IsFalse(msaLeft.IsFieldRelevant(MoStemMsaTags.kflidInflectionClass, propsToMonitor),
				"Inflection Class should not be relevant for LeftMsa.");
			Assert.IsFalse(msaRight.IsFieldRelevant(MoStemMsaTags.kflidInflectionClass, propsToMonitor),
				"Inflection Class should not be relevant for RightMsa.");
			Assert.IsFalse(msaTo.IsFieldRelevant(MoStemMsaTags.kflidInflectionClass, propsToMonitor),
				"Inflection Class should not be relevant for ToMsa if it does not have a category.");
			IPartOfSpeech pos = new PartOfSpeech();
			Cache.LangProject.PartsOfSpeechOA.PossibilitiesOS.Add(pos);
			msaTo.PartOfSpeechRA = pos;
			Assert.IsTrue(msaTo.IsFieldRelevant(MoStemMsaTags.kflidInflectionClass, propsToMonitor),
				"Inflection Class should be relevant for ToMsa when it has a category.");
		}
 public WordGrammarInfo(string initialForm, PartOfSpeech partOfSpeech)
 {
     InitialForm = initialForm;
     PartOfSpeech = partOfSpeech;
 }
Пример #41
0
        private void findSP(List<int> allResultIds, PartOfSpeech PartOfSpeech)
        {
            // из всех текущих id выбираем такие, которые являются заданным типом СЧР
            List<int> idsToAnalyze = new List<int>();
            foreach (var resultId in allResultIds)
            {
                if (_sentence.WordList.Exists(x => x.Id == resultId && x.PartOfSpeech.Value == PartOfSpeech.Value))
                    idsToAnalyze.Add(resultId);
            }

            foreach (var wordId in idsToAnalyze)
            {
                //ищем дочернее слово для СЧР
                List<SentenceWord> childWords = _sentence.WordList.FindAll(x => x.DOM == wordId);

                foreach (var childWord in childWords)
                {
                    // найдем в текущих результатах такой элемент, id которого либо равен исследуемому, либо в его ServiceParts присутствует исследуемый id - чтобы знать куда добавлять инфу
                    var resultItem = Result.Items.Find(x => x.Id == wordId);
                    if (resultItem == null)
                    {
                        foreach (var i in Result.Items)
                        {
                            if (i.ServiceParts.Exists(x => x.Id == wordId))
                                resultItem = i;
                        }
                    }
                    Debug.Assert(resultItem != null);

                    // если дочернего слова нет в списке предварительных элеметнов, то добавляем его вместо текущего элемента, присоединяя к нему СЧР с заданным типом СЧР
                    if (!allResultIds.Exists(x => x == childWord.Id))
                    {
                        Stage2ResultElement itemToAdd = new Stage2ResultElement();
                        itemToAdd.IsRestoredFromServicePart = true;
                        itemToAdd.CopyFromSourceWord(childWord);
                        itemToAdd.IsConfirmed = true;
                        if (itemToAdd.ServiceParts.Find(x => x.Id == wordId) == null && itemToAdd.Id != wordId)
                            itemToAdd.ServiceParts.Add(_sentence.WordList.Find(x => x.Id == wordId));
                        Result.Items.Remove(resultItem);

                        Result.Items.Add(itemToAdd);
                    }
                    // а если такое слово есть, то берем его и объединяем с СЧР, с заданным типом
                    else
                    {
                        if (resultItem.ServiceParts.Find(x => x.Id == wordId) == null && resultItem.Id != wordId)
                            resultItem.ServiceParts.Add(_sentence.WordList.Find(x => x.Id == wordId));
                        Result.Items.RemoveAll(x => x.Id == wordId);

                    }

                    allResultIds = getAllMeaningPartsIds();
                }

            }
        }
 public void AddLookup(PartOfSpeech pos, CoNLLToken token) 
 {
     if (token.PredictedLemmas == null || (token.PredictedLemmas != null && token.PredictedLemmas.Count == 0))
     {
         this.AddMissingLookup(pos, token.Form, token.Lemma, token.PredictedLemmas);
     }
     else
     {
         if (token.PredictedLemmas.Count == 1)
         {
             this.AddWrongLookup(pos, token.Form, token.Lemma, token.PredictedLemmas);
         }
         else
         {
             this.AddAmbiguousLookup(pos, token.Form, token.Lemma, token.PredictedLemmas);
         }
     }
 }
Пример #43
0
		IPartOfSpeech IPartOfSpeechFactory.Create(Guid guid, ICmPossibilityList owner)
		{
			if (owner == null) throw new ArgumentNullException("owner");

			IPartOfSpeech pos;
			if (guid == Guid.Empty)
			{
				pos = Create();
			}
			else
			{
				int hvo = ((IDataReader)m_cache.ServiceLocator.GetInstance<IDataSetup>()).GetNextRealHvo();
				pos = new PartOfSpeech(m_cache, hvo, guid);
			}
			owner.PossibilitiesOS.Add(pos);
			return pos;
		}
Пример #44
0
		IPartOfSpeech IPartOfSpeechFactory.Create(Guid guid, IPartOfSpeech owner)
		{
			if (owner == null) throw new ArgumentNullException("owner");

			int hvo = ((IDataReader)m_cache.ServiceLocator.GetInstance<IDataSetup>()).GetNextRealHvo();

			var retval = new PartOfSpeech(m_cache, hvo, guid);
			owner.SubPossibilitiesOS.Add(retval);
			return retval;
		}