예제 #1
0
        /// <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);
                    }
                }
            }
        }
예제 #2
0
        /// <summary> Returns the analysis result list for all sentence in the result. When you use this method,
        /// you need to pay attention on the size of the data. If the size of data is big, it may show
        /// lower performance than using getResultOfSentence() repeatedly.
        ///
        /// The return type of the object depends on the analysis phase of the work flow so you must give
        /// the relevant type of parameter. In this way, you can get the analysis result with a relevant
        /// object, so you don't need to parse the result string again. If you just want to see the result,
        /// consider to use "String getResultOfDocument()" instead.
        ///
        /// </summary>
        /// <param name="<T>">- One of PlainSentence (for the first phase), Sentence (for the second phase), and SetOfSentences (for the third phase).
        /// </param>
        /// <param name="a">- the object to specify the return type
        /// </param>
        /// <returns> the list of the analysis result for all sentences in the document
        /// </returns>
        /// <throws>  ResultTypeException </throws>
        public LinkedList <T> getResultOfDocument <T>(T a)  where T : class
        {
            Type           objClass = a.GetType();
            LinkedList <T> list     = new LinkedList <T>();

            try
            {
                if (typeof(PlainSentence).Equals(objClass))
                {
                    if (outputPhaseNum != 1)
                    {
                        throw new ResultTypeException(outputPhaseNum);
                    }
                    LinkedBlockingQueue <PlainSentence> queue = queuePhase1[outputQueueNum];
                    while (true)
                    {
                        PlainSentence ps = queue.Take();
                        list.AddLast(ps as T);
                        if (ps.EndOfDocument)
                        {
                            break;
                        }
                    }
                }
                else if (typeof(SetOfSentences).Equals(objClass))
                {
                    if (outputPhaseNum != 2)
                    {
                        throw new ResultTypeException(outputPhaseNum);
                    }
                    LinkedBlockingQueue <SetOfSentences> queue = queuePhase2[outputQueueNum];
                    while (true)
                    {
                        SetOfSentences sos = queue.Take();
                        list.AddLast(sos as T);
                        if (sos.EndOfDocument)
                        {
                            break;
                        }
                    }
                }
                else if (typeof(Sentence).Equals(objClass))
                {
                    if (outputPhaseNum != 3)
                    {
                        throw new ResultTypeException(outputPhaseNum);
                    }
                    LinkedBlockingQueue <Sentence> queue = queuePhase3[outputQueueNum];
                    while (true)
                    {
                        Sentence sent = queue.Take();
                        list.AddLast(sent as T);
                        if (sent.EndOfDocument)
                        {
                            break;
                        }
                    }
                }
                else
                {
                    throw new ResultTypeException(outputPhaseNum);
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.ToString());
            }
            return(list);
        }