本文整理汇总了Java中jason.asSyntax.Literal.getArity方法的典型用法代码示例。如果您正苦于以下问题:Java Literal.getArity方法的具体用法?Java Literal.getArity怎么用?Java Literal.getArity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jason.asSyntax.Literal
的用法示例。
在下文中一共展示了Literal.getArity方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: makeVarsAnnon
import jason.asSyntax.Literal; //导入方法依赖的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: fixAgInIAandFunctions
import jason.asSyntax.Literal; //导入方法依赖的package包/类
private void fixAgInIAandFunctions(Agent a, Literal l) throws Exception {
// if l is internal action/function
if (l instanceof InternalActionLiteral) {
((InternalActionLiteral)l).setIA(null); // reset the IA in the literal, the IA there will be updated next getIA call
}
if (l instanceof ArithFunctionTerm) {
((ArithFunctionTerm)l).setAgent(a);
}
if (l instanceof Rule) {
LogicalFormula f = ((Rule)l).getBody();
if (f instanceof Literal) {
fixAgInIAandFunctions(a, (Literal)f);
}
}
for (int i=0; i<l.getArity(); i++) {
if (l.getTerm(i) instanceof Literal)
fixAgInIAandFunctions(a, (Literal)l.getTerm(i));
}
}
示例3: prepareArguments
import jason.asSyntax.Literal; //导入方法依赖的package包/类
public Term[] prepareArguments(Literal body, Unifier un) {
Term[] terms = new Term[body.getArity()];
for (int i=0; i<terms.length; i++) {
terms[i] = body.getTerm(i).capply(un);
}
return terms;
}
示例4: getWhere
import jason.asSyntax.Literal; //导入方法依赖的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 "";
}
示例5: getInsert
import jason.asSyntax.Literal; //导入方法依赖的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();
}
示例6: checkHardDeadline
import jason.asSyntax.Literal; //导入方法依赖的package包/类
protected void checkHardDeadline(final Event evt) {
final Literal body = evt.getTrigger().getLiteral();
Literal hdl = body.getAnnot(ASSyntax.hardDeadLineStr);
if (hdl == null)
return;
if (hdl.getArity() < 1)
return;
// schedule the verification of deadline for the intention
final Intention intention = evt.getIntention();
final int isize;
if (intention == null)
isize = 0;
else
isize = intention.size();
int deadline = 0;
try {
deadline = (int)((NumberTerm)hdl.getTerm(0)).solve();
} catch (NoValueException e1) {
e1.printStackTrace();
}
Agent.getScheduler().schedule(new Runnable() {
public void run() {
runAtBeginOfNextCycle(new Runnable() {
public void run() {
boolean drop = false;
if (intention == null) { // deadline in !!g, test if the agent still desires it
drop = desire.allDesires(C, body, new Unifier()).hasNext();
} else if (intention.size() >= isize && intention.hasTrigger(evt.getTrigger(), new Unifier())) {
drop = true;
}
if (drop) {
try {
FailWithDeadline ia = new FailWithDeadline(intention, evt.getTrigger());
ia.drop(TransitionSystem.this, body, new Unifier());
} catch (Exception e) {
e.printStackTrace();
}
}
}
});
getUserAgArch().wakeUpSense();
}
}, deadline, TimeUnit.MILLISECONDS);
}
示例7: unifyTerms
import jason.asSyntax.Literal; //导入方法依赖的package包/类
protected boolean unifyTerms(Term t1g, Term t2g) {
// if args are expressions, apply them and use their values
if (t1g.isArithExpr())
t1g = t1g.capply(this);
if (t2g.isArithExpr())
t2g = t2g.capply(this);
final boolean t1gisvar = t1g.isVar();
final boolean t2gisvar = t2g.isVar();
// one of the args is a var
if (t1gisvar || t2gisvar) {
final VarTerm t1gv = t1gisvar ? (VarTerm)t1g : null;
final VarTerm t2gv = t2gisvar ? (VarTerm)t2g : null;
// get their values
final Term t1vl = t1gisvar ? get(t1gv) : t1g;
final Term t2vl = t2gisvar ? get(t2gv) : t2g;
if (t1vl != null && t2vl != null) { // unifies the two values of the vars
return unifiesNoUndo(t1vl, t2vl);
} else if (t1vl != null) { // unifies var with value
return bind(t2gv, t1vl);
} else if (t2vl != null) {
return bind(t1gv, t2vl);
} else { // unify two vars
if (! t1gv.getNS().equals(t2gv.getNS()))
return false;
if (t1gv.negated() != t2gv.negated())
return false;
bind(t1gv, t2gv);
return true;
}
}
// both terms are not vars
// if any of the terms is not a literal (is a number or a
// string), they must be equal
// (for unification, lists are literals)
if (!t1g.isLiteral() && !t1g.isList() || !t2g.isLiteral() && !t2g.isList())
return t1g.equals(t2g);
// both terms are literal
Literal t1s = (Literal)t1g;
Literal t2s = (Literal)t2g;
// different arities
final int ts = t1s.getArity();
if (ts != t2s.getArity())
return false;
// if both are literal, they must have the same negated
if (t1s.negated() != t2s.negated())
return false;
// different functor
if (!t1s.getFunctor().equals(t2s.getFunctor()))
return false;
// different name space
if (!unifiesNamespace(t1s, t2s))
return false;
// unify inner terms
// do not use iterator! (see ListTermImpl class)
for (int i = 0; i < ts; i++)
if (!unifiesNoUndo(t1s.getTerm(i), t2s.getTerm(i)))
return false;
// the first's annots must be subset of the second's annots
if ( ! t1s.hasSubsetAnnot(t2s, this))
return false;
return true;
}
示例8: add
import jason.asSyntax.Literal; //导入方法依赖的package包/类
@Override
public boolean add(Literal bel) {
Structure kb = indexedBels.get(bel.getFunctor());
if (kb != null && kb.getArity() == bel.getArity()) { // is a constrained bel?
// find the bel in BB and eventually remove it
u.clear();
Literal linbb = null;
boolean remove = false;
Iterator<Literal> relevant = getCandidateBeliefs(bel, null);
if (relevant != null) {
final int kbArity = kb.getArity();
while (relevant.hasNext() && !remove) {
linbb = relevant.next();
if (!linbb.isRule()) {
// check equality of all terms that are "key"
// if some key is different, no problem
// otherwise, remove the current bel
boolean equals = true;
for (int i = 0; i<kbArity; i++) {
Term kbt = kb.getTerm(i);
if (!kbt.isVar()) { // is key?
if (!u.unifies(bel.getTerm(i), linbb.getTerm(i))) {
equals = false;
break;
}
}
}
if (equals) {
remove = true;
}
}
}
}
if (remove) {
remove(linbb);
}
}
return super.add(bel);
}