Esempio n. 1
0
 private void Run()
 {
     while (m_keepThreadAlive)
     {
         NlpQuery pending = null;
         if (m_requestQueue.TryDequeue(out pending))
         {
             var analysis = AnalyseText(pending);
             m_responseBucket.AddOrUpdate(pending.Id, analysis, (key, prev) => analysis);
             m_waitEvent.Set();
         }
         else
         {
             Thread.Sleep(500);
         }
     }
 }
Esempio n. 2
0
        private NlpAnalysis AnalyseText(NlpQuery query)
        {
            var analysis = new NlpAnalysis();

            if (IsInitialized)
            {
                var text       = query.Text;
                var annotation = new Annotation(text);
                m_pipeline.annotate(annotation);

                var sentences = annotation.get(typeof(CoreAnnotations.SentencesAnnotation)) as ArrayList;
                if (sentences != null)
                {
                    analysis.Sentences = sentences;
                }
            }
            return(analysis);
        }
Esempio n. 3
0
        public NlpAnalysis AnalyseText(string queryText)
        {
            var analysis = new NlpAnalysis();

            if (IsInitialized)
            {
                var query = new NlpQuery(queryText);
                m_requestQueue.Enqueue(query);
                m_waitEvent.WaitOne();

                if (!m_responseBucket.TryRemove(query.Id, out analysis))
                {
                    throw new Exception("Could not remove analysis from the bucket.");
                }
            }
            else
            {
                throw new InvalidOperationException("NlpEngineThread not yet initialized");
            }
            return(analysis);
        }