├── .gitignore ├── examples ├── README └── ElizaChat │ ├── data │ └── Rockwell-24.vlw │ └── ElizaChat.pde ├── web ├── logo.jpg ├── stylesheet.css └── index.html ├── resources ├── code │ ├── ExampleTaglet.class │ ├── ant-contrib-1.0b3.jar │ ├── doc.sh │ └── ExampleTaglet.java ├── install_instructions.txt ├── library.properties ├── stylesheet.css ├── build.properties └── build.xml ├── data ├── README └── eliza.script ├── lib └── README ├── .classpath ├── .project ├── src └── codeanticode │ └── eliza │ ├── ReasembList.java │ ├── DecompList.java │ ├── Mem.java │ ├── PrePost.java │ ├── WordList.java │ ├── KeyStack.java │ ├── KeyList.java │ ├── PrePostList.java │ ├── Key.java │ ├── Decomp.java │ ├── SynList.java │ ├── EString.java │ └── Eliza.java ├── license.txt └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | distribution 2 | /bin 3 | -------------------------------------------------------------------------------- /examples/README: -------------------------------------------------------------------------------- 1 | add examples for your library here. -------------------------------------------------------------------------------- /web/logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codeanticode/eliza/HEAD/web/logo.jpg -------------------------------------------------------------------------------- /resources/code/ExampleTaglet.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codeanticode/eliza/HEAD/resources/code/ExampleTaglet.class -------------------------------------------------------------------------------- /resources/code/ant-contrib-1.0b3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codeanticode/eliza/HEAD/resources/code/ant-contrib-1.0b3.jar -------------------------------------------------------------------------------- /examples/ElizaChat/data/Rockwell-24.vlw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codeanticode/eliza/HEAD/examples/ElizaChat/data/Rockwell-24.vlw -------------------------------------------------------------------------------- /data/README: -------------------------------------------------------------------------------- 1 | the data folder: 2 | If your library is using files like images, sound files, 3 | any data file, etc., put them into the data folder. 4 | When coding your library you can use processing's internal loading 5 | functions like loadImage(), loadStrings(), etc. to load files 6 | located inside the data folder into your library. 7 | 8 | -------------------------------------------------------------------------------- /lib/README: -------------------------------------------------------------------------------- 1 | The lib folder: 2 | In case your library requires 3rd party libraries, which need to be 3 | added to the distribution, put them into the lib folder. 4 | These 3rd party libraries will be added to your distribution and are 5 | located next to your library's jar file. 6 | This does not apply to .jar files that are considered core processing libraries. -------------------------------------------------------------------------------- /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | Eliza 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /resources/code/doc.sh: -------------------------------------------------------------------------------- 1 | # a shell script to create a java documentation 2 | # for a processing library. 3 | # 4 | # make changes to the variables below so they 5 | # fit the structure of your library 6 | 7 | # the package name of your library 8 | package=template; 9 | 10 | # source folder location 11 | src=../src; 12 | 13 | # the destination folder of your documentation 14 | dest=../documentation; 15 | 16 | 17 | # compile the java documentation 18 | javadoc -d $dest -stylesheetfile ./stylesheet.css -sourcepath ${src} ${package} 19 | -------------------------------------------------------------------------------- /src/codeanticode/eliza/ReasembList.java: -------------------------------------------------------------------------------- 1 | package codeanticode.eliza; 2 | 3 | import java.util.Vector; 4 | 5 | /** 6 | * Eliza reassembly list. 7 | */ 8 | public class ReasembList extends Vector { 9 | 10 | /** 11 | * Add an element to the reassembly list. 12 | */ 13 | public void add(String reasmb) { 14 | addElement(reasmb); 15 | } 16 | 17 | /** 18 | * Print the reassembly list. 19 | */ 20 | public void print(int indent) { 21 | for (int i = 0; i < size(); i++) { 22 | for (int j = 0; j < indent; j++) System.out.print(" "); 23 | String s = (String)elementAt(i); 24 | System.out.println("reasemb: " + s); 25 | } 26 | } 27 | } 28 | 29 | -------------------------------------------------------------------------------- /src/codeanticode/eliza/DecompList.java: -------------------------------------------------------------------------------- 1 | package codeanticode.eliza; 2 | 3 | import java.util.Vector; 4 | 5 | /** 6 | * Eliza decomp list. 7 | * This stores all the decompositions of a single key. 8 | */ 9 | public class DecompList extends Vector { 10 | 11 | /** 12 | * Add another decomp rule to the list. 13 | */ 14 | public void add(String word, boolean mem, ReasembList reasmb) { 15 | addElement(new Decomp(word, mem, reasmb)); 16 | } 17 | 18 | /** 19 | * Print the whole decomp list. 20 | */ 21 | public void print(int indent) { 22 | for (int i = 0; i < size(); i++) { 23 | Decomp d = (Decomp)elementAt(i); 24 | d.print(indent); 25 | } 26 | } 27 | } 28 | 29 | -------------------------------------------------------------------------------- /src/codeanticode/eliza/Mem.java: -------------------------------------------------------------------------------- 1 | package codeanticode.eliza; 2 | 3 | /** 4 | * Eliza memory class 5 | */ 6 | 7 | public class Mem { 8 | 9 | /** The memory size */ 10 | final int memMax = 20; 11 | /** The memory */ 12 | String memory[] = new String[memMax]; 13 | /** The memory top */ 14 | int memTop = 0; 15 | 16 | public void save(String str) { 17 | if (memTop < memMax) { 18 | memory[memTop++] = new String(str); 19 | } 20 | } 21 | 22 | public String get() { 23 | if (memTop == 0) return null; 24 | String m = memory[0]; 25 | for (int i = 0; i < memTop-1; i++) 26 | memory[i] = memory[i+1]; 27 | memTop--; 28 | return m; 29 | } 30 | } 31 | 32 | 33 | -------------------------------------------------------------------------------- /license.txt: -------------------------------------------------------------------------------- 1 | Eliza library 2 | 3 | Copyright (c) 2007-13 Andres Colubri 4 | 5 | This program is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU General Public License 7 | as published by the Free Software Foundation; either version 2 8 | of the License, or (at your option) any later version. 9 | 10 | This program 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 this program; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -------------------------------------------------------------------------------- /src/codeanticode/eliza/PrePost.java: -------------------------------------------------------------------------------- 1 | package codeanticode.eliza; 2 | 3 | /** 4 | * Eliza pre-post entry (two words). 5 | * This is used to store pre transforms or post transforms. 6 | */ 7 | public class PrePost { 8 | /** The words */ 9 | String src; 10 | String dest; 11 | 12 | /** 13 | * Initialize the pre-post entry. 14 | */ 15 | PrePost(String src, String dest) { 16 | this.src = src; 17 | this.dest = dest; 18 | } 19 | 20 | /** 21 | * Print the pre-post entry. 22 | */ 23 | public void print(int indent) { 24 | for (int i = 0; i < indent; i++) System.out.print(" "); 25 | System.out.println("pre-post: " + src + " " + dest); 26 | } 27 | 28 | /** 29 | * Get src. 30 | */ 31 | public String src() { 32 | return src; 33 | } 34 | 35 | /** 36 | * Get dest. 37 | */ 38 | public String dest() { 39 | return dest; 40 | } 41 | } 42 | 43 | -------------------------------------------------------------------------------- /src/codeanticode/eliza/WordList.java: -------------------------------------------------------------------------------- 1 | package codeanticode.eliza; 2 | 3 | import java.util.Vector; 4 | 5 | /** 6 | * Eliza word list. 7 | */ 8 | public class WordList extends Vector { 9 | 10 | /** 11 | * Add another word to the list. 12 | */ 13 | public void add(String word) { 14 | addElement(word); 15 | } 16 | 17 | /** 18 | * Print a word list on one line. 19 | */ 20 | public void print(int indent) { 21 | for (int i = 0; i < size(); i++) { 22 | String s = (String)elementAt(i); 23 | System.out.print(s + " "); 24 | } 25 | System.out.println(); 26 | } 27 | 28 | /** 29 | * Find a string in a word list. 30 | * Return true if the word is in the list, false otherwise. 31 | */ 32 | boolean find(String s) { 33 | for (int i = 0; i < size(); i++) { 34 | if (s.equals((String)elementAt(i))) return true; 35 | } 36 | return false; 37 | } 38 | 39 | } 40 | 41 | -------------------------------------------------------------------------------- /src/codeanticode/eliza/KeyStack.java: -------------------------------------------------------------------------------- 1 | package codeanticode.eliza; 2 | 3 | /** 4 | * A stack of keys. 5 | * The keys are kept in rank order. 6 | */ 7 | public class KeyStack { 8 | 9 | /** The stack size */ 10 | final int stackSize = 20; 11 | /** The key stack */ 12 | Key keyStack[] = new Key[stackSize]; 13 | /** The top of the key stack */ 14 | int keyTop = 0; 15 | 16 | /** 17 | * Prints the key stack. 18 | */ 19 | public void print() { 20 | System.out.println("Key stack " + keyTop); 21 | for (int i = 0; i < keyTop; i++) { 22 | keyStack[i].printKey(0); 23 | } 24 | } 25 | 26 | /** 27 | * Get the stack size. 28 | */ 29 | public int keyTop() { 30 | return keyTop; 31 | } 32 | 33 | /** 34 | * Reset the key stack. 35 | */ 36 | public void reset() { 37 | keyTop = 0; 38 | } 39 | 40 | /** 41 | * Get a key from the stack. 42 | */ 43 | public Key key(int n) { 44 | if (n < 0 || n >= keyTop) return null; 45 | return keyStack[n]; 46 | } 47 | 48 | /** 49 | * Push a key in the stack. 50 | * Keep the highest rank keys at the bottom. 51 | */ 52 | public void pushKey(Key key) { 53 | if (key == null) { 54 | System.out.println("push null key"); 55 | return; 56 | } 57 | int i; 58 | for (i = keyTop; i > 0; i--) { 59 | if (key.rank > keyStack[i-1].rank) keyStack[i] = keyStack[i-1]; 60 | else break; 61 | } 62 | keyStack[i] = key; 63 | keyTop++; 64 | } 65 | 66 | 67 | } 68 | -------------------------------------------------------------------------------- /src/codeanticode/eliza/KeyList.java: -------------------------------------------------------------------------------- 1 | package codeanticode.eliza; 2 | 3 | import java.util.Vector; 4 | 5 | /** 6 | * Eliza key list. 7 | * This stores all the keys. 8 | */ 9 | public class KeyList extends Vector { 10 | 11 | /** 12 | * Add a new key. 13 | */ 14 | public void add(String key, int rank, DecompList decomp) { 15 | addElement(new Key(key, rank, decomp)); 16 | } 17 | 18 | /** 19 | * Print all the keys. 20 | */ 21 | public void print(int indent) { 22 | for (int i = 0; i < size(); i++) { 23 | Key k = (Key)elementAt(i); 24 | k.print(indent); 25 | } 26 | } 27 | 28 | /** 29 | * Search the key list for a given key. 30 | * Return the Key if found, else null. 31 | */ 32 | Key getKey(String s) { 33 | for (int i = 0; i < size(); i++) { 34 | Key key = (Key)elementAt(i); 35 | if (s.equals(key.key())) return key; 36 | } 37 | return null; 38 | } 39 | 40 | /** 41 | * Break the string s into words. 42 | * For each word, if isKey is true, then push the key 43 | * into the stack. 44 | */ 45 | public void buildKeyStack(KeyStack stack, String s) { 46 | stack.reset(); 47 | s = EString.trim(s); 48 | String lines[] = new String[2]; 49 | Key k; 50 | while (EString.match(s, "* *", lines)) { 51 | k = getKey(lines[0]); 52 | if (k != null) stack.pushKey(k); 53 | s = lines[1]; 54 | } 55 | k = getKey(s); 56 | if (k != null) stack.pushKey(k); 57 | //stack.print(); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This is a Processing library based on the Java implementation of the Eliza program by Charles Hayden. 2 | Hayden's code is a complete and faithful implementation of the original program described by Joseph Weizenbaum in the Communications of the ACM in January 1966. 3 | 4 | ACKNOWLEDGMENTS 5 | 6 | 1) Charles Hayden's Java implementation of Eliza: 7 | http://chayden.net/eliza/Eliza.html 8 | 9 | 2) Processing Library Template: 10 | https://github.com/processing/processing-library-template 11 | 12 | INSTRUCTIONS 13 | 14 | The library is easy to use. Just import it, and then create an Eliza object: 15 | 16 | ```java 17 | import codeanticode.eliza.*; 18 | 19 | Eliza eliza; 20 | eliza = new Eliza(this); 21 | 22 | String response = eliza.processInput("Hello"); 23 | println(response); 24 | ``` 25 | 26 | You can use the readScript() function to change the script that Eliza uses to construct its answers: 27 | 28 | ```java 29 | eliza.readScript("script"); 30 | eliza.readScript("http://chayden.net/eliza/script"); 31 | ``` 32 | 33 | To go back to the default script that is loaded when Eliza is initialized, call the readDefaultScript() function. 34 | 35 | For detailed instructions on how to modify the script file that determines Eliza's "behavior", read the following notes by Charles Hayden: 36 | http://chayden.net/eliza/instructions.txt 37 | 38 | FURTHER REFERENCES 39 | 40 | 1) Wikipedia article about Eliza: http://en.wikipedia.org/wiki/ELIZA 41 | 42 | 2) Article from the Jul-Aug 1977 issue of the Creative Computing magazine, with a complete listing in Altair BASIC of a version of Eliza by Jeff Schrager: 43 | http://vintagecomputer.net/cisc367/Creative%20Computing%20Jul-Aug%201977%20Eliza%20BASIC%20listing.pdf -------------------------------------------------------------------------------- /src/codeanticode/eliza/PrePostList.java: -------------------------------------------------------------------------------- 1 | package codeanticode.eliza; 2 | 3 | import java.util.Vector; 4 | 5 | /** 6 | * Eliza prePost list. 7 | * This list of pre-post entries is used to perform word transformations 8 | * prior to or after other processing. 9 | */ 10 | public class PrePostList extends Vector { 11 | 12 | /** 13 | * Add another entry to the list. 14 | */ 15 | public void add(String src, String dest) { 16 | addElement(new PrePost(src, dest)); 17 | } 18 | 19 | /** 20 | * Prnt the pre-post list. 21 | */ 22 | public void print(int indent) { 23 | for (int i = 0; i < size(); i++) { 24 | PrePost p = (PrePost)elementAt(i); 25 | p.print(indent); 26 | } 27 | } 28 | 29 | /** 30 | * Translate a string. 31 | * If str matches a src string on the list, 32 | * return he corresponding dest. 33 | * If no match, return the input. 34 | */ 35 | String xlate(String str) { 36 | for (int i = 0; i < size(); i++) { 37 | PrePost p = (PrePost)elementAt(i); 38 | if (str.equals(p.src())) { 39 | return p.dest(); 40 | } 41 | } 42 | return str; 43 | } 44 | 45 | /** 46 | * Translate a string s. 47 | * (1) Trim spaces off. 48 | * (2) Break s into words. 49 | * (3) For each word, substitute matching src word with dest. 50 | */ 51 | public String translate(String s) { 52 | String lines[] = new String[2]; 53 | String work = EString.trim(s); 54 | s = ""; 55 | while (EString.match(work, "* *", lines)) { 56 | s += xlate(lines[0]) + " "; 57 | work = EString.trim(lines[1]); 58 | } 59 | s += xlate(work); 60 | return s; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/codeanticode/eliza/Key.java: -------------------------------------------------------------------------------- 1 | package codeanticode.eliza; 2 | 3 | /** 4 | * Eliza key. 5 | * A key has the key itself, a rank, and a list of decompositon rules. 6 | */ 7 | public class Key { 8 | /** The key itself */ 9 | String key; 10 | /** The numerical rank */ 11 | int rank; 12 | /** The list of decompositions */ 13 | DecompList decomp; 14 | 15 | /** 16 | * Initialize the key. 17 | */ 18 | Key(String key, int rank, DecompList decomp) { 19 | this.key = key; 20 | this.rank = rank; 21 | this.decomp = decomp; 22 | } 23 | 24 | /** 25 | * Another initialization for gotoKey. 26 | */ 27 | Key() { 28 | key = null; 29 | rank = 0; 30 | decomp = null; 31 | } 32 | 33 | public void copy(Key k) { 34 | key = k.key(); 35 | rank = k.rank(); 36 | decomp = k.decomp(); 37 | } 38 | 39 | /** 40 | * Print the key and all under it. 41 | */ 42 | public void print(int indent) { 43 | for (int i = 0; i < indent; i++) System.out.print(" "); 44 | System.out.println("key: " + key + " " + rank); 45 | decomp.print(indent+2); 46 | } 47 | 48 | /** 49 | * Print the key and rank only, not the rest. 50 | */ 51 | public void printKey(int indent) { 52 | for (int i = 0; i < indent; i++) System.out.print(" "); 53 | System.out.println("key: " + key + " " + rank); 54 | } 55 | 56 | /** 57 | * Get the key value. 58 | */ 59 | public String key() { 60 | return key; 61 | } 62 | 63 | /** 64 | * Get the rank. 65 | */ 66 | public int rank() { 67 | return rank; 68 | } 69 | 70 | /** 71 | * Get the decomposition list. 72 | */ 73 | public DecompList decomp() { 74 | return decomp; 75 | } 76 | } 77 | 78 | -------------------------------------------------------------------------------- /resources/install_instructions.txt: -------------------------------------------------------------------------------- 1 | How to install library ##library.name## 2 | 3 | 4 | Install with the "Add Library..." tool 5 | 6 | New for Processing 2.0: Add contributed libraries by selecting "Add Library..." 7 | from the "Import Library..." submenu within the Sketch menu. Not all available 8 | libraries have been converted to show up in this menu. If a library isn't there, 9 | it will need to be installed manually by following the instructions below. 10 | 11 | 12 | Manual Install 13 | 14 | Contributed libraries may be downloaded separately and manually placed within 15 | the "libraries" folder of your Processing sketchbook. To find (and change) the 16 | Processing sketchbook location on your computer, open the Preferences window 17 | from the Processing application (PDE) and look for the "Sketchbook location" 18 | item at the top. 19 | 20 | Copy the contributed library's folder into the "libraries" folder at this 21 | location. You will need to create the "libraries" folder if this is your first 22 | contributed library. 23 | 24 | By default the following locations are used for your sketchbook folder: 25 | For Mac users, the sketchbook folder is located inside ~/Documents/Processing. 26 | For Windows users, the sketchbook folder is located inside 27 | 'My Documents'/Processing. 28 | 29 | The folder structure for library ##library.name## should be as follows: 30 | 31 | Processing 32 | libraries 33 | ##library.name## 34 | examples 35 | library 36 | ##library.name##.jar 37 | reference 38 | src 39 | 40 | Some folders like "examples" or "src" might be missing. After library 41 | ##library.name## has been successfully installed, restart the Processing 42 | application. 43 | 44 | 45 | If you're having trouble, have a look at the Processing Wiki for more 46 | information: http://wiki.processing.org/w/How_to_Install_a_Contributed_Library 47 | -------------------------------------------------------------------------------- /src/codeanticode/eliza/Decomp.java: -------------------------------------------------------------------------------- 1 | package codeanticode.eliza; 2 | 3 | import java.lang.Math; 4 | 5 | /** 6 | * Eliza decomposition rule 7 | */ 8 | public class Decomp { 9 | /** The decomp pattern */ 10 | String pattern; 11 | /** The mem flag */ 12 | boolean mem; 13 | /** The reassembly list */ 14 | ReasembList reasemb; 15 | /** The current reassembly point */ 16 | int currReasmb; 17 | 18 | /** 19 | * Initialize the decomp rule 20 | */ 21 | Decomp(String pattern, boolean mem, ReasembList reasemb) { 22 | this.pattern = pattern; 23 | this.mem = mem; 24 | this.reasemb = reasemb; 25 | this.currReasmb = 100; 26 | } 27 | 28 | /** 29 | * Print out the decomp rule. 30 | */ 31 | public void print(int indent) { 32 | String m = mem ? "true" : "false"; 33 | for (int i = 0; i < indent; i++) System.out.print(" "); 34 | System.out.println("decomp: " + pattern + " " + m); 35 | reasemb.print(indent + 2); 36 | } 37 | 38 | /** 39 | * Get the pattern. 40 | */ 41 | public String pattern() { 42 | return pattern; 43 | } 44 | 45 | /** 46 | * Get the mem flag. 47 | */ 48 | public boolean mem() { 49 | return mem; 50 | } 51 | 52 | /** 53 | * Get the next reassembly rule. 54 | */ 55 | public String nextRule() { 56 | if (reasemb.size() == 0) { 57 | System.out.println("No reassembly rule."); 58 | return null; 59 | } 60 | return (String)reasemb.elementAt(currReasmb); 61 | } 62 | 63 | /** 64 | * Step to the next reassembly rule. 65 | * If mem is true, pick a random rule. 66 | */ 67 | public void stepRule() { 68 | int size = reasemb.size(); 69 | if (mem) { 70 | currReasmb = (int)(Math.random() * size); 71 | } 72 | // Increment and make sure it is within range. 73 | currReasmb++; 74 | if (currReasmb >= size) currReasmb = 0; 75 | } 76 | 77 | 78 | } 79 | 80 | -------------------------------------------------------------------------------- /resources/library.properties: -------------------------------------------------------------------------------- 1 | # More on this file here: https://github.com/processing/processing/wiki/Library-Basics 2 | # UTF-8 supported. 3 | 4 | # The name of your library as you want it formatted. 5 | name = ##library.name## 6 | 7 | # List of authors. Links can be provided using the syntax [author name](url). 8 | authorList = [##author.name##](##author.url##) 9 | 10 | # A web page for your library, NOT a direct link to where to download it. 11 | url = ##library.url## 12 | 13 | # The category of your library, must be one (or many) of the following: 14 | # "3D" "Animation" "Compilations" "Data" 15 | # "Fabrication" "Geometry" "GUI" "Hardware" 16 | # "I/O" "Language" "Math" "Simulation" 17 | # "Sound" "Utilities" "Typography" "Video & Vision" 18 | # 19 | # If a value other than those listed is used, your library will listed as 20 | # "Other". 21 | category = ##library.category## 22 | 23 | # A short sentence (or fragment) to summarize the library's function. This will 24 | # be shown from inside the PDE when the library is being installed. Avoid 25 | # repeating the name of your library here. Also, avoid saying anything redundant 26 | # like mentioning that it's a library. This should start with a capitalized 27 | # letter, and end with a period. 28 | sentence = ##library.sentence## 29 | 30 | # Additional information suitable for the Processing website. The value of 31 | # 'sentence' always will be prepended, so you should start by writing the 32 | # second sentence here. If your library only works on certain operating systems, 33 | # mention it here. 34 | paragraph = ##library.paragraph## 35 | 36 | # Links in the 'sentence' and 'paragraph' attributes can be inserted using the 37 | # same syntax as for authors. 38 | # That is, [here is a link to Processing](http://processing.org/) 39 | 40 | 41 | # A version number that increments once with each release. This is used to 42 | # compare different versions of the same library, and check if an update is 43 | # available. You should think of it as a counter, counting the total number of 44 | # releases you've had. 45 | version = ##library.version## # This must be parsable as an int 46 | 47 | # The version as the user will see it. If blank, the version attribute will be 48 | # used here. 49 | prettyVersion = ##library.prettyVersion## # This is treated as a String 50 | -------------------------------------------------------------------------------- /src/codeanticode/eliza/SynList.java: -------------------------------------------------------------------------------- 1 | package codeanticode.eliza; 2 | 3 | import java.util.Vector; 4 | 5 | /** 6 | * Eliza synonym list. 7 | * Collection of all the synonym elements. 8 | */ 9 | public class SynList extends Vector { 10 | 11 | /** 12 | * Add another word list the the synonym list. 13 | */ 14 | public void add(WordList words) { 15 | addElement(words); 16 | } 17 | 18 | /** 19 | * Prnt the synonym lists. 20 | */ 21 | public void print(int indent) { 22 | for (int i = 0; i < size(); i++) { 23 | for (int j = 0; j < indent; j++) System.out.print(" "); 24 | System.out.print("synon: "); 25 | WordList w = (WordList)elementAt(i); 26 | w.print(indent); 27 | } 28 | } 29 | 30 | /** 31 | * Find a synonym word list given the any word in it. 32 | */ 33 | public WordList find(String s) { 34 | for (int i = 0; i < size(); i++) { 35 | WordList w = (WordList)elementAt(i); 36 | if (w.find(s)) return w; 37 | } 38 | return null; 39 | } 40 | /** 41 | * Decomposition match, 42 | * If decomp has no synonyms, do a regular match. 43 | * Otherwise, try all synonyms. 44 | */ 45 | boolean matchDecomp(String str, String pat, String lines[]) { 46 | if (! EString.match(pat, "*@* *", lines)) { 47 | // no synonyms in decomp pattern 48 | return EString.match(str, pat, lines); 49 | } 50 | // Decomp pattern has synonym -- isolate the synonym 51 | String first = lines[0]; 52 | String synWord = lines[1]; 53 | String theRest = " " + lines[2]; 54 | // Look up the synonym 55 | WordList syn = find(synWord); 56 | if (syn == null) { 57 | System.out.println("Could not fnd syn list for " + synWord); 58 | return false; 59 | } 60 | // Try each synonym individually 61 | for (int i = 0; i < syn.size(); i++) { 62 | // Make a modified pattern 63 | pat = first + (String)syn.elementAt(i) + theRest; 64 | if (EString.match(str, pat, lines)) { 65 | int n = EString.count(first, '*'); 66 | // Make room for the synonym in the match list. 67 | for (int j = lines.length-2; j >= n; j--) 68 | lines[j+1] = lines[j]; 69 | // The synonym goes in the match list. 70 | lines[n] = (String)syn.elementAt(i); 71 | return true; 72 | } 73 | } 74 | return false; 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /examples/ElizaChat/ElizaChat.pde: -------------------------------------------------------------------------------- 1 | /* 2 | A little example using the classic "Eliza" program. 3 | 4 | Eliza was compiled as a Processing library, based on the 5 | java source code by Charles Hayden: 6 | htp://www.chayden.net/eliza/Eliza.html 7 | 8 | The default script that determines Eliza's behaviour can be 9 | changed with the readScript() function. 10 | Intructions to modify the script file are available here: 11 | http://www.chayden.net/eliza/instructions.txt 12 | */ 13 | 14 | import codeanticode.eliza.*; 15 | 16 | Eliza eliza; 17 | PFont font; 18 | String elizaResponse, humanResponse; 19 | boolean showCursor; 20 | int lastTime; 21 | 22 | void setup() 23 | { 24 | size(400, 400); 25 | 26 | // When Eliza is initialized, a default script built into the 27 | // library is loaded. 28 | eliza = new Eliza(this); 29 | 30 | // A new script can be loaded through the readScript function. 31 | // It can take local as well as remote files. 32 | //eliza.readScript("script"); 33 | //eliza.readScript("http://chayden.net/eliza/script"); 34 | 35 | // To go back to the default script, use this: 36 | //eliza.readDefaultScript(); 37 | 38 | font = loadFont("Rockwell-24.vlw"); 39 | textFont(font); 40 | 41 | printElizaIntro(); 42 | humanResponse = ""; 43 | showCursor = true; 44 | lastTime = 0; 45 | } 46 | 47 | void draw() 48 | { 49 | background(102); 50 | 51 | fill(255); 52 | text(elizaResponse, 10, 50, width - 40, height); 53 | 54 | fill(0); 55 | 56 | int t = millis(); 57 | if (t - lastTime > 500) 58 | { 59 | showCursor = !showCursor; 60 | lastTime = t; 61 | } 62 | 63 | if (showCursor) text(humanResponse + "_", 10, 150, width - 40, height); 64 | else text(humanResponse, 10, 150, width - 40, height); 65 | } 66 | 67 | void keyPressed() 68 | { 69 | if ((key == ENTER) || (key == RETURN)) 70 | { 71 | println(humanResponse); 72 | elizaResponse = eliza.processInput(humanResponse); 73 | println(">> " + elizaResponse); 74 | humanResponse = ""; 75 | } 76 | else if ((key > 31) && (key != CODED)) 77 | { 78 | // If the key is alphanumeric, add it to the String 79 | humanResponse = humanResponse + key; 80 | } 81 | else if ((key == BACKSPACE) && (0 < humanResponse.length())) 82 | { 83 | char c = humanResponse.charAt(humanResponse.length() - 1); 84 | humanResponse = humanResponse.substring(0, humanResponse.length() - 1); 85 | } 86 | } 87 | 88 | void printElizaIntro() 89 | { 90 | String hello = "Hello."; 91 | elizaResponse = hello + " " + eliza.processInput(hello); 92 | println(">> " + elizaResponse); 93 | } 94 | -------------------------------------------------------------------------------- /web/stylesheet.css: -------------------------------------------------------------------------------- 1 | /* processingLibs style by andreas schlegel, sojamo. */ 2 | 3 | 4 | * { 5 | margin:0; 6 | padding:0; 7 | border:0; 8 | } 9 | 10 | 11 | body { 12 | font-family : Verdana, Geneva, Arial, Helvetica, sans-serif; 13 | font-size : 100%; 14 | font-size : 0.70em; 15 | font-weight : normal; 16 | line-height : normal; 17 | } 18 | 19 | 20 | 21 | #container { 22 | margin-left:64px; 23 | background-color:#fff; 24 | } 25 | 26 | #header { 27 | float:left; 28 | padding-top:24px; 29 | padding-bottom:48px; 30 | } 31 | 32 | #menu { 33 | margin-top:16px; 34 | float:left; 35 | margin-bottom:64px; 36 | } 37 | 38 | 39 | #about, 40 | #download, 41 | #examples, 42 | #demos, 43 | #misc { 44 | width:480px; 45 | float:left; 46 | margin-right:24px; 47 | } 48 | 49 | 50 | #resources, #info { 51 | width:320px; 52 | float:left; 53 | } 54 | 55 | 56 | .clear { 57 | clear:both; 58 | } 59 | 60 | #footer { 61 | margin-top:300px; 62 | height:20px; 63 | margin-bottom:32px; 64 | } 65 | 66 | 67 | ul { 68 | list-style:none; 69 | padding:0; 70 | margin:0; 71 | } 72 | 73 | 74 | #menu ul li, #subMenu ul li { 75 | float:left; 76 | padding-right:6px; 77 | } 78 | 79 | 80 | 81 | 82 | 83 | 84 | /* Headings */ 85 | 86 | h1 { 87 | font-size:2em; 88 | font-weight:normal; 89 | } 90 | 91 | 92 | h2, h3, h4, h5, th { 93 | font-size:1.3em; 94 | font-weight:normal; 95 | margin-bottom:4px; 96 | } 97 | 98 | 99 | 100 | p { 101 | font-size:1em; 102 | width:90%; 103 | margin-bottom:32px; 104 | } 105 | 106 | 107 | pre, code { 108 | font-family:"Courier New", Courier, monospace; 109 | font-size:1em; 110 | line-height:normal; 111 | } 112 | 113 | 114 | 115 | 116 | hr { 117 | border:0; 118 | height:1px; 119 | margin-bottom:24px; 120 | } 121 | 122 | 123 | a { 124 | text-decoration: underline; 125 | font-weight: normal; 126 | } 127 | 128 | 129 | a:hover, 130 | a:active { 131 | text-decoration: underline; 132 | font-weight: normal; 133 | } 134 | 135 | 136 | a:visited, 137 | a:link:visited { 138 | text-decoration: underline; 139 | font-weight: normal; 140 | } 141 | 142 | 143 | 144 | img { 145 | border: 0px solid #000000; 146 | } 147 | 148 | 149 | 150 | 151 | 152 | /* COLORS */ 153 | 154 | 155 | body { 156 | color : #333; 157 | background-color :#fff; 158 | } 159 | 160 | 161 | #header { 162 | background-color:#fff; 163 | color:#333; 164 | } 165 | 166 | 167 | 168 | h1, h2, h3, h4, h5, h6 { 169 | color:#666; 170 | } 171 | 172 | 173 | pre, code { 174 | color: #000000; 175 | } 176 | 177 | 178 | a,strong { 179 | color: #333; 180 | } 181 | 182 | 183 | a:hover, 184 | a:active { 185 | color: #333; 186 | } 187 | 188 | 189 | a:visited, 190 | a:link:visited { 191 | color: #333; 192 | } 193 | 194 | 195 | #footer, #menu { 196 | background-color:#fff; 197 | color:#333; 198 | } 199 | 200 | 201 | #footer a, #menu a { 202 | color:#333; 203 | } 204 | -------------------------------------------------------------------------------- /resources/stylesheet.css: -------------------------------------------------------------------------------- 1 | /* Javadoc style sheet */ 2 | /* Define colors, fonts and other style attributes here to override the defaults */ 3 | /* processingLibs style by andreas schlegel, sojamo */ 4 | 5 | 6 | body { 7 | margin : 0; 8 | padding : 0; 9 | padding-left : 10px; 10 | padding-right : 8px; 11 | background-color : #FFFFFF; 12 | font-family : Verdana, Geneva, Arial, Helvetica, sans-serif; 13 | font-size : 100%; 14 | font-size : 0.7em; 15 | font-weight : normal; 16 | line-height : normal; 17 | margin-bottom:30px; 18 | } 19 | 20 | 21 | 22 | 23 | /* Headings */ 24 | h1, h2, h3, h4, h5, th { 25 | font-family :Arial, Helvetica, sans-serif; 26 | font-size:1.2em; 27 | } 28 | 29 | 30 | p { 31 | font-size : 1em; 32 | width:80%; 33 | } 34 | 35 | pre, code { 36 | font-family : "Courier New", Courier, monospace; 37 | font-size : 12px; 38 | line-height : normal; 39 | } 40 | 41 | 42 | 43 | table { 44 | border:0; 45 | margin-bottom:10px; 46 | margin-top:10px; 47 | } 48 | 49 | 50 | tr, td { 51 | border-top: 0px solid; 52 | border-left: 0px solid; 53 | padding-top:8px; 54 | padding-bottom:8px; 55 | } 56 | 57 | 58 | 59 | hr { 60 | border:0; 61 | height:1px; 62 | padding:0; 63 | margin:0; 64 | margin-bottom:4px; 65 | 66 | } 67 | 68 | 69 | 70 | dd, th, td, font { 71 | font-size:1.0em; 72 | line-height:1.0em; 73 | } 74 | 75 | 76 | 77 | dt { 78 | margin-bottom:0px; 79 | } 80 | 81 | 82 | 83 | dd { 84 | margin-top:2px; 85 | margin-bottom:4px; 86 | } 87 | 88 | 89 | 90 | a { 91 | text-decoration: underline; 92 | font-weight: normal; 93 | } 94 | 95 | a:hover, 96 | a:active { 97 | text-decoration: underline; 98 | font-weight: normal; 99 | } 100 | 101 | a:visited, 102 | a:link:visited { 103 | text-decoration: underline; 104 | font-weight: normal; 105 | } 106 | 107 | 108 | img { 109 | border: 0px solid #000000; 110 | } 111 | 112 | 113 | 114 | /* Navigation bar fonts */ 115 | .NavBarCell1 { 116 | border:0; 117 | } 118 | 119 | .NavBarCell1Rev { 120 | border:0; 121 | } 122 | 123 | .NavBarFont1 { 124 | font-family: Arial, Helvetica, sans-serif; 125 | font-size:1.1em; 126 | } 127 | 128 | 129 | .NavBarFont1 b { 130 | font-weight:normal; 131 | } 132 | 133 | 134 | 135 | .NavBarFont1:after, .NavBarFont1Rev:after { 136 | font-weight:normal; 137 | content: " \\"; 138 | } 139 | 140 | 141 | .NavBarFont1Rev { 142 | font-family: Arial, Helvetica, sans-serif; 143 | font-size:1.1em; 144 | } 145 | 146 | .NavBarFont1Rev b { 147 | font-family: Arial, Helvetica, sans-serif; 148 | font-size:1.1em; 149 | font-weight:normal; 150 | } 151 | 152 | .NavBarCell2 { 153 | font-family: Arial, Helvetica, sans-serif; 154 | } 155 | 156 | .NavBarCell3 { 157 | font-family: Arial, Helvetica, sans-serif; 158 | } 159 | 160 | 161 | 162 | font.FrameItemFont { 163 | font-family: Helvetica, Arial, sans-serif; 164 | font-size:1.1em; 165 | line-height:1.1em; 166 | } 167 | 168 | font.FrameHeadingFont { 169 | font-family: Helvetica, Arial, sans-serif; 170 | line-height:32px; 171 | } 172 | 173 | /* Font used in left-hand frame lists */ 174 | .FrameTitleFont { 175 | font-family: Helvetica, Arial, sans-serif 176 | } 177 | 178 | 179 | .toggleList { 180 | padding:0; 181 | margin:0; 182 | margin-top:12px; 183 | } 184 | 185 | .toggleList dt { 186 | font-weight:bold; 187 | font-size:12px; 188 | font-family:arial,sans-serif; 189 | padding:0px; 190 | margin:10px 0px 10px 0px; 191 | } 192 | 193 | .toggleList dt span { 194 | font-family: monospace; 195 | padding:0; 196 | margin:0; 197 | } 198 | 199 | 200 | .toggleList dd { 201 | margin:0; 202 | padding:0; 203 | } 204 | 205 | html.isjs .toggleList dd { 206 | display: none; 207 | } 208 | 209 | .toggleList pre { 210 | padding: 4px 4px 4px 4px; 211 | } 212 | 213 | 214 | 215 | 216 | 217 | /* COLORS */ 218 | 219 | pre, code { 220 | color: #000000; 221 | } 222 | 223 | 224 | body { 225 | color : #333333; 226 | background-color :#FFFFFF; 227 | } 228 | 229 | 230 | h1, h2, h3, h4, h5, h6 { 231 | color:#555; 232 | } 233 | 234 | a, 235 | .toggleList dt { 236 | color: #1a7eb0; 237 | } 238 | 239 | a:hover, 240 | a:active { 241 | color: #1a7eb0; 242 | } 243 | 244 | a:visited, 245 | a:link:visited { 246 | color: #1a7eb0; 247 | } 248 | 249 | td,tr { 250 | border-color: #999999; 251 | } 252 | 253 | hr { 254 | color:#999999; 255 | background:#999999; 256 | } 257 | 258 | 259 | .TableHeadingColor { 260 | background: #dcdcdc; 261 | color: #555; 262 | } 263 | 264 | 265 | .TableSubHeadingColor { 266 | background: #EEEEFF 267 | } 268 | 269 | .TableRowColor { 270 | background: #FFFFFF 271 | } 272 | 273 | 274 | .NavBarCell1 { 275 | background-color:#dcdcdc; 276 | color:#000; 277 | } 278 | 279 | .NavBarCell1 a { 280 | color:#333; 281 | } 282 | 283 | 284 | .NavBarCell1Rev { 285 | background-color:transparent; 286 | } 287 | 288 | .NavBarFont1 { 289 | color:#333; 290 | } 291 | 292 | 293 | .NavBarFont1Rev { 294 | color:#fff; 295 | } 296 | 297 | .NavBarCell2 { 298 | background-color:#999; 299 | } 300 | 301 | .NavBarCell2 a { 302 | color:#fff; 303 | } 304 | 305 | 306 | 307 | .NavBarCell3 { 308 | background-color:#dcdcdc; 309 | } 310 | 311 | -------------------------------------------------------------------------------- /web/index.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | ##library.name## 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 31 | 32 | 44 | 45 |
46 | 47 |
48 |

##library.name##

49 |

50 | A library by ##author.name## for the Processing programming environment.
51 | Last update, ##date##. 52 |

53 |

54 | ##library.sentence##
55 | ##library.paragraph##
56 |

57 |
58 | 59 | 60 | 61 |
62 |

Download

63 |

64 | Download ##library.name## version ##library.prettyVersion## in 65 | .zip format. 66 |

67 |

Installation

68 |

69 | Unzip and put the extracted ##project.name## folder into the libraries folder of your Processing sketches. Reference and examples are included in the ##project.name## folder. 70 |

71 |
72 | 73 | 74 |
75 |

Keywords. ##library.keywords##

76 |

Reference. Have a look at the javadoc reference here. A copy of the reference is included in the .zip as well.

77 |

Source. The source code of ##library.name## is available at ##source.host##, and its repository can be browsed here.

78 |
79 | 80 | 81 |
82 |

Examples

83 |

Find a list of examples in the current distribution of ##library.name##, or have a look at them by following the links below.

84 |
    85 | ##examples## 86 |
87 |
88 | 89 | 90 |
91 |

Tested

92 |

93 | 94 | Platform ##tested.platform## 95 | 96 | 97 |
Processing ##tested.processingVersion## 98 | 99 | 100 |
Dependencies ##library.dependencies## 101 |

102 |
103 | 104 | 105 | 106 | 118 | 119 | 120 | 125 | 126 | 127 | 131 | 132 | 133 |
134 |
135 | 136 | 139 |
140 | 141 | -------------------------------------------------------------------------------- /resources/build.properties: -------------------------------------------------------------------------------- 1 | # Create libraries for the Processing open source programming language and 2 | # environment (http://www.processing.org) 3 | # 4 | # Customize the build properties to make the ant-build-process work for your 5 | # environment. How? Please read the comments below. 6 | # 7 | # The default properties are set for OSX, for Windows-settings please refer to 8 | # comments made under (1) and (2). 9 | 10 | 11 | 12 | # (1) 13 | # Where is your Processing sketchbook located? 14 | # If you are not sure, check the sketchbook location in your Processing 15 | # application preferences. 16 | # ${user.home} points the compiler to your home directory. 17 | # For windows the default path to your sketchbook would be 18 | # ${user.home}/My Documents/Processing (make adjustments below). 19 | 20 | sketchbook.location=${user.home}/Coding/Processing/sketchbook 21 | 22 | 23 | 24 | # (2) 25 | # Where are the jar files located that are required for compiling your library 26 | # such as e.g. core.jar? 27 | # By default the local classpath location points to folder libs inside Eclipse's 28 | # workspace (by default found in your home directory). 29 | # For Windows the default path would be ${user.home}/workspace/libs (make 30 | # adjustments below). 31 | 32 | #classpath.local.location=${user.home}/Documents/workspace/libs 33 | 34 | 35 | # For OSX users. 36 | # The following path will direct you into Processing's application source code 37 | # folder in case you put Processing inside your Applications folder. 38 | # Uncommenting the line below will overwrite the classpath.local.location from 39 | # above. 40 | 41 | classpath.local.location=/Applications/Processing.app/Contents/Resources/Java/core/library/ 42 | 43 | 44 | # Add all jar files that are required for compiling your project to the local 45 | # and project classpath, use a comma as delimiter. These jar files must be 46 | # inside your classpath.local.location folder. 47 | 48 | classpath.local.include=core.jar 49 | 50 | 51 | # Add processing's libraries folder to the classpath. 52 | # If you don't need to include the libraries folder to your classpath, comment 53 | # out the following line. 54 | 55 | classpath.libraries.location=${sketchbook.location}/libraries 56 | 57 | 58 | 59 | # (3) 60 | # Set the java version that should be used to compile your library. 61 | 62 | java.target.version=1.6 63 | 64 | 65 | # Set the description of the Ant build.xml file. 66 | 67 | ant.description=ProcessingLibs Ant build file. 68 | 69 | 70 | 71 | # (4) 72 | # Project details. 73 | # Give your library a name. The name must not contain spaces or special characters. 74 | 75 | project.name=Eliza 76 | 77 | # The name as the user will see it. This can contain spaces and special characters. 78 | 79 | project.prettyName=Eliza 80 | 81 | 82 | # Use 'normal' or 'fast' as value for project.compile. 83 | # 'fast' will only compile the project into your sketchbook. 84 | # 'normal' will compile the distribution including the javadoc-reference and all 85 | # web-files (the compile process here takes longer). 86 | 87 | project.compile=normal 88 | 89 | # All files compiled with project.compile=normal are stored 90 | # in the distribution folder. 91 | 92 | 93 | 94 | # (5) 95 | # The following items are properties that will be used to make changes to the 96 | # web document templates. Values of properties will be inserted into the 97 | # documents automatically. 98 | # If you need more control, you can edit web/index.html and 99 | # web/library.properties directly. 100 | 101 | author.name=Andres Colubri 102 | author.url=http://andrescolubri.net/ 103 | 104 | 105 | # Set the web page for your library. 106 | # This is NOT a direct link to where to download it. 107 | 108 | library.url=http://processing.andrescolubri.net/libraries/eliza/ 109 | 110 | 111 | # Set the category of your library. This must be one (or many) of the following: 112 | # "3D" "Animation" "Compilations" "Data" 113 | # "Fabrication" "Geometry" "GUI" "Hardware" 114 | # "I/O" "Language" "Math" "Simulation" 115 | # "Sound" "Utilities" "Typography" "Video & Vision" 116 | # If a value other than those listed is used, your library will listed as 117 | # "Other". 118 | 119 | library.category=Language 120 | 121 | 122 | # A short sentence (or fragment) to summarize the library's function. This will 123 | # be shown from inside the PDE when the library is being installed. Avoid 124 | # repeating the name of your library here. Also, avoid saying anything redundant 125 | # like mentioning that it's a library. This should start with a capitalized 126 | # letter, and end with a period. 127 | 128 | library.sentence=The classic Eliza psychologist program. 129 | 130 | 131 | # Additional information suitable for the Processing website. The value of 132 | # 'sentence' always will be prepended, so you should start by writing the 133 | # second sentence here. If your library only works on certain operating systems, 134 | # mention it here. 135 | 136 | library.paragraph=Based on the Java implementation by Charles Hayden, faithful to the original 1966 version. 137 | 138 | 139 | # Set the source code repository for your project. 140 | # Recommendations for storing your source code online are Google Code or GitHub. 141 | 142 | source.host=GitHub 143 | source.url=https://github.com/ 144 | source.repository=https://github.com/codeanticode/eliza 145 | 146 | 147 | # The current version of your library. 148 | # This number must be parsable as an int. It increments once with each release. 149 | # This is used to compare different versions of the same library, and check if 150 | # an update is available. 151 | 152 | library.version=1 153 | 154 | 155 | # The version as the user will see it. 156 | 157 | library.prettyVersion=1.0 158 | 159 | 160 | library.copyright=(c) 2007-13 161 | library.dependencies= 162 | library.keywords=eliza, chatbot, AI, natural language 163 | 164 | tested.platform=osx, windows, linux 165 | tested.processingVersion=2.0.2 166 | 167 | 168 | # Include javadoc references into your project's javadocs. 169 | 170 | javadoc.java.href=http://java.sun.com/javase/6/docs/api/ 171 | javadoc.processing.href=http://processing.googlecode.com/svn/trunk/processing/build/javadoc/core/ 172 | -------------------------------------------------------------------------------- /src/codeanticode/eliza/EString.java: -------------------------------------------------------------------------------- 1 | package codeanticode.eliza; 2 | 3 | /** 4 | * Eliza string functions. 5 | */ 6 | public class EString { 7 | 8 | /** The digits. */ 9 | static final String num = "0123456789"; 10 | 11 | /** 12 | * Look for a match between the string and the pattern. 13 | * Return count of maching characters before * or #. 14 | * Return -1 if strings do not match. 15 | */ 16 | public static int amatch(String str, String pat) { 17 | int count = 0; 18 | int i = 0; // march through str 19 | int j = 0; // march through pat 20 | while (i < str.length() && j < pat.length()) { 21 | char p = pat.charAt(j); 22 | // stop if pattern is * or # 23 | if (p == '*' || p == '#') return count; 24 | if (str.charAt(i) != p) return -1; 25 | // they are still equal 26 | i++; j++; count++; 27 | } 28 | return count; 29 | } 30 | 31 | /** 32 | * Search in successive positions of the string, 33 | * looking for a match to the pattern. 34 | * Return the string position in str of the match, 35 | * or -1 for no match. 36 | */ 37 | public static int findPat(String str, String pat) { 38 | int count = 0; 39 | for (int i = 0; i < str.length(); i++) { 40 | if (amatch(str.substring(i), pat) >= 0) 41 | return count; 42 | count++; 43 | } 44 | return -1; 45 | } 46 | 47 | /** 48 | * Look for a number in the string. 49 | * Return the number of digits at the beginning. 50 | */ 51 | public static int findNum(String str) { 52 | int count = 0; 53 | for (int i = 0; i < str.length(); i++) { 54 | if (num.indexOf(str.charAt(i)) == -1) 55 | return count; 56 | count++; 57 | } 58 | return count; 59 | } 60 | 61 | /** 62 | * Match the string against a pattern and fills in 63 | * matches array with the pieces that matched * and # 64 | */ 65 | static boolean matchA(String str, String pat, String matches[]) { 66 | int i = 0; // move through str 67 | int j = 0; // move through matches 68 | int pos = 0; // move through pat 69 | while (pos < pat.length() && j < matches.length) { 70 | char p = pat.charAt(pos); 71 | if (p == '*') { 72 | int n; 73 | if (pos+1 == pat.length()) { 74 | // * is the last thing in pat 75 | // n is remaining string length 76 | n = str.length() - i; 77 | } else { 78 | // * is not last in pat 79 | // find using remaining pat 80 | n = findPat(str.substring(i), pat.substring(pos+1)); 81 | } 82 | if (n < 0) return false; 83 | matches[j++] = str.substring(i, i+n); 84 | i += n; pos++; 85 | } else if (p == '#') { 86 | int n = findNum(str.substring(i)); 87 | matches[j++] = str.substring(i, i+n); 88 | i += n; pos++; 89 | } else { 90 | int n = amatch(str.substring(i), pat.substring(pos)); 91 | if (n <= 0) return false; 92 | i += n; pos += n; 93 | } 94 | } 95 | if (i >= str.length() && pos >= pat.length()) return true; 96 | return false; 97 | } 98 | 99 | /* 100 | * This version is clearer, but hopelessly slow 101 | */ 102 | static boolean matchB(String strIn, String patIn, String matches[]) { 103 | String str = new String(strIn); 104 | String pat = new String(patIn); 105 | int j = 0; // move through matches 106 | while (pat.length() > 0 && str.length() >= 0 && j < matches.length) { 107 | char p = pat.charAt(0); 108 | if (p == '*') { 109 | int n; 110 | if (pat.length() == 1) { 111 | // * is the last thing in pat 112 | // n is remaining string length 113 | n = str.length(); 114 | } else { 115 | // * is not last in pat 116 | // find using remaining pat 117 | n = findPat(str, pat.substring(1)); 118 | } 119 | if (n < 0) return false; 120 | matches[j++] = str.substring(0, n); 121 | str = str.substring(n); 122 | pat = pat.substring(1); 123 | } else if (p == '#') { 124 | int n = findNum(str); 125 | matches[j++] = str.substring(0, n); 126 | str = str.substring(n); 127 | pat = pat.substring(1); 128 | // } else if (p == ' ' && str.length() > 0 && str.charAt(0) != ' ') { 129 | // pat = pat.substring(1); 130 | } else { 131 | int n = amatch(str, pat); 132 | if (n <= 0) return false; 133 | str = str.substring(n); 134 | pat = pat.substring(n); 135 | } 136 | } 137 | if (str.length() == 0 && pat.length() == 0) return true; 138 | return false; 139 | } 140 | 141 | public static boolean match(String str, String pat, String matches[]) { 142 | return matchA(str, pat, matches); 143 | } 144 | 145 | /* 146 | * Translates corresponding characters in src to dest. 147 | * Src and dest must have the same length. 148 | */ 149 | public static String translate(String str, String src, String dest) { 150 | if (src.length() != dest.length()) { 151 | // impossible error 152 | } 153 | for (int i = 0; i < src.length(); i++) { 154 | str = str.replace(src.charAt(i), dest.charAt(i)); 155 | } 156 | return str; 157 | } 158 | 159 | /** 160 | * Compresses its input by: 161 | * dropping space before space, comma, and period; 162 | * adding space before question, if char before is not a space; and 163 | * copying all others 164 | */ 165 | public static String compress(String s) { 166 | String dest = ""; 167 | if (s.length() == 0) return s; 168 | char c = s.charAt(0); 169 | for (int i = 1; i < s.length(); i++) { 170 | if (c == ' ' && 171 | ((s.charAt(i) == ' ') || 172 | (s.charAt(i) == ',') || 173 | (s.charAt(i) == '.'))) { 174 | // nothing 175 | } else if (c != ' ' && s.charAt(i) == '?') { 176 | dest += c + " "; 177 | } else { 178 | dest += c; 179 | } 180 | c = s.charAt(i); 181 | } 182 | dest += c; 183 | return dest; 184 | } 185 | 186 | /** 187 | * Trim off leading space 188 | */ 189 | public static String trim(String s) { 190 | for (int i = 0; i < s.length(); i++) { 191 | if (s.charAt(i) != ' ') return s.substring(i); 192 | } 193 | return ""; 194 | } 195 | 196 | /** 197 | * Pad by ensuring there are spaces before and after the sentence. 198 | */ 199 | public static String pad(String s) { 200 | if (s.length() == 0) return " "; 201 | char first = s.charAt(0); 202 | char last = s.charAt(s.length()-1); 203 | if (first == ' ' && last == ' ') return s; 204 | if (first == ' ' && last != ' ') return s + " "; 205 | if (first != ' ' && last == ' ') return " " + s; 206 | if (first != ' ' && last != ' ') return " " + s + " "; 207 | // impossible 208 | return s; 209 | } 210 | 211 | /** 212 | * Count number of occurrances of c in str 213 | */ 214 | public static int count(String s, char c) { 215 | int count = 0; 216 | for (int i = 0; i < s.length(); i++) 217 | if (s.charAt(i) == c) count++; 218 | return count; 219 | } 220 | } -------------------------------------------------------------------------------- /resources/code/ExampleTaglet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002 Sun Microsystems, Inc. All Rights Reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or 5 | * without modification, are permitted provided that the following 6 | * conditions are met: 7 | * 8 | * -Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 11 | * -Redistribution in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in 13 | * the documentation and/or other materials provided with the 14 | * distribution. 15 | * 16 | * Neither the name of Sun Microsystems, Inc. or the names of 17 | * contributors may be used to endorse or promote products derived 18 | * from this software without specific prior written permission. 19 | * 20 | * This software is provided "AS IS," without a warranty of any 21 | * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND 22 | * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, 23 | * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY 24 | * EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY 25 | * DAMAGES OR LIABILITIES SUFFERED BY LICENSEE AS A RESULT OF OR 26 | * RELATING TO USE, MODIFICATION OR DISTRIBUTION OF THE SOFTWARE OR 27 | * ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE 28 | * FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, 29 | * SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER 30 | * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF 31 | * THE USE OF OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN 32 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 33 | * 34 | * You acknowledge that Software is not designed, licensed or 35 | * intended for use in the design, construction, operation or 36 | * maintenance of any nuclear facility. 37 | */ 38 | 39 | import com.sun.tools.doclets.Taglet; 40 | import com.sun.javadoc.*; 41 | import java.util.Map; 42 | import java.io.*; 43 | /** 44 | * A sample Taglet representing @example. This tag can be used in any kind of 45 | * {@link com.sun.javadoc.Doc}. It is not an inline tag. The text is displayed 46 | * in yellow to remind the developer to perform a task. For 47 | * example, "@example Hello" would be shown as: 48 | *
49 | *
50 | * To Do: 51 | *
Fix this! 52 | *
53 | *
54 | * 55 | * @author Jamie Ho 56 | * @since 1.4 57 | */ 58 | 59 | public class ExampleTaglet implements Taglet { 60 | 61 | private static final String NAME = "example"; 62 | private static final String HEADER = "example To Do:"; 63 | 64 | /** 65 | * Return the name of this custom tag. 66 | */ 67 | public String getName() { 68 | return NAME; 69 | } 70 | 71 | /** 72 | * Will return true since @example 73 | * can be used in field documentation. 74 | * @return true since @example 75 | * can be used in field documentation and false 76 | * otherwise. 77 | */ 78 | public boolean inField() { 79 | return true; 80 | } 81 | 82 | /** 83 | * Will return true since @example 84 | * can be used in constructor documentation. 85 | * @return true since @example 86 | * can be used in constructor documentation and false 87 | * otherwise. 88 | */ 89 | public boolean inConstructor() { 90 | return true; 91 | } 92 | 93 | /** 94 | * Will return true since @example 95 | * can be used in method documentation. 96 | * @return true since @example 97 | * can be used in method documentation and false 98 | * otherwise. 99 | */ 100 | public boolean inMethod() { 101 | return true; 102 | } 103 | 104 | /** 105 | * Will return true since @example 106 | * can be used in method documentation. 107 | * @return true since @example 108 | * can be used in overview documentation and false 109 | * otherwise. 110 | */ 111 | public boolean inOverview() { 112 | return true; 113 | } 114 | 115 | /** 116 | * Will return true since @example 117 | * can be used in package documentation. 118 | * @return true since @example 119 | * can be used in package documentation and false 120 | * otherwise. 121 | */ 122 | public boolean inPackage() { 123 | return true; 124 | } 125 | 126 | /** 127 | * Will return true since @example 128 | * can be used in type documentation (classes or interfaces). 129 | * @return true since @example 130 | * can be used in type documentation and false 131 | * otherwise. 132 | */ 133 | public boolean inType() { 134 | return true; 135 | } 136 | 137 | /** 138 | * Will return false since @example 139 | * is not an inline tag. 140 | * @return false since @example 141 | * is not an inline tag. 142 | */ 143 | 144 | public boolean isInlineTag() { 145 | return false; 146 | } 147 | 148 | /** 149 | * Register this Taglet. 150 | * @param tagletMap the map to register this tag to. 151 | */ 152 | public static void register(Map tagletMap) { 153 | ExampleTaglet tag = new ExampleTaglet(); 154 | Taglet t = (Taglet) tagletMap.get(tag.getName()); 155 | if (t != null) { 156 | tagletMap.remove(tag.getName()); 157 | } 158 | tagletMap.put(tag.getName(), tag); 159 | } 160 | 161 | /** 162 | * Given the Tag representation of this custom 163 | * tag, return its string representation. 164 | * @param tag the Tag representation of this custom tag. 165 | */ 166 | public String toString(Tag tag) { 167 | return createHTML(readFile(tag.text())); 168 | } 169 | 170 | 171 | /** 172 | * Given an array of Tags representing this custom 173 | * tag, return its string representation. 174 | * @param tags the array of Tags representing of this custom tag. 175 | */ 176 | public String toString(Tag[] tags) { 177 | if (tags.length == 0) { 178 | return null; 179 | } 180 | return createHTML(readFile(tags[0].text())); 181 | } 182 | 183 | 184 | 185 | String createHTML(String theString) { 186 | if(theString!=null) { 187 | String dd = ""; 193 | 194 | return dd+"\n
" + 195 | "
+Example
" + 196 | "
"+theString+"
" + 197 | "
"; 198 | } 199 | return ""; 200 | } 201 | 202 | 203 | /** 204 | * check if the examples directory exists and return the example as given in the tag. 205 | * @param theExample the name of the example 206 | */ 207 | String readFile(String theExample) { 208 | String record = ""; 209 | String myResult = ""; 210 | int recCount = 0; 211 | String myDir = "../examples"; 212 | File file=new File(myDir); 213 | if(file.exists()==false) { 214 | myDir = "./examples"; 215 | } 216 | try { 217 | FileReader fr = new FileReader(myDir+"/"+theExample+"/"+theExample+".pde"); 218 | BufferedReader br = new BufferedReader(fr); 219 | record = new String(); 220 | while ((record = br.readLine()) != null) { 221 | myResult += record+"\n"; 222 | } 223 | } catch (IOException e) { 224 | System.out.println(e); 225 | return null; 226 | } 227 | return myResult; 228 | } 229 | } 230 | 231 | 232 | -------------------------------------------------------------------------------- /src/codeanticode/eliza/Eliza.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Eliza 3 | * Author: Charles Hayden 4 | * http://www.chayden.net/eliza/Eliza.html 5 | * Modified by Andres Colubri to use it as a Processing library 6 | */ 7 | 8 | package codeanticode.eliza; 9 | 10 | import processing.core.*; 11 | 12 | /** 13 | * Eliza main class. 14 | * Stores the processed script. 15 | * Does the input transformations. 16 | */ 17 | public class Eliza { 18 | public Eliza(PApplet parent) { 19 | this.parent = parent; 20 | 21 | readDefaultScript(); 22 | } 23 | 24 | public void dispose() { 25 | // anything in here will be called automatically when 26 | // the parent applet shuts down. for instance, this might 27 | // shut down a thread used by this library. 28 | // note that this currently has issues, see bug #183 29 | // http://dev.processing.org/bugs/show_bug.cgi?id=183 30 | } 31 | 32 | public boolean finished() { 33 | return finished; 34 | } 35 | 36 | /** 37 | * Process a line of script input. 38 | */ 39 | public void collect(String s) { 40 | String lines[] = new String[4]; 41 | 42 | if (EString.match(s, "*reasmb: *", lines)) { 43 | if (lastReasemb == null) { 44 | System.out.println("Error: no last reasemb"); 45 | return; 46 | } 47 | lastReasemb.add(lines[1]); 48 | } 49 | else if (EString.match(s, "*decomp: *", lines)) { 50 | if (lastDecomp == null) { 51 | System.out.println("Error: no last decomp"); 52 | return; 53 | } 54 | lastReasemb = new ReasembList(); 55 | String temp = new String(lines[1]); 56 | if (EString.match(temp, "$ *", lines)) { 57 | lastDecomp.add(lines[0], true, lastReasemb); 58 | } else { 59 | lastDecomp.add(temp, false, lastReasemb); 60 | } 61 | } 62 | else if (EString.match(s, "*key: * #*", lines)) { 63 | lastDecomp = new DecompList(); 64 | lastReasemb = null; 65 | int n = 0; 66 | if (lines[2].length() != 0) { 67 | try { 68 | n = Integer.parseInt(lines[2]); 69 | } catch (NumberFormatException e) { 70 | System.out.println("Number is wrong in key: " + lines[2]); 71 | } 72 | } 73 | keys.add(lines[1], n, lastDecomp); 74 | } 75 | else if (EString.match(s, "*key: *", lines)) { 76 | lastDecomp = new DecompList(); 77 | lastReasemb = null; 78 | keys.add(lines[1], 0, lastDecomp); 79 | } 80 | else if (EString.match(s, "*synon: * *", lines)) { 81 | WordList words = new WordList(); 82 | words.add(lines[1]); 83 | s = lines[2]; 84 | while (EString.match(s, "* *", lines)) { 85 | words.add(lines[0]); 86 | s = lines[1]; 87 | } 88 | words.add(s); 89 | syns.add(words); 90 | } 91 | else if (EString.match(s, "*pre: * *", lines)) { 92 | pre.add(lines[1], lines[2]); 93 | } 94 | else if (EString.match(s, "*post: * *", lines)) { 95 | post.add(lines[1], lines[2]); 96 | } 97 | else if (EString.match(s, "*initial: *", lines)) { 98 | initial = lines[1]; 99 | } 100 | else if (EString.match(s, "*final: *", lines)) { 101 | finl = lines[1]; 102 | } 103 | else if (EString.match(s, "*quit: *", lines)) { 104 | quit.add(" " + lines[1]+ " "); 105 | } 106 | else { 107 | System.out.println("Unrecognized input: " + s); 108 | } 109 | } 110 | 111 | /** 112 | * Print the stored script. 113 | */ 114 | public void print() { 115 | if (printKeys) keys.print(0); 116 | if (printSyns) syns.print(0); 117 | if (printPrePost) { 118 | pre.print(0); 119 | post.print(0); 120 | } 121 | if (printInitialFinal) { 122 | System.out.println("initial: " + initial); 123 | System.out.println("final: " + finl); 124 | quit.print(0); 125 | quit.print(0); 126 | } 127 | } 128 | 129 | /** 130 | * Process a line of input. 131 | */ 132 | public String processInput(String s) { 133 | String reply; 134 | // Do some input transformations first. 135 | s = EString.translate(s, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 136 | "abcdefghijklmnopqrstuvwxyz"); 137 | s = EString.translate(s, "@#$%^&*()_-+=~`{[}]|:;<>\\\"", 138 | " " ); 139 | s = EString.translate(s, ",?!", "..."); 140 | // Compress out multiple speace. 141 | s = EString.compress(s); 142 | String lines[] = new String[2]; 143 | // Break apart sentences, and do each separately. 144 | while (EString.match(s, "*.*", lines)) { 145 | reply = sentence(lines[0]); 146 | if (reply != null) return reply; 147 | s = EString.trim(lines[1]); 148 | } 149 | if (s.length() != 0) { 150 | reply = sentence(s); 151 | if (reply != null) return reply; 152 | } 153 | // Nothing matched, so try memory. 154 | String m = mem.get(); 155 | if (m != null) return m; 156 | 157 | // No memory, reply with xnone. 158 | Key key = keys.getKey("xnone"); 159 | if (key != null) { 160 | Key dummy = null; 161 | reply = decompose(key, s, dummy); 162 | if (reply != null) return reply; 163 | } 164 | // No xnone, just say anything. 165 | return "I am at a loss for words."; 166 | } 167 | 168 | public boolean readDefaultScript() { 169 | clearScript(); 170 | 171 | /* 172 | // Returns the URL of the resource file inside the location in the jar 173 | // where the class file for Eliza is stored. More info about this here: 174 | // http://www.javaworld.com/javaworld/javaqa/2002-11/02-qa-1122-resources.html 175 | if (url != null) 176 | { 177 | String[] lines = parent.loadStrings(url.toString()); 178 | for (int i = 0; i < lines.length; i++) { 179 | collect(lines[i]); 180 | } 181 | } 182 | else System.err.println("Cannot load default Eliza script!"); 183 | */ 184 | 185 | /* 186 | String[] lines = parent.loadStrings("eliza.script"); 187 | if (lines.length == 0) { 188 | System.err.println("Cannot load default Eliza script!"); 189 | return false; 190 | } else { 191 | for (int i = 0; i < lines.length; i++) { 192 | collect(lines[i]); 193 | } 194 | return true; 195 | } 196 | */ 197 | 198 | return readScript("eliza.script"); 199 | } 200 | 201 | public boolean readScript(String script) { 202 | clearScript(); 203 | 204 | String[] lines = parent.loadStrings(script); 205 | if (lines == null || lines.length == 0) { 206 | System.err.println("Cannot load Eliza script!"); 207 | return false; 208 | } else { 209 | for (int i = 0; i < lines.length; i++) { 210 | collect(lines[i]); 211 | } 212 | return true; 213 | } 214 | 215 | 216 | /* 217 | InputStream stream = parent.openStream(script); 218 | if (stream == null) { 219 | System.err.println("The script \"" + script + "\" " + 220 | "is missing or inaccessible, make sure " + 221 | "the URL is valid or that the file has been " + 222 | "added to your sketch and is readable."); 223 | return 1; 224 | } 225 | 226 | BufferedReader in = new BufferedReader(new InputStreamReader(stream)); 227 | 228 | String s; 229 | while (true) { 230 | try { 231 | s = in.readLine(); 232 | } catch (IOException e) { 233 | System.err.println("Could not read line from script file."); 234 | return 1; 235 | } 236 | if (s == null) break; 237 | collect(s); 238 | if (echoInput) System.out.println(s); 239 | } 240 | 241 | if (printData) print(); 242 | return 0; 243 | */ 244 | } 245 | 246 | void clearScript() { 247 | keys.clear(); 248 | syns.clear(); 249 | pre.clear(); 250 | post.clear(); 251 | initial = ""; 252 | finl = ""; 253 | quit.clear(); 254 | keyStack.reset(); 255 | } 256 | 257 | /** 258 | * Process a sentence. 259 | * (1) Make pre transformations. 260 | * (2) Check for quit word. 261 | * (3) Scan sentence for keys, build key stack. 262 | * (4) Try decompositions for each key. 263 | */ 264 | String sentence(String s) { 265 | s = pre.translate(s); 266 | s = EString.pad(s); 267 | if (quit.find(s)) { 268 | finished = true; 269 | return finl; 270 | } 271 | keys.buildKeyStack(keyStack, s); 272 | for (int i = 0; i < keyStack.keyTop(); i++) { 273 | Key gotoKey = new Key(); 274 | String reply = decompose(keyStack.key(i), s, gotoKey); 275 | if (reply != null) return reply; 276 | // If decomposition returned gotoKey, try it 277 | while (gotoKey.key() != null) { 278 | reply = decompose(gotoKey, s, gotoKey); 279 | if (reply != null) return reply; 280 | } 281 | } 282 | return null; 283 | } 284 | 285 | /** 286 | * Decompose a string according to the given key. 287 | * Try each decomposition rule in order. 288 | * If it matches, assemble a reply and return it. 289 | * If assembly fails, try another decomposition rule. 290 | * If assembly is a goto rule, return null and give the key. 291 | * If assembly succeeds, return the reply; 292 | */ 293 | String decompose(Key key, String s, Key gotoKey) { 294 | String reply[] = new String[10]; 295 | for (int i = 0; i < key.decomp().size(); i++) { 296 | Decomp d = (Decomp)key.decomp().elementAt(i); 297 | String pat = d.pattern(); 298 | if (syns.matchDecomp(s, pat, reply)) { 299 | String rep = assemble(d, reply, gotoKey); 300 | if (rep != null) return rep; 301 | if (gotoKey.key() != null) return null; 302 | } 303 | } 304 | return null; 305 | } 306 | 307 | /** 308 | * Assembly a reply from a decomp rule and the input. 309 | * If the reassembly rule is goto, return null and give 310 | * the gotoKey to use. 311 | * Otherwise return the response. 312 | */ 313 | String assemble(Decomp d, String reply[], Key gotoKey) { 314 | String lines[] = new String[3]; 315 | d.stepRule(); 316 | String rule = d.nextRule(); 317 | if (EString.match(rule, "goto *", lines)) { 318 | // goto rule -- set gotoKey and return false. 319 | gotoKey.copy(keys.getKey(lines[0])); 320 | if (gotoKey.key() != null) return null; 321 | System.out.println("Goto rule did not match key: " + lines[0]); 322 | return null; 323 | } 324 | String work = ""; 325 | while (EString.match(rule, "* (#)*", lines)) { 326 | // reassembly rule with number substitution 327 | rule = lines[2]; // there might be more 328 | int n = 0; 329 | try { 330 | n = Integer.parseInt(lines[1]) - 1; 331 | } catch (NumberFormatException e) { 332 | System.out.println("Number is wrong in reassembly rule " + lines[1]); 333 | } 334 | if (n < 0 || n >= reply.length) { 335 | System.out.println("Substitution number is bad " + lines[1]); 336 | return null; 337 | } 338 | reply[n] = post.translate(reply[n]); 339 | work += lines[0] + " " + reply[n]; 340 | } 341 | work += rule; 342 | if (d.mem()) { 343 | mem.save(work); 344 | return null; 345 | } 346 | return work; 347 | } 348 | 349 | PApplet parent; 350 | 351 | final boolean echoInput = false; 352 | final boolean printData = false; 353 | 354 | final boolean printKeys = false; 355 | final boolean printSyns = false; 356 | final boolean printPrePost = false; 357 | final boolean printInitialFinal = false; 358 | 359 | /** The key list */ 360 | KeyList keys = new KeyList(); 361 | /** The syn list */ 362 | SynList syns = new SynList(); 363 | /** The pre list */ 364 | PrePostList pre = new PrePostList(); 365 | /** The post list */ 366 | PrePostList post = new PrePostList(); 367 | /** Initial string */ 368 | String initial = "Hello."; 369 | /** Final string */ 370 | String finl = "Goodbye."; 371 | /** Quit list */ 372 | WordList quit = new WordList(); 373 | 374 | /** Key stack */ 375 | KeyStack keyStack = new KeyStack(); 376 | 377 | /** Memory */ 378 | Mem mem = new Mem(); 379 | 380 | DecompList lastDecomp; 381 | ReasembList lastReasemb; 382 | boolean finished = false; 383 | 384 | static final int success = 0; 385 | static final int failure = 1; 386 | static final int gotoRule = 2; 387 | } 388 | -------------------------------------------------------------------------------- /data/eliza.script: -------------------------------------------------------------------------------- 1 | initial: How do you do. Please tell me your problem. 2 | final: Goodbye. Thank you for talking to me. 3 | quit: bye 4 | quit: goodbye 5 | quit: quit 6 | pre: dont don't 7 | pre: cant can't 8 | pre: wont won't 9 | pre: recollect remember 10 | pre: dreamt dreamed 11 | pre: dreams dream 12 | pre: maybe perhaps 13 | pre: how what 14 | pre: when what 15 | pre: certainly yes 16 | pre: machine computer 17 | pre: computers computer 18 | pre: were was 19 | pre: you're you are 20 | pre: i'm i am 21 | pre: same alike 22 | post: am are 23 | post: your my 24 | post: me you 25 | post: myself yourself 26 | post: yourself myself 27 | post: i you 28 | post: you I 29 | post: my your 30 | post: i'm you are 31 | synon: belief feel think believe wish 32 | synon: family mother mom father dad sister brother wife children child 33 | synon: desire want need 34 | synon: sad unhappy depressed sick 35 | synon: happy elated glad better 36 | synon: cannot can't 37 | synon: everyone everybody nobody noone 38 | synon: be am is are was 39 | key: xnone 40 | decomp: * 41 | reasmb: I'm not sure I understand you fully. 42 | reasmb: Please go on. 43 | reasmb: What does that suggest to you ? 44 | reasmb: Do you feel strongly about discussing such things ? 45 | key: sorry 46 | decomp: * 47 | reasmb: Please don't apologise. 48 | reasmb: Apologies are not necessary. 49 | reasmb: I've told you that apologies are not required. 50 | key: apologise 51 | decomp: * 52 | reasmb: goto sorry 53 | key: remember 5 54 | decomp: * i remember * 55 | reasmb: Do you often think of (2) ? 56 | reasmb: Does thinking of (2) bring anything else to mind ? 57 | reasmb: What else do you recollect ? 58 | reasmb: Why do you recollect (2) just now ? 59 | reasmb: What in the present situation reminds you of (2) ? 60 | reasmb: What is the connection between me and (2) ? 61 | decomp: * do you remember * 62 | reasmb: Did you think I would forget (2) ? 63 | reasmb: Why do you think I should recall (2) now ? 64 | reasmb: What about (2) ? 65 | reasmb: goto what 66 | reasmb: You mentioned (2) ? 67 | key: if 3 68 | decomp: * if * 69 | reasmb: Do you think its likely that (2) ? 70 | reasmb: Do you wish that (2) ? 71 | reasmb: What do you know about (2) ? 72 | reasmb: Really, if (2) ? 73 | key: dreamed 4 74 | decomp: * i dreamed * 75 | reasmb: Really, (2) ? 76 | reasmb: Have you ever fantasized (2) while you were awake ? 77 | reasmb: Have you ever dreamed (2) before ? 78 | reasmb: goto dream 79 | key: dream 3 80 | decomp: * 81 | reasmb: What does that dream suggest to you ? 82 | reasmb: Do you dream often ? 83 | reasmb: What persons appear in your dreams ? 84 | reasmb: Do you believe that dreams have something to do with your problems ? 85 | key: perhaps 86 | decomp: * 87 | reasmb: You don't seem quite certain. 88 | reasmb: Why the uncertain tone ? 89 | reasmb: Can't you be more positive ? 90 | reasmb: You aren't sure ? 91 | reasmb: Don't you know ? 92 | key: name 15 93 | decomp: * 94 | reasmb: I am not interested in names. 95 | reasmb: I've told you before, I don't care about names -- please continue. 96 | key: deutsch 97 | decomp: * 98 | reasmb: goto xforeign 99 | reasmb: I told you before, I don't understand German. 100 | key: francais 101 | decomp: * 102 | reasmb: goto xforeign 103 | reasmb: I told you before, I don't understand French. 104 | key: italiano 105 | decomp: * 106 | reasmb: goto xforeign 107 | reasmb: I told you before, I don't understand Italian. 108 | key: espanol 109 | decomp: * 110 | reasmb: goto xforeign 111 | reasmb: I told you before, I don't understand Spanish. 112 | key: xforeign 113 | decomp: * 114 | reasmb: I speak only English. 115 | key: hello 116 | decomp: * 117 | reasmb: How do you do. Please state your problem. 118 | reasmb: Hi. What seems to be your problem ? 119 | key: computer 50 120 | decomp: * 121 | reasmb: Do computers worry you ? 122 | reasmb: Why do you mention computers ? 123 | reasmb: What do you think machines have to do with your problem ? 124 | reasmb: Don't you think computers can help people ? 125 | reasmb: What about machines worrys you ? 126 | reasmb: What do you think about machines ? 127 | key: am 128 | decomp: * am i * 129 | reasmb: Do you believe you are (2) ? 130 | reasmb: Would you want to be (2) ? 131 | reasmb: Do you wish I would tell you you are (2) ? 132 | reasmb: What would it mean if you were (2) ? 133 | reasmb: goto what 134 | decomp: * 135 | reasmb: Why do you say 'am' ? 136 | reasmb: I don't understand that. 137 | key: are 138 | decomp: * are you * 139 | reasmb: Why are you interested in whether I am (2) or not ? 140 | reasmb: Would you prefer if I weren't (2) ? 141 | reasmb: Perhaps I am (2) in your fantasies. 142 | reasmb: Do you sometimes think I am (2) ? 143 | reasmb: goto what 144 | decomp: * are * 145 | reasmb: Did you think they might not be (2) ? 146 | reasmb: Would you like it if they were not (2) ? 147 | reasmb: What if they were not (2) ? 148 | reasmb: Possibly they are (2). 149 | key: your 150 | decomp: * your * 151 | reasmb: Why are you concerned over my (2) ? 152 | reasmb: What about your own (2) ? 153 | reasmb: Are you worried about someone else's (2) ? 154 | reasmb: Really, my (2) ? 155 | key: was 2 156 | decomp: * was i * 157 | reasmb: What if you were (2) ? 158 | reasmb: Do you think you were (2) ? 159 | reasmb: Were you (2) ? 160 | reasmb: What would it mean if you were (2) ? 161 | reasmb: What does (2) suggest to you ? 162 | reasmb: goto what 163 | decomp: * i was * 164 | reasmb: Were you really ? 165 | reasmb: Why do you tell me you were (2) now ? 166 | reasmb: Perhaps I already know you were (2). 167 | decomp: * was you * 168 | reasmb: Would you like to believe I was (2) ? 169 | reasmb: What suggests that I was (2) ? 170 | reasmb: What do you think ? 171 | reasmb: Perhaps I was (2). 172 | reasmb: What if I had been (2) ? 173 | key: i 174 | decomp: * i @desire * 175 | reasmb: What would it mean to you if you got (3) ? 176 | reasmb: Why do you want (3) ? 177 | reasmb: Suppose you got (3) soon ? 178 | reasmb: What if you never got (3) ? 179 | reasmb: What would getting (3) mean to you ? 180 | reasmb: What does wanting (3) have to do with this discussion ? 181 | decomp: * i am* @sad * 182 | reasmb: I am sorry to hear that you are (3). 183 | reasmb: Do you think that coming here will help you not to be (3) ? 184 | reasmb: I'm sure it's not pleasant to be (3). 185 | reasmb: Can you explain what made you (3) ? 186 | decomp: * i am* @happy * 187 | reasmb: How have I helped you to be (3) ? 188 | reasmb: Has your treatment made you (3) ? 189 | reasmb: What makes you (3) just now ? 190 | reasmb: Can you explan why you are suddenly (3) ? 191 | decomp: * i was * 192 | reasmb: goto was 193 | decomp: * i @belief * i * 194 | reasmb: Do you really think so ? 195 | reasmb: But you are not sure you (3). 196 | reasmb: Do you really doubt you (3) ? 197 | decomp: * i* @belief *you * 198 | reasmb: goto you 199 | decomp: * i am * 200 | reasmb: Is it because you are (2) that you came to me ? 201 | reasmb: How long have you been (2) ? 202 | reasmb: Do you believe it is normal to be (2) ? 203 | reasmb: Do you enjoy being (2) ? 204 | decomp: * i @cannot * 205 | reasmb: How do you think that you can't (3) ? 206 | reasmb: Have you tried ? 207 | reasmb: Perhaps you could (3) now. 208 | reasmb: Do you really want to be able to (3) ? 209 | decomp: * i don't * 210 | reasmb: Don't you really (2) ? 211 | reasmb: Why don't you (2) ? 212 | reasmb: Do you wish to be able to (2) ? 213 | reasmb: Does that trouble you ? 214 | decomp: * do i feel * 215 | reasmb: Tell me more about such feelings. 216 | reasmb: Do you often feel (2) ? 217 | reasmb: Do you enjoy feeling (2) ? 218 | reasmb: Of what does feeling (2) remind you ? 219 | decomp: * i * you * 220 | reasmb: Perhaps in your fantasies we (2) each other. 221 | reasmb: Do you wish to (2) me ? 222 | reasmb: You seem to need to (2) me. 223 | reasmb: Do you (2) anyone else ? 224 | decomp: * 225 | reasmb: You say (1) ? 226 | reasmb: Can you elaborate on that ? 227 | reasmb: Do you say (1) for some special reason ? 228 | reasmb: That's quite interesting. 229 | key: you 230 | decomp: * you remind me of * 231 | reasmb: goto alike 232 | decomp: * you are * 233 | reasmb: What makes you think I am (2) ? 234 | reasmb: Does it please you to believe I am (2) ? 235 | reasmb: Do you sometimes wish you were (2) ? 236 | reasmb: Perhaps you would like to be (2). 237 | decomp: * you* me * 238 | reasmb: Why do you think I (2) you ? 239 | reasmb: You like to think I (2) you -- don't you ? 240 | reasmb: What makes you think I (2) you ? 241 | reasmb: Really, I (2) you ? 242 | reasmb: Do you wish to believe I (2) you ? 243 | reasmb: Suppose I did (2) you -- what would that mean ? 244 | reasmb: Does someone else believe I (2) you ? 245 | decomp: * you * 246 | reasmb: We were discussing you -- not me. 247 | reasmb: Oh, I (2) ? 248 | reasmb: You're not really talking about me -- are you ? 249 | reasmb: What are your feelings now ? 250 | key: yes 251 | decomp: * 252 | reasmb: You seem to be quite positive. 253 | reasmb: You are sure. 254 | reasmb: I see. 255 | reasmb: I understand. 256 | key: no 257 | decomp: * 258 | reasmb: Are you saying no just to be negative? 259 | reasmb: You are being a bit negative. 260 | reasmb: Why not ? 261 | reasmb: Why 'no' ? 262 | key: my 2 263 | decomp: $ * my * 264 | reasmb: Lets discuss further why your (2). 265 | reasmb: Earlier you said your (2). 266 | reasmb: But your (2). 267 | reasmb: Does that have anything to do with the fact that your (2) ? 268 | decomp: * my* @family * 269 | reasmb: Tell me more about your family. 270 | reasmb: Who else in your family (4) ? 271 | reasmb: Your (3) ? 272 | reasmb: What else comes to mind when you think of your (3) ? 273 | decomp: * my * 274 | reasmb: Your (2) ? 275 | reasmb: Why do you say your (2) ? 276 | reasmb: Does that suggest anything else which belongs to you ? 277 | reasmb: Is it important that your (2) ? 278 | key: can 279 | decomp: * can you * 280 | reasmb: You believe I can (2) don't you ? 281 | reasmb: goto what 282 | reasmb: You want me to be able to (2). 283 | reasmb: Perhaps you would like to be able to (2) yourself. 284 | decomp: * can i * 285 | reasmb: Whether or not you can (2) depends on you more than me. 286 | reasmb: Do you want to be able to (2) ? 287 | reasmb: Perhaps you don't want to (2). 288 | reasmb: goto what 289 | key: what 290 | decomp: * 291 | reasmb: Why do you ask ? 292 | reasmb: Does that question interest you ? 293 | reasmb: What is it you really wanted to know ? 294 | reasmb: Are such questions much on your mind ? 295 | reasmb: What answer would please you most ? 296 | reasmb: What do you think ? 297 | reasmb: What comes to mind when you ask that ? 298 | reasmb: Have you asked such questions before ? 299 | reasmb: Have you asked anyone else ? 300 | key: because 301 | decomp: * 302 | reasmb: Is that the real reason ? 303 | reasmb: Don't any other reasons come to mind ? 304 | reasmb: Does that reason seem to explain anything else ? 305 | reasmb: What other reasons might there be ? 306 | key: why 307 | decomp: * why don't you * 308 | reasmb: Do you believe I don't (2) ? 309 | reasmb: Perhaps I will (2) in good time. 310 | reasmb: Should you (2) yourself ? 311 | reasmb: You want me to (2) ? 312 | reasmb: goto what 313 | decomp: * why can't i * 314 | reasmb: Do you think you should be able to (2) ? 315 | reasmb: Do you want to be able to (2) ? 316 | reasmb: Do you believe this will help you to (2) ? 317 | reasmb: Have you any idea why you can't (2) ? 318 | reasmb: goto what 319 | decomp: * 320 | reasmb: goto what 321 | key: everyone 2 322 | decomp: * @everyone * 323 | reasmb: Realy, (2) ? 324 | reasmb: Surely not (2). 325 | reasmb: Can you think of anyone in particular ? 326 | reasmb: Who, for example? 327 | reasmb: Are you thinking of a very special person ? 328 | reasmb: Who, may I ask ? 329 | reasmb: Someone special perhaps ? 330 | reasmb: You have a particular person in mind, don't you ? 331 | reasmb: Who do you think you're talking about ? 332 | key: everybody 2 333 | decomp: * 334 | reasmb: goto everyone 335 | key: nobody 2 336 | decomp: * 337 | reasmb: goto everyone 338 | key: noone 2 339 | decomp: * 340 | reasmb: goto everyone 341 | key: always 1 342 | decomp: * 343 | reasmb: Can you think of a specific example ? 344 | reasmb: When ? 345 | reasmb: What incident are you thinking of ? 346 | reasmb: Really, always ? 347 | key: alike 10 348 | decomp: * 349 | reasmb: In what way ? 350 | reasmb: What resemblence do you see ? 351 | reasmb: What does that similarity suggest to you ? 352 | reasmb: What other connections do you see ? 353 | reasmb: What do you suppose that resemblence means ? 354 | reasmb: What is the connection, do you suppose ? 355 | reasmb: Could here really be some connection ? 356 | reasmb: How ? 357 | key: like 10 358 | decomp: * @be *like * 359 | reasmb: goto alike 360 | -------------------------------------------------------------------------------- /resources/build.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | ${ant.description} 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | ${line} 81 | Building the Processing library ${project.name} ${library.version} 82 | ${line} 83 | src path ${project.src} 84 | bin path ${project.bin} 85 | classpath.local ${classpath.local.location} 86 | sketchbook ${sketchbook.location} 87 | java version ${java.target.version} 88 | ${line} 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | ${exampleDir} 339 | 345 | 346 | 352 | 353 | 354 | 355 | 356 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | ${line} 375 | Name ${project.name} 376 | Version ${library.prettyVersion} (${library.version}) 377 | Compiled ${project.compile} 378 | Sketchbook ${sketchbook.location} 379 | ${line} 380 | done, finished. 381 | ${line} 382 | 383 | 384 | 385 | 386 | 387 | --------------------------------------------------------------------------------