Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  // Copyright (C) 2003  Rafael H. Bordini, Jomi F. Hubner, et al.
  // This library is free software; you can redistribute it and/or
  // modify it under the terms of the GNU Lesser General Public
  // License as published by the Free Software Foundation; either
  // version 2.1 of the License, or (at your option) any later version.
  // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
 // Lesser General Public License for more details.
 // You should have received a copy of the GNU Lesser General Public
 // License along with this library; if not, write to the Free Software
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 // To contact the authors:
 package jason.stdlib;

Internal action: .add_annot.

Description: adds an annotation to a literal.


  • + belief(s) (literal or list): the literal where the annotation is to be added. If this parameter is a list, all literals in the list will have the annotation added.
  • + annotation (structure): the annotation.
  • +/- annotated beliefs(s) (literal or list): this argument unifies with the result of the annotation addition.


  • .add_annot(a,source(jomi),B): B unifies with a[source(jomi)].
  • .add_annot(a,source(jomi),b[jomi]): fails because the result of the addition does not unify with the third argument.
  • .add_annot([a1,a2], source(jomi), B): B unifies with [a1[source(jomi)], a2[source(jomi)]].

Note: instead of using this internal action, you can use direct unification.
.add_annot(a,source(jomi),B) can be replaced by B = a[source(jomi)];
.add_annot(X,source(jomi),B) can be replaced by B = X[source(jomi)].

 public class add_annot extends DefaultInternalAction {
     private static InternalAction singleton = null;
     public static InternalAction create() {
         if ( == null
              = new add_annot();
         return ;
     @Override public int getMinArgs() { return 3; }
     @Override public int getMaxArgs() { return 3; } 
     @Override public Object execute(TransitionSystem tsUnifier unTerm[] argsthrows Exception {
         Term result = addAnnotToList(unargs[0], args[1]);
         return un.unifies(result,args[2]);
     protected Term addAnnotToList(Unifier unifTerm lTerm annotthrows JasonException {
         if (l.isList()) {
             ListTerm result = new ListTermImpl();
             for (Term lTerm: (ListTerm)l) {
                 Term t = addAnnotToListuniflTermannot);
                if (t != null) {
            return result;
        } else if (l.isLiteral()) {
            return ((Literal)l).forceFullLiteralImpl().copy().addAnnots(annot);
        return l;
New to GrepCode? Check out our FAQ X