string gName="filename"; key gQueryID; list AIMList; list REPLYList; string data; string newmessage; integer gLine; integer handle; integer touched=0; integer myParse(string message) { float last_score=-1.0; //so every score after is an improvement over this float score; integer lenaimlist; //length of AIMList integer begin; //index of message string marking beginning of matched pattern integer end; //length of matched pattern, so ending index actually begin+end-1 integer begina; //as above integer enda; integer begin2; integer end2; integer end3; integer lenclust; integer i=0; //loop (line) number integer starindex; //beginning index of *ed expression in message integer poundindex; list msglist; //string message as parsed to list, separated by " " list new_reply_list; list prestarlist; list clusters; //first cluster of pre * words list cluster2;//cluster of post * words list cl; //individual words in clusters parsed to individual list entries list cl2; //individual words in cluster2 blah blah blah list cl_a; list cl_b; list headmsglist; list tailmsglist; string last_message; //not used yet string starstring; //string corresponding to *ed characters string poundstring; integer check_line; //no longer implemented string resp_line; integer ind; string string1; integer ind2; string unparsed_clusters_string; list unparsed_clusters; list starlist; list poundlist; list startopoundlist; //grabs text between star and pound string unparsed_reply; integer end_tag; string parsed_reply; list temp_reply_list; integer reply_index=-1; integer s_ind; integer error_cond=0; //use later string newmsg; string tempmessage=""; integer j; integer chat_channel=0; list cluster_a; list cluster_b; list newmsglist; //begin actual program integer punc_index=llStringLength(message); punc_index--; if(llGetSubString(message,punc_index,punc_index)=="." || llGetSubString(message,punc_index,punc_index)=="!" || llGetSubString(message,punc_index,punc_index)=="?") { message=llDeleteSubString(message,punc_index,punc_index); } lenaimlist=llGetListLength(AIMList); reply_index=-1; while(reply_index==-1 && i< lenaimlist)//for(i=0;i")!=-1) { //strip out and ind=llSubStringIndex(llList2String(AIMList,i),""); string1=llDeleteSubString(llList2String(AIMList,i),ind,ind+9); ind2=llSubStringIndex(string1,""); string override_string=llDeleteSubString(string1,ind2,ind2+10);//this now represents string to match to message if(llSubStringIndex(message,override_string)!=-1) { reply_index=i; last_score=10000; //so this will override other messages. } } //find clusters/cluster2 in AIMList entry if(llSubStringIndex(llList2String(AIMList,i),"")!=-1) { //strip out and from every line ind=llSubStringIndex(llList2String(AIMList,i),""); string1=llDeleteSubString(llList2String(AIMList,i),ind,ind+8); ind2=llSubStringIndex(string1,""); string unparsed_clusters_string=llDeleteSubString(string1,ind2,ind2+9);//this now represents string to match to message if(llSubStringIndex(unparsed_clusters_string,"*")!=-1)// && llSubStringIndex(unparsed_clusters_string,"#")==-1) //parse only lines using wildcard this way. non-wildcard parse follows { unparsed_clusters=llParseString2List(unparsed_clusters_string,["*"],[]); //break into 2 clusters, before * and after * lenclust=llGetListLength(unparsed_clusters); //unparsed_clusters=llDeleteSubList(unparsed_clusters,lenclust,lenclust);//what does this do? clusters=llList2List(unparsed_clusters,0,0); //Before * cluster cluster2=llList2List(unparsed_clusters,1,1);//after * cluster if(llSubStringIndex(unparsed_clusters_string,"*")==0) { cluster2=clusters; clusters=[]; } cl=llParseString2List( (string) clusters,[" "],[]); //breaks out individual words in clusters cl2=llParseString2List( (string) cluster2,[" "],[]); //breaks out individual words in cluster2 msglist=llParseString2List(message,[" "],[]); //breaks up input message into list of individual words. if(cl2==[]) cl2=["asdfasfads"]; //insert unmatcheable value into cl2 if(cl==[]) cl=["hgsjgh"]; //Case of cluster * if(llListFindList(msglist,cl)!=-1 && llListFindList(msglist,cl2)==-1) { begin =llListFindList(msglist,cl); //find cl in msglist end=llGetListLength(cl); end--; tailmsglist=llDeleteSubList(msglist,begin,begin+end); //return only * and post * words starindex=llListFindList(msglist,tailmsglist); //locates * end2=llGetListLength(msglist); end2--; //if(end>=0 && begin>=0 && starindex >=0 && end2>=0) //so no negative indexes // newmsg=llDumpList2String(llListReplaceList(msglist,["*"],starindex,starindex+end2)," "); //replaces phrase with * in message //what to replace * with in reply starlist=llList2List(msglist,starindex,starindex+end2); //score similarity of matched pattern with message string score= (float) llGetListLength(llListReplaceList(msglist,["*"],starindex, starindex+end2))/(float)llGetListLength(msglist); if(llListReplaceList(msglist,["*"],starindex,starindex+end2)==cl+"*") { reply_index=i; last_score=score;//this becomes last best score starstring=llDumpList2String(starlist," "); } } //Case of * cluster2 if(llListFindList(msglist,cl)==-1 && llListFindList(msglist,cl2)!=-1) { begin=llListFindList(msglist,cl2); end=llGetListLength(cl2); end--; headmsglist=llDeleteSubList(msglist,begin, begin+end); starindex=llListFindList(msglist,headmsglist); end2=llGetListLength(headmsglist); end2--; //if(end>=0 && begin >=0 && starindex>=0 && end2>=0) // new starlist=llList2List(msglist, starindex, starindex+end2); starstring=llDumpList2String(starlist," "); score = (float) llGetListLength(llListReplaceList(msglist,["*"],starindex,starindex+end2))/(float)llGetListLength(msglist); if(llListReplaceList(msglist,["*"],starindex,starindex+end2)=="*"+cl2) { reply_index=i; last_score=score; starstring=llDumpList2String(starlist," "); } } //Case of clusters * cluster2 if(llListFindList(msglist,cl)!=-1 && llListFindList(msglist,cl2)!=-1) { //first delete clusters from message begin=llListFindList(msglist, cl); end=llGetListLength(cl); end--; headmsglist=llDeleteSubList(msglist,begin,begin+end); //then delete cluster2 from tailmsglist begina =llListFindList(headmsglist, cl2); enda=llGetListLength(cl2); enda--; starlist=llDeleteSubList(headmsglist,begina,begina+enda); starindex=llListFindList(msglist,starlist); end2=llGetListLength(starlist); end2--; // starstring=llDumpList2String(starlist," "); score=llGetListLength( llListReplaceList(msglist,["*"],starindex,starindex+end2))/(float)llGetListLength(msglist); if(llListReplaceList(msglist,["*"],starindex,starindex+end2)==cl+"*"+cl2 ) { reply_index=i; last_score=score; starstring=llDumpList2String(starlist," "); } } //case of cluster * cluster_a # cluster_b if(llSubStringIndex(unparsed_clusters_string,"#")!=-1) { ////first delete clusters from message begin=llListFindList(msglist, cl); end=llGetListLength(cl); end--; headmsglist=llDeleteSubList(msglist,begin,begin+end); prestarlist=llList2List(msglist,begin,begin+end); //parse cluster2 into cluster_a and cluster_b startopoundlist=llParseString2List((string) cluster2, ["#"],[]); cluster_a=llList2List(startopoundlist,0,0); list cl_a=llParseString2List( (string) cluster_a,[" "],[]); //then delete cl_a from tailmsglist begina =llListFindList(headmsglist, cl_a); enda=llGetListLength(cl_a); enda--; //replace starlist in msglist first; integer endb=llGetListLength(headmsglist); starlist=llDeleteSubList(headmsglist,begina,endb--); starindex=llListFindList(msglist,starlist); end2=llGetListLength(starlist); end2--; //newmsglist=llListReplaceList(tailmsglist,["*"],starindex,starindex+end2); if(llGetListLength(startopoundlist)>1) { cluster_b=llList2List(startopoundlist,1,1); cl_b=llParseString2List( (string) cluster_b,[" "],[]); //find index of cl_b in msglist integer clbstart=llListFindList(headmsglist,llParseString2List((string) llList2List(startopoundlist,1,1),[" "],[])); //delete all but this integer lenmsglist=llGetListLength(headmsglist); poundlist=llDeleteSubList(headmsglist,clbstart,lenmsglist--); enda=llGetListLength(llParseString2List( (string) llList2List(startopoundlist,0,0),[" "],[])); poundlist=llDeleteSubList(poundlist,0,enda--) ; } //integer endb=llGetListLength(headmsglist); // starlist=llDeleteSubList(headmsglist,begina,endb--); starindex=llListFindList(msglist,starlist); // integer starlength=llGetListLength(starlist); starlength--; newmsglist=llListReplaceList(msglist,["*"],starindex,starindex+starlength--); integer poundindex=llListFindList(newmsglist,poundlist); integer poundlength=llGetListLength(poundlist); poundlength--; newmsglist=llListReplaceList(newmsglist,["#"],poundindex,poundindex+poundlength--); if(newmsglist==cl+["*"]+cl_a+["#"]+cl_b) { reply_index=i; last_score=score; starstring=llDumpList2String(starlist," "); poundstring=llDumpList2String(poundlist," "); } } } else { if(unparsed_clusters_string==message) reply_index=i; last_score=100; } } i++; } if(reply_index!=-1) //if a match exists { if(llSubStringIndex(llList2String(AIMList,reply_index+1),"")!=-1) { ind=llSubStringIndex(llList2String(AIMList,reply_index+1),""); string1=llDeleteSubString(llList2String(AIMList,reply_index+1),ind,ind+8); ind2=llSubStringIndex(string1,""); string chat_channel_string=llDeleteSubString(string1,ind2,ind2+9); chat_channel=(integer) chat_channel_string; } unparsed_reply=llList2String(REPLYList, reply_index); end_tag=llSubStringIndex(unparsed_reply,""); end_tag--; parsed_reply=llGetSubString(unparsed_reply,10,end_tag--); //from end of if(llSubStringIndex(parsed_reply, "")==-1) { if(llSubStringIndex(parsed_reply,""); // starindex2--; //if(starindex2!=-1) //{ // parsed_reply=llGetSubString(parsed_reply,6,starindex) +" " +starstring; //} //else //{ newmessage=llGetSubString(parsed_reply,6,termin); // } } } else // if expression exists, insert antecedant { //if expression exists if(llSubStringIndex(parsed_reply,""]); new_reply_list=llListReplaceList(temp_reply_list,[poundstring],s_ind,s_ind); parsed_reply=llDumpList2String(new_reply_list," "); llSay(0,(string)new_reply_list); } //else new_reply_list=llParseString2List(parsed_reply,[" "],[]); if(llSubStringIndex(parsed_reply,""]); temp_reply_list=llListReplaceList(temp_reply_list,[starstring],s_ind2,s_ind2); parsed_reply=llDumpList2String(temp_reply_list," "); llSay(chat_channel,parsed_reply); reply_index=0; } else { //strip out tags integer srai_ind1=llSubStringIndex(parsed_reply,""); integer srai_ind2=llSubStringIndex(parsed_reply,""); //parsed_reply=llDeleteSubString(parsed_reply,srai_ind1,srai_ind1+5); parsed_reply=llGetSubString(parsed_reply,srai_ind1+6,srai_ind2-=1); //if pound expression exists if(llSubStringIndex(parsed_reply,""); poundindex2--; if(poundindex2!=-1) { parsed_reply=llGetSubString(parsed_reply,6,poundindex2) +poundstring; parsed_reply=llDeleteSubString(parsed_reply,poundindex2,poundindex2+8); parsed_reply=llInsertString(parsed_reply,poundindex,poundstring); //use llDeleteSubString followed by llInsertString } else { parsed_reply=llGetSubString(parsed_reply,6,termin); } } error_cond=-1; integer lenp=llStringLength(parsed_reply); integer termin=lenp--; integer starindex2=llSubStringIndex(parsed_reply,""); starindex2--; if(starindex2!=-1) { parsed_reply=llGetSubString(parsed_reply,6,starindex2) +starstring; parsed_reply=llDeleteSubString(parsed_reply,starindex2,starindex2+8); parsed_reply=llInsertString(parsed_reply,starindex,starstring); //use llDeleteSubString followed by llInsertString } else { newmessage=llGetSubString(parsed_reply,6,termin); } } } } else { llSay(0,"I'm afraid I don't understand what you said...yet"); //llemail line here } return error_cond; } default { state_entry() { gQueryID=llGetNotecardLine(gName,gLine);//request first line gLine++; //increase line count } dataserver(key query_id,string data) { if(query_id==gQueryID) { if(data!=EOF) { if( llGetSubString(data,0,3)=="