revisionlogic
Class SentenceParser

java.lang.Object
  extended byrevisionlogic.SentenceParser

public class SentenceParser
extends java.lang.Object

SentenceParser is a converter between strings and ISent instances.

Author:
Daphne Liu, daphnel@sfu.ca; Sven Thiele, sthiele@rz.uni-potsdam.de

Field Summary
static java.util.regex.Matcher m
          The string pattern matcher for reading the KB caption from the KB input files.
 
Constructor Summary
SentenceParser()
          Creates a new default SentenceParser.
 
Method Summary
static void containsIllegalLiterals(ISent s)
          Checks all the literals in the sentence s to see if any contains logical or reserved symbols.
static java.util.Vector getCBICsFromFile(java.lang.String sFilename)
          Creates and returns a vector of consistency-based integrity constraints (CB IC) read from the text file sFilename.
static ISent getConjunctionFromFile(java.lang.String sFilename, java.lang.String fileType)
          Creates and returns a conjunction of revision sentences or a conjunction of entailment-based integrity constraints (EB IC) in the text file sFilename.
static java.util.Vector getContractionsFromFile(java.lang.String sFilename)
          Creates and returns a vector of contraction sentences read from the text file sFilename.
(package private) static ISent getContractResult(ISent AllKB, java.util.Vector CA, java.util.Vector EQLit)
          Returns and creates from AllKB an ISent sentence in which the renaming of literals based on the common atoms CA and the equivalence set literals EQLit is applied according to the renaming algorithm following contractions.
static java.util.Vector getKBsFromFile(java.lang.String sFilename)
          Creates and returns a vector of knowledge bases consisting of sentences in the text file sFilename.
(package private) static ISent parsePrimeString(java.lang.String s, java.util.Collection v, int n)
          Parses the string s and returns an ISent sentence in which the literals also appearing in the Vector v are either numbered if n is a positive integer or primed otherwise.
static ISent parseString(java.lang.String s)
          Parses the string s and returns the corresonponding ISent sentence.
(package private) static ISent parseUnNumberString(java.lang.String s, java.util.Vector EqLit)
          Parses the string s and returns an ISent sentence in which the numbered literals also appearing in the Vector EqLit are primed, and the numbered literals not in EqLit are negated and primed.
(package private) static ISent parseUnprimeString(java.lang.String s, java.util.Vector EqLit, java.util.Vector CA)
          Parses the string s and returns an ISent sentence in which for each primed literal, it is either negated and unprimed if it appears in Vector CA and not in Vector EqLit, or simply unprimed otherwise.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m

public static java.util.regex.Matcher m
The string pattern matcher for reading the KB caption from the KB input files.

Constructor Detail

SentenceParser

public SentenceParser()
Creates a new default SentenceParser.

Method Detail

getConjunctionFromFile

public static ISent getConjunctionFromFile(java.lang.String sFilename,
                                           java.lang.String fileType)
                                    throws InconsistencyException,
                                           SyntaxErrException
Creates and returns a conjunction of revision sentences or a conjunction of entailment-based integrity constraints (EB IC) in the text file sFilename.

Each sentence is on a new line and is interpreted as a conjunct.

Parameters:
sFilename - the absolute path of the text file containing conjuncts one on each line.
fileType - the string indicating whether sFilename is for "revision" or for "EB IC".
Returns:
a reference to an ISent conjunction of revision sentences or EB ICs in sFilename.
Throws:
InconsistencyException - if any conjunct is inconsistent or if any conjunct is mutually inconsistent with any other conjunct(s).
SyntaxErrException - if any conjunct is syntactically malformed.

getKBsFromFile

public static java.util.Vector getKBsFromFile(java.lang.String sFilename)
                                       throws SyntaxErrException
Creates and returns a vector of knowledge bases consisting of sentences in the text file sFilename.

Each new knowledge base begins with a caption matching "\\s*KB.*:.*"; further, each sentence for a knowledge base is interpreted as a conjunct as each knowledge base is returned as a conjunction.

Parameters:
sFilename - the absolute path of the text file containing sentences one on each line.
Returns:
a Vector of knowledge bases, each represented as an ISent conjunction of sentences in sFilename.
Throws:
SyntaxErrException - if any sentence is syntactically malformed.

getContractionsFromFile

public static java.util.Vector getContractionsFromFile(java.lang.String sFilename)
                                                throws InconsistencyException,
                                                       SyntaxErrException
Creates and returns a vector of contraction sentences read from the text file sFilename. Each sentence is on a new line and is interpreted as a sentence for contraction.

Parameters:
sFilename - the absolute path of the text file containing sentences one on each line.
Returns:
a Vector of contraction sentences, each represented as an ISent.
Throws:
InconsistencyException - if any contraction sentence is a tautology.
SyntaxErrException - if any sentence is syntactically malformed.

getCBICsFromFile

public static java.util.Vector getCBICsFromFile(java.lang.String sFilename)
                                         throws SyntaxErrException
Creates and returns a vector of consistency-based integrity constraints (CB IC) read from the text file sFilename. Each sentence is on a new line and is interpreted as a consistency-based integrity constraint.

Parameters:
sFilename - the absolute path of the text file containing sentences one on each line.
Returns:
a Vector of CB IC sentences, each represented as an ISent.
Throws:
SyntaxErrException - if any sentence is syntactically malformed.

containsIllegalLiterals

public static void containsIllegalLiterals(ISent s)
                                    throws SyntaxErrException
Checks all the literals in the sentence s to see if any contains logical or reserved symbols.

Parameters:
s - a reference to the ISent sentence whose literals are to be checked.
Throws:
SyntaxErrException - if any literal of s contains any logical or reserved symbols.

parseString

public static ISent parseString(java.lang.String s)
                         throws SyntaxErrException
Parses the string s and returns the corresonponding ISent sentence.

Parameters:
s - the string to be parsed as an ISent sentence.
Returns:
a reference to the corresponding ISent sentence for s.
Throws:
SyntaxErrException - if s is syntactically malformed.

parsePrimeString

static ISent parsePrimeString(java.lang.String s,
                              java.util.Collection v,
                              int n)
Parses the string s and returns an ISent sentence in which the literals also appearing in the Vector v are either numbered if n is a positive integer or primed otherwise.

Parameters:
s - the string to be parsed as an ISent sentence.
v - the Vector of literals to be checked against the literals of s.
n - an int specifying whether the common literals of s and v are to be numbered (if n > 0) or primed (if n <= 0).
Returns:
a reference to the corresponding ISent sentence for s.

parseUnNumberString

static ISent parseUnNumberString(java.lang.String s,
                                 java.util.Vector EqLit)
Parses the string s and returns an ISent sentence in which the numbered literals also appearing in the Vector EqLit are primed, and the numbered literals not in EqLit are negated and primed.

Parameters:
s - the string to be parsed as an ISent sentence.
EqLit - the Vector of literals to be checked against the numbered literals of s.
Returns:
a reference to the corresponding ISent sentence for s.

parseUnprimeString

static ISent parseUnprimeString(java.lang.String s,
                                java.util.Vector EqLit,
                                java.util.Vector CA)
Parses the string s and returns an ISent sentence in which for each primed literal, it is either negated and unprimed if it appears in Vector CA and not in Vector EqLit, or simply unprimed otherwise.

Parameters:
s - the string to be parsed as an ISent sentence.
EqLit - the Vector of literals to be checked against the primed literals of s.
CA - the Vector of literals to be checked against the primed literals of s.
Returns:
a reference to the corresponding ISent sentence for s.

getContractResult

static ISent getContractResult(ISent AllKB,
                               java.util.Vector CA,
                               java.util.Vector EQLit)
Returns and creates from AllKB an ISent sentence in which the renaming of literals based on the common atoms CA and the equivalence set literals EQLit is applied according to the renaming algorithm following contractions.

AllKB must be the ISent returned by parseUnprimeString( AllKB.getLabel(), equivalence set literals, common atoms, literals in contraction sentences).

Parameters:
AllKB - a reference to the resultant ISent knowledge base before it is conjoined with the revision.
CA - the Vector of common atoms to be checked against the literals of AllKB.
EQLit - the Vector of equivalence set literals to be checked against the literals of AllKB.
Returns:
a reference to the corresponding ISent sentence for AllKB after the renaming.