Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE HTML>
- <html>
- <head>
- <meta charset="utf-8"><meta name="viewport" content="width=device-width">
- <title>I can do this</title>
- <style>
- div {
- font-size: 30px;
- border: 4px solid blue;
- margin: 5px;
- border-radius: 15px;
- padding: 10px;
- }
- #aaa,#aaa * {
- color: #a11;
- font-size: 24px;
- border: 2px solid black;
- margin: 0px;
- border-radius: 0px;
- padding: 2px;
- }
- </style>
- </head>
- <body>
- <p>
- Type the next word in here. If this is empty, the code will generate a random word.
- </p>
- <textarea id="aaat1"></textarea>
- <p>
- Teach a new word to the program here. Write it as [word name],,,[what words can come after it],,,[what words can be before it],,,[words that should not be before it]. Add multiple at once by separating them using ;;;.
- </p>
- <textarea id="aaat2"></textarea>
- <!-- To do list:
- = Add before, after, start, and end to groups.
- = Allow groups within groups.
- = Automatic group making, as in automate grouping of words during paragraph analysis.
- = Automate groups of groups (maybe?).
- = Use more types of patterns when making groups (not just before and after).
- = Allow for conditionals in groups (like swapping a verb form if it comes after "he", "she", or "it").
- = Automate use of conditionals when making groups.
- = Compare groups to find similar types of patterns. Maybe this could try to use to simplify them.
- = Store "context" information as text is generated, and make groups inherit/know the context.
- = Create a learn mode that uses self generated examples and a score given by the user to learn over time.
- = Allow for promts which get generate replies. Add a toggle to turn on/off auto promting and auto replying.
- = Detect that somtheing looks like a prompt followed by a reply and learn patterns between the prompt and reply.
- -->
- <div id="aaaB1">
- Next word
- </div>
- <div id="aaaB2">
- Clear outputs
- </div>
- <div id="aaaB3">
- Add new word
- </div>
- <div id="aaaB4">
- Export words data
- </div>
- <div id="aaaB5">
- Import words data
- </div>
- <div id="aaaB6">
- Learn from the paragraph!
- </div>
- <div id="aaaB7">
- Add new word (to group)
- </div>
- <div id="aaaB8">
- Next word (from group)
- </div>
- <div id="aaa"></div>
- <script>
- //HTML functions
- function sssf(dddw, dddc) {
- if (!dddw&&!dddc) {
- dddw = document.body;
- }
- if (dddc) {
- if (!dddw) {
- return document.querySelectorAll("*");
- } else {
- return document.querySelectorAll(dddw);
- }
- } else {
- return document.getElementById(dddw);
- }
- }
- //creat a new dddwhat, named dddid. It will be put in dddwhere (0 will put it at the end of the document, and no dddwhere will put it in "aaaMAIN").
- function sssc(dddwhat, dddid, dddclass, dddwhere) {
- dddwhat=document.createElement(dddwhat);
- dddwhat.id=dddid;
- dddwhat.className=dddclass;
- if(dddwhere===0){
- document.body.appendChild(dddwhat);
- }
- else if(typeof dddwhere==="object"&&dddwhere.appendChild!==undefined){
- dddwhere.appendChild(dddwhat);
- }
- else{
- sssf(dddwhere).appendChild(dddwhat);
- }
- }
- function sssk(dddid,dddt){
- if(dddt){
- dddt=sssf(dddid,dddt);
- for(dddid=0;dddid<dddt.length;dddid++){
- dddt[dddid].remove();
- }
- }
- else{
- sssf(dddid).remove();
- }
- }
- function sssAEL(dddwhat,dddevent,dddact){
- if(!dddwhat.addEventListener){
- dddwhat=sssf(dddwhat);
- }
- /*sssquick([dddwhat,dddevent,dddact]);*/
- dddwhat.addEventListener(dddevent,dddact)
- }
- function sssREL(dddwhat,dddevent){}
- var bbbout=0;
- function sssout(dddwhat){
- bbbout++;
- if (typeof dddtype!=="string"){
- dddtype="1"
- };
- sssf("aaa").innerHTML+="Output # "+bbbout+"<br>"+dddwhat+"</div>";
- }
- console.log("Functions loaded");
- /*New structure of word dictiomairy (includes gruoups)
- bbbc=[
- group 0:[
- start words:[
- a:[name,[can come after],[can come before],[like after],[like before],fallback],
- j:[name,[can come after],[can come before],[like after],[like before],fallback],
- d:[name,[can come after],[can come before],[like after],[like before],fallback]
- ],
- words:[
- c:[name,[can come after],[can come before],[like after],[like before],fallback],
- a:[name,[can come after],[can come before],[like after],[like before],fallback],
- h:[name,[can come after],[can come before],[like after],[like before],fallback],
- h:[name,[can come after],[can come before],[like after],[like before],fallback],
- f:[name,[can come after],[can come before],[like after],[like before],fallback],
- d:[name,[can come after],[can come before],[like after],[like before],fallback],
- z:[name,[can come after],[can come before],[like after],[like before],fallback],
- j:[name,[can come after],[can come before],[like after],[like before],fallback]
- ]
- ],
- group 1:,
- group 2:,
- group 3:,
- group 4:
- ]
- */
- var bbbc=[
- [
- [
- [
- "a",
- ["b","ba","aab","and"],
- ["end","caa"],
- [0.3,0.4,0.5,0.6],
- [1,0.3],
- "lend"
- ],
- [
- "b",
- ["brrrr","and","zeb"],
- ["a","lend"],
- [0.5,0.5,0.5],
- [1,0.25],
- "ands"
- ]
- ],
- [
- [
- "a",
- ["b","ba","aab","and"],
- ["end","caa"],
- [0.3,0.4,0.5,0.6],
- [1,0.3],
- "lend"
- ],
- [
- "b",
- ["brrrr","and","zeb"],
- ["a","lend"],
- [0.5,0.5,0.5],
- [1,0.25],
- "ands"
- ],
- [
- "c",
- ["caa","baac"],
- ["ca","and","lend"],
- [0.42,0.7],
- [0.6,0.65,0.75],
- "ca"
- ],
- [
- "and",
- ["a","b","c"],
- ["a","b","c","ba"],
- [0.33,0.44,0.55],
- [0.22,0.33,0.44,0.66],
- "baac"
- ],
- [
- "baac",
- ["aaa","bbbc"],
- ["c","aaa"],
- [1,0.1],
- [0.22,0.39,0.43],
- "ands"
- ],
- [
- "lend",
- ["aaa","ba","ca"],
- ["a","b","c"],
- [0.81,0.4,0.6],
- [0.63,0.2,2],
- "a"
- ],
- [
- "aaa",
- ["baaac","lends","ands"],
- ["lend","baac",],
- [0,0,0],
- [0,0,0],
- "lend"
- ],
- [
- "ands",
- ["aaa","lends","brrrr"],
- ["a","ba","b"],
- [0,0,0],
- [0,0,0],
- "end"
- ],
- [
- "lends",
- ["bbbc","baaac"],
- ["ands","and","aaa"],
- [0,0,0],
- [0.7,0.4,0.48],
- "end"
- ],
- [
- "brrrr",
- ["end",false,"ba"],
- ["b","ands",],
- [0.3,1,0.35],
- [0.44,0.6],
- "baaac"
- ],
- [
- "baaac",
- ["end"],
- ["brrrr","lends","aaa"],
- [1],
- [0.23,0.34,0.45],
- false
- ],
- [
- "ba",
- ["end","ands","and"],
- ["a","b","c","brrrr","ca"],
- [0.6,0.3,0.1],
- [0.44,0.2,0.53,0.78,1],
- "end"
- ],
- [
- "ca",
- ["end","c","caa"],
- ["lend","caa"],
- [0.4,0.4,0.6],
- [0.37,0.2],
- "ba"
- ],
- [
- "caa",
- ["a","c","ca"],
- ["end","ca"],
- [0.4,0.4,0.6],
- [0.37,0.2],
- "ba"
- ],
- [
- "end",
- [false],
- ["baaac","brrrr","lends","ands","ba","ca","aaa","a","b","c"],
- [2],
- [0.4,0.4,0.4,0.4,0.4,0.4,0.4,1,1,1],
- false
- ]
- ]
- ]
- ];
- var bbbgroup=0,bbba=["a"],bbbi;
- console.log("group:",bbbgroup);
- function sssnG(a1){
- let ddd,dddc=bbbc,
- dddi=-1,
- _a,
- _b;
- if (typeof a1 === "string"){
- bbba.push(a1);
- }
- //typeof a1==="number"
- else{
- //"word finder" code
- bbbi=bbba.length-1;
- a1=false;
- for(let i=0;i<bbbc.length&&bbbgroup===undefined;i++){
- for(let ii=0;ii<bbbc[i][1].length;ii++){
- if(bbbc[i][1][ii][0]===bbba[bbbi]){
- bbbgroup=i;
- dddi=ii;
- }
- }
- }
- if(dddi===-1) {
- for(let ii=0;ii<bbbc[bbbgroup][1].length;ii++){
- if(bbbc[bbbgroup][1][ii][0]===bbba[bbbi]){
- ddd=ii;
- }
- }
- }
- //end of "word finder"
- //bbbfrom is a word object, like:
- //[name,[can come after],[can come before],[likea after],[like before]]
- bbbfrom=bbbc[bbbgroup][1][ddd];
- ddd=Math.floor(Math.random()*bbbfrom[2].length);
- let dontLoop=0;
- //while we don't have a feasable next word:
- while(dontLoop<100){
- dontLoop++;
- //bbbfrom[2][ddd] is the word to test
- //if we ran out of words, then we need to use the fallback, bbbfrom[5]
- _a=bbbfrom[1][ddd];
- //test the word, setting the boolean for the while loop:
- //find the word with "word finder" code.
- let dddgroup,dddb
- for(let i=0;i<bbbc.length&&dddgroup===undefined;i++){
- for(let ii=0;ii<bbbc[i][1].length;ii++){
- if(bbbc[i][1][ii][0]===_a){
- dddgroup=i;
- dddi=ii;
- }
- }
- }
- if(dddi===-1){
- for(let ii=0;ii<bbbc[dddgroup][1].length;ii++){
- if(bbbc[dddgroup][1][ii][0]===_a){
- dddi=ii;
- }
- }
- }
- _b=bbbc[dddgroup][1][dddi];
- _a=bbbfrom;
- //RECAP: bbbfrom selected the name _a, and we found _b as the object with the name of _a. _b and bbbfrom will now be "compared".
- //---
- //this comparison is IMPORTANT, consider changijng it in the future
- //---
- //now if the current attraction of each word to the other word is higher than a random number, the test succeeds, stopping the loop.
- _c=_a[3][_a[1].indexOf(_b[0])]+_b[4][_b[2].indexOf(_a[0])];
- if(_c>=Math.random()){
- break;
- }
- //our comparison failed, so destroy the current ddd and ...
- bbbfrom[1].splice(ddd,1);
- bbbfrom[3].splice(ddd,1);
- //...select a new ddd
- ddd=Math.floor(bbbfrom[1].length*Math.random());
- }
- }
- bbbc=dddc;
- }
- </script>
- </body>
- </html>
Add Comment
Please, Sign In to add comment