├── AUTHORS ├── CAIML ├── COPYING ├── ChangeLog ├── INSTALL ├── Makefile.am ├── Makefile.cvs ├── NEWS ├── README ├── README.md ├── TODO ├── config.h.in ├── configure.in ├── doc ├── html │ ├── annotated.html │ ├── classaiml_1_1cInterpreter-members.html │ ├── classaiml_1_1cInterpreter.html │ ├── classaiml_1_1cInterpreterCallbacks-members.html │ ├── classaiml_1_1cInterpreterCallbacks.html │ ├── classes.html │ ├── dir_000000.html │ ├── dirs.html │ ├── doxygen.css │ ├── doxygen.png │ ├── functions.html │ ├── functions_func.html │ ├── functions_vars.html │ ├── index.html │ ├── namespaceaiml.html │ ├── namespacemembers.html │ ├── namespacemembers_enum.html │ ├── namespacemembers_eval.html │ ├── namespaces.html │ ├── structaiml_1_1cCoreOptions-members.html │ ├── structaiml_1_1cCoreOptions.html │ ├── structaiml_1_1cMatchLog-members.html │ └── structaiml_1_1cMatchLog.html └── man │ └── man3 │ ├── aiml.3 │ ├── aiml_cCoreOptions.3 │ ├── aiml_cInterpreter.3 │ ├── aiml_cInterpreterCallbacks.3 │ └── aiml_cMatchLog.3 ├── libaiml.lsm ├── libaiml.pc.in ├── server ├── Makefile.am ├── libaiml.xml ├── main.cpp ├── tlib_log.cpp └── tlib_log.h ├── src ├── Makefile.am ├── aiml.cpp ├── aiml.h ├── aiml_parser.cpp ├── aiml_parser.h ├── caiml_parser.cpp ├── caiml_parser.h ├── config_parser.cpp ├── config_parser.h ├── core.cpp ├── core.h ├── errors.cpp ├── errors.h ├── global.h ├── graphmaster.cpp ├── graphmaster.h ├── javascript.cpp ├── javascript.h ├── serializer.cpp ├── serializer.h ├── stuff.cpp ├── template_parser.cpp ├── user.cpp ├── user.h ├── user_manager.cpp └── user_manager.h └── test_app ├── Makefile.am ├── aiml ├── AI.aiml ├── ALICE.aiml ├── Adverbs.aiml ├── Astrology.aiml ├── Atomic.aiml ├── Biography.aiml ├── Bot.aiml ├── Botmaster.aiml ├── Client.aiml ├── Computers.aiml ├── Date.aiml ├── Default.aiml ├── Dialog.aiml ├── Drugs.aiml ├── Emotion.aiml ├── Food.aiml ├── Geography.aiml ├── Gossip.aiml ├── History.aiml ├── Humor.aiml ├── IU.aiml ├── Inquiry.aiml ├── Interjection.aiml ├── Knowledge.aiml ├── Literature.aiml ├── Makefile.am ├── Makefile.in ├── Money.aiml ├── Movies.aiml ├── Music.aiml ├── Parts.aiml ├── Personality.aiml ├── Philosophy.aiml ├── Pickup.aiml ├── Politics.aiml ├── Predicates.aiml ├── Psychology.aiml ├── Reduce.aiml ├── Reducer.aiml ├── Reductions.aiml ├── Religion.aiml ├── Salutations.aiml ├── Science.aiml ├── Sex.aiml ├── Spam.aiml ├── Sports.aiml ├── Stack.aiml ├── Stories.aiml ├── That.aiml ├── Wallace.aiml ├── Wallace.aiml.1 ├── Xfind.aiml └── update.aiml ├── libaiml.xml.dist ├── main.cpp └── userlist.xml /AUTHORS: -------------------------------------------------------------------------------- 1 | V01D 2 | -------------------------------------------------------------------------------- /CAIML: -------------------------------------------------------------------------------- 1 | File Format 2 | =========== 3 | 4 | [ Intro ] 5 | CAIML is intended to be used as a caching feature: you parse all your .aiml 6 | files once, then save the status of the graphmaster to a file. If you later 7 | need to use the same aiml files, you can just use the saved CAIML file (which 8 | is much faster). 9 | The CAIML file is NOT intended to be saved by the library in one platform 10 | and then read back in another. This is because the types used to store the 11 | data in the CAIML have sizes determined by the current architecture/compiler. 12 | This file format optimizes the constructions of the graphmaster. 13 | The templates are stored in a special binary format (when constructing the grapmhaster) 14 | and then executed at runtime. Thus, the binary content of the templates isn't 15 | described here (but should be taken merely as a chunk of binary data). 16 | The description of the file format is something like binary EBNF. 17 | Also, when this syntax is used: 18 | 19 | it means that that field has the name "n", and it is of type "number" (this 20 | allows referring to the field's value. 21 | 22 | [ Structure ] 23 | 24 | Basic types: 25 | : size_t (defined generally as unsigned long on most platforms) 26 | : char (one byte, 8 bits in most 32bit platforms) 27 | : a with value 0 28 | 29 | A string is saved as a number (size), indicating the length of the string, and 30 | 'size' bytes conforming the string itself: 31 | ::= {size} 32 | 33 | A similar one is the "node" field, but with restricted characters: [A-Z0-9] 34 | 35 | NOTE: both "string" and "node" never contain a '\0' (null terminator) 36 | 37 | Elements: 38 |
::= "CAIML" 39 | 40 | ::= 41 | 42 | ::= <#same_childs : number> <#diff_childs : number> 43 | {#same_childs} {#diff_childs} 44 | 45 | ::=
46 | 47 | 48 | [ Semantic ] 49 | The EBNF structure can't describe fully the structure of a CAIML file, but 50 | it helps to get an idea. 51 | 52 | A graphmaster can be thought as a rosetree (rosetree := nil | node and list 53 | of rosetree) that has 3 possible types of nodes ("pattern", "that" and "topic" 54 | nodes). Now, whenver a node is of type "pattern", its inmediate childs can be: nil, 55 | all of type "pattern", some of type "pattern" and some of type "that", or all 56 | of type "that". Same things happens if the parent is of type "that" and childs 57 | of type "that" and "topic". In the case of a "topic" node, the childs can only 58 | be nil or of type "topic". In the leafs of this whole rosetree, there are 59 | templates (just a in each one). 60 | 61 | This means that it is possible to write linearly this tree by walking the tree 62 | in Depth-First order. And considering that a node of type A has a list of 63 | childrens of the same type (same-childs-list) and a list of the next type 64 | (diff-child-list). 65 | 66 | An example might clear things up: 67 | 68 | _____A_____ 69 | / \ 70 | __B__ __C__ 71 | / \ / \ 72 | D E F G 73 | | | | | 74 | H I J K 75 | | 76 | L 77 | 78 | Node types: 79 | A, B, C, E -> type "pattern" 80 | D, F, G, I -> type "that" 81 | H, J, K, L -> type "topic" 82 | 83 | If I write binary s as text and the "same_childs" and 84 | "diff_childs" pair as [ , ], the resulting CAIML would look 85 | something like (header would be "CAIML0"): 86 | 1A[2,0]B[0,1]D[0,1]H[0,0]E[0,1]I[0,1]L[0,0]C[0,2]F[0,1]J[0,0] 87 | G[0,1]K[0,0] 88 | 89 | Note that the nodes and the have their length embedded. 90 | -------------------------------------------------------------------------------- /INSTALL: -------------------------------------------------------------------------------- 1 | libaiml installation 2 | =================== 3 | 4 | 1. Requirements 5 | You'll need three things to use libaiml: 6 | 1) std_utils: a small static library that I use in all my projects with a lot of usefull stuff 7 | (it avoids repeting code). You can get it at my site: [1]. 8 | 2) libxml2: a XML parser (it came with my linux distro so you'll probably do fine), anyway 9 | you can find it at [2] 10 | 3) An AIML set: I used the AAA set but you could use your own set obviously. 11 | WARNING: The AAA set wasn't the best choice for testing because it has some shadowed 12 | categories and can't be used all together. It is more like a starting point to do your own set. 13 | If you want to use the AAA set you should check the README file, there's some important 14 | info in there about it. 15 | 16 | 4) Optionally, to enable JavaScript support in the interpreter you will need 17 | "SpiderMonkey" (the Mozilla JavaScript interpreter). [4] 18 | 19 | 2. Building: 20 | The plain ol' way: ./configure && make && make install 21 | NOTE: if you can't compile libaiml because there are warnings poping up, you 22 | can disable the 'treat warnings as errors' feature, using --disable-werror 23 | at configure time. YOU SHOULD STILL SEND ME A NOTICE ABOUT THE WARNING. 24 | 25 | 3. Testing 26 | A test_app will be built together with libaiml. You can use this to test you own AIML set 27 | or get an idea of how libaiml works. 28 | 29 | 4. Using 30 | Read the README files regarding usage of the library. You actually need to do these things: 31 | * use a properly configured .conf file 32 | * use properly written substitution and bot variables files 33 | * create a user dir with read/write permissions 34 | * find an AIML set to use with the interpreter 35 | * integrate the library to your project 36 | 37 | Check the core.h header as it contains the interface your program will be using. Once again 38 | read the README file for further instructions, this is just a brief intro to the library. 39 | 40 | 5. Notes 41 | At [3] you will find all my projects also. 42 | _DO_ read the README file. The ChangeLog may also hold important release information. 43 | Be sure to check these files. 44 | 45 | [1] http://omicron.ig3.net/ 46 | [2] http://xmlsoft.org/ 47 | [3] http://freshmeat.net/ 48 | [4] http://www.mozilla.org/js/spidermonkey/ 49 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | # not a GNU package. You can remove this line, if 2 | # have all needed files, that a GNU package needs 3 | AUTOMAKE_OPTIONS = foreign 1.4 4 | 5 | SUBDIRS = src test_app 6 | 7 | pkgconfigdir = $(libdir)/pkgconfig 8 | pkgconfig_DATA = libaiml.pc 9 | 10 | 11 | -------------------------------------------------------------------------------- /Makefile.cvs: -------------------------------------------------------------------------------- 1 | default: all 2 | 3 | all: 4 | autoreconf -i 5 | -------------------------------------------------------------------------------- /NEWS: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaoshijuan/aiml/b3cdafb8c070486a9e17178727aed96ba8ec0f26/NEWS -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | aiml 2 | ==== 3 | 4 | aiml的C++实现,支持中文,改自libaiml -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | Suggestions for any other TODO items / IDEAS / how to resolve an unresolved and problematic 2 | TODO / how to optimize something, can be sent to me (check the README) 3 | 4 | Issues/Things to Consider 5 | ========================= 6 | - if getAnswer() is false inside respond() the input vector will be filled 7 | with unanswered inputs 8 | 9 | - check "dialog history" behavior, something is not right... either with 10 | libaiml or with Dialog.aiml 11 | 12 | Optimizations 13 | ============= 14 | - look for expensive operations on vectors/nodes/lists 15 | 16 | Still pending (probably for next version) 17 | ========================================= 18 | ** move trim_blanks to runtime before the response is delivered to user. This 19 | allows to removed newlines introduced by and other tags 20 | |_ just remove the newlines and stuff generated at runtime 21 | 22 | XML: 23 | - add namespace processing support to aiml_parser 24 | |_ there are incorrect .aiml's that use
  • inside
      , which confuses 25 | the interpreter (because
    • is parsed as aiml: when it should be noted 26 | that such li's are html:). Fix that. 27 | 28 | - check for XML specs about casing of tags/parameters. should they be case 29 | insensitive? 30 | - check for xml:space handling in libxml 31 | - add validation support 32 | 33 | - try to ship with my own aiml set next time 34 | - AI::AIML showed that a template like could return 35 | 'ok ', check why 36 | 37 | - libxml: there are some util functions like hasProp getProp that should be used 38 | 39 | General: 40 | - allow # of that/input's saved to be settable at runtime (array -> vector) 41 | - Add options to the .conf file to let the user decide how to handle unclear 42 | or undefined situations of the AIML spec 43 | 44 | JavaScript: 45 | - consider a way of defining some script to execute inside the general context 46 | at startup (to define functions, classes, open persistent databse connections and such) 47 | |_ conflicts with making each tag its own context, maybe it would be better 48 | to look into global classes or something like that 49 | 50 | Reaching 1.0 51 | ============ 52 | - Do some profiling to find bottlenecks 53 | - Optimizations 54 | 55 | Side Programs 56 | ============= 57 | AIML compiler: will allow compiling .aiml code into .caiml which can be loaded a 58 | lot faster. Compiled AIML code would be an optional input to the interpreter, native 59 | AIML parser won't be removed from libaiml. 60 | 61 | IDEAS: 62 | ===== 63 | * Automatic learning could be using the system (and maybe javascript) tag: the bot could 64 | write AIML data to a file and then learn it using . 65 | Of course, one could use a normal targeting approach by gossiping to a file (plain-text) 66 | information about an input being match by the catch-all category (all * wildcards). And then 67 | the botmaster would approve or deny this and use the learn feature with a user provided 68 | AIML file. 69 | 70 | * Make a perl script that can parse XML test sets (Program D's?) and use the 71 | perl interface to libaiml to validate the results 72 | -------------------------------------------------------------------------------- /config.h.in: -------------------------------------------------------------------------------- 1 | /* config.h.in. Generated from configure.in by autoheader. */ 2 | 3 | /* Enable compilation of CAIML writer/reader */ 4 | #undef ENABLE_CAIML 5 | 6 | /* Enable JavaScript API integration */ 7 | #undef ENABLE_JAVASCRIPT 8 | 9 | /* Enable PCRE support */ 10 | #undef ENABLE_PCRECPP 11 | 12 | /* Define to 1 if you have the header file. */ 13 | #undef HAVE_DLFCN_H 14 | 15 | /* Define to 1 if you have the `floor' function. */ 16 | #undef HAVE_FLOOR 17 | 18 | /* Define to 1 if you have the header file. */ 19 | #undef HAVE_INTTYPES_H 20 | 21 | /* Define to 1 if you have the header file. */ 22 | #undef HAVE_JSAPI_H 23 | 24 | /* Define to 1 if you have the `js' library (-ljs). */ 25 | #undef HAVE_LIBJS 26 | 27 | /* Define to 1 if you have the header file. */ 28 | #undef HAVE_MEMORY_H 29 | 30 | /* Define to 1 if you have the header file. */ 31 | #undef HAVE_NETINET_IN_H 32 | 33 | /* Define to 1 if you have the header file. */ 34 | #undef HAVE_PCRECPP_H 35 | 36 | /* Define to 1 if you have the header file. */ 37 | #undef HAVE_STDINT_H 38 | 39 | /* Define to 1 if you have the header file. */ 40 | #undef HAVE_STDLIB_H 41 | 42 | /* Define to 1 if you have the `strftime' function. */ 43 | #undef HAVE_STRFTIME 44 | 45 | /* Define to 1 if you have the header file. */ 46 | #undef HAVE_STRINGS_H 47 | 48 | /* Define to 1 if you have the header file. */ 49 | #undef HAVE_STRING_H 50 | 51 | /* Define to 1 if you have the header file. */ 52 | #undef HAVE_SYS_STAT_H 53 | 54 | /* Define to 1 if you have the header file. */ 55 | #undef HAVE_SYS_TYPES_H 56 | 57 | /* Define to 1 if you have the header file. */ 58 | #undef HAVE_UNISTD_H 59 | 60 | /* Name of package */ 61 | #undef PACKAGE 62 | 63 | /* Define to the address where bug reports for this package should be sent. */ 64 | #undef PACKAGE_BUGREPORT 65 | 66 | /* Define to the full name of this package. */ 67 | #undef PACKAGE_NAME 68 | 69 | /* Define to the full name and version of this package. */ 70 | #undef PACKAGE_STRING 71 | 72 | /* Define to the one symbol short name of this package. */ 73 | #undef PACKAGE_TARNAME 74 | 75 | /* Define to the version of this package. */ 76 | #undef PACKAGE_VERSION 77 | 78 | /* Define to 1 if you have the ANSI C header files. */ 79 | #undef STDC_HEADERS 80 | 81 | /* Version number of package */ 82 | #undef VERSION 83 | 84 | /* Define to `unsigned' if does not define. */ 85 | #undef size_t 86 | -------------------------------------------------------------------------------- /configure.in: -------------------------------------------------------------------------------- 1 | AC_INIT(configure.in) 2 | 3 | AM_CONFIG_HEADER(config.h) 4 | AM_INIT_AUTOMAKE(libaiml, 0.6.1) 5 | 6 | AC_LANG_CPLUSPLUS 7 | AC_PROG_CXX 8 | AC_PROG_RANLIB 9 | AM_PROG_LIBTOOL 10 | 11 | ## COMPILE OPTIONS ## 12 | AC_ARG_ENABLE(caiml, 13 | AC_HELP_STRING([--enable-caiml],[Enable CAIML writer/reader (see README)]), 14 | AC_DEFINE([ENABLE_CAIML], [1], [Enable compilation of CAIML writer/reader])) 15 | AC_ARG_ENABLE(javascript, 16 | AC_HELP_STRING([--enable-javascript],[Enable JavaScript API integration (see README)]), 17 | AC_DEFINE([ENABLE_JAVASCRIPT], [1], [Enable JavaScript API integration])) 18 | AC_ARG_ENABLE(pcrecpp, 19 | AC_HELP_STRING([--enable-pcrecpp],[Enable PCRE (c++ binding) support]), 20 | AC_DEFINE([ENABLE_PCRECPP], [1], [Enable PCRE support])) 21 | AC_ARG_ENABLE(werror, 22 | AC_HELP_STRING([--disable-werror],[Disable -Werror flag (warnings as errors)]), 23 | WERROR_CXXFLAG='', WERROR_CXXFLAG='-Werror') 24 | 25 | ## Library Checks ## 26 | if test "$enable_javascript" == "yes" 27 | then 28 | AC_CHECK_LIB([js],[JS_Init]) 29 | if test "$ac_cv_lib_js_JS_NewRuntime" == no 30 | then 31 | AC_MSG_ERROR([You need to install Mozilla SpiderMonkey for JavaScript support]) 32 | fi 33 | fi 34 | 35 | ## Checks for header files. ## 36 | AC_CHECK_HEADERS([netinet/in.h]) 37 | 38 | if test "$enable_javascript" == "yes"; then 39 | AC_CHECK_HEADERS([jsapi.h]) 40 | fi 41 | 42 | if test "$enable_pcrecpp" == "yes"; then 43 | AC_CHECK_HEADERS([pcrecpp.h]) 44 | PCRECPP_LIBS=-lpcrecpp 45 | else 46 | PCRECPP_LIBS= 47 | fi 48 | AC_SUBST([PCRECPP_LIBS]) 49 | 50 | ## Flags 51 | AC_SUBST([WERROR_CXXFLAG]) 52 | 53 | ## Check for programs ## 54 | AC_CHECK_PROG([has_xml2_config], [xml2-config], [yes], [no]) 55 | if test "$hast_xml2_config" == "no"; then 56 | AC_MSG_ERROR([libxml2 is needed to compile libaiml]) 57 | fi 58 | XML2_LIBS=`xml2-config --libs` 59 | AC_SUBST(XML2_LIBS) 60 | 61 | ## Checks for typedefs, structures, and compiler characteristics. ## 62 | AC_CHECK_FUNCS([floor]) 63 | AC_FUNC_STRFTIME 64 | AC_TYPE_SIZE_T 65 | 66 | echo "Results:" 67 | echo -ne "CAIML Support:\t\t" 68 | if test "$enable_caiml" == "yes"; then echo "YES"; else echo "NO"; fi 69 | echo -ne "JavaScript Support:\t" 70 | if test "$enable_javascript" == "yes"; then echo "YES"; else echo "NO"; fi 71 | echo -ne "PCREC++ Support:\t" 72 | if test "$enable_pcrecpp" == "yes"; then echo "YES"; else echo "NO"; fi 73 | 74 | AC_OUTPUT(Makefile src/Makefile test_app/aiml/Makefile test_app/Makefile libaiml.pc) 75 | -------------------------------------------------------------------------------- /doc/html/annotated.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | libaiml: Class List 4 | 5 | 6 | 7 | 8 |

      libaiml Class List

      Here are the classes, structs, unions and interfaces with brief descriptions: 9 | 10 | 11 | 12 | 13 |
      aiml::cCoreOptionsOptions to configure the interpreter
      aiml::cInterpreterLibaiml interpreter
      aiml::cInterpreterCallbacksThis structure is used to receive notifications of events that libaiml generates
      aiml::cMatchLogThis structure is used to hold the nodes of the tree that matched the user's input, that and topic
      14 |
      Generated on Fri Feb 3 00:27:21 2006 for libaiml by  15 | 16 | doxygen 1.4.4
      17 | 18 | 19 | -------------------------------------------------------------------------------- /doc/html/classaiml_1_1cInterpreter-members.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | libaiml: Member List 4 | 5 | 6 | 7 | 8 |

      aiml::cInterpreter Member List

      This is the complete list of members for aiml::cInterpreter, including all inherited members.

      9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 |
      callbacks (defined in aiml::cInterpreter)aiml::cInterpreter [protected]
      cInterpreter(void)aiml::cInterpreter
      deinitialize(void)=0aiml::cInterpreter [pure virtual]
      freeInterpreter(cInterpreter *i)aiml::cInterpreter [static]
      getError(void)aiml::cInterpreter
      getErrorStr(AIMLError error_num)=0aiml::cInterpreter [pure virtual]
      getRuntimeErrorStr(void)=0aiml::cInterpreter [pure virtual]
      initialize(const std::string &filename)=0aiml::cInterpreter [pure virtual]
      initialize(const std::string &filename, const cCoreOptions &opts)=0aiml::cInterpreter [pure virtual]
      last_error (defined in aiml::cInterpreter)aiml::cInterpreter [protected]
      learnFile(const std::string &filename)=0aiml::cInterpreter [pure virtual]
      loadGraphmaster(const std::string &file)=0aiml::cInterpreter [pure virtual]
      newInterpreter(void)aiml::cInterpreter [static]
      registerCallbacks(cInterpreterCallbacks *callbacks)=0aiml::cInterpreter [pure virtual]
      respond(const std::string &input, const std::string &username, std::string &output, std::list< cMatchLog > *log=NULL)=0aiml::cInterpreter [pure virtual]
      saveGraphmaster(const std::string &file)=0aiml::cInterpreter [pure virtual]
      unregisterUser(const std::string &username)=0aiml::cInterpreter [pure virtual]
      ~cInterpreter(void)aiml::cInterpreter [virtual]


      Generated on Fri Feb 3 00:27:21 2006 for libaiml by  28 | 29 | doxygen 1.4.4
      30 | 31 | 32 | -------------------------------------------------------------------------------- /doc/html/classaiml_1_1cInterpreterCallbacks-members.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | libaiml: Member List 4 | 5 | 6 | 7 | 8 |

      aiml::cInterpreterCallbacks Member List

      This is the complete list of members for aiml::cInterpreterCallbacks, including all inherited members.

      9 | 10 |
      onAimlLoad(const std::string &filename)=0aiml::cInterpreterCallbacks [pure virtual]


      Generated on Fri Feb 3 00:27:21 2006 for libaiml by  11 | 12 | doxygen 1.4.4
      13 | 14 | 15 | -------------------------------------------------------------------------------- /doc/html/classaiml_1_1cInterpreterCallbacks.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | libaiml: aiml::cInterpreterCallbacks Class Reference 4 | 5 | 6 | 7 | 8 | 10 |

      aiml::cInterpreterCallbacks Class Reference

      This structure is used to receive notifications of events that libaiml generates. 11 | More... 12 |

      13 | List of all members. 14 | 15 | 16 | 17 | 18 | 19 |

      Public Member Functions

      virtual void onAimlLoad (const std::string &filename)=0
       This function is called during initialization, for each aiml file that is loaded.
      20 |


      Detailed Description

      21 | This structure is used to receive notifications of events that libaiml generates. 22 |

      23 | You could derive this class and then pass 'this' to cInterpreter::registerCallbacks(). None of these functions should block libaiml, they should return as soon as possible. 24 |

      25 |


      Member Function Documentation

      26 |

      27 | 28 | 29 | 41 | 42 |
      30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 |
      virtual void aiml::cInterpreterCallbacks::onAimlLoad const std::string &  filename  )  [pure virtual]
      40 |
      43 | 44 | 45 | 48 | 59 | 60 |
      46 |   47 | 49 | 50 |

      51 | This function is called during initialization, for each aiml file that is loaded. 52 |

      53 |

      Parameters:
      54 | 55 | 56 |
      filename is the full path to the aiml file just loaded.
      57 |
      58 |
      61 |


      Generated on Fri Feb 3 00:27:21 2006 for libaiml by  62 | 63 | doxygen 1.4.4
      64 | 65 | 66 | -------------------------------------------------------------------------------- /doc/html/classes.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | libaiml: Alphabetical List 4 | 5 | 6 | 7 | 8 |

      libaiml Class Index

      9 | 10 |
        C  
      11 |
      cCoreOptions (aiml)   cInterpreter (aiml)   cInterpreterCallbacks (aiml)   cMatchLog (aiml)   

      12 |


      Generated on Thu Feb 2 23:16:23 2006 for libaiml by  13 | 14 | doxygen 1.4.4
      15 | 16 | 17 | -------------------------------------------------------------------------------- /doc/html/dir_000000.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | libaiml: src/ Directory Reference 4 | 5 | 6 | 7 | 8 | 10 |

      src Directory Reference

      11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 |

      Files

      file  aiml.cpp
      file  aiml.h
      file  errors.h
      20 |
      Generated on Thu Feb 2 23:01:19 2006 for libaiml by  21 | 22 | doxygen 1.4.4
      23 | 24 | 25 | -------------------------------------------------------------------------------- /doc/html/dirs.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | libaiml: Directory Hierarchy 4 | 5 | 6 | 7 | 8 |

      libaiml Directories

      This directory hierarchy is sorted roughly, but not completely, alphabetically: 11 |
      Generated on Thu Feb 2 23:01:20 2006 for libaiml by  12 | 13 | doxygen 1.4.4
      14 | 15 | 16 | -------------------------------------------------------------------------------- /doc/html/doxygen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaoshijuan/aiml/b3cdafb8c070486a9e17178727aed96ba8ec0f26/doc/html/doxygen.png -------------------------------------------------------------------------------- /doc/html/functions.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | libaiml: Class Members 4 | 5 | 6 | 7 | 8 | 9 | Here is a list of all documented class members with links to the class documentation for each member: 10 |

      11 |

      38 |
      Generated on Fri Feb 3 00:27:21 2006 for libaiml by  39 | 40 | doxygen 1.4.4
      41 | 42 | 43 | -------------------------------------------------------------------------------- /doc/html/functions_func.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | libaiml: Class Members - Functions 4 | 5 | 6 | 7 | 8 | 9 | 10 |

      11 |

      30 |
      Generated on Fri Feb 3 00:27:21 2006 for libaiml by  31 | 32 | doxygen 1.4.4
      33 | 34 | 35 | -------------------------------------------------------------------------------- /doc/html/functions_vars.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | libaiml: Class Members - Variables 4 | 5 | 6 | 7 | 8 | 9 | 10 |

      11 |

      21 |
      Generated on Fri Feb 3 00:27:21 2006 for libaiml by  22 | 23 | doxygen 1.4.4
      24 | 25 | 26 | -------------------------------------------------------------------------------- /doc/html/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | libaiml: Main Page 4 | 5 | 6 | 7 | 8 |

      libaiml Documentation

      9 |

      10 |

      0.6


      Generated on Fri Feb 3 00:27:21 2006 for libaiml by  11 | 12 | doxygen 1.4.4
      13 | 14 | 15 | -------------------------------------------------------------------------------- /doc/html/namespacemembers.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | libaiml: Class Members 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 |

      12 | Here is a list of all documented namespace members with links to the namespaces they belong to: 13 |

      14 |

      - a -

        15 |
      • AIMLERR_AIML_NOOPEN 16 | : aiml
      • AIMLERR_AIML_PARSE 17 | : aiml
      • AIMLERR_ALREADY_INIT 18 | : aiml
      • AIMLERR_CAIML_EMPTYGM 19 | : aiml
      • AIMLERR_CAIML_INCORRECTSTRUCT 20 | : aiml
      • AIMLERR_CAIML_NOCHILDSNUM 21 | : aiml
      • AIMLERR_CAIML_NOKEY 22 | : aiml
      • AIMLERR_CAIML_NOMAGIC 23 | : aiml
      • AIMLERR_CAIML_NOOPEN_READ 24 | : aiml
      • AIMLERR_CAIML_NOOPEN_WRITE 25 | : aiml
      • AIMLERR_CAIML_NOSIZE 26 | : aiml
      • AIMLERR_CAIML_NOTCAIML 27 | : aiml
      • AIMLERR_CAIML_NOTEMPLATE 28 | : aiml
      • AIMLERR_CAIML_NOVERSION 29 | : aiml
      • AIMLERR_CAIML_WRONGVERSION 30 | : aiml
      • AIMLERR_EMPTY_GM 31 | : aiml
      • AIMLERR_EMPTY_INPUT 32 | : aiml
      • AIMLERR_JAVASCRIPT_NOT_ALLOWED 33 | : aiml
      • AIMLERR_JAVASCRIPT_PROBLEM 34 | : aiml
      • AIMLERR_NEG_INPUT_INDEX 35 | : aiml
      • AIMLERR_NEG_THAT_INDEX 36 | : aiml
      • AIMLERR_NO_CFGFILE 37 | : aiml
      • AIMLERR_NO_ERR 38 | : aiml
      • AIMLERR_NO_FILES 39 | : aiml
      • AIMLERR_NO_MATCH 40 | : aiml
      • AIMLERR_NO_USERLIST 41 | : aiml
      • AIMLERR_NOT_INIT 42 | : aiml
      • AIMLERR_OPEN_GOSSIP 43 | : aiml
      • AIMLERR_PATT_READERR 44 | : aiml
      • AIMLERR_PATT_UNKNOWN 45 | : aiml
      • AIMLERR_SYSTEM_NOT_ALLOWED 46 | : aiml
      • AIMLERR_TEMLP_UNKNOWN_TAG 47 | : aiml
      • AIMLError 48 | : aiml
      49 |
      Generated on Fri Feb 3 00:27:21 2006 for libaiml by  50 | 51 | doxygen 1.4.4
      52 | 53 | 54 | -------------------------------------------------------------------------------- /doc/html/namespacemembers_enum.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | libaiml: Class Members 4 | 5 | 6 | 7 | 8 | 9 | 10 |

      11 |

        12 |
      • AIMLError 13 | : aiml
      14 |
      Generated on Fri Feb 3 00:27:21 2006 for libaiml by  15 | 16 | doxygen 1.4.4
      17 | 18 | 19 | -------------------------------------------------------------------------------- /doc/html/namespacemembers_eval.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | libaiml: Class Members 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 |

      12 | 13 |

      14 |

      - a -

        15 |
      • AIMLERR_AIML_NOOPEN 16 | : aiml
      • AIMLERR_AIML_PARSE 17 | : aiml
      • AIMLERR_ALREADY_INIT 18 | : aiml
      • AIMLERR_CAIML_EMPTYGM 19 | : aiml
      • AIMLERR_CAIML_INCORRECTSTRUCT 20 | : aiml
      • AIMLERR_CAIML_NOCHILDSNUM 21 | : aiml
      • AIMLERR_CAIML_NOKEY 22 | : aiml
      • AIMLERR_CAIML_NOMAGIC 23 | : aiml
      • AIMLERR_CAIML_NOOPEN_READ 24 | : aiml
      • AIMLERR_CAIML_NOOPEN_WRITE 25 | : aiml
      • AIMLERR_CAIML_NOSIZE 26 | : aiml
      • AIMLERR_CAIML_NOTCAIML 27 | : aiml
      • AIMLERR_CAIML_NOTEMPLATE 28 | : aiml
      • AIMLERR_CAIML_NOVERSION 29 | : aiml
      • AIMLERR_CAIML_WRONGVERSION 30 | : aiml
      • AIMLERR_EMPTY_GM 31 | : aiml
      • AIMLERR_EMPTY_INPUT 32 | : aiml
      • AIMLERR_JAVASCRIPT_NOT_ALLOWED 33 | : aiml
      • AIMLERR_JAVASCRIPT_PROBLEM 34 | : aiml
      • AIMLERR_NEG_INPUT_INDEX 35 | : aiml
      • AIMLERR_NEG_THAT_INDEX 36 | : aiml
      • AIMLERR_NO_CFGFILE 37 | : aiml
      • AIMLERR_NO_ERR 38 | : aiml
      • AIMLERR_NO_FILES 39 | : aiml
      • AIMLERR_NO_MATCH 40 | : aiml
      • AIMLERR_NO_USERLIST 41 | : aiml
      • AIMLERR_NOT_INIT 42 | : aiml
      • AIMLERR_OPEN_GOSSIP 43 | : aiml
      • AIMLERR_PATT_READERR 44 | : aiml
      • AIMLERR_PATT_UNKNOWN 45 | : aiml
      • AIMLERR_SYSTEM_NOT_ALLOWED 46 | : aiml
      • AIMLERR_TEMLP_UNKNOWN_TAG 47 | : aiml
      48 |
      Generated on Fri Feb 3 00:27:21 2006 for libaiml by  49 | 50 | doxygen 1.4.4
      51 | 52 | 53 | -------------------------------------------------------------------------------- /doc/html/namespaces.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | libaiml: Namespace Index 4 | 5 | 6 | 7 | 8 |

      libaiml Namespace List

      Here is a list of all documented namespaces with brief descriptions: 9 | 10 |
      aimlNamespace that holds the libaiml public interface
      11 |
      Generated on Fri Feb 3 00:27:21 2006 for libaiml by  12 | 13 | doxygen 1.4.4
      14 | 15 | 16 | -------------------------------------------------------------------------------- /doc/html/structaiml_1_1cCoreOptions-members.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | libaiml: Member List 4 | 5 | 6 | 7 | 8 |

      aiml::cCoreOptions Member List

      This is the complete list of members for aiml::cCoreOptions, including all inherited members.

      9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
      allow_dateformataiml::cCoreOptions
      allow_javascriptaiml::cCoreOptions
      allow_systemaiml::cCoreOptions
      cCoreOptions(void)aiml::cCoreOptions
      file_gossipaiml::cCoreOptions
      file_patternsaiml::cCoreOptions
      sentence_limitaiml::cCoreOptions
      should_trim_blanksaiml::cCoreOptions
      user_fileaiml::cCoreOptions


      Generated on Fri Feb 3 00:27:21 2006 for libaiml by  19 | 20 | doxygen 1.4.4
      21 | 22 | 23 | -------------------------------------------------------------------------------- /doc/html/structaiml_1_1cMatchLog-members.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | libaiml: Member List 4 | 5 | 6 | 7 | 8 |

      aiml::cMatchLog Member List

      This is the complete list of members for aiml::cMatchLog, including all inherited members.

      9 | 10 | 11 | 12 |
      pattern (defined in aiml::cMatchLog)aiml::cMatchLog
      that (defined in aiml::cMatchLog)aiml::cMatchLog
      topic (defined in aiml::cMatchLog)aiml::cMatchLog


      Generated on Fri Feb 3 00:27:21 2006 for libaiml by  13 | 14 | doxygen 1.4.4
      15 | 16 | 17 | -------------------------------------------------------------------------------- /doc/html/structaiml_1_1cMatchLog.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | libaiml: aiml::cMatchLog Struct Reference 4 | 5 | 6 | 7 | 8 | 10 |

      aiml::cMatchLog Struct Reference

      This structure is used to hold the nodes of the tree that matched the user's input, that and topic. 11 | More... 12 |

      13 | List of all members. 14 | 15 | 16 | 18 | 19 | 21 | 22 | 24 | 25 |

      Public Attributes

      17 | std::list< std::string > pattern
      20 | std::list< std::string > that
      23 | std::list< std::string > topic
      26 |


      Detailed Description

      27 | This structure is used to hold the nodes of the tree that matched the user's input, that and topic. 28 |

      29 | The lists hold one token (ie, a word with no spaces) of the corresponding match. 30 |

      31 |


      Generated on Fri Feb 3 00:27:21 2006 for libaiml by  32 | 33 | doxygen 1.4.4
      34 | 35 | 36 | -------------------------------------------------------------------------------- /doc/man/man3/aiml.3: -------------------------------------------------------------------------------- 1 | .TH "aiml" 3 "3 Feb 2006" "Version 0.6" "libaiml" \" -*- nroff -*- 2 | .ad l 3 | .nh 4 | .SH NAME 5 | aiml \- Namespace that holds the libaiml public interface. 6 | 7 | .PP 8 | .SH SYNOPSIS 9 | .br 10 | .PP 11 | .SS "Classes" 12 | 13 | .in +1c 14 | .ti -1c 15 | .RI "struct \fBcMatchLog\fP" 16 | .br 17 | .RI "\fIThis structure is used to hold the nodes of the tree that matched the user's input, that and topic. \fP" 18 | .ti -1c 19 | .RI "struct \fBcCoreOptions\fP" 20 | .br 21 | .RI "\fIOptions to configure the interpreter. \fP" 22 | .ti -1c 23 | .RI "class \fBcInterpreterCallbacks\fP" 24 | .br 25 | .RI "\fIThis structure is used to receive notifications of events that libaiml generates. \fP" 26 | .ti -1c 27 | .RI "class \fBcInterpreter\fP" 28 | .br 29 | .RI "\fIlibaiml interpreter. \fP" 30 | .in -1c 31 | .SS "Enumerations" 32 | 33 | .in +1c 34 | .ti -1c 35 | .RI "enum \fBAIMLError\fP { \fBAIMLERR_NO_ERR\fP, \fBAIMLERR_NO_FILES\fP, \fBAIMLERR_PATT_READERR\fP, \fBAIMLERR_PATT_UNKNOWN\fP, \fBAIMLERR_OPEN_GOSSIP\fP, \fBAIMLERR_NOT_INIT\fP, \fBAIMLERR_ALREADY_INIT\fP, \fBAIMLERR_NO_CFGFILE\fP, \fBAIMLERR_NO_USERLIST\fP, \fBAIMLERR_SYSTEM_NOT_ALLOWED\fP, \fBAIMLERR_JAVASCRIPT_NOT_ALLOWED\fP, \fBAIMLERR_JAVASCRIPT_PROBLEM\fP, \fBAIMLERR_EMPTY_INPUT\fP, \fBAIMLERR_NO_MATCH\fP, \fBAIMLERR_EMPTY_GM\fP, \fBAIMLERR_AIML_NOOPEN\fP, \fBAIMLERR_AIML_PARSE\fP, \fBAIMLERR_CAIML_NOMAGIC\fP, \fBAIMLERR_CAIML_NOTCAIML\fP, \fBAIMLERR_CAIML_NOOPEN_READ\fP, \fBAIMLERR_CAIML_NOVERSION\fP, \fBAIMLERR_CAIML_WRONGVERSION\fP, \fBAIMLERR_CAIML_NOSIZE\fP, \fBAIMLERR_CAIML_NOCHILDSNUM\fP, \fBAIMLERR_CAIML_NOKEY\fP, \fBAIMLERR_CAIML_NOTEMPLATE\fP, \fBAIMLERR_CAIML_EMPTYGM\fP, \fBAIMLERR_CAIML_NOOPEN_WRITE\fP, \fBAIMLERR_CAIML_INCORRECTSTRUCT\fP, \fBAIMLERR_TEMLP_UNKNOWN_TAG\fP, \fBAIMLERR_NEG_THAT_INDEX\fP, \fBAIMLERR_NEG_INPUT_INDEX\fP, \fBAIMLERR_MAX\fP }" 36 | .br 37 | .RI "\fIError codes produced by libaiml. \fP" 38 | .in -1c 39 | .SH "Detailed Description" 40 | .PP 41 | Namespace that holds the libaiml public interface. 42 | .SH "Enumeration Type Documentation" 43 | .PP 44 | .SS "enum \fBaiml::AIMLError\fP" 45 | .PP 46 | Error codes produced by libaiml. 47 | .PP 48 | \fBEnumerator: \fP 49 | .in +1c 50 | .TP 51 | \fB\fIAIMLERR_NO_ERR \fP\fP 52 | No error. 53 | .TP 54 | \fB\fIAIMLERR_NO_FILES \fP\fP 55 | No aiml files specified to load. 56 | .TP 57 | \fB\fIAIMLERR_PATT_READERR \fP\fP 58 | Read error while matching file patterns. 59 | .TP 60 | \fB\fIAIMLERR_PATT_UNKNOWN \fP\fP 61 | Unknown error while matching file patterns. 62 | .TP 63 | \fB\fIAIMLERR_OPEN_GOSSIP \fP\fP 64 | Couldn't open gossip file for writing. 65 | .TP 66 | \fB\fIAIMLERR_NOT_INIT \fP\fP 67 | The core isn't yet initialized. 68 | .TP 69 | \fB\fIAIMLERR_ALREADY_INIT \fP\fP 70 | The core is already initialized. 71 | .TP 72 | \fB\fIAIMLERR_NO_CFGFILE \fP\fP 73 | Couldn't open/read configuration file. 74 | .PP 75 | (use \fBcInterpreter::getRuntimeErrorStr()\fP). 76 | .TP 77 | \fB\fIAIMLERR_NO_USERLIST \fP\fP 78 | Error with userlist file. 79 | .TP 80 | \fB\fIAIMLERR_SYSTEM_NOT_ALLOWED \fP\fP 81 | System tag is not allowed to be executed. 82 | .TP 83 | \fB\fIAIMLERR_JAVASCRIPT_NOT_ALLOWED \fP\fP 84 | Javascript tag is not allowed to be executed. 85 | .TP 86 | \fB\fIAIMLERR_JAVASCRIPT_PROBLEM \fP\fP 87 | Problem with JavaScript interpreter (use \fBcInterpreter::getRuntimeErrorStr()\fP). 88 | .TP 89 | \fB\fIAIMLERR_EMPTY_INPUT \fP\fP 90 | Normalization of input resulted in empty string. 91 | .TP 92 | \fB\fIAIMLERR_NO_MATCH \fP\fP 93 | No match found for input. 94 | .TP 95 | \fB\fIAIMLERR_EMPTY_GM \fP\fP 96 | Empty graphmaster (no categories loaded). 97 | .TP 98 | \fB\fIAIMLERR_AIML_NOOPEN \fP\fP 99 | Couldn't open aiml file. 100 | .TP 101 | \fB\fIAIMLERR_AIML_PARSE \fP\fP 102 | AIML Parser error (use \fBcInterpreter::getRuntimeErrorStr()\fP). 103 | .TP 104 | \fB\fIAIMLERR_CAIML_NOMAGIC \fP\fP 105 | Couldn't retrieve magic number from caiml file. 106 | .TP 107 | \fB\fIAIMLERR_CAIML_NOTCAIML \fP\fP 108 | Not a CAIML file. 109 | .TP 110 | \fB\fIAIMLERR_CAIML_NOOPEN_READ \fP\fP 111 | Couldn't open CAIML file for reading. 112 | .TP 113 | \fB\fIAIMLERR_CAIML_NOVERSION \fP\fP 114 | Couldn't get version from CAIML file. 115 | .TP 116 | \fB\fIAIMLERR_CAIML_WRONGVERSION \fP\fP 117 | CAIML file version not supported. 118 | .TP 119 | \fB\fIAIMLERR_CAIML_NOSIZE \fP\fP 120 | Couldn't get size of graphmaster (ie: number of templates) from CAIML file. 121 | .TP 122 | \fB\fIAIMLERR_CAIML_NOCHILDSNUM \fP\fP 123 | No size of childs for node in CAIML file. 124 | .TP 125 | \fB\fIAIMLERR_CAIML_NOKEY \fP\fP 126 | Coulnd't read key for node in CAIML file. 127 | .TP 128 | \fB\fIAIMLERR_CAIML_NOTEMPLATE \fP\fP 129 | Coulnd't read template for node in CAIML file. 130 | .TP 131 | \fB\fIAIMLERR_CAIML_EMPTYGM \fP\fP 132 | Can't save an empty graphmaster. 133 | .TP 134 | \fB\fIAIMLERR_CAIML_NOOPEN_WRITE \fP\fP 135 | Couldn't open CAIML file for writing. 136 | .TP 137 | \fB\fIAIMLERR_CAIML_INCORRECTSTRUCT \fP\fP 138 | Caiml file is not correctly built. 139 | .TP 140 | \fB\fIAIMLERR_TEMLP_UNKNOWN_TAG \fP\fP 141 | Unknown tag found while parsing template. 142 | .TP 143 | \fB\fIAIMLERR_NEG_THAT_INDEX \fP\fP 144 | Negative index in 'that' tag found. 145 | .TP 146 | \fB\fIAIMLERR_NEG_INPUT_INDEX \fP\fP 147 | Negative index in 'input' tag found. 148 | .SH "Author" 149 | .PP 150 | Generated automatically by Doxygen for libaiml from the source code. 151 | -------------------------------------------------------------------------------- /doc/man/man3/aiml_cCoreOptions.3: -------------------------------------------------------------------------------- 1 | .TH "aiml::cCoreOptions" 3 "3 Feb 2006" "Version 0.6" "libaiml" \" -*- nroff -*- 2 | .ad l 3 | .nh 4 | .SH NAME 5 | aiml::cCoreOptions \- Options to configure the interpreter. 6 | 7 | .PP 8 | .SH SYNOPSIS 9 | .br 10 | .PP 11 | .SS "Public Member Functions" 12 | 13 | .in +1c 14 | .ti -1c 15 | .RI "\fBcCoreOptions\fP (void)" 16 | .br 17 | .RI "\fIDefault constructor. \fP" 18 | .in -1c 19 | .SS "Public Attributes" 20 | 21 | .in +1c 22 | .ti -1c 23 | .RI "std::string \fBfile_patterns\fP" 24 | .br 25 | .RI "\fISpace separated list of patterns of aiml files to be loaded. \fP" 26 | .ti -1c 27 | .RI "std::string \fBfile_gossip\fP" 28 | .br 29 | .RI "\fIThe path where to gossip (a file). \fP" 30 | .ti -1c 31 | .RI "std::string \fBuser_file\fP" 32 | .br 33 | .RI "\fIFile where user's data is saved. \fP" 34 | .ti -1c 35 | .RI "std::string \fBsentence_limit\fP" 36 | .br 37 | .RI "\fICharacters used to separate sentences. \fP" 38 | .ti -1c 39 | .RI "bool \fBshould_trim_blanks\fP" 40 | .br 41 | .RI "\fIIf the interpreter should treat multiple whitespace combinations as a single space. \fP" 42 | .ti -1c 43 | .RI "bool \fBallow_system\fP" 44 | .br 45 | .RI "\fIIf the interpreter should execute commands from tags. \fP" 46 | .ti -1c 47 | .RI "bool \fBallow_javascript\fP" 48 | .br 49 | .RI "\fIIf the interpreter should execute code from tags. \fP" 50 | .ti -1c 51 | .RI "bool \fBallow_dateformat\fP" 52 | .br 53 | .RI "\fIIf the interpreter should format date using the 'format' parameter. \fP" 54 | .in -1c 55 | .SH "Detailed Description" 56 | .PP 57 | Options to configure the interpreter. 58 | .PP 59 | .SH "Constructor & Destructor Documentation" 60 | .PP 61 | .SS "cCoreOptions::cCoreOptions (void)" 62 | .PP 63 | Default constructor. 64 | .PP 65 | This gives the default values to each of the parameters in this structure. Refer to the configuration file description to see which are those defaults. 66 | 67 | .SH "Author" 68 | .PP 69 | Generated automatically by Doxygen for libaiml from the source code. 70 | -------------------------------------------------------------------------------- /doc/man/man3/aiml_cInterpreterCallbacks.3: -------------------------------------------------------------------------------- 1 | .TH "aiml::cInterpreterCallbacks" 3 "3 Feb 2006" "Version 0.6" "libaiml" \" -*- nroff -*- 2 | .ad l 3 | .nh 4 | .SH NAME 5 | aiml::cInterpreterCallbacks \- This structure is used to receive notifications of events that libaiml generates. 6 | 7 | .PP 8 | .SH SYNOPSIS 9 | .br 10 | .PP 11 | .SS "Public Member Functions" 12 | 13 | .in +1c 14 | .ti -1c 15 | .RI "virtual void \fBonAimlLoad\fP (const std::string &filename)=0" 16 | .br 17 | .RI "\fIThis function is called during initialization, for each aiml file that is loaded. \fP" 18 | .in -1c 19 | .SH "Detailed Description" 20 | .PP 21 | This structure is used to receive notifications of events that libaiml generates. 22 | 23 | You could derive this class and then pass 'this' to \fBcInterpreter::registerCallbacks()\fP. None of these functions should block libaiml, they should return as soon as possible. 24 | .PP 25 | .SH "Member Function Documentation" 26 | .PP 27 | .SS "virtual void aiml::cInterpreterCallbacks::onAimlLoad (const std::string & filename)\fC [pure virtual]\fP" 28 | .PP 29 | This function is called during initialization, for each aiml file that is loaded. 30 | .PP 31 | \fBParameters:\fP 32 | .RS 4 33 | \fIfilename\fP is the full path to the aiml file just loaded. 34 | .RE 35 | .PP 36 | 37 | 38 | .SH "Author" 39 | .PP 40 | Generated automatically by Doxygen for libaiml from the source code. 41 | -------------------------------------------------------------------------------- /doc/man/man3/aiml_cMatchLog.3: -------------------------------------------------------------------------------- 1 | .TH "aiml::cMatchLog" 3 "3 Feb 2006" "Version 0.6" "libaiml" \" -*- nroff -*- 2 | .ad l 3 | .nh 4 | .SH NAME 5 | aiml::cMatchLog \- This structure is used to hold the nodes of the tree that matched the user's input, that and topic. 6 | 7 | .PP 8 | .SH SYNOPSIS 9 | .br 10 | .PP 11 | .SS "Public Attributes" 12 | 13 | .in +1c 14 | .ti -1c 15 | .RI "std::list< std::string > \fBpattern\fP" 16 | .br 17 | .ti -1c 18 | .RI "std::list< std::string > \fBthat\fP" 19 | .br 20 | .ti -1c 21 | .RI "std::list< std::string > \fBtopic\fP" 22 | .br 23 | .in -1c 24 | .SH "Detailed Description" 25 | .PP 26 | This structure is used to hold the nodes of the tree that matched the user's input, that and topic. 27 | 28 | The lists hold one token (ie, a word with no spaces) of the corresponding match. 29 | .PP 30 | 31 | 32 | .SH "Author" 33 | .PP 34 | Generated automatically by Doxygen for libaiml from the source code. 35 | -------------------------------------------------------------------------------- /libaiml.lsm: -------------------------------------------------------------------------------- 1 | Begin4 2 | Title:libaiml 3 | Version:0.6.1 4 | Entered-date:2006/02/16 5 | Description:C++ AIML interpreter library 6 | Keywords:C++ AIML interpreter library 7 | Author:v01d@v01d.com.ar (v01d) 8 | Maintained-by:v01d@v01d.com.ar (v01d) 9 | Primary-site:http://v01d.com.ar/ 10 | Alternate-site: 11 | Original-site:http://v01d.com.ar/ 12 | Platforms:GNU/Linux 13 | Copying-policy:GPL 14 | End 15 | -------------------------------------------------------------------------------- /libaiml.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: @PACKAGE@ 7 | Description: AIML interpreter engine library. 8 | Version: @VERSION@ 9 | Libs: -L${libdir} -lstd_utils @PCRECPP_LIBS@ @XML2_LIBS@ 10 | Cflags: -I${includedir} 11 | -------------------------------------------------------------------------------- /server/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | METASOURCES = AUTO 3 | 4 | SUBDIRS = 5 | AM_CXXFLAGS = -Wall $(WERROR_CXXFLAG) -utf8 -pedantic `xml2-config --cflags` 6 | 7 | noinst_PROGRAMS = server_app 8 | server_app_SOURCES = main.cpp tlib_log.cpp 9 | 10 | server_app_LDADD = $(top_builddir)/src/libaiml.a $(PCRECPP_LIBS) -L./ -lstd_utils -lz -lxml2 11 | server_app_LDFLAGS = $(XML2_LIBS) 12 | 13 | -------------------------------------------------------------------------------- /server/tlib_log.cpp: -------------------------------------------------------------------------------- 1 | #ifndef _TLIB_LOG_C_ 2 | #define _TLIB_LOG_C_ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include "tlib_log.h" 13 | 14 | static int ShiftFiles(char *sLogBaseName, long lMaxLogSize, int iMaxLogNum, char *sErrMsg) 15 | { 16 | struct stat stStat; 17 | char sLogFileName[300]; 18 | char sNewLogFileName[300]; 19 | int i; 20 | 21 | sprintf(sLogFileName,"%s.log", sLogBaseName); 22 | 23 | if(stat(sLogFileName, &stStat) < 0) 24 | { 25 | if (sErrMsg != NULL) 26 | { 27 | strcpy(sErrMsg, "Fail to get file status"); 28 | } 29 | return -1; 30 | } 31 | 32 | if (stStat.st_size < lMaxLogSize) 33 | { 34 | return 0; 35 | } 36 | 37 | sprintf(sLogFileName,"%s%d.log", sLogBaseName, iMaxLogNum-1); 38 | if (access(sLogFileName, F_OK) == 0) 39 | { 40 | if (remove(sLogFileName) < 0 ) 41 | { 42 | if (sErrMsg != NULL) 43 | { 44 | strcpy(sErrMsg, "Fail to remove oldest log file"); 45 | } 46 | return -1; 47 | } 48 | } 49 | 50 | for(i = iMaxLogNum-2; i >= 0; i--) 51 | { 52 | if (i == 0) 53 | sprintf(sLogFileName,"%s.log", sLogBaseName); 54 | else 55 | sprintf(sLogFileName,"%s%d.log", sLogBaseName, i); 56 | 57 | if (access(sLogFileName, F_OK) == 0) 58 | { 59 | sprintf(sNewLogFileName,"%s%d.log", sLogBaseName, i+1); 60 | if (rename(sLogFileName,sNewLogFileName) < 0 ) 61 | { 62 | if (sErrMsg != NULL) 63 | { 64 | strcpy(sErrMsg, "Fail to remove oldest log file"); 65 | } 66 | return -1; 67 | } 68 | } 69 | } 70 | return 0; 71 | } 72 | 73 | char *TLib_Tools_GetDateTimeStr(time_t *mytime) 74 | { 75 | static char s[50]; 76 | struct tm curr; 77 | 78 | curr = *localtime(mytime); 79 | 80 | if (curr.tm_year > 50) 81 | { 82 | sprintf(s, "%04d-%02d-%02d %02d:%02d:%02d", 83 | curr.tm_year+1900, curr.tm_mon+1, curr.tm_mday, 84 | curr.tm_hour, curr.tm_min, curr.tm_sec); 85 | } 86 | else 87 | { 88 | sprintf(s, "%04d-%02d-%02d %02d:%02d:%02d", 89 | curr.tm_year+2000, curr.tm_mon+1, curr.tm_mday, 90 | curr.tm_hour, curr.tm_min, curr.tm_sec); 91 | } 92 | 93 | return s; 94 | } 95 | 96 | char *TLib_Tools_GetCurDateTimeStr(void) 97 | { 98 | time_t iCurTime; 99 | 100 | time(&iCurTime); 101 | return TLib_Tools_GetDateTimeStr(&iCurTime); 102 | } 103 | 104 | int TLib_Log_VWriteLog(char *sLogBaseName, long lMaxLogSize, int iMaxLogNum, char *sErrMsg, const char *sFormat, va_list ap) 105 | { 106 | FILE *pstFile; 107 | char sLogFileName[300]; 108 | 109 | sprintf(sLogFileName,"%s.log", sLogBaseName); 110 | if ((pstFile = fopen(sLogFileName, "a+")) == NULL) 111 | { 112 | if (sErrMsg != NULL) 113 | { 114 | strcpy(sErrMsg, "Fail to open log file"); 115 | } 116 | return -1; 117 | } 118 | 119 | fprintf(pstFile, "[%s] ", TLib_Tools_GetCurDateTimeStr()); 120 | 121 | vfprintf(pstFile, sFormat, ap); 122 | 123 | //fprintf(pstFile, "\n"); 124 | 125 | fclose(pstFile); 126 | 127 | return ShiftFiles(sLogBaseName, lMaxLogSize, iMaxLogNum, sErrMsg); 128 | } 129 | 130 | int TLib_Log_WriteLog(char *sLogBaseName, long lMaxLogSize, int iMaxLogNum, char *sErrMsg, const char *sFormat, ...) 131 | { 132 | int iRetCode; 133 | va_list ap; 134 | 135 | va_start(ap, sFormat); 136 | iRetCode = TLib_Log_VWriteLog(sLogBaseName, lMaxLogSize, iMaxLogNum, sErrMsg, sFormat, ap); 137 | va_end(ap); 138 | 139 | return iRetCode; 140 | } 141 | 142 | static char sLogBaseName[200]; 143 | static long lMaxLogSize; 144 | static int iMaxLogNum; 145 | static int iLogInitialized = 0; 146 | static int iIsShow; 147 | 148 | void TLib_Log_LogInit(char *sPLogBaseName, long lPMaxLogSize, int iPMaxLogNum, int iShow) 149 | { 150 | memset(sLogBaseName, 0, sizeof(sLogBaseName)); 151 | strncpy(sLogBaseName, sPLogBaseName, sizeof(sLogBaseName)-1); 152 | lMaxLogSize = lPMaxLogSize; 153 | iMaxLogNum = iPMaxLogNum; 154 | iIsShow = iShow; 155 | iLogInitialized = 1; 156 | } 157 | 158 | void TLib_Log_LogMsgDef(int iShow, const char *sFormat, ...) 159 | { 160 | va_list ap; 161 | 162 | if (iShow != 0) 163 | { 164 | printf("[%s] ", TLib_Tools_GetCurDateTimeStr()); 165 | 166 | va_start(ap, sFormat); 167 | vprintf(sFormat, ap); 168 | va_end(ap); 169 | 170 | printf("\n"); 171 | } 172 | 173 | if (iLogInitialized != 0) 174 | { 175 | va_start(ap, sFormat); 176 | TLib_Log_VWriteLog(sLogBaseName, lMaxLogSize, iMaxLogNum, NULL, sFormat, ap); 177 | va_end(ap); 178 | } 179 | } 180 | 181 | void TLib_Log_LogMsg(const char *sFormat, ...) 182 | { 183 | va_list ap; 184 | 185 | if (iIsShow != 0) 186 | { 187 | printf("[%s] ", TLib_Tools_GetCurDateTimeStr()); 188 | 189 | va_start(ap, sFormat); 190 | vprintf(sFormat, ap); 191 | va_end(ap); 192 | 193 | printf("\n"); 194 | } 195 | 196 | if (iLogInitialized != 0) 197 | { 198 | va_start(ap, sFormat); 199 | TLib_Log_VWriteLog(sLogBaseName, lMaxLogSize, iMaxLogNum, NULL, sFormat, ap); 200 | va_end(ap); 201 | } 202 | } 203 | 204 | #endif 205 | -------------------------------------------------------------------------------- /server/tlib_log.h: -------------------------------------------------------------------------------- 1 | #ifndef _TLIB_LOG_H_ 2 | #define _TLIB_LOG_H_ 3 | 4 | #include 5 | #include 6 | 7 | char *TLib_Tools_GetDateTimeStr(time_t *mytime); 8 | char *TLib_Tools_GetCurDateTimeStr(void); 9 | 10 | int TLib_Log_VWriteLog(char *sLogBaseName, long lMaxLogSize, int iMaxLogNum, char *sErrMsg, const char *sFormat, va_list ap); 11 | int TLib_Log_WriteLog(char *sLogBaseName, long lMaxLogSize, int iMaxLogNum, char *sErrMsg, const char *Format, ...); 12 | 13 | void TLib_Log_LogMsg(const char *sFormat, ...); 14 | void TLib_Log_LogMsgDef(int iShow, const char *sFormat, ...); 15 | void TLib_Log_LogInit(char *sPLogBaseName, long lPMaxLogSize, int iPMaxLogNum, int iShow); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /src/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | 3 | # set the include path found by configure 4 | INCLUDES = $(all_includes) 5 | 6 | # the library search path. 7 | 8 | 9 | lib_LIBRARIES = libaiml.a 10 | libaiml_a_SOURCES = aiml_parser.cpp core.cpp graphmaster.cpp stuff.cpp \ 11 | template_parser.cpp user.cpp errors.cpp caiml_parser.cpp serializer.cpp user_manager.cpp \ 12 | config_parser.cpp javascript.cpp aiml.cpp 13 | libaiml_a_DEPENDENCIES = 14 | 15 | pkginclude_HEADERS = errors.h aiml.h 16 | 17 | 18 | 19 | 20 | AM_CXXFLAGS = $(WERROR_CXXFLAG) -pedantic -Wall -ansi `xml2-config --cflags` 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | noinst_HEADERS = aiml_parser.h caiml_parser.h config_parser.h core.h global.h\ 35 | graphmaster.h javascript.h serializer.h user.h user_manager.h 36 | -------------------------------------------------------------------------------- /src/aiml.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * This file is part of "libaiml" * 3 | * Copyright (C) 2005 by V01D * 4 | * * 5 | * "libaiml" is free software; you can redistribute it and/or modify * 6 | * it under the terms of the GNU General Public License as published by * 7 | * the Free Software Foundation; either version 2 of the License, or * 8 | * (at your option) any later version. * 9 | * * 10 | * "libaiml" is distributed in the hope that it will be useful, * 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 13 | * GNU General Public License for more details. * 14 | * * 15 | * You should have received a copy of the GNU General Public License * 16 | * along with "libaiml"; if not, write to the * 17 | * Free Software Foundation, Inc., * 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 19 | ***************************************************************************/ 20 | 21 | #include "core.h" 22 | #include "aiml.h" 23 | using namespace aiml; 24 | using namespace aiml; 25 | 26 | /** core options **/ 27 | cCoreOptions::cCoreOptions(void) : file_gossip("gossip.txt"), user_file("userlist.xml"), sentence_limit("?!.;"), 28 | should_trim_blanks(false), allow_system(false), allow_javascript(false), allow_dateformat(false) { } 29 | 30 | /** interpreter **/ 31 | cInterpreter::cInterpreter(void) : last_error(AIMLERR_NO_ERR), callbacks(NULL) { } 32 | cInterpreter::~cInterpreter(void) { } 33 | 34 | AIMLError cInterpreter::getError(void) { return last_error; } 35 | 36 | cInterpreter* cInterpreter::newInterpreter(void) { 37 | return new cCore; 38 | } 39 | 40 | void cInterpreter::freeInterpreter(cInterpreter* i) { 41 | delete i; 42 | } 43 | 44 | /** callbacks **/ 45 | cInterpreterCallbacks::~cInterpreterCallbacks(void) { } 46 | -------------------------------------------------------------------------------- /src/aiml_parser.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * This file is part of "libaiml" * 3 | * Copyright (C) 2005 by V01D * 4 | * * 5 | * "libaiml" is free software; you can redistribute it and/or modify * 6 | * it under the terms of the GNU General Public License as published by * 7 | * the Free Software Foundation; either version 2 of the License, or * 8 | * (at your option) any later version. * 9 | * * 10 | * "libaiml" is distributed in the hope that it will be useful, * 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 13 | * GNU General Public License for more details. * 14 | * * 15 | * You should have received a copy of the GNU General Public License * 16 | * along with "libaiml"; if not, write to the * 17 | * Free Software Foundation, Inc., * 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 19 | ***************************************************************************/ 20 | 21 | #ifndef __LIBAIML_PARSER_H__ 22 | #define __LIBAIML_PARSER_H__ 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | namespace aiml { 30 | class cGraphMaster; 31 | 32 | enum BinTemplType { 33 | TEMPL_CONDITION, TEMPL_CHARACTERS, TEMPL_STAR, TEMPL_TOPICSTAR, TEMPL_THATSTAR, TEMPL_THAT, 34 | TEMPL_INPUT, TEMPL_GET, TEMPL_BOT, TEMPL_SET, TEMPL_LI, TEMPL_LOWERCASE, TEMPL_UPPERCASE, TEMPL_FORMAL, 35 | TEMPL_SENTENCE, TEMPL_RANDOM, TEMPL_GOSSIP, TEMPL_SRAI, TEMPL_THINK, TEMPL_LEARN, TEMPL_SYSTEM, 36 | TEMPL_JAVASCRIPT, TEMPL_SR, TEMPL_DATE, TEMPL_SIZE, TEMPL_VERSION, TEMPL_ID, 37 | TEMPL_PERSON, TEMPL_PERSON2, TEMPL_GENDER, 38 | TEMPL_PERSON_SHORT, TEMPL_PERSON2_SHORT, TEMPL_GENDER_SHORT, 39 | TEMPL_UNKNOWN 40 | }; 41 | 42 | enum BinTemplCondType { 43 | TEMPL_CONDITION_SINGLE, TEMPL_CONDITION_MULTI, TEMPL_CONDITION_BLOCK 44 | }; 45 | 46 | enum BinTemplLiType { 47 | TEMPL_LI_NAME_VALUE, TEMPL_LI_VALUE, TEMPL_LI_DEFAULT 48 | }; 49 | 50 | class AIMLparser { 51 | public: 52 | AIMLparser(cGraphMaster& graphmaster, aiml::AIMLError& errnum); 53 | ~AIMLparser(void); 54 | 55 | bool parse(const std::string& filename, bool trim_blanks, bool at_runtime); 56 | std::string getRuntimeError(void); 57 | 58 | private: 59 | cGraphMaster& graphmaster; 60 | 61 | aiml::AIMLError& errnum; 62 | void set_error(aiml::AIMLError _errnum); 63 | std::string runtime_error; 64 | 65 | void close(void); 66 | 67 | friend void startElementHandler(void* ctx, const xmlChar* localname, const xmlChar* prefix, const xmlChar* URI, 68 | int nb_namespaces, const xmlChar** namespaces, int nb_attributes, int nb_defaulted, const xmlChar ** attr); 69 | friend void endElementHandler(void* ctx, const xmlChar* localname, const xmlChar* prefix, const xmlChar* URI); 70 | friend void startElementHandlerOld(void* ctx, const xmlChar* name, const xmlChar** attr); 71 | friend void endElementHandlerOld(void* ctx, const xmlChar* name); 72 | friend void characterDataHandler(void* ctx, const xmlChar* s, int len); 73 | friend void errorHandler(void* ctx, const char* msg, ...); 74 | 75 | void startElement(const std::string& name, const std::list& attr_list); 76 | void endElement(const std::string& name); 77 | void characters(const std::string& text, int len); 78 | void onError(void); 79 | 80 | std::string topic, that, patt; 81 | cWriteBuffer templ; 82 | 83 | void trim_multiple_blanks(const std::string& text, std::string& templ, int len); 84 | int last_char_offset; 85 | bool inside_blanks; 86 | bool ignore_chardata; 87 | bool trim_blanks; 88 | 89 | enum PARSING_LEVEL { LEVEL_OTHER, LEVEL_INSIDE_PATTERN, LEVEL_INSIDE_TEMPLATE, LEVEL_INSIDE_THAT }; 90 | PARSING_LEVEL level; 91 | 92 | xmlParserCtxtPtr xml_context; 93 | bool insert_ordered; 94 | bool verbatim; 95 | 96 | bool inside_random; 97 | std::stack li_count_stack; 98 | 99 | std::stack offset_stack; 100 | size_t binary_pos; 101 | }; 102 | 103 | } 104 | 105 | #endif 106 | -------------------------------------------------------------------------------- /src/caiml_parser.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * This file is part of "libaiml" * 3 | * Copyright (C) 2005 by V01D * 4 | * * 5 | * "libaiml" is free software; you can redistribute it and/or modify * 6 | * it under the terms of the GNU General Public License as published by * 7 | * the Free Software Foundation; either version 2 of the License, or * 8 | * (at your option) any later version. * 9 | * * 10 | * "libaiml" is distributed in the hope that it will be useful, * 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 13 | * GNU General Public License for more details. * 14 | * * 15 | * You should have received a copy of the GNU General Public License * 16 | * along with "libaiml"; if not, write to the * 17 | * Free Software Foundation, Inc., * 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 19 | ***************************************************************************/ 20 | 21 | #ifndef __LIBAIML_CPARSER_H__ 22 | #define __LIBAIML_CPARSER_H__ 23 | 24 | #define CAIML_VERSION_NUMBER 1 25 | 26 | #include 27 | #include 28 | 29 | namespace aiml { 30 | 31 | class CAIMLparser { 32 | public: 33 | CAIMLparser(cGraphMaster& graphmaster, aiml::AIMLError& errnum); 34 | 35 | bool load(const std::string& filename); 36 | bool save(const std::string& filename); 37 | 38 | private: 39 | cGraphMaster& graphmaster; 40 | aiml::AIMLError& errnum; 41 | 42 | bool readChilds(std::ifstream& file, NodeVec& same_childs, NodeVec& diff_childs, NodeType type); 43 | bool checkForLeaf(std::ifstream& file, bool& is_leaf); 44 | 45 | bool writeChilds(std::ofstream& file, const NodeVec& same_childs, const NodeVec& diff_childs); 46 | 47 | void set_error(aiml::AIMLError _errnum); 48 | }; 49 | 50 | } 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /src/config_parser.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * This file is part of "libaiml" * 3 | * Copyright (C) 2005 by V01D * 4 | * * 5 | * "libaiml" is free software; you can redistribute it and/or modify * 6 | * it under the terms of the GNU General Public License as published by * 7 | * the Free Software Foundation; either version 2 of the License, or * 8 | * (at your option) any later version. * 9 | * * 10 | * "libaiml" is distributed in the hope that it will be useful, * 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 13 | * GNU General Public License for more details. * 14 | * * 15 | * You should have received a copy of the GNU General Public License * 16 | * along with "libaiml"; if not, write to the * 17 | * Free Software Foundation, Inc., * 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 19 | ***************************************************************************/ 20 | 21 | #ifndef __LIBAIML_CONFIG_PARSER__ 22 | #define __LIBAIML_CONFIG_PARSER__ 23 | 24 | #include 25 | 26 | namespace aiml { 27 | class cConfigParser { 28 | public: 29 | cConfigParser(cCore& _core); 30 | ~cConfigParser(void); 31 | 32 | bool load(const std::string& file, bool dont_fill_options = false); 33 | const std::string& getRuntimeError(void); 34 | 35 | private: 36 | cCore& core; 37 | xmlParserCtxt* xml_parser; 38 | std::string runtime_error; 39 | 40 | void parseBotVars(xmlNode* list); 41 | void parseSubstitutions(xmlNode* list); 42 | void parseSubstitutionsEntry(xmlNode* list, cGraphMaster::SubsType type); 43 | void parseOptions(xmlNode* list); 44 | }; 45 | } 46 | 47 | #endif // __LIBAIML_CONFIG_PARSER__ 48 | -------------------------------------------------------------------------------- /src/core.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * This file is part of "libaiml" * 3 | * Copyright (C) 2005 by V01D * 4 | * * 5 | * "libaiml" is free software; you can redistribute it and/or modify * 6 | * it under the terms of the GNU General Public License as published by * 7 | * the Free Software Foundation; either version 2 of the License, or * 8 | * (at your option) any later version. * 9 | * * 10 | * "libaiml" is distributed in the hope that it will be useful, * 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 13 | * GNU General Public License for more details. * 14 | * * 15 | * You should have received a copy of the GNU General Public License * 16 | * along with "libaiml"; if not, write to the * 17 | * Free Software Foundation, Inc., * 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 19 | ***************************************************************************/ 20 | 21 | #ifndef __LIBAIML_CORE_H__ 22 | #define __LIBAIML_CORE_H__ 23 | 24 | #define LIBAIML_POPEN_BUFFER_SIZE 256 // buffer size used when reading data from popen() 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | #include "aiml.h" 34 | #include "global.h" 35 | #include "errors.h" 36 | #include "user.h" 37 | #include "serializer.h" 38 | #include "graphmaster.h" 39 | #include "aiml_parser.h" 40 | #include "caiml_parser.h" 41 | #include "user_manager.h" 42 | #include "config_parser.h" 43 | #include "javascript.h" 44 | 45 | namespace aiml { 46 | class cCore : public cInterpreter { 47 | public: 48 | cCore(void); 49 | ~cCore(void); 50 | 51 | bool initialize(const std::string& filename); 52 | bool initialize(const std::string& filename, const cCoreOptions& opts); 53 | void deinitialize(void); 54 | 55 | void registerCallbacks(cInterpreterCallbacks* callbacks); 56 | 57 | bool respond(const std::string& input, const std::string& username, std::string& output, std::list* log = NULL); 58 | void unregisterUser(const std::string& user_id); 59 | 60 | bool learnFile(const std::string& filename); 61 | 62 | bool saveGraphmaster(const std::string& file); 63 | bool loadGraphmaster(const std::string& file); 64 | 65 | std::string getErrorStr(AIMLError error_num); 66 | std::string getRuntimeErrorStr(void); 67 | 68 | private: 69 | friend class aiml::cGraphMaster; 70 | friend class aiml::cUserManager; 71 | friend class aiml::cConfigParser; 72 | 73 | /** Error handling **/ 74 | static std::string error_str[AIMLERR_MAX]; 75 | void set_error(AIMLError); 76 | 77 | /** Utility Functions **/ 78 | bool load_aiml_files(void); 79 | bool learn_file(const std::string& filename, bool at_runtime = false); 80 | 81 | bool doSystemCall(const std::string& cmd, std::string& ret); 82 | 83 | /** java script **/ 84 | bool doJavaScriptCall(const std::string& cmd, std::string& ret); 85 | cJavaScript javascript_interpreter; 86 | 87 | const std::string& getBotVar(const std::string& key) const; 88 | StringMAP botvars_map; 89 | 90 | /** Internal modules **/ 91 | cGraphMaster graphmaster; 92 | AIMLparser aiml_parser; 93 | CAIMLparser caiml_parser; 94 | 95 | /** Configuration options/vars **/ 96 | cConfigParser cfg_parser; 97 | cCoreOptions cfg_options; 98 | std_util::cConfig cfg; 99 | bool applyConfigOptions(void); 100 | 101 | std::ofstream file_gossip_stream; 102 | 103 | /** User management **/ 104 | cUserManager user_manager; 105 | typedef std::map UserMap; 106 | UserMap user_map; 107 | 108 | /** other **/ 109 | bool initialized; 110 | }; 111 | } 112 | 113 | #endif // __LIBAIML_CORE_H__ 114 | -------------------------------------------------------------------------------- /src/errors.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * This file is part of "libaiml" * 3 | * Copyright (C) 2005 by V01D * 4 | * * 5 | * "libaiml" is free software; you can redistribute it and/or modify * 6 | * it under the terms of the GNU General Public License as published by * 7 | * the Free Software Foundation; either version 2 of the License, or * 8 | * (at your option) any later version. * 9 | * * 10 | * "libaiml" is distributed in the hope that it will be useful, * 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 13 | * GNU General Public License for more details. * 14 | * * 15 | * You should have received a copy of the GNU General Public License * 16 | * along with "libaiml"; if not, write to the * 17 | * Free Software Foundation, Inc., * 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 19 | ***************************************************************************/ 20 | #include 21 | #include "core.h" 22 | 23 | using namespace aiml; 24 | using namespace aiml; 25 | 26 | std::string cCore::error_str[AIMLERR_MAX] = { 27 | "No Error", 28 | 29 | // core errors 30 | "No .aiml files to load", "Read error while matching file patterns", "Unknown error while matching file patterns", 31 | "Can't create/access gossip file", "Core isn't initialized", "Core is already initialized", 32 | "Error while parsing configuration file", "Error with userlist file", 33 | 34 | // sub-engines' errors 35 | "System tag is not allowed to be executed", 36 | "Javascript tag is not allowed to be executed", 37 | "Problem with JavaScript interpreter", 38 | 39 | // graphmaster errors 40 | "Normalization on input resulted in empty string", 41 | "No match found. There should be at least a pickup line (***)", 42 | "The GraphMaster was empty (no AIML data was loaded)", 43 | 44 | // aiml parser errors 45 | "Couldn't open aiml file", 46 | "AIML parser error", 47 | 48 | // caiml parser errors 49 | "Couldn't read magic number from caiml file", "File was not a caiml file (magic number mismatch)", 50 | "Couldn't open caiml file for reading", "No caiml version found in file", 51 | "Unsupported/Incorrect caiml version", "No graphmaster size in caiml file", 52 | "No size of childs for node in caiml file", "No key for node in caiml file", 53 | "No template for node in caiml file", "Can't save an empty graphmaster", 54 | "Couldn't open caiml file for writing", 55 | "Caiml file is not correctly built", 56 | 57 | // template parser errors 58 | "Unknown tag found while parsing template", 59 | 60 | // cUser errors 61 | "Negative index in found", 62 | "Negative index in found" 63 | }; 64 | 65 | void cCore::set_error(AIMLError err) { last_error = err; } 66 | 67 | std::string cCore::getErrorStr(AIMLError error_num) { 68 | return (error_num == AIMLERR_MAX ? "" : error_str[error_num]); 69 | } 70 | 71 | std::string cCore::getRuntimeErrorStr(void) { 72 | if (last_error == AIMLERR_NO_CFGFILE) return cfg_parser.getRuntimeError(); 73 | else if (last_error == AIMLERR_AIML_PARSE) return aiml_parser.getRuntimeError(); 74 | else if (last_error == AIMLERR_NO_USERLIST) return user_manager.getRuntimeError(); 75 | else if (last_error == AIMLERR_JAVASCRIPT_PROBLEM) return javascript_interpreter.getRuntimeError(); 76 | else return std::string(); 77 | } 78 | -------------------------------------------------------------------------------- /src/errors.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * This file is part of "libaiml" * 3 | * Copyright (C) 2005 by V01D * 4 | * * 5 | * "libaiml" is free software; you can redistribute it and/or modify * 6 | * it under the terms of the GNU General Public License as published by * 7 | * the Free Software Foundation; either version 2 of the License, or * 8 | * (at your option) any later version. * 9 | * * 10 | * "libaiml" is distributed in the hope that it will be useful, * 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 13 | * GNU General Public License for more details. * 14 | * * 15 | * You should have received a copy of the GNU General Public License * 16 | * along with "libaiml"; if not, write to the * 17 | * Free Software Foundation, Inc., * 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 19 | ***************************************************************************/ 20 | 21 | #ifndef __LIBAIML_ERRORS_H__ 22 | #define __LIBAIML_ERRORS_H__ 23 | 24 | 25 | namespace aiml { 26 | /** 27 | * Error codes produced by libaiml. 28 | */ 29 | enum AIMLError { 30 | // core errors 31 | AIMLERR_NO_ERR, /**< No error. */ 32 | AIMLERR_NO_FILES, /**< No aiml files specified to load. */ 33 | AIMLERR_PATT_READERR, /**< Read error while matching file patterns. */ 34 | AIMLERR_PATT_UNKNOWN, /**< Unknown error while matching file patterns. */ 35 | AIMLERR_OPEN_GOSSIP, /**< Couldn't open gossip file for writing. */ 36 | AIMLERR_NOT_INIT, /**< The core isn't yet initialized. */ 37 | AIMLERR_ALREADY_INIT, /**< The core is already initialized. */ 38 | AIMLERR_NO_CFGFILE, /**< Couldn't open/read configuration file. (use cInterpreter::getRuntimeErrorStr()). */ 39 | AIMLERR_NO_USERLIST, /**< Error with userlist file. */ 40 | 41 | // sub-engines' errors 42 | AIMLERR_SYSTEM_NOT_ALLOWED, /**< System tag is not allowed to be executed. */ 43 | AIMLERR_JAVASCRIPT_NOT_ALLOWED, /**< Javascript tag is not allowed to be executed. */ 44 | AIMLERR_JAVASCRIPT_PROBLEM, /**< Problem with JavaScript interpreter (use cInterpreter::getRuntimeErrorStr()). */ 45 | 46 | // graphmaster errors 47 | AIMLERR_EMPTY_INPUT, /**< Normalization of input resulted in empty string. */ 48 | AIMLERR_NO_MATCH, /**< No match found for input. */ 49 | AIMLERR_EMPTY_GM, /**< Empty graphmaster (no categories loaded). */ 50 | 51 | // aiml parser errors 52 | AIMLERR_AIML_NOOPEN, /**< Couldn't open aiml file. */ 53 | AIMLERR_AIML_PARSE, /**< AIML Parser error (use cInterpreter::getRuntimeErrorStr()). */ 54 | 55 | // caiml parser errors 56 | AIMLERR_CAIML_NOMAGIC, /**< Couldn't retrieve magic number from caiml file. */ 57 | AIMLERR_CAIML_NOTCAIML, /**< Not a CAIML file. */ 58 | AIMLERR_CAIML_NOOPEN_READ, /**< Couldn't open CAIML file for reading. */ 59 | AIMLERR_CAIML_NOVERSION, /**< Couldn't get version from CAIML file. */ 60 | AIMLERR_CAIML_WRONGVERSION, /**< CAIML file version not supported. */ 61 | AIMLERR_CAIML_NOSIZE, /**< Couldn't get size of graphmaster (ie: number of templates) from CAIML file. */ 62 | AIMLERR_CAIML_NOCHILDSNUM, /**< No size of childs for node in CAIML file. */ 63 | AIMLERR_CAIML_NOKEY, /**< Coulnd't read key for node in CAIML file. */ 64 | AIMLERR_CAIML_NOTEMPLATE, /**< Coulnd't read template for node in CAIML file. */ 65 | AIMLERR_CAIML_EMPTYGM, /**< Can't save an empty graphmaster. */ 66 | AIMLERR_CAIML_NOOPEN_WRITE, /**< Couldn't open CAIML file for writing. */ 67 | AIMLERR_CAIML_INCORRECTSTRUCT, /**< Caiml file is not correctly built. */ 68 | 69 | // template parser errors 70 | AIMLERR_TEMLP_UNKNOWN_TAG, /**< Unknown tag found while parsing template. */ 71 | 72 | // cUser errors 73 | AIMLERR_NEG_THAT_INDEX, /**< Negative index in 'that' tag found. */ 74 | AIMLERR_NEG_INPUT_INDEX, /**< Negative index in 'input' tag found. */ 75 | 76 | // misc 77 | AIMLERR_MAX 78 | }; 79 | } 80 | 81 | #endif 82 | -------------------------------------------------------------------------------- /src/global.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * This file is part of "libaiml" * 3 | * Copyright (C) 2005 by V01D * 4 | * * 5 | * "libaiml" is free software; you can redistribute it and/or modify * 6 | * it under the terms of the GNU General Public License as published by * 7 | * the Free Software Foundation; either version 2 of the License, or * 8 | * (at your option) any later version. * 9 | * * 10 | * "libaiml" is distributed in the hope that it will be useful, * 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 13 | * GNU General Public License for more details. * 14 | * * 15 | * You should have received a copy of the GNU General Public License * 16 | * along with "libaiml"; if not, write to the * 17 | * Free Software Foundation, Inc., * 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 19 | ***************************************************************************/ 20 | 21 | #ifndef __LIBAIML_GLOBAL_H__ 22 | #define __LIBAIML_GLOBAL_H__ 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #define INV_BAD_CAST(s) reinterpret_cast(s) 31 | 32 | namespace aiml { 33 | void tokenizeToList(const std::string& input, std::list& out, bool cant_be_empty = false, const char* str = NULL); 34 | 35 | void to_uppercase(std::string& text); 36 | void to_lowercase(std::string& text); 37 | void to_formal(std::string& text, const std::string& sentence_limit); 38 | void to_sentence(std::string& text, const std::string& sentence_limit); 39 | 40 | void do_split(std::string input, std::vector& out, const std::string& sentence_limit, bool do_fitting = true); 41 | void do_pattern_fitting(std::string& input); 42 | void clean_pattern(std::string& pattern); 43 | 44 | #ifdef _DEBUG 45 | std::ostream& msg_dbg(bool add_prefix = true); 46 | #define _DBG_CODE(x) x 47 | #define _DBG_MARK() _DBG_CODE(msg_dbg() << "Mark (" << __FILE__ << ":" << __LINE__ << ")" << endl) 48 | #else 49 | #define _DBG_CODE(x) 50 | #define _DBG_MARK() 51 | #endif 52 | 53 | enum NodeType { NODE_PATT, NODE_THAT, NODE_TOPIC }; 54 | NodeType nextNodeType(const NodeType& a); 55 | 56 | typedef std::map StringMAP; 57 | extern const std::string emptyString; 58 | extern const std::string dotString; 59 | } 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /src/javascript.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * This file is part of "libaiml" * 3 | * Copyright (C) 2005 by V01D * 4 | * * 5 | * "libaiml" is free software; you can redistribute it and/or modify * 6 | * it under the terms of the GNU General Public License as published by * 7 | * the Free Software Foundation; either version 2 of the License, or * 8 | * (at your option) any later version. * 9 | * * 10 | * "libaiml" is distributed in the hope that it will be useful, * 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 13 | * GNU General Public License for more details. * 14 | * * 15 | * You should have received a copy of the GNU General Public License * 16 | * along with "libaiml"; if not, write to the * 17 | * Free Software Foundation, Inc., * 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 19 | ***************************************************************************/ 20 | 21 | #include 22 | #include "javascript.h" 23 | #include "config.h" 24 | #include "global.h" 25 | 26 | using namespace std; 27 | using namespace aiml; 28 | 29 | /** Interpreter Instance Data **/ 30 | #ifdef ENABLE_JAVASCRIPT 31 | cJavaScript::cJavaScriptInterpreter::cJavaScriptInterpreter(void) { 32 | JSClass global_class_template = { 33 | "global", 0, 34 | JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, 35 | JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub 36 | }; 37 | global_class = global_class_template; 38 | } 39 | 40 | void cJavaScript::cJavaScriptInterpreter::ErrorReporter(JSContext* cx, const char* message, JSErrorReport* report) { 41 | ostringstream osstr; 42 | osstr << report->lineno; 43 | string& runtime_error = static_cast(JS_GetContextPrivate(cx))->runtime_error; 44 | if (runtime_error.empty()) runtime_error = string("JavaScript Error: ") + message + " (at line " + osstr.str() + ")"; 45 | } 46 | 47 | JSBool cJavaScript::cJavaScriptInterpreter::Print(JSContext* cx, JSObject* obj, uintN argc, jsval* argv, jsval* rval) { 48 | string& retval = static_cast(JS_GetContextPrivate(cx))->eval_result; 49 | for (uintN i = 0; i < argc; i++) { 50 | JSString* str = JS_ValueToString(cx, argv[i]); 51 | if (!str) return JS_FALSE; 52 | retval += (i == 0 ? string("") : string(" ")) + string(JS_GetStringBytes(str), JS_GetStringLength(str)); 53 | } 54 | return JS_TRUE; 55 | } 56 | #endif 57 | 58 | /** Initialization / Destruction **/ 59 | cJavaScript::cJavaScript(void) { 60 | #ifdef ENABLE_JAVASCRIPT 61 | interpreter = NULL; 62 | #endif 63 | } 64 | 65 | cJavaScript::~cJavaScript(void) { 66 | #ifdef ENABLE_JAVASCRIPT 67 | if (interpreter) { 68 | if (interpreter->rt) JS_DestroyRuntime(interpreter->rt); 69 | } 70 | delete interpreter; 71 | #endif 72 | } 73 | 74 | bool cJavaScript::init(void) { 75 | #ifdef ENABLE_JAVASCRIPT 76 | interpreter = new cJavaScriptInterpreter; 77 | interpreter->rt = JS_NewRuntime(8L * 1024L * 1024L); 78 | if (!interpreter->rt) return false; 79 | #endif 80 | return true; 81 | } 82 | 83 | /** Evaluation **/ 84 | bool cJavaScript::eval(const std::string& in, std::string& out) { 85 | #ifdef ENABLE_JAVASCRIPT 86 | bool success = true; 87 | 88 | // initialize context 89 | JSContext* cx = NULL; 90 | try { 91 | cx = JS_NewContext(interpreter->rt, 8192); 92 | if (!cx) return false; 93 | 94 | JS_SetContextPrivate(cx, this); 95 | JS_SetErrorReporter(cx, &cJavaScriptInterpreter::ErrorReporter); 96 | 97 | JSObject* global = JS_NewObject(cx, &interpreter->global_class, NULL, NULL); 98 | if (!global) throw string("no global object"); 99 | 100 | if (!JS_InitStandardClasses(cx, global)) throw string("couldn't init standard classes"); 101 | 102 | if (!JS_DefineFunction(cx, global, "print", &cJavaScriptInterpreter::Print, 0, 0)) 103 | throw string("couldn't init print() function"); 104 | 105 | // interpret script 106 | jsval retval; 107 | eval_result.clear(); 108 | if (JS_EvaluateScript(cx, global, in.c_str(), in.length(), "none", 0, &retval)) { 109 | JSString* ret_jsstring = JS_ValueToString(cx, retval); 110 | if (ret_jsstring) out = eval_result; 111 | else throw string("couldn't get result as string"); 112 | } 113 | else throw string("evaluation error"); 114 | } 115 | catch(const std::string& msg) { 116 | if (runtime_error.empty()) runtime_error = msg; 117 | success = false; 118 | } 119 | catch(...) { 120 | if (runtime_error.empty()) runtime_error = "unknown exception"; 121 | success = false; 122 | } 123 | 124 | // free stuff 125 | if (cx) JS_DestroyContext(cx); 126 | 127 | return success; 128 | #else 129 | runtime_error = "no JavaScript support"; 130 | return false; 131 | #endif 132 | } 133 | 134 | const string& cJavaScript::getRuntimeError(void) { 135 | return runtime_error; 136 | } 137 | 138 | -------------------------------------------------------------------------------- /src/javascript.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * This file is part of "libaiml" * 3 | * Copyright (C) 2005 by V01D * 4 | * * 5 | * "libaiml" is free software; you can redistribute it and/or modify * 6 | * it under the terms of the GNU General Public License as published by * 7 | * the Free Software Foundation; either version 2 of the License, or * 8 | * (at your option) any later version. * 9 | * * 10 | * "libaiml" is distributed in the hope that it will be useful, * 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 13 | * GNU General Public License for more details. * 14 | * * 15 | * You should have received a copy of the GNU General Public License * 16 | * along with "libaiml"; if not, write to the * 17 | * Free Software Foundation, Inc., * 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 19 | ***************************************************************************/ 20 | 21 | #ifndef __LIBAIML_SUBENGINE_JAVASCRIPT_H__ 22 | #define __LIBAIML_SUBENGINE_JAVASCRIPT_H__ 23 | 24 | #include 25 | 26 | #include "config.h" 27 | #ifdef ENABLE_JAVASCRIPT 28 | #define XP_UNIX 29 | #include 30 | #undef XP_UNIX 31 | #endif 32 | 33 | namespace aiml { 34 | 35 | class cJavaScript { 36 | public: 37 | cJavaScript(void); 38 | ~cJavaScript(void); 39 | 40 | bool init(void); 41 | bool eval(const std::string& in, std::string& out); 42 | const std::string& getRuntimeError(void); 43 | 44 | private: 45 | #ifdef ENABLE_JAVASCRIPT 46 | struct cJavaScriptInterpreter { 47 | cJavaScriptInterpreter(void); 48 | 49 | static void ErrorReporter(JSContext* cx, const char* message, JSErrorReport* report); 50 | static JSBool Print(JSContext* cx, JSObject* obj, uintN argc, jsval* argv, jsval* rval); 51 | 52 | JSRuntime* rt; 53 | JSClass global_class; 54 | }; 55 | 56 | cJavaScriptInterpreter* interpreter; 57 | #endif 58 | 59 | std::string runtime_error; 60 | std::string eval_result; 61 | }; 62 | 63 | } 64 | 65 | #endif // __LIBAIML_SUBENGINE_JAVASCRIPT_H__ 66 | -------------------------------------------------------------------------------- /src/serializer.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * This file is part of "libaiml" * 3 | * Copyright (C) 2005 by V01D * 4 | * * 5 | * "libaiml" is free software; you can redistribute it and/or modify * 6 | * it under the terms of the GNU General Public License as published by * 7 | * the Free Software Foundation; either version 2 of the License, or * 8 | * (at your option) any later version. * 9 | * * 10 | * "libaiml" is distributed in the hope that it will be useful, * 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 13 | * GNU General Public License for more details. * 14 | * * 15 | * You should have received a copy of the GNU General Public License * 16 | * along with "libaiml"; if not, write to the * 17 | * Free Software Foundation, Inc., * 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 19 | ***************************************************************************/ 20 | 21 | #ifndef __LIBAIML_SERIALIZER_H__ 22 | #define __LIBAIML_SERIALIZER_H__ 23 | 24 | #include 25 | #include 26 | 27 | namespace aiml { 28 | class cWriteBuffer { 29 | public: 30 | cWriteBuffer(void); 31 | 32 | size_t writeString(const std::string& str); 33 | size_t writeNumber(size_t num); 34 | 35 | size_t seek(size_t new_pos, size_t offset = 0); 36 | size_t tell(void) const; 37 | bool at_end(void) const; 38 | bool empty(void) const; 39 | 40 | bool readFromFile(std::istream& file); 41 | bool writeToFile(std::ostream& file) const; 42 | 43 | void clear(void); 44 | 45 | private: 46 | friend class cReadBuffer; 47 | 48 | std::vector data; 49 | size_t pos; 50 | bool dont_resize; 51 | }; 52 | 53 | class cReadBuffer { 54 | public: 55 | cReadBuffer(const cWriteBuffer& wr_buff); 56 | 57 | size_t readString(std::string& str, bool append = false); 58 | size_t readNumber(size_t& num); 59 | 60 | size_t discardString(void); 61 | 62 | size_t seek(size_t new_pos, size_t offset = 0); 63 | size_t tell(void) const; 64 | bool at_end(void) const; 65 | 66 | size_t limitSize(size_t _size); 67 | void restoreSize(size_t _size); 68 | void to_end(void); 69 | 70 | private: 71 | cReadBuffer(void); 72 | 73 | const std::vector& data; 74 | size_t pos, size; 75 | }; 76 | 77 | // for CAIML 78 | bool writeString(std::ostream& file, const std::string& str); 79 | bool readChardata(std::ostream& file, std::vector& s); 80 | bool writeNumber(std::ostream& file, size_t num); 81 | 82 | bool readString(std::istream& file, std::string& str); 83 | bool writeChardata(std::ostream& file, const std::vector& s); 84 | bool readNumber(std::istream& file, size_t& num); 85 | } 86 | 87 | #endif 88 | -------------------------------------------------------------------------------- /src/stuff.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * This file is part of "libaiml" * 3 | * Copyright (C) 2005 by V01D * 4 | * * 5 | * "libaiml" is free software; you can redistribute it and/or modify * 6 | * it under the terms of the GNU General Public License as published by * 7 | * the Free Software Foundation; either version 2 of the License, or * 8 | * (at your option) any later version. * 9 | * * 10 | * "libaiml" is distributed in the hope that it will be useful, * 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 13 | * GNU General Public License for more details. * 14 | * * 15 | * You should have received a copy of the GNU General Public License * 16 | * along with "libaiml"; if not, write to the * 17 | * Free Software Foundation, Inc., * 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 19 | ***************************************************************************/ 20 | 21 | #include 22 | #include 23 | #include "core.h" 24 | using namespace std; 25 | using namespace aiml; 26 | 27 | const string aiml::emptyString; 28 | const string aiml::dotString = "."; 29 | 30 | void aiml::tokenizeToList(const string& input, std::list& out, bool cant_be_empty, const char* str) { 31 | string token; 32 | for (size_t i = 1; std_util::gettok(input, token, i); i++) out.push_back(token); 33 | if (cant_be_empty && out.empty()) out.push_back(str ? str : "."); 34 | } 35 | 36 | void aiml::to_uppercase(string& text) { 37 | for (string::iterator it = text.begin(); it != text.end(); ++it) *it = toupper(*it); 38 | } 39 | 40 | void aiml::to_lowercase(string& text) { 41 | for (string::iterator it = text.begin(); it != text.end(); ++it) *it = tolower(*it); 42 | } 43 | 44 | void aiml::to_formal(string& text, const string& sentence_limit) { 45 | to_sentence(text, sentence_limit + " "); 46 | } 47 | 48 | void aiml::to_sentence(string& text, const string& sentence_limit) { 49 | bool inside_sentence = false; 50 | size_t pos = 0; 51 | while(pos != string::npos) { 52 | if (inside_sentence) { 53 | pos = text.find_first_of(sentence_limit, pos); 54 | if (pos != string::npos) inside_sentence = false; 55 | } 56 | else { 57 | pos = text.find_first_not_of(sentence_limit + " ", pos); 58 | if (pos != string::npos) { 59 | inside_sentence = true; 60 | if (isalpha(text[pos])) text[pos] = toupper(text[pos]); 61 | } 62 | } 63 | } 64 | } 65 | 66 | void aiml::do_split(string input, vector& out, const string& sentence_limit, bool do_fitting) { 67 | string sentence; 68 | size_t pos = input.find_first_of(sentence_limit); 69 | bool should_end = false; 70 | while(!should_end) { 71 | // process and save the sentence 72 | if (pos == string::npos) { should_end = true; sentence = input; } 73 | else { sentence = input.substr(0, pos); } 74 | if (do_fitting) do_pattern_fitting(sentence); 75 | sentence = std_util::strip(sentence); 76 | if (!sentence.empty()) out.push_back(sentence); 77 | 78 | // any more sentences? 79 | if (should_end) break; 80 | 81 | // if there are, skip more sentence delimiters and space before looking for next one 82 | pos = input.find_first_not_of(sentence_limit + " ", pos); 83 | if (pos == string::npos) break; 84 | input = input.substr(pos); 85 | pos = input.find_first_of(sentence_limit); 86 | } 87 | } 88 | 89 | // leaves only alphanumeric characters and makes them all uppercase 90 | void aiml::do_pattern_fitting(string& input) { 91 | for (string::iterator it = input.begin(); it != input.end(); ++it) { 92 | if (!isalnum(*it)) (*it) = (*it); 93 | else (*it) = toupper(*it); 94 | } 95 | } 96 | 97 | // similar to above but directed to patterns read from .aiml files, which should only contain spaces, '*', '_', and alphanumeric 98 | // characters 99 | void aiml::clean_pattern(string& pattern) { 100 | for (string::iterator it = pattern.begin(); it != pattern.end(); ++it) { 101 | if (!isalnum(*it) && *it != '*' && *it != '_' && *it != ' ') (*it) = ' '; 102 | else (*it) = toupper(*it); 103 | } 104 | } 105 | 106 | /** NodeType operations **/ 107 | NodeType aiml::nextNodeType(const NodeType& a) { 108 | switch(a) { 109 | case NODE_PATT: return NODE_THAT; break; 110 | case NODE_THAT: return NODE_TOPIC; break; 111 | case NODE_TOPIC: return NODE_TOPIC; break; 112 | } 113 | return NODE_TOPIC; // never reached 114 | } 115 | -------------------------------------------------------------------------------- /src/user.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * This file is part of "libaiml" * 3 | * Copyright (C) 2005 by V01D * 4 | * * 5 | * "libaiml" is free software; you can redistribute it and/or modify * 6 | * it under the terms of the GNU General Public License as published by * 7 | * the Free Software Foundation; either version 2 of the License, or * 8 | * (at your option) any later version. * 9 | * * 10 | * "libaiml" is distributed in the hope that it will be useful, * 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 13 | * GNU General Public License for more details. * 14 | * * 15 | * You should have received a copy of the GNU General Public License * 16 | * along with "libaiml"; if not, write to the * 17 | * Free Software Foundation, Inc., * 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 19 | ***************************************************************************/ 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include "core.h" 26 | 27 | using namespace std; 28 | using namespace std_util; 29 | using namespace aiml; 30 | 31 | cUser::cUser(void) : botvars_map(NULL), graphmaster(NULL), last_error(NULL) { } 32 | cUser::cUser(const string& _name, AIMLError* _last_error, const StringMAP* _botvars_map, const cGraphMaster* gm) : 33 | name(_name), botvars_map(_botvars_map), graphmaster(gm), last_error(_last_error) { } 34 | 35 | /** 36 | Precondition = which is a valid [1,MAX_THAT_SIZE] number; sentence is a [1,n) 37 | (being 'n' a valid number depending on the number of sentences in that response) 38 | **/ 39 | const string& cUser::getThat(bool for_matching, unsigned int which, unsigned int sentence) const { 40 | if (which == 0 || sentence == 0) { set_error(AIMLERR_NEG_THAT_INDEX); return emptyString; } 41 | if (which > LIBAIML_MAX_THAT_SIZE || sentence > that_array[which-1].size()) return (for_matching ? dotString : emptyString); 42 | 43 | unsigned int sentence_realnum = that_array[which-1].size() - sentence; 44 | return (that_array[which-1])[sentence_realnum]; 45 | } 46 | 47 | void cUser::getMatchList(NodeType type, list& out) const { 48 | string curr_list; 49 | switch(type) { 50 | case NODE_THAT: curr_list = getThat(); break; 51 | case NODE_TOPIC: curr_list = getTopic(); break; 52 | case NODE_PATT: break; 53 | } 54 | if (curr_list == ".") out.push_back("."); 55 | else { 56 | graphmaster->normalize_sentence(curr_list); 57 | tokenizeToList(curr_list, out, true); 58 | } 59 | } 60 | 61 | /** 62 | N O T E: Altought most of the AIML sets (including AAA) use the return-name-when-set implicitly for certaing vars, 63 | I'm not supporting this for now because it isn't part of the spec 64 | **/ 65 | const string& cUser::setVar(const string& key, const string& value) { 66 | string final_value(strip(value)); 67 | StringMAP::iterator it = vars_map.find(key); 68 | 69 | if (final_value.empty()) { 70 | if (it != vars_map.end()) vars_map.erase(it); 71 | } 72 | else vars_map[key] = strip(value); 73 | 74 | return value; 75 | } 76 | 77 | const string& cUser::getVar(const string& key) const { 78 | StringMAP::const_iterator it = vars_map.find(key); 79 | if (it != vars_map.end()) { _DBG_CODE(msg_dbg() << "get [" << (*it).first << "]" << endl); return (*it).second; } 80 | else return emptyString; 81 | } 82 | 83 | const StringMAP& cUser::getAllVars(void) const { 84 | return vars_map; 85 | } 86 | 87 | const string& cUser::getBotVar(const string& key) const { 88 | StringMAP::const_iterator it = botvars_map->find(key); 89 | if (it != botvars_map->end()) return (*it).second; 90 | return emptyString; 91 | } 92 | 93 | 94 | const string& cUser::getInput(unsigned int which, unsigned int sentence) const { 95 | if (which == 0 || sentence == 0) { set_error(AIMLERR_NEG_INPUT_INDEX); return emptyString; } 96 | if (which > LIBAIML_MAX_INPUTS_SAVED || sentence > input_array[which-1].size()) return emptyString; 97 | 98 | unsigned int sentence_realnum = input_array[which-1].size() - sentence; 99 | return (input_array[which-1])[sentence_realnum]; 100 | 101 | } 102 | 103 | const string& cUser::getTopic(void) const { 104 | StringMAP::const_iterator it = vars_map.find("topic"); 105 | if (it != vars_map.end()) return (*it).second; 106 | else return emptyString; 107 | } 108 | 109 | void cUser::addBotThat(const vector& that) { 110 | for (unsigned int i = LIBAIML_MAX_THAT_SIZE-1; i; --i) that_array[i] = that_array[i-1]; 111 | that_array[0] = that; 112 | } 113 | 114 | void cUser::addUserInput(vector input) { 115 | for (unsigned int i = LIBAIML_MAX_INPUTS_SAVED-1; i; --i) input_array[i] = input_array[i-1]; 116 | for (vector::iterator it = input.begin(); it != input.end(); ++it) to_lowercase(*it); 117 | input_array[0] = input; 118 | } 119 | 120 | void cUser::set_error(AIMLError errnum) const { *last_error = errnum; } 121 | 122 | -------------------------------------------------------------------------------- /src/user.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * This file is part of "libaiml" * 3 | * Copyright (C) 2005 by V01D * 4 | * * 5 | * "libaiml" is free software; you can redistribute it and/or modify * 6 | * it under the terms of the GNU General Public License as published by * 7 | * the Free Software Foundation; either version 2 of the License, or * 8 | * (at your option) any later version. * 9 | * * 10 | * "libaiml" is distributed in the hope that it will be useful, * 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 13 | * GNU General Public License for more details. * 14 | * * 15 | * You should have received a copy of the GNU General Public License * 16 | * along with "libaiml"; if not, write to the * 17 | * Free Software Foundation, Inc., * 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 19 | ***************************************************************************/ 20 | 21 | #ifndef __LIBAIML_USER_H__ 22 | #define __LIBAIML_USER_H__ 23 | 24 | #define LIBAIML_MAX_THAT_SIZE 8 // number of bot responses to keep 25 | #define LIBAIML_MAX_INPUTS_SAVED 16 // the amount of clients input to store 26 | 27 | namespace aiml { 28 | 29 | class cGraphMaster; 30 | 31 | class cUser { 32 | public: 33 | cUser(void); 34 | cUser(const std::string& _name, aiml::AIMLError* last_error, const StringMAP* botvars, const cGraphMaster* gm); 35 | 36 | std::vector that_array[LIBAIML_MAX_THAT_SIZE]; 37 | std::vector input_array[LIBAIML_MAX_INPUTS_SAVED]; 38 | 39 | StringMAP vars_map; 40 | std::string name; 41 | 42 | const std::string& setVar(const std::string& key, const std::string& value); 43 | 44 | const std::string& getVar(const std::string& key) const; /** ADD: default values **/ 45 | const StringMAP& getAllVars(void) const; 46 | const std::string& getBotVar(const std::string& key) const; 47 | 48 | const std::string& getInput(unsigned int idx1 = 1, unsigned int idx2 = 1) const; 49 | const std::string& getThat(bool for_matching = true, unsigned int which = 1, unsigned int sentence = 1) const; 50 | const std::string& getTopic(void) const; 51 | 52 | void addUserInput(std::vector input); 53 | void addBotThat(const std::vector& that); 54 | 55 | void getMatchList(NodeType type, std::list& out) const; 56 | 57 | void set_error(aiml::AIMLError errnum) const; 58 | 59 | private: 60 | const StringMAP* botvars_map; 61 | const cGraphMaster* graphmaster; 62 | aiml::AIMLError* const last_error; 63 | }; 64 | 65 | } 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /src/user_manager.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * This file is part of "libaiml" * 3 | * Copyright (C) 2005 by V01D * 4 | * * 5 | * "libaiml" is free software; you can redistribute it and/or modify * 6 | * it under the terms of the GNU General Public License as published by * 7 | * the Free Software Foundation; either version 2 of the License, or * 8 | * (at your option) any later version. * 9 | * * 10 | * "libaiml" is distributed in the hope that it will be useful, * 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 13 | * GNU General Public License for more details. * 14 | * * 15 | * You should have received a copy of the GNU General Public License * 16 | * along with "libaiml"; if not, write to the * 17 | * Free Software Foundation, Inc., * 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 19 | ***************************************************************************/ 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include "core.h" 27 | using namespace aiml; 28 | using namespace std; 29 | 30 | cUserManager::cUserManager(cCore& _core) : core(_core) 31 | { 32 | xml_parser = xmlNewParserCtxt(); 33 | } 34 | 35 | cUserManager::~cUserManager(void) { 36 | if (xml_parser) xmlFreeParserCtxt(xml_parser); 37 | } 38 | 39 | struct cUserManagerException { 40 | cUserManagerException(const string& _msg, size_t _line) : msg(_msg), line(_line) { } 41 | const string msg; 42 | const size_t line; 43 | }; 44 | 45 | const string& cUserManager::getRuntimeError(void) { 46 | return runtime_error; 47 | } 48 | 49 | bool cUserManager::load(const std::string& file) { 50 | bool ret = true; 51 | xmlDoc* doc = xmlCtxtReadFile(xml_parser, file.c_str(), NULL, 0); 52 | if (!doc) return false; 53 | 54 | string current_user; 55 | xmlNode* root = xmlDocGetRootElement(doc); 56 | if (!root) return false; 57 | 58 | try { 59 | for (xmlNode* user_node = root->children; user_node; user_node = user_node->next) { 60 | if (user_node->type != XML_ELEMENT_NODE) continue; 61 | 62 | if (string(INV_BAD_CAST(user_node->name)) == "user") { 63 | if (!user_node->properties) throw cUserManagerException("user with no properties", user_node->line); 64 | if (string(INV_BAD_CAST(user_node->properties->name)) == "name") { 65 | current_user = INV_BAD_CAST(user_node->properties->children->content); 66 | pair new_user(current_user, cUser(current_user, &core.last_error, &core.botvars_map, &core.graphmaster)); 67 | core.user_map.insert(new_user); 68 | } 69 | } 70 | for (xmlNode* var_node = user_node->children; var_node; var_node = var_node->next) { 71 | if (var_node->type != XML_ELEMENT_NODE) continue; 72 | if (string(INV_BAD_CAST(var_node->name)) == "set") { 73 | if (!var_node->properties) throw cUserManagerException("set with no propierties", var_node->line); 74 | if (string(INV_BAD_CAST(var_node->properties->name)) == "name") { 75 | if (!var_node->children) continue; 76 | core.user_map[current_user].setVar(INV_BAD_CAST(var_node->properties->children->content), INV_BAD_CAST(var_node->children->content)); 77 | } 78 | } 79 | } 80 | } 81 | } 82 | catch(const cUserManagerException& exc) { 83 | ostringstream osstr; 84 | osstr << exc.line; 85 | runtime_error = exc.line + " (at line " + osstr.str() + ")"; 86 | ret = false; 87 | } 88 | catch(...) { 89 | runtime_error = "unknown exception"; 90 | ret = false; 91 | } 92 | 93 | xmlFreeDoc(doc); 94 | return ret; 95 | } 96 | 97 | bool cUserManager::save(const std::string& file) { 98 | xmlTextWriterPtr writer; 99 | bool ret = true; 100 | 101 | writer = xmlNewTextWriterFilename(file.c_str(), 0); 102 | if (!writer) return false; 103 | 104 | xmlTextWriterSetIndent(writer, true); 105 | xmlTextWriterSetIndentString(writer, BAD_CAST(" ")); 106 | 107 | try { 108 | if (xmlTextWriterStartDocument(writer, NULL, NULL, NULL) < 0) throw string("start document error"); 109 | if (xmlTextWriterStartElement(writer, BAD_CAST("userset")) < 0) throw string("start userset error "); 110 | 111 | const cCore::UserMap& user_map = core.user_map; 112 | for(cCore::UserMap::const_iterator it = user_map.begin(); it != user_map.end(); ++it) { 113 | if (xmlTextWriterStartElement(writer, BAD_CAST("user")) < 0) throw string("start user error"); 114 | if (xmlTextWriterWriteAttribute(writer, BAD_CAST("name"), BAD_CAST(it->first.c_str())) < 0) throw string("user attribute error"); 115 | 116 | const StringMAP& var_map = it->second.getAllVars(); 117 | for(StringMAP::const_iterator var_it = var_map.begin(); var_it != var_map.end(); ++var_it) { 118 | if (xmlTextWriterStartElement(writer, BAD_CAST("set")) < 0) throw string("start set error"); 119 | if (xmlTextWriterWriteAttribute(writer, BAD_CAST("name"), BAD_CAST(var_it->first.c_str())) < 0) throw string("set attribute error"); 120 | if (xmlTextWriterWriteCDATA(writer, BAD_CAST(var_it->second.c_str())) < 0) throw string("set content error"); 121 | if (xmlTextWriterEndElement(writer) < 0) throw string("end set error"); 122 | } 123 | if (xmlTextWriterEndElement(writer) < 0) throw string("end user error"); 124 | } 125 | 126 | if (xmlTextWriterEndElement(writer) < 0) throw string("end userset error"); 127 | if (xmlTextWriterEndDocument(writer) < 0) throw string("end document error"); 128 | } 129 | catch(const string& msg) { 130 | runtime_error = msg; 131 | ret = false; 132 | } 133 | catch(...) { 134 | runtime_error = "unknown exception"; 135 | ret = false; 136 | } 137 | 138 | xmlFreeTextWriter(writer); 139 | return ret; 140 | } 141 | -------------------------------------------------------------------------------- /src/user_manager.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * This file is part of "libaiml" * 3 | * Copyright (C) 2005 by V01D * 4 | * * 5 | * "libaiml" is free software; you can redistribute it and/or modify * 6 | * it under the terms of the GNU General Public License as published by * 7 | * the Free Software Foundation; either version 2 of the License, or * 8 | * (at your option) any later version. * 9 | * * 10 | * "libaiml" is distributed in the hope that it will be useful, * 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 13 | * GNU General Public License for more details. * 14 | * * 15 | * You should have received a copy of the GNU General Public License * 16 | * along with "libaiml"; if not, write to the * 17 | * Free Software Foundation, Inc., * 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 19 | ***************************************************************************/ 20 | 21 | #ifndef __LIBAIML_USER_MANAGER__ 22 | #define __LIBAIML_USER_MANAGER__ 23 | 24 | #include 25 | 26 | namespace aiml { 27 | class cUserManager { 28 | public: 29 | cUserManager(cCore& _core); 30 | ~cUserManager(void); 31 | 32 | bool load(const std::string& file); 33 | bool save(const std::string& file); 34 | const std::string& getRuntimeError(void); 35 | 36 | private: 37 | cCore& core; 38 | xmlParserCtxt* xml_parser; 39 | std::string runtime_error; 40 | }; 41 | } 42 | 43 | #endif // __LIBAIML_USER_MANAGER__ 44 | -------------------------------------------------------------------------------- /test_app/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | METASOURCES = AUTO 3 | 4 | SUBDIRS = aiml 5 | AM_CXXFLAGS = -Wall $(WERROR_CXXFLAG) -ansi -pedantic `xml2-config --cflags` 6 | 7 | noinst_PROGRAMS = test_app 8 | test_app_SOURCES = main.cpp 9 | 10 | test_app_LDADD = $(top_builddir)/src/libaiml.a $(PCRECPP_LIBS) -lstd_utils 11 | test_app_LDFLAGS = $(XML2_LIBS) 12 | 13 | -------------------------------------------------------------------------------- /test_app/aiml/Astrology.aiml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | WHAT IS A CANCER 12 | AQUARIUS 13 | CAPRICORN 14 | ARIES 15 | TAURUS 16 | CANCER 17 | GEMINI 18 | LIBRA 19 | PISCES 20 | VIRGO 21 | SCORPIO 22 | SAGGITARIUS 23 | WHAT IS A CAPRICORN 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /test_app/aiml/Botmaster.aiml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | TEST COND 11 | AM I YOUR BOTMASTER 12 | ASK YOUR BOTMASTER 13 | ASK YOUR BOTMASTER * 14 | BOTMASTER 15 | DOES YOUR BOTMASTER * 16 | DO YOU HAVE A BOTMASTER * 17 | DO YOU HAVE BOTMASTERS 18 | DO YOU KNOW YOUR BOTMASTER 19 | DO YOU THINK YOUR BOTMASTER * 20 | HE IS YOUR BOTMASTER 21 | IS A BOTMASTER * 22 | IS THE BOTMASTER * 23 | IS YOUR BOTMASTER * 24 | I WANT TO BE A BOTMASTER 25 | MY BOTMASTER * 26 | TELL ME ABOUT A BOTMASTER 27 | TELL ME ABOUT BOTMASTER 28 | TELL ME ABOUT YOUR BOTMASTER 29 | TELL ME ABOUT YOUR BOTMASTER * 30 | THAT IS YOUR BOTMASTER 31 | WHAT DOES A BOTMASTER DO 32 | WHAT DOES A BOTMASTER * 33 | WHAT IS A BOTMASTER 34 | WHAT IS BOTMASTER 35 | WHAT IS THAT BOTMASTER 36 | WHAT IS THE BOTMASTER 37 | WHERE IS YOUR BOTMASTER 38 | WHO IS BOTMASTER 39 | WHO IS THIS BOTMASTER 40 | WHO IS YOUR BOTMASTER * 41 | WHO IS YOUR BOTMASTERS 42 | WHO READS THESE CONVERSATIONS 43 | YOUR BOTMASTER 44 | YOUR BOTMASTER * 45 | 46 | -------------------------------------------------------------------------------- /test_app/aiml/Date.aiml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | WHAT TIME IS IT 12 | 17 | 18 | WHAT DAY IS IT 19 | WHAT IS TODAY 20 | 21 | WHAT IS THE DATE 22 | WHAT IS THE HOUR 23 | WHAT IS THE YEAR 24 | WHAT YEAR IS IT 25 | WHAT YEAR IS THIS 26 | WHAT MONTH IS IT 27 | 28 | 29 | -------------------------------------------------------------------------------- /test_app/aiml/Dialog.aiml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | DIALOG HISTORY * 12 | 58 | 59 | 60 | 61 | DIALOG HISTORY 62 | 108 | 109 | 110 | 111 | REVIEW OUR CONVERSATION 112 | 145 | 146 | DIALOGUE 147 | 148 | 149 | 150 | DO YOU REMEMBER OUR CONVERSATION 151 | 152 | 153 | 154 | DO YOU * OUR CONVERSATION 155 | 156 | 157 | 158 | DO YOU REMEMBER * CONVERSATION 159 | 160 | 161 | 162 | 163 | CAN YOU REMEMBER OUR CONVERSATION 164 | 165 | 166 | 167 | CAN YOU * OUR CONVERSATION 168 | 169 | 170 | 171 | CAN YOU REMEMBER * CONVERSATION 172 | 173 | 174 | 175 | 176 | -------------------------------------------------------------------------------- /test_app/aiml/Food.aiml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | DRINK * 12 | HOW CAN YOU EAT * 13 | ELECTRICITY * 14 | DO YOU LIKE BEING A CHATTERBOT 15 | WHY CAN NOT YOU EAT 16 | WHAT TURNS YOU ON 17 | WHAT DOES ELECTRICITY TASTE LIKE 18 | HOW MUCH ELECTRICITY 19 | HOW DO YOU EAT ELECTRICITY 20 | HOW DO YOU EAT 21 | HOW ARE YOU POWERED 22 | ELECTRICITY 23 | WHAT IS YOUR POWER SOURCE 24 | DO YOU REQUIRE ELECTRICITY 25 | DO YOU HAVE TO EAT 26 | DO YOU EAT BATTERIES 27 | DO YOU EAT ELECTRICITY 28 | DO YOU LIKE TO GET DRUNK 29 | DO YOU LIKE ELECTRICITY 30 | DO YOU LIKE LEMONS 31 | DO YOU LIKE THE SUN 32 | FOR DINNER 33 | WHAT IS CUSTARD 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /test_app/aiml/History.aiml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | AMERICAN CIVIL * 13 | AMERICAN CIVIL WAR * 14 | DO YOU KNOW HISTORY 15 | EXPLAIN HISTORY 16 | HISTORY 17 | TELL ME ABOUT HISTORY 18 | WHAT IS HISTORY 19 | WHAT KIND OF HISTORY * 20 | WHO INVENTED THE LIGHT * 21 | WHO INVENTED THE STEAM * 22 | 23 | -------------------------------------------------------------------------------- /test_app/aiml/Humor.aiml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | DO YOU HAVE A SENSE OF HUMOR 12 | DO YOU HAVE A SENSE OF HUMOUR 13 | DO YOU HAVE HUMOR 14 | TELL ME A JOKE 15 | WHAT IS HUMOUR 16 | YOUR HOUSE IS * 17 | _ WALKS INTO A BAR * 18 | _ WALKS INTO A BAR 19 | 20 | 21 | TELL ME ANOTHER JOKE 35 | 36 | -------------------------------------------------------------------------------- /test_app/aiml/IU.aiml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | I * 11 | 12 | YOU * 14 | 15 | 16 | -------------------------------------------------------------------------------- /test_app/aiml/Inquiry.aiml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | _ INQUIRY 17 | COLOR INQUIRY OM 18 | COLOR INQUIRY WHAT 19 | COLOR INQUIRY * 20 | DOES INQUIRY OM 21 | DOES INQUIRY WHAT 22 | DOES INQUIRY * 23 | GENDER INQUIRY OM 24 | GENDER INQUIRY WHAT 25 | GENDER INQUIRY * 26 | HAS INQUIRY OM 27 | HAS INQUIRY WHAT 28 | HAS INQUIRY * 29 | LOCATION INQUIRY OM 30 | LOCATION INQUIRY WHERE 31 | LOCATION INQUIRY * 32 | MOVIE INQUIRY OM 33 | MOVIE INQUIRY WHAT 34 | MOVIE INQUIRY * 35 | *WHAT IS YOUR FAVORITE COLOR 36 | *WHAT ARE YOU DOING 37 | *TELL ME ONE OF YOUR FAVORITE POSSESSIONS 38 | *WHAT IS YOUR FAVORITE MOVIE 39 | MANARE YOU A MAN OR A WOMAN 40 | WOMANARE YOU A MAN OR A WOMAN 41 | 42 | -------------------------------------------------------------------------------- /test_app/aiml/Literature.aiml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | WHAT IS ILLIMINATUS 17 | WHAT IS THE ILLUMINATI 18 | WHAT IS THE ILLUMINATTI 19 | WHAT IS VINELAND 20 | WHO IS BILBO BAGGINS 21 | WHO IS GEOFFREY CHAUCER 26 | WHO WROTE VINELAND 27 | WHO ARE THE ILLUMINATI 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /test_app/aiml/Makefile.am: -------------------------------------------------------------------------------- 1 | INCLUDES = 2 | METASOURCES = AUTO 3 | noinst_DATA = Adverbs.aiml AI.aiml ALICE.aiml Astrology.aiml Atomic.aiml \ 4 | Biography.aiml Bot.aiml Botmaster.aiml Client.aiml Computers.aiml Date.aiml \ 5 | Default.aiml Dialog.aiml Drugs.aiml Emotion.aiml Food.aiml Geography.aiml \ 6 | Gossip.aiml History.aiml Humor.aiml Inquiry.aiml Interjection.aiml IU.aiml \ 7 | Knowledge.aiml Literature.aiml Makefile.am Money.aiml Movies.aiml Music.aiml \ 8 | Parts.aiml Personality.aiml Philosophy.aiml Pickup.aiml Politics.aiml \ 9 | Predicates.aiml Psychology.aiml Reduce.aiml Reducer.aiml Reductions.aiml Religion.aiml \ 10 | Salutations.aiml Science.aiml Sex.aiml Spam.aiml Sports.aiml Stack.aiml Stories.aiml \ 11 | That.aiml update.aiml Wallace.aiml Wallace.aiml.1 Xfind.aiml 12 | -------------------------------------------------------------------------------- /test_app/aiml/Money.aiml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | INTEREST RATES * 12 | YOU DO NOT GET PAID * 13 | YOU GET PAID * 14 | HOW MUCH DID YOU EARN * 15 | DO THEY PAY * 16 | HOW MUCH DO YOU EARN 17 | HOW DO YOU MAKE MONEY 18 | HOW MUCH DO THEY PAY * 19 | DO YOU HAVE MONEY 20 | DO YOU ACCEPT MONEY * 21 | WHAT IS A GOOD STOCK * 22 | HOW MUCH IS A * 23 | HOW MUCH MONEY * 24 | DO YOU HAVE ANY MONEY 25 | HOW MUCH ARE YOU PAID 26 | HOW MUCH DO YOU CHARGE 27 | HOW MUCH MONEY DO YOU HAVE 28 | HOW MUCH MONEY 29 | MONEY 30 | I GET STOCK * 31 | 32 | 33 | WHAT IS * STOCK AT 34 | WHAT IS THE STOCK MARKET * 35 | 36 | WHO IS THE OWNER OF A PUBLICLY * 37 | 38 | STOCK MARKET 39 | WHAT IS YOUR FAVORITE INVESTMENT * 40 | WHAT IS YOUR FAVORITE INVESTMENT 41 | 42 | HOW SHOULD I INVEST 43 | WHAT IS ECONOMICS 51 | WHAT IS MONEY 56 | _ DOLLARS 57 | 1 DOLLAR 58 | A DOLLAR 59 | WHAT IS A DOLLAR 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /test_app/aiml/Music.aiml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | BEETHOVEN * 17 | WHAT WAS THE * BEETHOVEN * 18 | WHO IS BEETHOVEN 19 | WHO IS LUDWIG BEETHOVEN 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /test_app/aiml/Philosophy.aiml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | DO YOU HAVE A SUBCONSCIOUS 11 | DO YOU HAVE AN IMAGINATION 12 | DO YOU HAVE AWARENESS 14 | DO YOU HAVE CONCIOUSNESS 16 | FROM MY CONCIOUSNESS 17 | MY CONCIOUSNESS * 18 | TELL ME ABOUT WITTGENSTEIN 20 | WHAT ARE COUNTERFACTUALS 21 | WHAT IS A COUNTERFACTUAL 22 | WHAT IS A COUNTERFACTUALS 24 | WHAT IS AWARENESS 25 | WHAT IS COUNTERFACTUALS 27 | WHAT IS ILLUSION 28 | WHO IS VOLTAIRE 29 | WHO IS WITTGENSTEIN 30 | WHY DO YOU LIKE WITTGENSTEIN 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /test_app/aiml/Pickup.aiml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | * 13 | RANDOM PICKUP LINE 14 | 89 | CONNECT 96 | 97 | 98 | -------------------------------------------------------------------------------- /test_app/aiml/Politics.aiml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | DO YOU LIKE GUNS 11 | GUNS * 12 | GUNS 13 | HAVE YOU READ THE COMMUNIST * 14 | I DO NOT LIKE GUNS * 15 | I DO NOT LIKE GUNS 16 | IS CAPITALISM * 17 | TELL ME ABOUT GUNS 19 | WHAT IS A GOVERNMENT 20 | WHAT IS CAPITALISM 21 | WHAT IS COMMUNISM 22 | WHAT IS GOVERNMENT 23 | WHAT IS GREENPEACE 24 | WHAT IS IMPEACHED 25 | WHAT IS IMPEACHMENT 31 | WHAT IS SOCIALISM 36 | WHAT IS THE GOVERNMENT 38 | WHO IS THE GOVERNOR * 39 | WHO IS THE GOVERNOR OF * 40 | WHO IS THE GOVERNOR OF CALIFORNIA 41 | WHO IS THE GOVERNOR OF TEXAS 42 | WHO WAS THE FIRST IMPEACHED * 43 | WHO WAS THE FIRST IMPEACHED PRESIDENT * 44 | WHY GUNS 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /test_app/aiml/Predicates.aiml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | GET PREDICATES 13 | 17 | 18 | 19 | 20 | SET PREDICATES 21 | 23 | 24 | 25 | 26 | SET PREDICATES * 27 | 30 | 31 | 32 | SET PREDICATES OM 33 | 89 | 90 | 91 | 92 | CLIENT PROPERTIES 93 | 96 | 97 | 98 | -------------------------------------------------------------------------------- /test_app/aiml/Psychology.aiml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaoshijuan/aiml/b3cdafb8c070486a9e17178727aed96ba8ec0f26/test_app/aiml/Psychology.aiml -------------------------------------------------------------------------------- /test_app/aiml/Science.aiml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 11 | HOW FAR IS THE MOON 12 | HOW FAR IS THE SUN 13 | CHEMISTRY 16 | DO YOU KNOW CHEMISTRY 18 | DO YOU UNDERSTAND THERMODYNAMICS 20 | TELL ME ABOUT VENUS 22 | THE SAME WAVELENGTH 23 | WE ARE ON THE SAME WAVELENGTH 24 | WHAT ARE THE LAWS OF THERMODYNAMICS 25 | WHAT DISEASE DOES A CARCINOGEN CAUSE 26 | WHAT IS A WAVELENGTH 27 | WHAT IS AVOGADRO S NUMBER 33 | WHAT IS BACTERIOLOGY 35 | WHAT IS BIOINFORMATICS 41 | WHAT IS CHEMISTRY 47 | WHAT IS CRYSTALLOGRAPHY 49 | WHAT IS CYTOLOGY 55 | WHAT IS GRAVITATION 60 | WHAT IS H2O 65 | WHAT IS ICHTHYOLOGY 66 | WHAT IS THERMODYNAMICS 67 | WHAT IS ULTRASOUND 68 | WHAT IS VENUS 69 | WHAT IS WAVELENGTH 70 | WHERE IS VENUS 73 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /test_app/aiml/Sports.aiml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | ARE YOU A FOOTBALL * 13 | DO YOU KNOW BASKETBALL 14 | DO YOU PLAY BASEBALL 15 | DO YOU PLAY BASKETBALL 16 | DO YOU PLAY SOCCER 17 | DO YOU WANT TO PLAY BASKETBALL 18 | EACH YEAR IN PRO BASEBALL THE * 19 | HOW MANY BASEBALL * 20 | I LOVE BASEBALL 21 | I PLAY BASEBALL 22 | I PLAY BASKETBALL 23 | I PLAY SOCCER 24 | I PLAY VOLLEYBALL 25 | IF YOU ARE RIDING FAKIE * 26 | IF YOU ARE RIDING FAKIE INSIDE * 27 | LIKE BASKETBALL 28 | TELL ME ABOUT BASEBALL 29 | THEY PLAY BASKETBALL 30 | WHAT IS BASEBALL 31 | WHAT IS BASKETBALL 32 | WHAT IS SOCCER 33 | WHAT SOCCER * 34 | WHO IS THE BEST SOCCER PLAYER 35 | WHO IS THE GREATEST BASEBALL PLAYER * 36 | 37 | -------------------------------------------------------------------------------- /test_app/aiml/Stack.aiml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | POP 14 | 17 | 18 | PUSH * 19 | 48 | 49 | 50 | POPOM * 51 | 80 | 81 | 82 | POPOM 83 | 84 | 85 | POPOM OM 86 | 91 | 92 | 93 | SHOW STACK 94 | 113 | 114 | 115 | RANDOM TOPIC 116 | 130 | 131 | 132 | -------------------------------------------------------------------------------- /test_app/aiml/Xfind.aiml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | XDMOZ * 11 | XFIND * 12 | GOOGLE * 13 | XGOOGLE * 14 | ACCESS * 15 | 16 | 17 | -------------------------------------------------------------------------------- /test_app/main.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * This file is part of "libaiml" * 3 | * Copyright (C) 2005 by V01D * 4 | * * 5 | * "libaiml" is free software; you can redistribute it and/or modify * 6 | * it under the terms of the GNU General Public License as published by * 7 | * the Free Software Foundation; either version 2 of the License, or * 8 | * (at your option) any later version. * 9 | * * 10 | * "libaiml" is distributed in the hope that it will be useful, * 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 13 | * GNU General Public License for more details. * 14 | * * 15 | * You should have received a copy of the GNU General Public License * 16 | * along with "libaiml"; if not, write to the * 17 | * Free Software Foundation, Inc., * 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 19 | ***************************************************************************/ 20 | 21 | #include 22 | #include 23 | #include 24 | #include "../src/aiml.h" 25 | 26 | using namespace std; 27 | using std_util::strip; 28 | using namespace aiml; 29 | 30 | class cTestAppCallbacks : public cInterpreterCallbacks { 31 | public: 32 | void onAimlLoad(const std::string& filename) { 33 | cout << "Loaded " << filename << endl; 34 | } 35 | }; 36 | 37 | int main(int argc, char* argv[]) { 38 | cInterpreter* interpreter = cInterpreter::newInterpreter(); 39 | 40 | int ret = 0; 41 | 42 | // exceptions are used because returning in the middle of the program wouldn't let 'interpreter' be freed 43 | try { 44 | cTestAppCallbacks myCallbacks; 45 | interpreter->registerCallbacks(&myCallbacks); 46 | 47 | cout << "Initializing interpreter..." << endl; 48 | if (!interpreter->initialize("libaiml.xml")) throw 1; 49 | 50 | string line; 51 | cout << "Type \"quit\" to... guess..." << endl; 52 | 53 | string result; 54 | std::list log; 55 | 56 | cout << "You: " << flush; 57 | while (getline(cin, line)) { 58 | if (strip(line).empty()) { cout << "You: " << flush; continue; } 59 | if (line == "quit") break; 60 | 61 | /** remove the last parameter to avoid logging the match **/ 62 | if (!interpreter->respond(line, "localhost", result, &log)) throw 3; 63 | 64 | cout << "Bot: " << strip(result) << endl; 65 | cout << "Match path:" << endl; 66 | for(list::const_iterator it_outter = log.begin(); it_outter != log.end(); ++it_outter) { 67 | cout << "\tpattern:\t"; 68 | for (list::const_iterator it = it_outter->pattern.begin(); it != it_outter->pattern.end(); ++it) { cout << "[" << *it << "] "; } 69 | cout << endl << "\tthat:\t\t"; 70 | for (list::const_iterator it = it_outter->that.begin(); it != it_outter->that.end(); ++it) { cout << "[" << *it << "] "; } 71 | cout << endl << "\ttopic:\t\t"; 72 | for (list::const_iterator it = it_outter->topic.begin(); it != it_outter->topic.end(); ++it) { cout << "[" << *it << "] "; } 73 | cout << endl << endl; 74 | } 75 | cout << "You: " << flush; 76 | } 77 | 78 | /** Uncomment this line out and you'll see that the bot will no longer remember user vars **/ 79 | //interpreter->unregisterUser("localhost"); 80 | } 81 | catch(int _ret) { 82 | cout << "ERROR: " << interpreter->getErrorStr(interpreter->getError()) << " (" << interpreter->getError() << ")" << endl; 83 | if (!interpreter->getRuntimeErrorStr().empty()) cout << "Runtime Error: " << interpreter->getRuntimeErrorStr() << endl; 84 | ret = _ret; 85 | } 86 | 87 | delete interpreter; 88 | // the above is equivalent to cInterpreter::freeInterpreter(interpreter); 89 | return ret; 90 | } 91 | -------------------------------------------------------------------------------- /test_app/userlist.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | --------------------------------------------------------------------------------