override public void Run() { PlainSentence ps = null; try { while (true) { ps = in_Renamed.Take(); if ((ps = plainTextProcessor.doProcess(ps)) != null) { out_Renamed.Add(ps); } while (plainTextProcessor.hasRemainingData()) { if ((ps = plainTextProcessor.doProcess(null)) != null) { out_Renamed.Add(ps); } } if ((ps = plainTextProcessor.flush()) != null) { out_Renamed.Add(ps); } } } catch (System.Threading.ThreadInterruptedException e) { plainTextProcessor.shutdown(); } }
/// <summary> It adds the specified input text to the input queue of the work flow. After this method, /// you are allowed to get the analysis result by using one of the following methods: /// /// - getResultOfSentence() : to get the result for one sentence at the front of result queue /// - getResultOfDocument() : to get the entire result for all sentences /// /// If the input document is not small, getResultOfDocument() may show lower performance, and it /// could be better to call getResultOfSentence() repeatedly. You need to pay attention on this. /// /// </summary> /// <param name="document">- the path for the text file to be analyzed /// </param> /// <throws> IOException </throws> public virtual void analyze(System.IO.FileInfo document) { System.IO.StreamReader br = new System.IO.StreamReader(document.FullName, System.Text.Encoding.UTF8); LinkedBlockingQueue <PlainSentence> queue = queuePhase1[0]; if (queue == null) { return; } System.String line = null; int i = 0; while ((line = br.ReadLine()) != null) { if (br.Peek() != -1) { queue.Add(new PlainSentence(0, i++, false, line.Trim())); } else { queue.Add(new PlainSentence(0, i++, true, line.Trim())); break; } } br.Close(); if (!isThreadMode) { analyzeInSingleThread(); } }
protected override bool DoSend(IMessage message, TimeSpan timeout) { if (message == null) { return(false); } // TODO check success of sending the message _queue.Add(message); return(true); }
/// <summary> It adds the specified input text to the input queue of the work flow. After this method, /// you are allowed to get the analysis result by using one of the following methods: /// /// - getResultOfSentence() : to get the result for one sentence at the front of result queue /// - getResultOfDocument() : to get the entire result for all sentences /// /// If the input document is not small, getResultOfDocument() may show lower performance, and it /// could be better to call getResultOfSentence() repeatedly. You need to pay attention on this. /// /// </summary> /// <param name="document">- sequence of sentences separated with newlines. /// </param> public virtual void analyze(System.String document) { System.String[] strArray = document.Split("\n"); LinkedBlockingQueue <PlainSentence> queue = queuePhase1[0]; if (queue == null) { return; } for (int i = 0; i < strArray.Length - 1; i++) { queue.Add(new PlainSentence(0, i, false, strArray[i].Trim())); } queue.Add(new PlainSentence(0, strArray.Length - 1, true, strArray[strArray.Length - 1].Trim())); if (!isThreadMode) { analyzeInSingleThread(); } }
override public void Run() { Sentence sent = null; try { while (true) { sent = in_Renamed.Take(); if ((sent = posProcessor.doProcess(sent)) != null) { out_Renamed.Add(sent); } } } catch (System.Threading.ThreadInterruptedException e) { posProcessor.shutdown(); } }
override public void Run() { SetOfSentences sos = null; try { while (true) { sos = in_Renamed.Take(); if ((sos = morphProcessor.doProcess(sos)) != null) { out_Renamed.Add(sos); } } } catch (System.Threading.ThreadInterruptedException e) { morphProcessor.shutdown(); } }
override public void Run() { SetOfSentences sos = null; Sentence sent = null; try { while (true) { sos = in_Renamed.Take(); if ((sent = tagger.tagPOS(sos)) != null) { out_Renamed.Add(sent); } } } catch (System.Threading.ThreadInterruptedException e) { tagger.shutdown(); } }
override public void Run() { PlainSentence ps = null; SetOfSentences sos = null; try { while (true) { ps = in_Renamed.Take(); if ((sos = ma.morphAnalyze(ps)) != null) { out_Renamed.Add(sos); } } } catch (System.Threading.ThreadInterruptedException e) { ma.shutdown(); } }
/// <summary> Analyze the text in the single thread. </summary> private void analyzeInSingleThread() { // first phase if (plainTextPluginCnt == 0) { return; } LinkedBlockingQueue <PlainSentence> inQueue1 = null; LinkedBlockingQueue <PlainSentence> outQueue1 = null; PlainSentence ps = null; outQueue1 = queuePhase1[0]; for (int i = 0; i < plainTextPluginCnt; i++) { inQueue1 = outQueue1; outQueue1 = queuePhase1[i + 1]; while ((ps = inQueue1.Poll()) != null) { if ((ps = plainTextProcessors[i].doProcess(ps)) != null) { outQueue1.Add(ps); } while (plainTextProcessors[i].hasRemainingData()) { if ((ps = plainTextProcessors[i].doProcess(null)) != null) { outQueue1.Add(ps); } } if ((ps = plainTextProcessors[i].flush()) != null) { outQueue1.Add(ps); } } } // second phase if (morphAnalyzer == null) { return; } LinkedBlockingQueue <SetOfSentences> inQueue2 = null; LinkedBlockingQueue <SetOfSentences> outQueue2 = null; SetOfSentences sos = null; inQueue1 = outQueue1; outQueue2 = queuePhase2[0]; while ((ps = inQueue1.Poll()) != null) { if ((sos = morphAnalyzer.morphAnalyze(ps)) != null) { outQueue2.Add(sos); } } if (morphemePluginCnt == 0) { return; } for (int i = 0; i < morphemePluginCnt; i++) { inQueue2 = outQueue2; outQueue2 = queuePhase2[i + 1]; while ((sos = inQueue2.Poll()) != null) { if ((sos = morphemeProcessors[i].doProcess(sos)) != null) { outQueue2.Add(sos); } } } // third phase if (posTagger == null) { return; } LinkedBlockingQueue <Sentence> inQueue3 = null; LinkedBlockingQueue <Sentence> outQueue3 = null; Sentence sent = null; inQueue2 = outQueue2; outQueue3 = queuePhase3[0]; while ((sos = inQueue2.Poll()) != null) { if ((sent = posTagger.tagPOS(sos)) != null) { outQueue3.Add(sent); } } if (posPluginCnt == 0) { return; } for (int i = 0; i < posPluginCnt; i++) { inQueue3 = outQueue3; outQueue3 = queuePhase3[i + 1]; while ((sent = inQueue3.Poll()) != null) { if ((sent = posProcessors[i].doProcess(sent)) != null) { outQueue3.Add(sent); } } } }
public void TestAdd() { try { LinkedBlockingQueue<String> q = new LinkedBlockingQueue<String>(SIZE); for (int i = 0; i < SIZE; ++i) { Assert.IsTrue(q.Add(i.ToString())); } Assert.AreEqual(0, q.RemainingCapacity()); q.Add(SIZE.ToString()); } catch (IllegalStateException) { } }
public void TestAddNull() { try { LinkedBlockingQueue<String> q = new LinkedBlockingQueue<String>(); q.Add(null); ShouldThrow(); } catch (NullReferenceException) {} }
public void TestEmptyFull() { LinkedBlockingQueue<String> q = new LinkedBlockingQueue<String>(2); Assert.IsTrue(q.IsEmpty()); Assert.AreEqual(2, q.RemainingCapacity(), "should have room for 2"); q.Add(one); Assert.IsFalse(q.IsEmpty()); q.Add(two); Assert.IsFalse(q.IsEmpty()); Assert.AreEqual(0, q.RemainingCapacity()); Assert.IsFalse(q.Offer(three)); }