cz.cuni.mff.procasor.parsingTools.parser
Class Parser

java.lang.Object
  extended bycz.cuni.mff.procasor.parsingTools.parser.Parser

public class Parser
extends java.lang.Object

The class where runs parsing tools. Parser translates the sentence into parse tree. Manages all user's communication with lingsvistic tools (we call them Parser Tools). Parsing tools are connected together with system of pipes, which we call the PipeLine. Sentence is subsequently processed by parsing tools - PipeLine. The final result of these operations is stored in xml format. Parser creates all instances of Parsing Tools, connect them into the sequence of pipes and processes which together form the PipeLine.

Author:
ales

Field Summary
 boolean isRunning
          true if the Pipeline is running
 boolean isStarting
          true if the Pipeline is starting
 int running
          0 - the pipeline is not running, 1 - the pipeline is running
 
Constructor Summary
Parser(cz.cuni.mff.procasor.gui.ParserMessageSender pmSender)
          Constructor Creates instance of InfoQueue for recieving InfoRecord instances from Parsing tools.
 
Method Summary
 int close()
          Called when nothing is to be done and we want to clost the PipeLine Close input and output pipes of the PipeLine, we close the input stream, parsing tools recognize EOF signal on the input of their pipes and shutdown.
 int init()
          Description: Building the PipeLine.
 java.lang.String parse(java.lang.String sentence)
          This method is used by user to process the sentence.
 int restart()
          Method close the PipeLine and creates another.
protected  void setPipeLine()
          Creates apropriate filters for reading and writing data from the pipes, which are connected directly to the PipeLine.
protected  void setTools()
          Method for building the PipeLine inside the Parser.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

running

public int running
0 - the pipeline is not running, 1 - the pipeline is running


isRunning

public boolean isRunning
true if the Pipeline is running


isStarting

public boolean isStarting
true if the Pipeline is starting

Constructor Detail

Parser

public Parser(cz.cuni.mff.procasor.gui.ParserMessageSender pmSender)
Constructor Creates instance of InfoQueue for recieving InfoRecord instances from Parsing tools.

Method Detail

init

public int init()
         throws cz.cuni.mff.procasor.parsingTools.parser.parseExceptions.StartingProcessException
Description: Building the PipeLine. 1. Creates instances of parsing processes. 2. Creates pipes for communication between tools. 3. Creates pipes for communication with MorphA tool. 4. Initialization processes of parsing tools. 5. Sets IO of the PipeLine. 6. Run the Gobblers. Gobblers are independent threads used for transfering data between system processes of Parsing Tools and ParserTool thread. When error occures, init() throws StartingProcesException, with is child of ParseException. This exception encampusaltes all information about the problem including the chain of precedent exceptions. Rules for calling: isStarting = false && isRunning == false

Returns:
0 if started properly, -1 otherwise
Throws:
cz.cuni.mff.procasor.parsingTools.parser.parseExceptions.StartingProcessException - if initialization fails

parse

public java.lang.String parse(java.lang.String sentence)
                       throws cz.cuni.mff.procasor.parsingTools.parser.parseExceptions.RunningProcessException
This method is used by user to process the sentence. The input sentence is passed to the PipeLine, where is subsequently processed by parsing tools. Then is launched the control method for reading information records from each parsing tool. Here are successful processes or occured errors recognized. When wverything goes properly, parse tree of input sentence is created. The parse tree is stored in special format which we have to translate to XML. Therefor is the tree passed to the method parseTreeToXMl(). Rules for calling: isRunning == true sentence input sentence which you want to parse. The parseTree will be created from the sentence.

Returns:
ParseTree of the sentence in xml format.
Throws:
cz.cuni.mff.procasor.parsingTools.parser.parseExceptions.RunningProcessException
cz.cuni.mff.procasor.parsingTools.parser.parseExceptions.ParseException

setTools

protected void setTools()
                 throws cz.cuni.mff.procasor.parsingTools.parser.parseExceptions.ParseException
Method for building the PipeLine inside the Parser. We have to instantiate all parsing tools and connect them with pipes to the PipeLine. At first all needed pipes are created. Then we create the instances of parsing Tools and pass them out pipes as a set of their I/O channels. We set the Error output of parsing tools here too. All parsing tools write their error outputs to according log files. Parsing tool have to know the InfoQueue to which they should send the infromation about their state.

Throws:
cz.cuni.mff.procasor.parsingTools.parser.parseExceptions.ParseException

setPipeLine

protected void setPipeLine()
Creates apropriate filters for reading and writing data from the pipes, which are connected directly to the PipeLine. We are opening direct connection with the PipeLine, it is closed when work with parsers is over.


close

public int close()
          throws cz.cuni.mff.procasor.parsingTools.parser.parseExceptions.RunningProcessException
Called when nothing is to be done and we want to clost the PipeLine Close input and output pipes of the PipeLine, we close the input stream, parsing tools recognize EOF signal on the input of their pipes and shutdown. Reads all messages from InfoQueue, ParseTools tell the Parser, that they have finished properly. Rules for calling: isStarting = true || isRunning == true

Throws:
cz.cuni.mff.procasor.parsingTools.parser.parseExceptions.RunningProcessException

restart

public int restart()
            throws cz.cuni.mff.procasor.parsingTools.parser.parseExceptions.RunningProcessException,
                   cz.cuni.mff.procasor.parsingTools.parser.parseExceptions.StartingProcessException
Method close the PipeLine and creates another. It is used when error occurs in old PipeLine and we have to create the new one. Rules for calling restart: isRunning == true || isStarting == true

Throws:
cz.cuni.mff.procasor.parsingTools.parser.parseExceptions.RunningProcessException - - error while shutting down the parser (PipeLine)
cz.cuni.mff.procasor.parsingTools.parser.parseExceptions.StartingProcessException - - error while initializating new parser (PipeLine)