Ejemplo n.º 1
0
        /// <summary> It activates the work flow with the plug-ins that were set up. The work flow can be activated in
        /// the thread mode where each plug-in works on its own thread. It may show better performance
        /// in the machines with multi-processor.
        ///
        /// </summary>
        /// <param name="threadMode">- true: multi-thread mode, false: sigle thread mode
        /// </param>
        /// <throws>  Exception  </throws>
        public virtual void activateWorkflow(bool threadMode)
        {
            if (threadMode)
            {
                isThreadMode = true;

                // initialize the first phase supplement plug-ins and the communication queues
                LinkedBlockingQueue <PlainSentence> in1  = null;
                LinkedBlockingQueue <PlainSentence> out1 = new LinkedBlockingQueue <PlainSentence>();

                queuePhase1.Add(out1);

                for (int i = 0; i < plainTextPluginCnt; i++)
                {
                    in1  = out1;
                    out1 = new LinkedBlockingQueue <PlainSentence>();
                    queuePhase1.Add(out1);

                    plainTextProcessors[i].initialize(baseDir, plainTextProcessorsConfFiles[i]);
                    threadList.AddLast(new PlainTextProcThread(plainTextProcessors[i], in1, out1));
                }

                if (morphAnalyzer == null)
                {
                    outputPhaseNum = 1;
                    outputQueueNum = plainTextPluginCnt;
                    runThreads();
                    return;
                }
                in1 = out1;

                // initialize the second phase major plug-in and the communication queues
                LinkedBlockingQueue <SetOfSentences> in2  = null;
                LinkedBlockingQueue <SetOfSentences> out2 = new LinkedBlockingQueue <SetOfSentences>();

                queuePhase2.Add(out2);
                morphAnalyzer.initialize(baseDir, morphAnalyzerConfFile);

                threadList.AddLast(new MorphAnalyzerThread(morphAnalyzer, in1, out2));

                // initialize the second phase supplement plug-ins and the communication queues
                for (int i = 0; i < morphemePluginCnt; i++)
                {
                    in2  = out2;
                    out2 = new LinkedBlockingQueue <SetOfSentences>();

                    queuePhase2.Add(out2);
                    morphemeProcessors[i].initialize(baseDir, morphemeProcessorsConfFiles[i]);

                    threadList.AddLast(new MorphemeProcThread(morphemeProcessors[i], in2, out2));
                }

                if (posTagger == null)
                {
                    outputPhaseNum = 2;
                    outputQueueNum = morphemePluginCnt;
                    runThreads();
                    return;
                }
                in2 = out2;

                // initialize the third phase major plug-in and the communication queues
                LinkedBlockingQueue <Sentence> in3  = null;
                LinkedBlockingQueue <Sentence> out3 = new LinkedBlockingQueue <Sentence>();

                posTagger.initialize(baseDir, posTaggerConfFile);
                queuePhase3.Add(out3);

                threadList.AddLast(new PosTaggerThread(posTagger, in2, out3));

                // initialize the third phase supplement plug-ins and the communication queues
                for (int i = 0; i < posPluginCnt; i++)
                {
                    in3  = out3;
                    out3 = new LinkedBlockingQueue <Sentence>();

                    queuePhase3.Add(out3);
                    posProcessors[i].initialize(baseDir, posProcessorConfFiles[i]);

                    threadList.AddLast(new PosProcThread(posProcessors[i], in3, out3));
                }

                outputPhaseNum = 3;
                outputQueueNum = posPluginCnt;
                runThreads();
            }
            else
            {
                isThreadMode = false;

                // initialize the first phase supplement plug-ins and the communication queues
                queuePhase1.Add(new LinkedBlockingQueue <PlainSentence>());

                for (int i = 0; i < plainTextPluginCnt; i++)
                {
                    plainTextProcessors[i].initialize(baseDir, plainTextProcessorsConfFiles[i]);
                    queuePhase1.Add(new LinkedBlockingQueue <PlainSentence>());
                }

                if (morphAnalyzer == null)
                {
                    outputPhaseNum = 1;
                    outputQueueNum = plainTextPluginCnt;
                    return;
                }

                // initialize the second phase major plug-in and the communication queue
                morphAnalyzer.initialize(baseDir, morphAnalyzerConfFile);
                queuePhase2.Add(new LinkedBlockingQueue <SetOfSentences>());

                // initialize the second phase supplement plug-ins and the communication queues
                for (int i = 0; i < morphemePluginCnt; i++)
                {
                    morphemeProcessors[i].initialize(baseDir, morphemeProcessorsConfFiles[i]);
                    queuePhase2.Add(new LinkedBlockingQueue <SetOfSentences>());
                }

                if (posTagger == null)
                {
                    outputPhaseNum = 2;
                    outputQueueNum = morphemePluginCnt;
                    return;
                }

                // initialize the third phase major plug-in and the communication queue
                posTagger.initialize(baseDir, posTaggerConfFile);
                queuePhase3.Add(new LinkedBlockingQueue <Sentence>());

                // initialize the third phase supplement plug-in and the communication queues
                for (int i = 0; i < posPluginCnt; i++)
                {
                    posProcessors[i].initialize(baseDir, posProcessorConfFiles[i]);
                    queuePhase3.Add(new LinkedBlockingQueue <Sentence>());
                }

                outputPhaseNum = 3;
                outputQueueNum = posPluginCnt;
            }
        }