예제 #1
0
        public bool UpdateWordform(IWfiWordform wordform, ParserPriority priority)
        {
            CheckDisposed();

            int       wordformHash = 0;
            ITsString form         = null;
            int       hvo          = 0;

            using (new WorkerThreadReadHelper(m_cache.ServiceLocator.GetInstance <IWorkerThreadReadHandler>()))
            {
                if (wordform.IsValidObject)
                {
                    wordformHash = wordform.Checksum;
                    form         = wordform.Form.VernacularDefaultWritingSystem;
                }
            }
            // 'form' will now be null, if it could not find the wordform for whatever reason.
            // uiCRCWordform will also now be 0, if 'form' is null.
            if (form == null || string.IsNullOrEmpty(form.Text))
            {
                return(false);
            }

            CheckNeedsUpdate();
            ParseResult result = m_parser.ParseWord(
                CustomIcu.GetIcuNormalizer(FwNormalizationMode.knmNFD)
                .Normalize(form.Text.Replace(' ', '.')));

            if (wordformHash == result.GetHashCode())
            {
                return(false);
            }

            return(m_parseFiler.ProcessParse(wordform, priority, result));
        }
예제 #2
0
        /// <summary>
        /// Try parsing a wordform, optionally getting a trace of the parse
        /// </summary>
        /// <param name="sForm">the word form to parse</param>
        /// <param name="fDoTrace">whether or not to trace the parse</param>
        /// <param name="sSelectTraceMorphs">list of msa hvos to limit trace to </param>
        public void TryAWord(string sForm, bool fDoTrace, int[] sSelectTraceMorphs)
        {
            CheckDisposed();

            if (sForm == null)
            {
                throw new ArgumentNullException("sForm", "TryAWord cannot trace a Null string.");
            }
            if (sForm == String.Empty)
            {
                throw new ArgumentException("Can't try a word with no content.", "sForm");
            }

            CheckNeedsUpdate();
            using (var task = new TaskReport(string.Format(ParserCoreStrings.ksTraceWordformX, sForm), m_taskUpdateHandler))
            {
                string normForm = CustomIcu.GetIcuNormalizer(FwNormalizationMode.knmNFD).Normalize(sForm);
                task.Details = fDoTrace ? m_parser.TraceWordXml(normForm, sSelectTraceMorphs) : m_parser.ParseWordXml(normForm);
            }
        }
예제 #3
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Normalizes the strings read from the file into D (compatible decomposed).
 /// </summary>
 /// ------------------------------------------------------------------------------------
 private void NormalizeFileData()
 {
     // The following list of control characters should never appear in plain Unicode
     // data.
     char[] controlChars =
     {
         '\x01', '\x02', '\x03', '\x04', '\x05', '\x06', '\x07', '\x08', '\x0E', '\x0F',
         '\x10', '\x11', '\x12', '\x13', '\x14', '\x15', '\x16', '\x17', '\x18', '\x19',
         '\x1A', '\x1B', '\x7F'
     };
     for (int i = 0; i < m_fileData.Length; i++)
     {
         if (m_fileData[i].Length > 0)
         {
             if (m_fileData[i].IndexOfAny(controlChars) >= 0)
             {
                 throw new Exception(FWCoreDlgsErrors.ksInvalidControlCharacterFound);
             }
             m_fileData[i] = CustomIcu.GetIcuNormalizer(FwNormalizationMode.knmNFD)
                             .Normalize(m_fileData[i]);
         }
     }
 }