📄 racertermparser.java
字号:
* @return java.lang.Object The representation of the at-least term (null for this class).
* @param v java.util.Vector A vector of strings. The first position is filled with "at-least", the second
with an integer and the third with a role term.
* @exception jracer.RacerIllegalConstruction If the term is not a racer term.
*/
protected Object parseAtLeast(Vector v) throws RacerIllegalConstruction {
if (v.size()<3 || v.size()>4) throw new RacerIllegalConstruction(v);
int n=parseInteger((String)v.elementAt(1));
Object role=parseRole((String)v.elementAt(2));
if (v.size()==3) return buildAtLeast(n,role);
Object concept=parseConcept((String)v.elementAt(3));
return buildAtLeast(n,role,concept);
}
/** This method returns the representation of the at-most concept represented by the vector. For this class,
the returned value is null.
* @return java.lang.Object The representation of the at-most term (null for this class).
* @param v java.util.Vector A vector of strings. The first position is filled with "at-most", the second
with an integer and the third with a role term.
* @exception jracer.RacerIllegalConstruction If the term is not a racer term.
*/
protected Object parseAtMost(Vector v) throws RacerIllegalConstruction {
if (v.size()<3 || v.size()>4) throw new RacerIllegalConstruction(v);
int n=parseInteger((String)v.elementAt(1));
Object role=parseRole((String)v.elementAt(2));
if (v.size()==3) return buildAtMost(n,role);
Object concept=parseConcept((String)v.elementAt(3));
return buildAtMost(n,role,concept);
}
/** This method parses a concept term and returns the parsed object (that should correspond to a
representation of the term). The behaviour provided in this base class is to return always null.
Anyway, the method can be used for syntax checking purposes.
* @return java.lang.Object The parsed concept.
* @param c java.lang.String The string representation of the concept.
* @exception jracer.RacerIllegalConstruction Thrown when the term does not correspond to a RACER
term.
*/
public Object parseConcept(String c) throws RacerIllegalConstruction {
if (c.equalsIgnoreCase("top")) return buildTop();
if (c.equalsIgnoreCase("bottom")) return buildBottom();
if (c.charAt(0) == '|' && c.charAt(c.length()-1) == '|') return buildLitteral();
if (c.indexOf(' ')==-1 && c.indexOf('(')==-1 && c.indexOf(')')==-1) return buildAtomicConcept(c);
Vector v=RacerClient.parseLispList(c);
String constructor=(String)v.elementAt(0);
if (constructor.equalsIgnoreCase("and")) return parseConjunction(v);
if (constructor.equalsIgnoreCase("or")) return parseDisjunction(v);
if (constructor.equalsIgnoreCase("some")) return parseSome(v);
if (constructor.equalsIgnoreCase("all")) return parseAll(v);
if (constructor.equalsIgnoreCase("at-least")) return parseAtLeast(v);
if (constructor.equalsIgnoreCase("at-most")) return parseAtMost(v);
if (constructor.equalsIgnoreCase("not")) return parseNot(v);
throw new RacerIllegalConstruction(c+" is not a correct concept term.");
}
/** This method returns the representation of the conjunction represented by the vector. For this class,
the returned value is null.
* @return java.lang.Object The representation of the conjunction term (null for this class).
* @param v java.util.Vector A vector of strings. The first position is filled with "and", and the rest
of positions are filled by the subterms.
* @exception jracer.RacerIllegalConstruction If the term is not a racer term.
*/
protected Object parseConjunction(Vector v) throws RacerIllegalConstruction {
Object[] terms=new Object[v.size()-1];
for(int i=1;i<v.size();i++) {
String subterm=(String)v.elementAt(i);
terms[i-1]=parseConcept(subterm);
}
return buildConjunction(terms);
}
/** This method returns the representation of the conjunction represented by the vector. For this class,
the returned value is null.
* @return java.lang.Object The representation of the conjunction term (null for this class).
* @param v java.util.Vector A vector of strings. The first position is filled with "and", and the rest
of positions are filled by the subterms.
* @exception jracer.RacerIllegalConstruction If the term is not a racer term.
*/
protected Object parseDisjunction(Vector v) throws RacerIllegalConstruction {
Object[] terms=new Object[v.size()-1];
for(int i=1;i<v.size();i++) {
String subterm=(String)v.elementAt(i);
terms[i-1]=parseConcept(subterm);
}
return buildDisjunction(terms);
}
/** This method returns the representation of the at-most concept represented by the vector. For this class,
the returned value is null.
* @return java.lang.Object The representation of the at-most term (null for this class).
* @param v java.util.Vector A vector of strings. The first position is filled with "at-most", the second
with an integer and the third with a role term.
* @exception jracer.RacerIllegalConstruction If the term is not a racer term.
*/
protected Object parseExactly(Vector v) throws RacerIllegalConstruction {
if (v.size()<3 || v.size()>4) throw new RacerIllegalConstruction(v);
int n=parseInteger((String)v.elementAt(1));
Object role=parseRole((String)v.elementAt(2));
if (v.size()==3) return buildExactly(n,role);
Object concept=parseConcept((String)v.elementAt(3));
return buildExactly(n,role,concept);
}
/** This method parses an integer from a string.
* @return int The integer value.
* @param s java.lang.String The string representation of the integer.
* @exception jracer.RacerIllegalConstruction When the string does not correspond to an integer.
*/
protected int parseInteger(String s) throws RacerIllegalConstruction {
int i;
try { i=Integer.parseInt(s); }
catch (NumberFormatException e) { throw new RacerIllegalConstruction(s+" is not a correct integer term"); }
return i;
}
/** This method returns the representation of the inverse role represented by the vector. For this class,
the returned value is null.
* @return java.lang.Object The representation of the inverse term (null for this class).
* @param v java.util.Vector A vector of strings. The first position is filled with "inv", the second
with the role term.
* @exception jracer.RacerIllegalConstruction If the term is not a racer term.
*/
protected Object parseInverse(Vector v) throws RacerIllegalConstruction {
if (v.size()!=2) throw new RacerIllegalConstruction(v);
Object role=parseRole((String)v.elementAt(1));
return buildInverse(role);
}
/** This method returns the representation of the not concept represented by the vector. For this class,
the returned value is null.
* @return java.lang.Object The representation of the not term (null for this class).
* @param v java.util.Vector A vector of strings. The first position is filled with "not", the second
with the concept term.
* @exception jracer.RacerIllegalConstruction If the term is not a racer term.
*/
protected Object parseNot(Vector v) throws RacerIllegalConstruction {
if (v.size()!=2) throw new RacerIllegalConstruction(v);
Object c=parseConcept((String)v.elementAt(1));
return buildNot(c);
}
/** This method parses a role term and returns the parsed object (that should correspond to a
representation of the term). The behaviour provided in this base class is to return always null.
Anyway, the method can be used for syntax checking purposes.
* @return java.lang.Object The parsed role.
* @param c java.lang.String The string representation of the role.
* @exception jracer.RacerIllegalConstruction Thrown when the term does not correspond to a RACER
term.
*/
public Object parseRole(String c) throws RacerIllegalConstruction {
if (c.indexOf(' ')==-1 && c.indexOf('(')==-1 && c.indexOf(')')==-1) return buildAtomicRole(c);
Vector v=RacerClient.parseLispList(c);
String constructor=(String)v.elementAt(0);
if (constructor.equalsIgnoreCase("inv")) return parseInverse(v);
throw new RacerIllegalConstruction(c+" is not a correct role term.");
}
/** This method returns the representation of the some concept represented by the vector. For this class,
the returned value is null.
* @return java.lang.Object The representation of the some term (null for this class).
* @param v java.util.Vector A vector of strings. The first position is filled with "some", the second
with the role term and the third with a concept term.
* @exception jracer.RacerIllegalConstruction If the term is not a racer term.
*/
protected Object parseSome(Vector v) throws RacerIllegalConstruction {
if (v.size()!=3) throw new RacerIllegalConstruction(v);
Object role=parseRole((String)v.elementAt(1));
Object concept=parseConcept((String)v.elementAt(2));
return buildSome(role,concept);
}
/** This method parses a concrete domain attribute and returns the parsed object (that should correspond to a
representation of the term). The behaviour provided in this base class is to return always null.
Anyway, the method can be used for syntax checking purposes.
* @return java.lang.Object The parsed attribute.
* @param c java.lang.String The string representation of the attribute.
* @exception jracer.RacerIllegalConstruction Thrown when the term does not correspond to a RACER
term.
*/
public Object parseAttribute(String c) throws RacerIllegalConstruction {
if (c.indexOf(' ')==-1 && c.indexOf('(')==-1 && c.indexOf(')')==-1) return buildAtomicRole(c);
throw new RacerIllegalConstruction(c+" is not a correct attribute name.");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -