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
 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 // 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:
 // http://www.inf.ufrgs.br/~bordini
 // http://www.das.ufsc.br/~jomi
 //
 //----------------------------------------------------------------------------
 
 
 package jason.stdlib;
 

Internal action: .add_nested_source.

Description: adds a source annotation to a literal (used in communication).

Parameters:

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

Examples:

  • .add_nested_source(a,jomi,B): B unifies with a[source(jomi)].
  • .add_nested_source([a1,a2], jomi, B): B unifies with [a1[source(jomi)], a2[source(jomi)]].
  • .add_nested_source(a[source(bob)],jomi,B): B unifies with a[source(jomi)[source(bob)]], which means `I believe in a and the source for that is agent jomi, the source for jomi was bob'; bob sent a tell to jomi that sent a tell to me.
 
 public class add_nested_source extends DefaultInternalAction {
 
     private static InternalAction singleton = null;
     public static InternalAction create() {
         if ( == null
              = new add_nested_source();
         return ;
     }
     
     @Override public int getMinArgs() { return 3; }
     @Override public int getMaxArgs() { return 3; }
 
     @Override public Object execute(TransitionSystem tsUnifier unTerm[] argsthrows Exception {
         checkArguments(args);
         Term result = addAnnotToList(args[0], args[1]);
         return un.unifies(result,args[2]);
     }
 
     public static Term addAnnotToList(Term lTerm source) {
         if (l.isList()) {
             ListTerm result = new ListTermImpl();
             for (Term lTerm: (ListTerm)l) {
                 Term t = addAnnotToListlTermsource);
                 if (t != null) {
                     result.add(t);
                 }
            }
            return result;
        } else if (l.isLiteral()) {
            Literal result;
            if (l.isAtom()) {
                result = new LiteralImpl((Atom)l);
            } else {
                result = (Literal)l.clone();                
            }
             
            // create the source annots
            Literal ts = new Pred("source",1).addTerms(source).addAnnots(result.getAnnots("source"));
            
            result.delSources();
            result.addAnnot(ts);
            return result;
        } else {
            return l;
        }
    }   
New to GrepCode? Check out our FAQ X