Пример #1
0
        /// <summary>
        /// Load one wordform from DB 'reader'.
        /// As long as the wf id is the same, then keep going,
        /// as it is the same wordform.
        /// </summary>
        /// <param name="reader">'true' if there are more rows (wordforms) to process, otherwise, 'false'.</param>
        /// <returns></returns>
        internal bool LoadFromDB(SqlDataReader reader)
        {
            bool moreRows = true;             // Start on the optimistic side.

            if (m_id == 0)
            {
                int analId = reader.GetInt32(1);
                m_id = analId;
                while (moreRows && (reader.GetInt32(1) == m_id))
                {
                    int wfId = reader.GetInt32(0);
                    analId = reader.GetInt32(1);
                    int ord      = reader.GetInt32(2);
                    int senseId  = reader.IsDBNull(3) ? 0 : reader.GetInt32(3);
                    int morphId  = reader.IsDBNull(4) ? 0 : reader.GetInt32(4);
                    int msaId    = reader.IsDBNull(5) ? 0 : reader.GetInt32(5);
                    int msaClass = reader.IsDBNull(6) ? 0 : reader.GetInt32(6);
                    //Debug.WriteLine(String.Format("wfId: {0} analId: {1} ord: {2} senseId: {3} morphId:> {4} msaId: {5} msaClass: {6}",
                    //	wfId, analId, ord, senseId, morphId, msaId, msaClass));
                    FwMorphBundle mb = new FwMorphBundle(
                        ord,
                        senseId,
                        morphId,
                        new FwMsa(msaId, msaClass));
                    moreRows = reader.Read();
                    m_morphBundles.Add(ord, mb);
                }
            }

            return(moreRows);
        }
Пример #2
0
		/// <summary>
		/// Load one wordform from DB 'reader'.
		/// As long as the wf id is the same, then keep going,
		/// as it is the same wordform.
		/// </summary>
		/// <param name="reader">'true' if there are more rows (wordforms) to process, otherwise, 'false'.</param>
		/// <returns></returns>
		internal bool LoadFromDB(SqlDataReader reader)
		{
			bool moreRows = true; // Start on the optimistic side.

			if (m_id == 0)
			{
				int analId = reader.GetInt32(1);
				m_id = analId;
				while (moreRows && (reader.GetInt32(1) == m_id))
				{
					int wfId = reader.GetInt32(0);
					analId = reader.GetInt32(1);
					int ord = reader.GetInt32(2);
					int senseId = reader.IsDBNull(3) ? 0 : reader.GetInt32(3);
					int morphId = reader.IsDBNull(4) ? 0 : reader.GetInt32(4);
					int msaId = reader.IsDBNull(5) ? 0 : reader.GetInt32(5);
					int msaClass = reader.IsDBNull(6) ? 0 : reader.GetInt32(6);
					//Debug.WriteLine(String.Format("wfId: {0} analId: {1} ord: {2} senseId: {3} morphId:> {4} msaId: {5} msaClass: {6}",
					//	wfId, analId, ord, senseId, morphId, msaId, msaClass));
					FwMorphBundle mb = new FwMorphBundle(
						ord,
						senseId,
						morphId,
						new FwMsa(msaId, msaClass));
					moreRows = reader.Read();
					m_morphBundles.Add(ord, mb);
				}
			}

			return moreRows;
		}
Пример #3
0
        internal void Convert(SqlCommand cmd, GAFAWSData gData, Dictionary <string, FwMsa> prefixes, Dictionary <string, List <FwMsa> > stems, Dictionary <string, FwMsa> suffixes)
        {
            if (!CanConvert)
            {
                return;
            }

            WordRecord wr = new WordRecord();
            // Deal with prefixes, if any.
            int startStemOrd = 0;

            foreach (KeyValuePair <int, FwMorphBundle> kvp in m_morphBundles)
            {
                FwMorphBundle mb     = kvp.Value;
                string        msaKey = mb.GetMsaKey(cmd);
                if (mb.MSA.Class == 5001 || mb.MSA.Class == 5031 || mb.MSA.Class == 5032 || mb.MSA.Class == 5117)                 // What about 5117-MoUnclassifiedAffixMsa?
                {
                    // stem or derivational prefix, so bail out of this loop.
                    startStemOrd = kvp.Key;
                    break;
                }

                // Add prefix, if not already present.
                if (wr.Prefixes == null)
                {
                    wr.Prefixes = new List <Affix>();
                }
                if (!prefixes.ContainsKey(msaKey))
                {
                    prefixes.Add(msaKey, mb.MSA);
                    gData.Morphemes.Add(new Morpheme(MorphemeType.prefix, msaKey));
                }
                Affix afx = new Affix();
                afx.MIDREF = msaKey;
                wr.Prefixes.Add(afx);
            }

            // Deal with suffixes, if any.
            // Work through the suffixes from the end of the word.
            // We stop when we hit the stem or a derivational suffix.
            int endStemOrd = 0;

            for (int i = m_morphBundles.Count; i > 0; --i)
            {
                FwMorphBundle mb     = m_morphBundles[i];
                string        msaKey = mb.GetMsaKey(cmd);
                if (mb.MSA.Class == 5001 || mb.MSA.Class == 5031 || mb.MSA.Class == 5032 || mb.MSA.Class == 5117)                 // What about 5117-MoUnclassifiedAffixMsa?
                {
                    // stem or derivational suffix, so bail out of this loop.
                    endStemOrd = i;
                    break;
                }

                // Add suffix, if not already present.
                if (wr.Suffixes == null)
                {
                    wr.Suffixes = new List <Affix>();
                }
                if (!suffixes.ContainsKey(msaKey))
                {
                    suffixes.Add(msaKey, mb.MSA);
                    gData.Morphemes.Add(new Morpheme(MorphemeType.suffix, msaKey));
                }
                Affix afx = new Affix();
                afx.MIDREF = msaKey;
                wr.Suffixes.Insert(0, afx);
            }

            // Deal with stem.
            List <FwMsa> localStems = new List <FwMsa>();
            string       sStem      = "";

            foreach (KeyValuePair <int, FwMorphBundle> kvp in m_morphBundles)
            {
                FwMorphBundle mb         = kvp.Value;
                int           currentOrd = kvp.Key;
                if (currentOrd >= startStemOrd && currentOrd <= endStemOrd)
                {
                    string msaKey = mb.GetMsaKey(cmd);
                    string spacer = (currentOrd == 1) ? "" : " ";
                    sStem += spacer + msaKey;
                }
            }
            if (!stems.ContainsKey(sStem))
            {
                stems.Add(sStem, localStems);
                gData.Morphemes.Add(new Morpheme(MorphemeType.stem, sStem));
            }

            Stem stem = new Stem();

            stem.MIDREF = sStem;
            wr.Stem     = stem;

            // Add wr.
            gData.WordRecords.Add(wr);
        }