本文整理汇总了Java中jason.asSyntax.Term.isString方法的典型用法代码示例。如果您正苦于以下问题:Java Term.isString方法的具体用法?Java Term.isString怎么用?Java Term.isString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jason.asSyntax.Term
的用法示例。
在下文中一共展示了Term.isString方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: makeVarsAnnon
import jason.asSyntax.Term; //导入方法依赖的package包/类
public void makeVarsAnnon(Literal l, Unifier un) {
try {
for (int i=0; i<l.getArity(); i++) {
Term t = l.getTerm(i);
if (t.isString()) {
StringTerm st = (StringTerm)t;
Matcher matcher = regex.matcher(st.getString());
StringBuffer sb = new StringBuffer();
while (matcher.find()) {
String sVar = matcher.group();
sVar = sVar.substring(2, sVar.length() - 1);
Term v = ASSyntax.parseTerm(sVar);
if (v.isVar()) {
VarTerm to = ((Structure)l).varToReplace(v, un);
matcher.appendReplacement(sb, "#{"+to.toString()+"}");
}
}
matcher.appendTail(sb);
l.setTerm(i, new StringTermImpl(sb.toString()));
}
}
} catch (ParseException pe) {
pe.printStackTrace();
}
}
示例2: execute
import jason.asSyntax.Term; //导入方法依赖的package包/类
@Override
public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
checkArguments(args);
Term l1 = args[0];
if (l1.isList()) {
ListTerm lt = (ListTerm) l1;
return lt.isEmpty();
} else if (l1.isString()) {
StringTerm st = (StringTerm) l1;
return st.getString().isEmpty();
}
return false;
}
示例3: delegateSendToArch
import jason.asSyntax.Term; //导入方法依赖的package包/类
private void delegateSendToArch(Term to, TransitionSystem ts, Message m) throws Exception {
if (!to.isAtom() && !to.isString())
throw new JasonException("The TO parameter ('"+to+"') of the internal action 'send' is not an atom!");
String rec = null;
if (to.isString())
rec = ((StringTerm)to).getString();
else
rec = to.toString();
if (rec.equals("self"))
rec = ts.getUserAgArch().getAgName();
m.setReceiver(rec);
ts.getUserAgArch().sendMsg(m);
}
示例4: testString
import jason.asSyntax.Term; //导入方法依赖的package包/类
private Structure testString(Term t) {
if (t.isStructure())
return (Structure)t;
if (t.isString())
return Structure.parse(((StringTerm)t).getString());
return null;
}
示例5: getWhere
import jason.asSyntax.Term; //导入方法依赖的package包/类
/** returns the where clausule for a select for literal l */
protected String getWhere(Literal l) throws SQLException {
ResultSetMetaData meta = belsDB.get(l.getPredicateIndicator());
StringBuilder q = new StringBuilder(" where ");
String and = "";
// for all ground terms of l
for (int i = 0; i < l.getArity(); i++) {
Term t = l.getTerm(i);
if (t.isGround()) {
q.append(and);
String ts;
if (t.isString()) {
ts = "'" + ((StringTerm) t).getString() + "'";
} else if (t.isNumeric()) {
ts = t.toString();
} else {
ts = "'" + t.toString() + "'";
}
q.append(meta.getColumnName(i + 1) + " = " + ts);
and = " and ";
}
}
if (isCreatedByJason(l.getPredicateIndicator())) {
q.append(and + COL_NEG + " = " + l.negated());
}
//System.out.println(q.toString());
if (and.length() > 0) // add nothing in the clausule
return q.toString();
else
return "";
}
示例6: getInsert
import jason.asSyntax.Term; //导入方法依赖的package包/类
/** returns the SQL command to insert l into the DB */
protected String getInsert(Literal l) throws Exception {
StringBuilder q = new StringBuilder("insert into ");
ResultSetMetaData meta = belsDB.get(l.getPredicateIndicator());
q.append(meta.getTableName(1));
q.append(" values(");
// values
for (int i = 0; i < l.getArity(); i++) {
Term t = l.getTerm(i);
if (t.isString()) {
q.append("'" + ((StringTerm) t).getString() + "'");
} else {
Timestamp timestamp = structure2timestamp(t);
if (timestamp != null) {
q.append("TIMESTAMP '" + structure2timestamp(t) + "'");
} else {
q.append("'" + t.toString() + "'");
}
}
if (i < meta.getColumnCount() - 1) {
q.append(",");
}
}
if (isCreatedByJason(l.getPredicateIndicator())) {
q.append(l.negated() + ",");
if (l.hasAnnot()) {
q.append("\'" + l.getAnnots() + "\'");
} else {
q.append("\'[]\'");
}
}
q.append(")");
return q.toString();
}
示例7: execute
import jason.asSyntax.Term; //导入方法依赖的package包/类
@Override
public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
checkArguments(args);
StringBuffer sb = new StringBuffer();
for (Term term : args) {
if (!term.isString()) {
continue;
}
StringTerm st = (StringTerm) term;
Matcher matcher = regex.matcher(st.getString());
while (matcher.find()) {
/*
* System.out.println("I found the text \""+matcher.group()+ "\"
* starting at index "+matcher.start()+ " and ending at index
* "+matcher.end());
*/
String sVar = matcher.group();
sVar = sVar.substring(2, sVar.length() - 1);
try {
Term t = ASSyntax.parseTerm(sVar);
//We use t.apply to evaluate any logical or arithmetic expression in Jason
t = t.capply(un);
matcher.appendReplacement(sb, t.toString());
} catch (ParseException pe) {
// TODO: handle exception
// TODO: Decide whether or not we should ignore the exception and print the call instead
// Right now, if I get a parse error from ASSyntax, I just print the original escaped
// sequence, so a user can see that his/her expression was problematic
matcher.appendReplacement(sb, "#{"+sVar+"}");
}
}
matcher.appendTail(sb);
}
if (args[args.length - 1].isVar()) {
StringTerm stRes = new StringTermImpl(sb.toString());
return un.unifies(stRes, args[args.length - 1]);
} else {
ts.getLogger().info(sb.toString());
return true;
}
}