|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectaminePlatform.util.parserGenerator.ObjectParsing
Title : parserGenerator.ObjectParsing Class
Description : This class is concerned by Amine Object parsing.
Amine Object here means : an Integer, a Double, a Boolean, an Identifier, a String, a Variable, a Term, an AmineList, an AmineSet, a Concept or a CG.
This class offers methods that parse a String to recognize an Amine object (for instance, the method parseTerm() will fail if the String doesn't correspond to a term) and, optionnally, to produce and return the internal representation of the corresponding Amine Object.
Also, the class has methods to parse (and produce) Concept and CG from a Linear Form or from a CGIF form or from a textual formulation without any further specification about the used notation (Linear Form or CGIF). ObjectParsing is specialized into LFParserGenerator and CGIFParserGenerator subclasses to deal with CG Linear Notation and CG CGIF Notation respectively. ObjectParsing is specialized also by the Prolog+CG compiler.
NEW Amine 2.5, by Adil: In SYNERGY, a concept can play the role of a parameter;
an in or out parameter with a specific range. The two information are recorded in
the new attribute ParameterModes.
The syntax of a concept :
Old syntax of Concept
Concept ::= "[" Conc_Type [ParameterModes] [":" Designator]
["#" PseudoDesignator] [CoReferent] ["=" Descriptor] ["$" State] ["&" Point] "]"
New syntax of Concept, which integrates both the old syntax and recommandations of Standard CGIF
Concept ::= "[" [Comment] Conc_Type [ParameterModes (generate in EndComment)] [CoReferent]
[":"] [CoReferent] [Designator] [CoReferent] ["="] [Descriptor] [CoReferent]
["$" State (generate in EndComment)] ["&" Point (generate in EndComment)] [EndComment] "]"
Conc_Type ::= Type | Variable | ComposedType | Term
Designator ::= IndividualIdent | SetOfIndividualIdent | Variable
CoReferent ::= ("*" | "?") Variable
Descriptor ::= Amine_Object | Variable
ParameterModes ::= ("in" | "out") Integer.
State ::= A byte that represents the state of a concept, according to SYNERGY
Point ::= Integer Integer
Amine Structures Notation Grammar
Amine_Object_Var ::= Amine_Object | Variable .
Amine_Object ::= Elementary_Object | AmineList | AmineSet | Term | CG .
Elementary_Object ::= Integer | Double | Boolean | String | Identifier .
AmineList ::= "[" [ Amine_Object_Var ("," Amine_Object_Var)* [ "|" Variable] ] "]" .
AmineSet ::= "{" [ Elementary_Object ("," Elementary_Object)* ] "}" .
Term ::= Identifier "(" Amine_Object_Var ("," Amine_Object_Var)* ")" .
Identifier ::= Letter Letter (Character)* .
Variable ::= ( Letter [ (Digit | "_") (Character)* ] ) | ( "_" (Character)* ) .
Subclasses : LFParserGenerator, CGIFParserGenerator, prologPlusCG.ppcgCompiler.Compile
Copyright : Copyright (c) Adil KABBAJ 2004-2009
Field Summary | |
protected boolean |
generateCode
A boolean that indicates if the parsing should be completed by the production of the internal representation of the object parsed (value true) or not (i.e., do parsing only and in this case, generateCode is false). |
protected Variable |
genericCoref
|
protected Lexicon |
lexicon
The lexicon in use that will be consulted during the parsing. |
protected TextTokenizer |
txtTokenizer
The text tokenizer that treats the text to parse |
Constructor Summary | |
ObjectParsing()
|
|
ObjectParsing(Lexicon lexicon)
Construct an ObjectParsing object with the specified lexicon. |
|
ObjectParsing(TextTokenizer txtTokenizer,
Lexicon lexicon)
Construct an ObjectParsing object with the specified lexicon for the parsing of a text that will be handled by the specified TextTokenizer. |
Method Summary | |
protected void |
addPseudoCorefs(CG cg,
java.util.ArrayList concsWithPseudoCoref)
To generate LF ou CGIF for the CG cg, addition of pseudo-coreferents, for some concepts, is required. |
protected int |
addPseudoCorefs(CG cg,
java.util.ArrayList concsWithPseudoCoref,
int indxSupCoref)
|
java.lang.String |
conceptToString(BindingContext bindContext,
Concept concept,
java.lang.Object bindInf)
Generate the textual formulation of a concept from its internal representation (the parameter concept). |
java.lang.String |
conceptToString(BindingContext bindContext,
Concept concept,
java.lang.Object bindInf,
boolean complete,
int indent)
Generate the textual formulation of a concept from its internal representation (the parameter concept) taking ito account the variable binding. |
(package private) void |
deletePseudoCorefs(CG cg)
Pseudo coreferents are coreferents that are used in LF or in CGIF to refeer to the same concept, in the same CG, from different locations/occurrences. |
(package private) void |
deletePseudoCorefs(CG cg,
java.util.HashMap pseudoCorefConcepts)
|
protected void |
deletePseudoDesignators(CG cg)
delete pseudo-designators from any concept of the specified CG cg : replace the pseudo-designators by a null designator (null). |
byte |
determineCGForm()
This method is the same as the method defined in this class with the same name except that this one assumes and operates on the current textTokenizer. |
byte |
determineCGForm(java.lang.String strgCG)
Determine the nature of the CG form (Linear Form -LF- or CGIF) from the specified textual formulation (a String) of the CG strgCG. |
void |
finalize()
|
protected void |
generateDesignator(BindingContext bindContext,
java.lang.StringBuffer sConcept,
java.lang.Object designator,
java.lang.Object bindInf)
Generate the textual formulation of the specified designator. |
static java.lang.String |
getBlancsString(int nbrBlancs)
Form a string of blanks, the number of blanks is specified by nbrBlancs |
boolean |
getGenerateCode()
Get the value of the attribute generateCode associated to the current ObjectParsing |
Lexicon |
getLexicon()
Get the lexicon associated to the current ObjectParsing |
TextTokenizer |
getTxtTokenizer()
Get the TextTokenizer associated to the current ObjectParsing |
boolean |
getWithDrawingInf()
|
protected boolean |
hasSeveralSuper(CG cg)
|
(package private) boolean |
isAdditiveOper(byte tokenType)
|
(package private) boolean |
isDescriptor(byte nxtTokenType)
|
boolean |
isDesignator(byte nxtTokenType)
|
(package private) boolean |
isInt(java.lang.String si)
|
(package private) boolean |
isMultiplicativeOper(byte tokenType)
|
(package private) boolean |
isNotOper(byte tokenType)
|
(package private) boolean |
isParameterMode(java.lang.String s)
|
(package private) boolean |
isRelationalOper(byte tokenType)
|
(package private) java.lang.String |
parameterMode()
|
protected AmineList |
parseAmineList()
This method assumes that the textual formulation of the AmineList was already given to the textTokenizer of the current ObjectParsing and that lexical analysis was already done. |
AmineList |
parseAmineList(java.lang.String strgList)
Parse the textual formulation of an Amine List (parameter strgList) and produce its internal representation. |
protected java.lang.Object |
parseAmineObject()
This method is the protected version of the method parseAmineObject(String strgObj); it can be used by ObjectParsing's subclasses only since it assumes that some steps have been made and that the environment is already established. |
java.lang.Object |
parseAmineObject(java.lang.String strgObj)
Parse the textual formulation of an Amine Object (parameter strgObj) and produce its internal representation. |
protected AmineSet |
parseAmineSet()
This method assumes that the textual formulation of the AmineSet was already given to the textTokenizer of the current ObjectParsing and that lexical analysis was already done. |
AmineSet |
parseAmineSet(java.lang.String strgSet)
Parse the textual formulation of an Amine Set (parameter strgSet) and produce its internal representation. |
protected CG |
parseCG()
This method is overriden in LFParserGenerator and CGIFParserGenerator. |
CG |
parseCG(java.lang.String strgCG)
Parse the textual formulation of a CG (parameter strgCG) and produce its internal representation. |
CG |
parseCG(java.lang.String strgCG,
AmineList newTypes)
|
CG |
parseCG(TextTokenizer textTokenizer)
This method is similar to parseCG(String strgCG) except that its argument is a TextTokenizer that is already created for the treatment of strgCG; the textual formulation of a CG. |
CG |
parseCG(TextTokenizer textTokenizer,
AmineList newTypes)
This method is similar to parseCG(TextTokenizer) except that it considers the case where new concept types are encountered in the CG. |
protected java.lang.Object |
parseConcept()
Parse the textual formulation of a concept and produce its corresponding internal representation if this step is intended (this is determined by the attribute generateCode : if true, the internal representation is produced, if false only the parsing is done). |
protected java.lang.Object |
parseConcept(CG cg)
This method is a variant of the method parseConcept() defined in this class, except that the parsing is done in the context of a particular CG (the parameter cg). |
Concept |
parseConcept(java.lang.String strgConc)
Parse the textual formulation of a Concept (parameter strgConc) and produce its internal representation. |
(package private) java.awt.Point |
parseConcPoint()
|
(package private) Variable |
parseCoref(byte nxtTokenType)
|
Variable |
parseCoreferent()
Recognize a coreferent which should be a variable. |
(package private) byte |
parseCState()
|
java.lang.Object |
parseDescriptor()
Parse the descriptor of the current concept. |
protected java.lang.Object |
parseDesignator()
Parse the concept designator that can be an individual identifier, a variable identifier or a set of individual identifiers. |
protected java.lang.Object |
parseExpression()
Parsing of an Expression |
(package private) java.lang.Object |
parseExprTerm()
|
(package private) java.lang.Object |
parseFactor()
|
protected Term |
parseMessage()
|
(package private) Identifier |
parseOperName(byte nxtTokenType)
|
protected java.awt.Point |
parsePoint()
|
protected java.lang.String |
parsePseudoDesignator()
Recognize a pseudo-designator which could be an identifier or a number. |
protected java.lang.Object |
parseRelationType(java.lang.StringBuffer sBuffer)
Parsing of a Relation Type |
protected void |
parseSegmentPoints(java.util.ArrayList segmentPoints)
|
static AmineList |
parseSentence(java.lang.String strgSentence)
Parse the specified string that corresponds to a sentence and produce an AmineList with the words of the sentence as elements. |
(package private) java.lang.Object |
parseSimpleExpression()
|
protected byte |
parseState()
Recognize a state which is a byte. |
(package private) AmineSet |
parseStdSetDesignator(java.lang.Object designator)
|
protected Term |
parseTerm()
This method assumes that the textual formulation of the Term was already given to the textTokenizer of the current ObjectParsing and that lexical analysis was already done. |
protected Term |
parseTerm(boolean isMethod)
|
Term |
parseTerm(java.lang.String strgTerm)
Parse the textual formulation of a Term (parameter strgTerm) and produce its internal representation. |
void |
setGenerateCode(boolean generateCode)
Set the specified generateCode as the associated generateCode for the current ObjectParsing. |
void |
setLexicon(Lexicon lexicon)
Set the specified lexicon as the associated lexicon for the current ObjectParsing |
void |
setTxtTokenizer(TextTokenizer txtTokenizer)
Set the specified txtTokenizer as the associated TextTokenizer for the current ObjectParsing |
void |
setWithDrawingInf(boolean withDrawInf)
|
Methods inherited from class java.lang.Object |
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected TextTokenizer txtTokenizer
protected Lexicon lexicon
protected Variable genericCoref
protected boolean generateCode
Constructor Detail |
public ObjectParsing()
public ObjectParsing(TextTokenizer txtTokenizer, Lexicon lexicon) throws ParsingException
txtTokenizer
- A TextTokenizer that will handle the text to parselexicon
- The lexicon to use during the parsing
ParsingException
- if lexicon is nullpublic ObjectParsing(Lexicon lexicon) throws ParsingException
lexicon
- The lexicon to use during the parsing
ParsingException
- if lexicon is nullMethod Detail |
public void finalize()
public Lexicon getLexicon()
public void setLexicon(Lexicon lexicon)
lexicon
- A Lexiconpublic TextTokenizer getTxtTokenizer()
public void setTxtTokenizer(TextTokenizer txtTokenizer)
public boolean getGenerateCode()
public void setGenerateCode(boolean generateCode)
generateCode
- : a boolean value for the attribute generateCode of the
current ObjectParsingpublic boolean getWithDrawingInf()
public void setWithDrawingInf(boolean withDrawInf)
public java.lang.Object parseAmineObject(java.lang.String strgObj) throws ParsingException
strgObj
- a textual formulation of an Amine Object
throws
- ParsingException if lexico-syntactic errors occurs during parsing
ParsingException
protected java.lang.Object parseAmineObject() throws ParsingException
ParsingException
- if errors occur during parsingpublic CG parseCG(java.lang.String strgCG) throws ParsingException
strgCG
- a textual formulation of a CG
throws
- ParsingException if lexico-syntaxic errors occurs during parsing
ParsingException
public CG parseCG(java.lang.String strgCG, AmineList newTypes) throws ParsingException
ParsingException
public CG parseCG(TextTokenizer textTokenizer) throws ParsingException
textTokenizer
- a TextTokenizer to treat the parsing of a textual formulation of a CG
throws
- ParsingException if lexico-syntaxic errors occurs during parsing
ParsingException
public CG parseCG(TextTokenizer textTokenizer, AmineList newTypes) throws ParsingException
textTokenizer
- TextTokenizernewTypes
- AmineList
ParsingException
protected CG parseCG() throws ParsingException
ParsingException
- if lexico-syntaxic errors occur during parsingpublic Concept parseConcept(java.lang.String strgConc) throws ParsingException
strgConc
- a textual formulation of a Concept
throws
- ParsingException if lexicon is null or if
lexico-syntaxic errors occurs during parsing
ParsingException
protected java.lang.Object parseConcept() throws ParsingException
ParsingException
- if txtTokenizer is null, if generateCode is true and
lexicon is null and if errors occur during parsingprotected java.lang.Object parseConcept(CG cg) throws ParsingException
cg
- : a CG
ParsingException
- if txtTokenizer is null, if generateCode is true and
lexicon is null and if errors occur during parsingboolean isParameterMode(java.lang.String s)
java.lang.String parameterMode() throws ParsingException
ParsingException
Variable parseCoref(byte nxtTokenType) throws ParsingException
ParsingException
boolean isDescriptor(byte nxtTokenType)
protected java.lang.Object parseDesignator() throws ParsingException
ParsingException
- if txtTokenizer is null, or lexicon is null or
errors occur during parsingAmineSet parseStdSetDesignator(java.lang.Object designator) throws ParsingException
ParsingException
public boolean isDesignator(byte nxtTokenType)
protected java.lang.String parsePseudoDesignator() throws ParsingException
ParsingException
- if errors occur during parsingbyte parseCState() throws ParsingException
ParsingException
protected byte parseState() throws ParsingException
ParsingException
- if errors occur during parsingpublic Variable parseCoreferent() throws ParsingException
ParsingException
- if errors occur during parsingpublic java.lang.Object parseDescriptor() throws ParsingException
ParsingException
- if txtTokenizer is null, if generateCode is true and
lexicon is null and if errors occur during parsingjava.awt.Point parseConcPoint() throws ParsingException
ParsingException
public java.lang.String conceptToString(BindingContext bindContext, Concept concept, java.lang.Object bindInf) throws ToStringException
bindContext
- The Binding contextconcept
- A ConceptbindInf
- The binding information related to the binding context and to concept
throws
- ToStringException if no identifier is associated to a CS
in the specified lexicon (and in the main language to, if mixed language is allowed).
ToStringException
public java.lang.String conceptToString(BindingContext bindContext, Concept concept, java.lang.Object bindInf, boolean complete, int indent) throws ToStringException
bindContext
- The Binding contextconcept
- A ConceptbindInf
- The binding information related to the binding context and to conceptcomplete
- a boolean : if true, the description will be complete, else
it will be partialindent
- an integer that specifies the required indentation
ToStringException
- if concept or lexicon is null or no identifier is
associated to a CS in the current lexicon (and in the main language to, if mixed
language is allowed).protected void generateDesignator(BindingContext bindContext, java.lang.StringBuffer sConcept, java.lang.Object designator, java.lang.Object bindInf) throws ToStringException
bindContext
- The Binding contextsConcept
- a StringBuffer that will contain the textual formulation of
the whole concept.designator
- a concept designatorbindInf
- The binding information related to the binding context and to designator
ToStringException
- if no identifier is associated to an Individual in the current
lexicon (and in the main language to, if mixed language is allowed).protected java.lang.Object parseRelationType(java.lang.StringBuffer sBuffer) throws ParsingException
ParsingException
boolean isInt(java.lang.String si)
protected java.awt.Point parsePoint() throws ParsingException
ParsingException
protected void parseSegmentPoints(java.util.ArrayList segmentPoints) throws ParsingException
ParsingException
public Term parseTerm(java.lang.String strgTerm) throws ParsingException
strgTerm
- a textual formulation of a Term
throws
- ParsingException if lexico-syntaxic errors occurs during parsing
ParsingException
protected Term parseTerm() throws ParsingException
ParsingException
- if lexico-syntaxic errors occur during parsingprotected Term parseTerm(boolean isMethod) throws ParsingException
ParsingException
protected Term parseMessage() throws ParsingException
ParsingException
public AmineList parseAmineList(java.lang.String strgList) throws ParsingException
A 'stand alone' version of this method, called parse(), is defined in cg.AmineList class.
strgList
- a textual formulation of an Amine List
throws
- ParsingException if lexico-syntaxic errors occurs during parsing
ParsingException
protected AmineList parseAmineList() throws ParsingException
A 'stand alone' version of this method, called parse() is defined in cg.AmineList class, it receives the textual formulation of an AmineList as argument and produces its internal representation.
ParsingException
- if lexico-syntaxic errors occur during parsingpublic AmineSet parseAmineSet(java.lang.String strgSet) throws ParsingException
A 'stand alone' version of this method, called parse(), is defined in cg.AmineSet class.
strgSet
- a textual formulation of an Amine Set
throws
- ParsingException if lexico-syntaxic errors occurs during parsing
ParsingException
protected AmineSet parseAmineSet() throws ParsingException
A 'stand alone' version of this method, called parse() is defined in cg.AmineSet class, it receives the textual formulation of an AmineSet as argument and produces its internal representation.
ParsingException
- if lexico-syntaxic errors occur during parsingprotected java.lang.Object parseExpression() throws ParsingException
ParsingException
java.lang.Object parseSimpleExpression() throws ParsingException
ParsingException
java.lang.Object parseExprTerm() throws ParsingException
ParsingException
java.lang.Object parseFactor() throws ParsingException
ParsingException
Identifier parseOperName(byte nxtTokenType)
boolean isRelationalOper(byte tokenType)
boolean isAdditiveOper(byte tokenType)
boolean isMultiplicativeOper(byte tokenType)
boolean isNotOper(byte tokenType)
public static AmineList parseSentence(java.lang.String strgSentence) throws ParsingException
strgSentence
- : a string that represents a sentence
ParsingException
- if errors occur during parsingpublic byte determineCGForm(java.lang.String strgCG) throws ParsingException
In more detail : If the current ObjectParsing is a LFParserGenerator or a CGIFParserGenerator, then the CG form is determined from the current ObjectParsing. Otherwise, we have to determine the form from the syntax of the textual representation of the CG. The ambiguity occurs when the CGIF begins with a concept, like the Linear form. In this case, we should look after the concept, except if the concept is a context (it contains a CG) in which case we can determine the form from the nested CG. Note first that the method is called after a look ahead of scope 3 (see the definition of the method parseAmineObject() and especially the case of 'lcOpBrkt' (open bracket '[') which could be the begining of a list or of a concept and hence a CG) and we are sure that we deal with a concept.
The problem is that a concept alone cannot tell if the notation is a linear form or a CGIF form except if it has a descriptor that contains a CG, the embedded CG will tell what is the notation of the outer context. The treatment of the descriptor will be complex because it could be a list or a term that contains other lists or terms or CG !
Our solution is to use a counter for open bracket '[' (because brackets are used for concepts and also for lists !) that will enable us to know when the end of the current concept occurs (i.e. which ']' encounterd corresponds to the end of the current concept and not to the end of a list). So the counter will allow us to determine the scope of our search. The treatment is as follows : we will use the counter, set to 1 for the first '[' and advance in the look ahead of the end of the concept ']'. During this advance, we increment the counter for each '[' encountered and decremente for each ']', the counter is equal to 0 is one condition to stop the advance, and we check for the pattern '] [' or '] (' which is a sign of a CGIF CG or the pattern ']-' or ']<-' which is a sign of a linear CG. If one of the two patterns occurs then the advance will stop (the second condition) because the notation has been determined !! Otherwise, we will reach the end of the current concept and we will look at the next token to determine the notation.
Since we perform a double pass (the first lexical and the second generation of the internal representation of the CG), we determine the nature of the CG form (when the case occur) at the first pass and we record the result in a HashMap with key=CurrElemInString and value=cgFormInString. At the second pass, we read only the recorded result from the HashMap.
strgCG
- A textual formulation of a CG
ParsingException
- exception if strgCG is null or empty
or if errors occur during the parsingpublic byte determineCGForm() throws ParsingException
ParsingException
- exception if errors occur during the parsingpublic static java.lang.String getBlancsString(int nbrBlancs)
nbrBlancs
- : the number of blanks to put in the string
void deletePseudoCorefs(CG cg) throws ParsingException
cg
- CG
ParsingException
void deletePseudoCorefs(CG cg, java.util.HashMap pseudoCorefConcepts) throws ParsingException
ParsingException
protected void addPseudoCorefs(CG cg, java.util.ArrayList concsWithPseudoCoref)
cg
- CGconcsWithPseudoCoref
- ArrayListprotected int addPseudoCorefs(CG cg, java.util.ArrayList concsWithPseudoCoref, int indxSupCoref)
protected boolean hasSeveralSuper(CG cg)
protected void deletePseudoDesignators(CG cg)
cg
- : a CG
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |