|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectai.krr.propositions.KifSentenceAdaptor
public class KifSentenceAdaptor
This class is an adaptor between the ai.krr.propositions.Sentence class that can be used as an internal representation for reasoning and its external form as defined by the KIF syntax as described below.
Atoms in propositional KIF can be either the boolean constants TRUE and FALSE, or they can be a named proposition represented by a NamedSymbol. The boolean constants are written as TRUE and FALSE. Named propositions that are represented by internal Symbols cannot be handled here and an attempt to write them will cause an Exception. NamedSymbols that have an associated NameSpace are written with their NameSpace. The full NameSpace URI will prefix the name of the proposition.
Standard KIF is defined to be case-insensitive. However, NamedSymbols are case-sensitive. This fundamental incompatibility is handled here by the property "case-sensitive" which should have the value "true" or "false". Only if the property is set to "true" are lower case letters in NamedSymbols not explicitly escaped. This may increase readablility and result in shorter String representations. The default behaviour for this SyntaxAdaptor is to be case-insensitive, which is standard for KIF.
The syntax of Atoms can be defined as follows:
<Atom> ::= TRUE | FALSE | <NamedSymbol> <NamedSymbol> ::= <NameSpace-URI>\#<Name>
Literals must contain a named proposition, i.e. they cannot be the boolean constants. If the proposition is an internal Symbol, this will cause an Exception. Symbols with NameSpace are written with the full NameSpace URI. Positive Literals are written like an Atom whereas negative Literals are written like a NegatedSentece. The formal syntax is as follows:
<Literal> ::= <NamedSymbol> | (not <NamedSymbol>)Atoms and Literals are the basic building blocks for Sentences. The remaining constructs are more complex in the sense that they allow for Sentences as their content, which means definitions become recursive. The simplest of these more complex structures is a NegatedSentence which contains exactly one Sentence, which is what is negated here. The syntax is defined as:
<NegatedSentence> ::= (not <Sentence>)
A ConnectedSentence is a List containing the String representing the Connective followed by the connected Sentences (at least two):
<ConnectedSentence> ::= (<Connective> <Sentence> <Sentence><sup>+</sup>) <Connective> ::= and | or | => | <= | <=>
Finally, a Sentence can be any of the basic or complex structures defined above:
<Sentence> ::= <Atom> | <Literal> | <NegatedSentence> | <ConnectedSentence>
Standard KIF is defined to be case-insensitive. However, NamedSymbols are case-sensitive. This fundamental incompatibility is handled here by the property "case-sensitive" which should have the value "true" or "false". Only if the property is set to "true" are word lexemes not converted to their upper case equivalents as prescribed in KIF. The default behaviour for this SyntaxAdaptor is to be case-insensitive, which is standard for KIF.
By default, it is not allowed to use NamedSymbols that are internal, i.e. that do not have a NameSpace. This can be changed by setting the property ~"namespace-aware" to "false".
property | possible values | default |
---|---|---|
case-sensitive | true, false | true |
namespace-aware | true, false | true |
indent-string | any string | " " |
line-width | positive int | 80 |
Field Summary | |
---|---|
protected static inf.compilers.LexicalAnalyzer.TokenType |
andTT
the token types used |
protected static inf.compilers.LexicalAnalyzer.TokenType |
closebracketTT
the token types used |
protected static inf.compilers.LexicalAnalyzer.TokenType |
coimplTT
the token types used |
protected static inf.compilers.LexicalAnalyzer.TokenType |
ignorableTT
the token types used |
protected static inf.compilers.LexicalAnalyzer.TokenType |
limplTT
the token types used |
protected static inf.compilers.LexicalAnalyzer.TokenType |
notTT
the token types used |
protected static inf.compilers.LexicalAnalyzer.TokenType |
openbracketTT
the token types used |
protected static inf.compilers.LexicalAnalyzer.TokenType |
orTT
the token types used |
protected java.util.Properties |
props
the properties used for reading and writing |
protected static inf.compilers.LexicalAnalyzer.TokenType |
rimplTT
the token types used |
protected inf.compilers.LexicalAnalyzer |
scanner
the lexical analyzer used for tokenizing the input |
Constructor Summary | |
---|---|
KifSentenceAdaptor()
This constructor creates a SyntaxAdaptor that can be used to read statements in a (propositional) KIF syntax and create a propositional Sentence for it, or it can be used to write out a propositional Sentence in KIF syntax. |
Method Summary | |
---|---|
protected KifSymbolAdaptor |
clone()
|
java.lang.Class<Sentence> |
getInternalClass()
This function returns the Class that holds the internal representation this adaptor translates to and from. |
java.lang.String |
getProperty(java.lang.String key)
This function gets the property that is associated with the given key. |
java.lang.String |
getSyntaxName()
This function returns the name that should identify the syntactical language that this adaptor translates to and from. |
static Sentence |
parseSentence(inf.compilers.LexicalAnalyzer scanner,
java.util.Properties props)
This function attempts to parse a propositional Sentence in KIF syntax from the underlying LexicalAnalyzer. |
static java.util.List<Sentence> |
parseSentences(inf.compilers.LexicalAnalyzer scanner,
java.util.Properties props)
This function attempts to parse a sequence of at least two Sentences from the given LexicalAnalyzer. |
void |
prettyPrint(int indent,
Sentence stmt,
java.io.Writer w)
This function takes a logical Sentence which is a Java Object in the internal representation, and writes it to the given Writer as a string conforming to the KIF syntax. |
static void |
prettyPrintConnectedSentence(int indent,
ConnectedSentence stmt,
java.io.Writer w,
java.util.Properties props)
This function pretty-prints the given ConnectedSentence to the given Writer. |
static void |
prettyPrintNegatedSentence(int indent,
NegatedSentence stmt,
java.io.Writer w,
java.util.Properties props)
This function pretty-prints the given NegatedSentence to the given Writer. |
static void |
prettyPrintSentence(int indent,
Sentence stmt,
java.io.Writer w,
java.util.Properties props)
This function takes a logical Sentence which is a Java Object in the internal representation, and wrties it to the given Writer as a string conforming to the KIF syntax. |
Sentence |
read(java.io.Reader r)
This function attempts to parse characters from the given Reader until a Sentence that represents an object in the internal representation has been parsed. |
void |
setProperty(java.lang.String key,
java.lang.String value)
This function sets the property associated with the given key to the given value. |
void |
write(Sentence stmt,
java.io.Writer w)
This function takes a logical Sentence which is a Java Object in the internal representation, and writes it to the given Writer as a string conforming to the KIF syntax. |
static void |
writeAtom(Atom atom,
java.io.Writer w,
java.util.Properties props)
This function writes the given Atom to the given Writer. |
static void |
writeConnectedSentence(ConnectedSentence stmt,
java.io.Writer w,
java.util.Properties props)
This function writes the given ConnectedSentence to the given Writer. |
static void |
writeLiteral(Literal lit,
java.io.Writer w,
java.util.Properties props)
This function writes the given Literal to the given Writer. |
static void |
writeNegatedSentence(NegatedSentence stmt,
java.io.Writer w,
java.util.Properties props)
This function writes the given NegatedSentence to the given Writer. |
static void |
writeSentence(Sentence stmt,
java.io.Writer w,
java.util.Properties props)
This function takes a logical Sentence which is a Java Object in the internal representation, and writes it to the given Writer as a string conforming to the KIF syntax. |
static void |
writeTruthValue(TruthValue tValue,
java.io.Writer w,
java.util.Properties props)
This function writes the given TruthValue to the given Writer. |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static inf.compilers.LexicalAnalyzer.TokenType ignorableTT
protected static inf.compilers.LexicalAnalyzer.TokenType openbracketTT
protected static inf.compilers.LexicalAnalyzer.TokenType closebracketTT
protected static inf.compilers.LexicalAnalyzer.TokenType notTT
protected static inf.compilers.LexicalAnalyzer.TokenType andTT
protected static inf.compilers.LexicalAnalyzer.TokenType orTT
protected static inf.compilers.LexicalAnalyzer.TokenType rimplTT
protected static inf.compilers.LexicalAnalyzer.TokenType limplTT
protected static inf.compilers.LexicalAnalyzer.TokenType coimplTT
protected inf.compilers.LexicalAnalyzer scanner
protected java.util.Properties props
Constructor Detail |
---|
public KifSentenceAdaptor()
This constructor creates a SyntaxAdaptor that can be used to read statements in a (propositional) KIF syntax and create a propositional Sentence for it, or it can be used to write out a propositional Sentence in KIF syntax.
Method Detail |
---|
protected KifSymbolAdaptor clone() throws java.lang.CloneNotSupportedException
clone
in class java.lang.Object
java.lang.CloneNotSupportedException
public java.lang.Class<Sentence> getInternalClass()
This function returns the Class that holds the internal representation this adaptor translates to and from.
getInternalClass
in interface inf.compilers.SyntaxAdaptor<Sentence>
public java.lang.String getSyntaxName()
This function returns the name that should identify the syntactical language that this adaptor translates to and from.
getSyntaxName
in interface inf.compilers.SyntaxAdaptor<Sentence>
public void write(Sentence stmt, java.io.Writer w) throws inf.compilers.ExpressivenessException, java.io.IOException
This function takes a logical Sentence which is a Java Object in the internal representation, and writes it to the given Writer as a string conforming to the KIF syntax.
write
in interface inf.compilers.SyntaxAdaptor<Sentence>
stmt
- a Sentence in the internal representationw
- the Writer to which the syntactical translation is written
inf.compilers.ExpressivenessException
- if the syntactical language cannot
represent the given statement
java.io.IOException
- if writing to the given Writer failspublic void prettyPrint(int indent, Sentence stmt, java.io.Writer w) throws inf.compilers.ExpressivenessException, java.io.IOException
This function takes a logical Sentence which is a Java Object in the internal representation, and writes it to the given Writer as a string conforming to the KIF syntax.
prettyPrint
in interface inf.compilers.SyntaxAdaptor<Sentence>
indent
- the amount of indentation for the first linestmt
- a Sentence in the internal representationw
- the Writer to which the syntactical translation is written
inf.compilers.ExpressivenessException
- if the syntactical language cannot
represent the given statement
java.io.IOException
- if writing to the given Writer failspublic Sentence read(java.io.Reader r) throws inf.compilers.ExpressivenessException, java.text.ParseException, java.io.IOException
This function attempts to parse characters from the given Reader until a Sentence that represents an object in the internal representation has been parsed.
read
in interface inf.compilers.SyntaxAdaptor<Sentence>
r
- the Reader from which the representation is to be parsed
inf.compilers.ExpressivenessException
- if the internal representation class is
not expressive enough for the given statement
java.text.ParseException
- if there is a syntax error in the given string
java.io.IOException
- if reading from the Reader failspublic java.lang.String getProperty(java.lang.String key)
This function gets the property that is associated with the given key. Not e that the key should not be null.
getProperty
in interface inf.compilers.SyntaxAdaptor<Sentence>
public void setProperty(java.lang.String key, java.lang.String value)
This function sets the property associated with the given key to the given value. The given key must not be null, but the value may be.
setProperty
in interface inf.compilers.SyntaxAdaptor<Sentence>
key
- the key with which the value is associatedvalue
- the associated valuepublic static void writeSentence(Sentence stmt, java.io.Writer w, java.util.Properties props) throws inf.compilers.ExpressivenessException, java.io.IOException
This function takes a logical Sentence which is a Java Object in the internal representation, and writes it to the given Writer as a string conforming to the KIF syntax.
stmt
- a Sentence in the internal representationw
- the Writer to which the syntactical translation is writtenprops
- the Properties used for writing
inf.compilers.ExpressivenessException
- if the syntactical language cannot
represent the given statement
java.io.IOException
- if writing to the given Writer failspublic static void prettyPrintSentence(int indent, Sentence stmt, java.io.Writer w, java.util.Properties props) throws inf.compilers.ExpressivenessException, java.io.IOException
This function takes a logical Sentence which is a Java Object in the internal representation, and wrties it to the given Writer as a string conforming to the KIF syntax.
indent
- the amount of indentation for the first linestmt
- a Sentence in the internal representationw
- the Writer to which the syntactical translation is writtenprops
- the Properties used for writing
inf.compilers.ExpressivenessException
- if the syntactical language cannot
represent the given statement
java.io.IOException
- if writng to the given Writer failspublic static void writeConnectedSentence(ConnectedSentence stmt, java.io.Writer w, java.util.Properties props) throws inf.compilers.ExpressivenessException, java.io.IOException
This function writes the given ConnectedSentence to the given Writer. A ConnectedSentence is a List containing the String representing the Connective followed by the connected Sentences (at least two).
<ConnectedSentence> ::= (<Connective> <Sentence> <Sentence>+) <Connective> ::= and | or | => | <= | <=>
stmt
- the ConnectedSentence that is to be writtenw
- the Writer to which the ConnectedSentence is to be writtenprops
- the Properties used for writing
inf.compilers.ExpressivenessException
- if any contained NamedSymbol is internal
or the Connective is XOR (which KIF does not have)
java.io.IOException
- if writing to the Writer failspublic static void prettyPrintConnectedSentence(int indent, ConnectedSentence stmt, java.io.Writer w, java.util.Properties props) throws inf.compilers.ExpressivenessException, java.io.IOException
This function pretty-prints the given ConnectedSentence to the given Writer.
indent
- the amount of indentation for the first linestmt
- the ConnectedSentence that is to be writtenw
- the Writer to which the ConnectedSentence is to be writtenprops
- the Properties used for writing
inf.compilers.ExpressivenessException
- if any contained NamedSymbol is internal
or the Connective is XOR (which KIF does not have)
java.io.IOException
- if writing to the Writer failspublic static void writeNegatedSentence(NegatedSentence stmt, java.io.Writer w, java.util.Properties props) throws inf.compilers.ExpressivenessException, java.io.IOException
This function writes the given NegatedSentence to the given Writer. A NegatedSentence is a List containing the String "not" followed by the contained Sentence.
<NegatedSentence> ::= (not <Sentence>)
stmt
- the NegatedSentence that is to be writtenw
- the Writer to which the NegatedSentence is to be writtenprops
- the Properties used for writing
inf.compilers.ExpressivenessException
- if any contained NamedSymbol is internal
java.io.IOException
- if writing to the Writer failspublic static void prettyPrintNegatedSentence(int indent, NegatedSentence stmt, java.io.Writer w, java.util.Properties props) throws inf.compilers.ExpressivenessException, java.io.IOException
This function pretty-prints the given NegatedSentence to the given Writer.
indent
- the amount of indentation for the first linestmt
- the NegatedSentence that is to be writtenw
- the Writer to which the NegatedSentence is to be writtenprops
- the Properties used for writing
inf.compilers.ExpressivenessException
- if any contained NamedSymbol is internal
java.io.IOException
- if writing to the Writer failspublic static void writeLiteral(Literal lit, java.io.Writer w, java.util.Properties props) throws inf.compilers.ExpressivenessException, java.io.IOException
This function writes the given Literal to the given Writer. If the Literal is positive it is written like an Atom, simply as the contained NamedSymbol. Otherwiese it is written like a negated Sentence.
<Literal> ::= <NamedSymbol> | (not <NamedSymbol>)
lit
- the Literal that is to be writtenw
- the Writer to which the Literal is to be writtenprops
- the Properties used for writing
inf.compilers.ExpressivenessException
- if the contained NamedSymbol is internal
java.io.IOException
- if writing to the Writer failspublic static void writeAtom(Atom atom, java.io.Writer w, java.util.Properties props) throws inf.compilers.ExpressivenessException, java.io.IOException
This function writes the given Atom to the given Writer. It is written as the NamedSymbol including its NameSpace as a full URI.
<Atom> ::= <NamedSymbol>
atom
- the Atom that is to be writtenw
- the Writer to which the Atom is to be writtenprops
- the Properties used for writing
inf.compilers.ExpressivenessException
- if the contained NamedSymbol is internal
java.io.IOException
- if writing to the Writer failspublic static void writeTruthValue(TruthValue tValue, java.io.Writer w, java.util.Properties props) throws inf.compilers.ExpressivenessException, java.io.IOException
This function writes the given TruthValue to the given Writer. It is written as "TRUE" or "FALSE" (without any NameSpace).
<TruthValue> ::= TRUE | FALSE
tValue
- the TruthValue that is to be writtenw
- the Writer to which the TruthValue is to be writtenprops
- the Properties used for writing
java.io.IOException
- if writing to the Writer fails
inf.compilers.ExpressivenessException
public static Sentence parseSentence(inf.compilers.LexicalAnalyzer scanner, java.util.Properties props) throws inf.compilers.ExpressivenessException, java.text.ParseException, java.io.IOException
This function attempts to parse a propositional Sentence in KIF syntax from the underlying LexicalAnalyzer. Since the target representation is propositional and KIF is a much more expressive syntax, there are many reasons why an ExpressivenessException may be thrown. However, some of these may look like syntax problem to this parser and thus will be thrown as ParseExceptions.
scanner
- the LexicalAnalyzer from which character input is readprops
- the properties used for reading
inf.compilers.ExpressivenessException
- if the input is not propositional
java.text.ParseException
- if the KIF syntax is violated
java.io.IOException
- if reading from the LexicalAnalyzer failspublic static java.util.List<Sentence> parseSentences(inf.compilers.LexicalAnalyzer scanner, java.util.Properties props) throws inf.compilers.ExpressivenessException, java.text.ParseException, java.io.IOException
This function attempts to parse a sequence of at least two Sentences from the given LexicalAnalyzer.
scanner
- the LexicalAnalyzer from which character input is readprops
- the properties used for reading
inf.compilers.ExpressivenessException
- form sub-Sentences
java.text.ParseException
- if there are fewer than two Sentences
java.io.IOException
- if reading fails
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |