Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/alicebot/server/core/processor/SRAIProcessor.java


1   /*
2       Alicebot Program D
3       Copyright (C) 1995-2001, A.L.I.C.E. AI Foundation
4       
5       This program is free software; you can redistribute it and/or
6       modify it under the terms of the GNU General Public License
7       as published by the Free Software Foundation; either version 2
8       of the License, or (at your option) any later version.
9       
10      You should have received a copy of the GNU General Public License
11      along with this program; if not, write to the Free Software
12      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, 
13      USA.
14  */
15  
16  /*
17      Code cleanup (4.1.3 [00] - October 2001, Noel Bush)
18      - formatting cleanup
19      - complete javadoc
20      - made all imports explicit
21      - inlined method calls to avoid temporary variable
22  */
23  
24  /*
25      Further optimizations {4.1.3 [01] - November 2001, Noel Bush)
26      - changed to extend (not implement) AIMLProcessor (latter is now an abstract class)
27        (includes necessary public field "label")
28  */
29  
30  /*
31      More fixes (4.1.3 [02] - November 2001, Noel Bush)
32      - added match trace indicator
33      - changed to use getInternalResponse() method of ActiveMultiplexor
34  */
35  
36  package org.alicebot.server.core.processor;
37  
38  import java.util.Iterator;
39  
40  import org.alicebot.server.core.ActiveMultiplexor;
41  import org.alicebot.server.core.Globals;
42  import org.alicebot.server.core.Graphmaster;
43  import org.alicebot.server.core.Multiplexor;
44  import org.alicebot.server.core.logging.Log;
45  import org.alicebot.server.core.util.Trace;
46  import org.alicebot.server.core.parser.TemplateParser;
47  import org.alicebot.server.core.parser.XMLNode;
48  
49  
50  /**
51   *  Implements the <srai/> element.
52   *
53   *  @version    4.1.3
54   *  @author     Jon Baer
55   *  @author     Thomas Ringate, Pedro Colla
56   */
57  public class SRAIProcessor extends AIMLProcessor
58  {
59      public static final String label = "srai";
60  
61  
62      /**
63       *  Processes a <srai/> element.
64       *
65       *  First, all elements contained within a given <srai/>
66       *  are evaluated, and the result is recursively fed as input
67       *  to the pattern matching process. The result of such evaluation
68       *  (which itself might be recursive) is returned as the result.
69       *
70       *  @see AIMLProcessor#process
71       */
72      public String process(int level, XMLNode tag, TemplateParser parser) throws AIMLProcessorException
73      {
74          String result = new String();
75          
76          if (tag.XMLType == XMLNode.TAG)
77          {
78              // Check for infinite loops.
79              if (tag.XMLChild.size() == 1)
80              {
81                  XMLNode sraiChild = (XMLNode)tag.XMLChild.get(0);
82  
83                  if (sraiChild.XMLType == XMLNode.DATA)
84                  {
85                      String sraiContent = sraiChild.XMLData;
86                      //adjamir
87                      /*Iterator inputsIterator = parser.getInputs().iterator();
88  
89                      while (inputsIterator.hasNext())
90                      {
91                          String input = (String)inputsIterator.next();
92  
93                          if (sraiContent.equalsIgnoreCase(input))
94                          {
95                              if (!sraiContent.equalsIgnoreCase(Globals.getInfiniteLoopInput()))
96                              {
97                                  sraiChild.XMLData = Globals.getInfiniteLoopInput();
98                                  Log.userinfo("Infinite loop detected; substituting \"" + Globals.getInfiniteLoopInput() + "\".", Log.RUNTIME);
99                              }
100                             else
101                             {
102                                 Log.userinfo("Unrecoverable infinite loop.", Log.RUNTIME);
103                                 return EMPTY_STRING;
104                             }
105                         }
106                     }
107                     */
108                     parser.addInput(sraiContent);
109                 }
110             }
111             if (Globals.showMatchTrace())
112             {
113                 Trace.userinfo("Symbolic Reduction:");
114             }
115             parser.push();
116             result = Multiplexor.getInternalResponse(parser.evaluate(level++, tag.XMLChild),
117                                                                        parser.getUserID(), parser.getBotID(),
118                                                                        parser);
119             parser.pop();
120             return result;
121         }
122         else
123         {
124             throw new AIMLProcessorException("<srai></srai> must have content!");
125         }
126     }
127 }