/// <summary> /// returns the number of the Wordforms in the low priority queue. /// </summary> public int GetQueueSize(ParserPriority priority) { CheckDisposed(); lock (SyncRoot) return(m_queueCounts[(int)priority]); }
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(Icu.Normalize(form.Text.Replace(' ', '.'), Icu.UNormalizationMode.UNORM_NFD)); if (wordformHash == result.GetHashCode()) { return(false); } return(m_parseFiler.ProcessParse(wordform, priority, result)); }
/// <summary> /// Process the parse result. /// </summary> /// <param name="wordform">The wordform.</param> /// <param name="priority">The priority.</param> /// <param name="parseResult">The parse result.</param> public bool ProcessParse(IWfiWordform wordform, ParserPriority priority, ParseResult parseResult) { lock (m_syncRoot) m_workQueue.Enqueue(new WordformUpdateWork(wordform, priority, parseResult)); m_idleQueue.Add(IdleQueuePriority.Low, UpdateWordforms); return(true); }
private void FireWordformUpdated(IWfiWordform wordform, ParserPriority priority) { if (WordformUpdated != null) { WordformUpdated(this, new WordformUpdatedEventArgs(wordform, priority)); } }
public bool UpdateWordform(IWfiWordform wordform, ParserPriority priority) { CheckDisposed(); uint crcWordform = 0; ITsString form = null; int hvo = 0; using (new WorkerThreadReadHelper(m_cache.ServiceLocator.GetInstance <IWorkerThreadReadHandler>())) { if (wordform.IsValidObject) { crcWordform = (uint)wordform.Checksum; form = wordform.Form.VernacularDefaultWritingSystem; hvo = wordform.Hvo; } } // '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(); string result = GetOneWordformResult(hvo, form.Text.Replace(' ', '.')); // LT-7334 to allow for phrases uint crc = CrcStream.GetCrc(result); if (crcWordform == crc) { return(false); } return(m_parseFiler.ProcessParse(priority, result, crc)); }
public void ScheduleWordformsForUpdate(IEnumerable <IWfiWordform> wordforms, ParserPriority priority) { CheckDisposed(); foreach (var wordform in wordforms) { ScheduleOneWordformForUpdate(wordform, priority); } }
public ParseResult(IWfiWordform wordform, uint crc, ParserPriority priority, IList <ParseAnalysis> analyses, string errorMessage) { Wordform = wordform; Crc = crc; Priority = priority; Analyses = analyses; ErrorMessage = errorMessage; }
/// <summary> /// Process the XML data. /// </summary> /// <param name="priority">The priority.</param> /// <param name="parse">The XML data to process.</param> /// <param name="crc">The CRC.</param> /// <remarks> /// The 'parser' XML string may, or may not, be well formed XML. /// If there is an Exception node in the XML, then it may not be well-formed XML beyond that node, /// since the XAmple parser may have choked. /// This is why we can't use a DOM to get all of the XML, but we have to read it as it goes by in a stream. /// /// ENHANCE (DamienD): right now we are not supporting malformed XML /// </remarks> public bool ProcessParse(ParserPriority priority, string parse, uint crc) { var wordformElem = XElement.Parse(parse); string errorMessage = null; var exceptionElem = wordformElem.Element("Exception"); if (exceptionElem != null) { var totalAnalysesValue = (string)exceptionElem.Attribute("totalAnalyses"); switch ((string)exceptionElem.Attribute("code")) { case "ReachedMaxAnalyses": errorMessage = String.Format(ParserCoreStrings.ksReachedMaxAnalysesAllowed, totalAnalysesValue); break; case "ReachedMaxBufferSize": errorMessage = String.Format(ParserCoreStrings.ksReachedMaxInternalBufferSize, totalAnalysesValue); break; } } else { errorMessage = (string)wordformElem.Element("Error"); } try { ParseResult result; using (new WorkerThreadReadHelper(m_cache.ServiceLocator.GetInstance <IWorkerThreadReadHandler>())) { var wordform = m_wordformRepository.GetObject((int)wordformElem.Attribute("DbRef")); IList <ParseAnalysis> analyses = null; analyses = (from analysisElem in wordformElem.Descendants("WfiAnalysis") let morphs = from morphElem in analysisElem.Descendants("Morph") let morph = CreateParseMorph(morphElem) where morph != null select morph where morphs.Any() select new ParseAnalysis(morphs.ToList())).ToList(); result = new ParseResult(wordform, crc, priority, analyses, errorMessage); } lock (m_syncRoot) m_resultQueue.Enqueue(result); m_idleQueue.Add(IdleQueuePriority.Low, UpdateWordforms); return(true); } catch (KeyNotFoundException) { // a wordform, form, or MSA no longer exists, so skip this parse result } return(false); }
private void DecrementQueueCount(ParserPriority priority) { bool isIdle; lock (SyncRoot) { m_queueCounts[(int)priority]--; isIdle = m_queueCounts[(int)ParserPriority.TryAWord] == 0 && m_queueCounts[(int)ParserPriority.Low] == 0 && m_queueCounts[(int)ParserPriority.Medium] == 0 && m_queueCounts[(int)ParserPriority.High] == 0; } if (isIdle && (m_TaskReport == null || m_TaskReport.Description == ParserCoreStrings.ksIdle_)) { if (m_TaskReport != null) { m_TaskReport.Dispose(); } m_TaskReport = new TaskReport(ParserCoreStrings.ksIdle_, HandleTaskUpdate); } }
public void UpdateWordform(IWfiWordform wordform, ParserPriority priority) { CheckDisposed(); m_scheduler.ScheduleOneWordformForUpdate(wordform, priority); }
public void ScheduleOneWordformForUpdate(IWfiWordform wordform, ParserPriority priority) { CheckDisposed(); m_thread.EnqueueWork(priority, new UpdateWordformWork(this, priority, wordform)); }
public WordformUpdatedEventArgs(IWfiWordform wordform, ParserPriority priority) { Wordform = wordform; Priority = priority; }
public WordformUpdateWork(IWfiWordform wordform, ParserPriority priority, ParseResult parseResult) { m_wordform = wordform; m_priority = priority; m_parseResult = parseResult; }
public void UpdateWordforms(IEnumerable <IWfiWordform> wordforms, ParserPriority priority) { CheckDisposed(); m_scheduler.ScheduleWordformsForUpdate(wordforms, priority); }
public void ScheduleWordformsForUpdate(IEnumerable<IWfiWordform> wordforms, ParserPriority priority) { CheckDisposed(); foreach (var wordform in wordforms) ScheduleOneWordformForUpdate(wordform, priority); }
private void DecrementQueueCount(ParserPriority priority) { bool isIdle; lock (SyncRoot) { m_queueCounts[(int) priority]--; isIdle = m_queueCounts[(int)ParserPriority.TryAWord] == 0 && m_queueCounts[(int)ParserPriority.Low] == 0 && m_queueCounts[(int)ParserPriority.Medium] == 0 && m_queueCounts[(int)ParserPriority.High] == 0; } if (isIdle && (m_TaskReport == null || m_TaskReport.Description == ParserCoreStrings.ksIdle_)) { if (m_TaskReport != null) m_TaskReport.Dispose(); m_TaskReport = new TaskReport(ParserCoreStrings.ksIdle_, HandleTaskUpdate); } }
private void IncrementQueueCount(ParserPriority priority) { lock (SyncRoot) m_queueCounts[(int) priority]++; }
/// <summary> /// returns the number of the Wordforms in the low priority queue. /// </summary> public int GetQueueSize(ParserPriority priority) { CheckDisposed(); lock (SyncRoot) return m_queueCounts[(int) priority]; }
protected ParserWork(ParserScheduler scheduler, ParserPriority priority) { m_scheduler = scheduler; m_priority = priority; m_scheduler.IncrementQueueCount(m_priority); }
public UpdateWordformWork(ParserScheduler scheduler, ParserPriority priority, IWfiWordform wordform) : base(scheduler, priority) { m_wordform = wordform; }
/// <summary> /// Process the parse result. /// </summary> /// <param name="wordform">The wordform.</param> /// <param name="priority">The priority.</param> /// <param name="parseResult">The parse result.</param> public bool ProcessParse(IWfiWordform wordform, ParserPriority priority, ParseResult parseResult) { lock (m_syncRoot) m_workQueue.Enqueue(new WordformUpdateWork(wordform, priority, parseResult)); m_idleQueue.Add(IdleQueuePriority.Low, UpdateWordforms); return true; }
public int GetQueueSize(ParserPriority priority) { CheckDisposed(); return(m_scheduler.GetQueueSize(priority)); }
public void UpdateWordforms(IEnumerable<IWfiWordform> wordforms, ParserPriority priority) { CheckDisposed(); m_scheduler.ScheduleWordformsForUpdate(wordforms, priority); }
public int GetQueueSize(ParserPriority priority) { CheckDisposed(); return m_scheduler.GetQueueSize(priority); }
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(Icu.Normalize(form.Text.Replace(' ', '.'), Icu.UNormalizationMode.UNORM_NFD)); if (wordformHash == result.GetHashCode()) return false; return m_parseFiler.ProcessParse(wordform, priority, result); }
private void IncrementQueueCount(ParserPriority priority) { lock (SyncRoot) m_queueCounts[(int)priority]++; }
private void FireWordformUpdated(IWfiWordform wordform, ParserPriority priority) { if (WordformUpdated != null) WordformUpdated(this, new WordformUpdatedEventArgs(wordform, priority)); }