Difference between revisions of "User talk:Perry Mizin"
Perry Mizin (talk | contribs) |
Perry Mizin (talk | contribs) |
||
Line 15: | Line 15: | ||
== THE CODE BELOW IS NOT TESTED == | == THE CODE BELOW IS NOT TESTED == | ||
<lsl> | |||
//txTxtLot() = sendTextBatch() | |||
txTxtLot(integer txch, string txtxt) | txTxtLot(integer txch, string txtxt) | ||
{ | { | ||
Line 36: | Line 36: | ||
llMessageLinked(LINK_ALL_CHILDREN, 6634934, (string)<0.25, 0, 0.25>, ""); | llMessageLinked(LINK_ALL_CHILDREN, 6634934, (string)<0.25, 0, 0.25>, ""); | ||
} | } | ||
//string rxTxtLot() = string receiveTextBatch() | |||
string rxTxtLot(key rxid, string rxmsg) | string rxTxtLot(key rxid, string rxmsg) | ||
{ | { | ||
Line 88: | Line 86: | ||
} | } | ||
} | } | ||
//string rxTxtLotPrv() = string receiveTextBatchPrivate() | |||
string rxTxtLotPrv(key prxid, string prxmsg) | string rxTxtLotPrv(key prxid, string prxmsg) | ||
{ | { | ||
Line 107: | Line 104: | ||
return prxmsg; | return prxmsg; | ||
} | } | ||
//updateTranslatorList() | |||
updateTranslatorList() | updateTranslatorList() | ||
{ | { | ||
Line 178: | Line 174: | ||
llMessageLinked(LINK_THIS, 34829304, (string)isMaster, ""); | llMessageLinked(LINK_THIS, 34829304, (string)isMaster, ""); | ||
} | } | ||
//sendHeartbeat() | |||
sendHeartbeat() | sendHeartbeat() | ||
{ | { | ||
Line 192: | Line 187: | ||
} | } | ||
} | } | ||
//string checkLanguage() | |||
string checkLanguage(string tempString) | string checkLanguage(string tempString) | ||
{ | { | ||
Line 216: | Line 210: | ||
return tempString; | return tempString; | ||
} | } | ||
//addAgent() | |||
addAgent(key avid, string avlan, integer chklan) | addAgent(key avid, string avlan, integer chklan) | ||
{ | { | ||
Line 241: | Line 234: | ||
} | } | ||
} | } | ||
//string addNewAgent() | |||
string addNewAgent(key id) | string addNewAgent(key id) | ||
{ | { | ||
Line 264: | Line 256: | ||
return speakerLanguage; | return speakerLanguage; | ||
} | } | ||
//key getAgentKey() | |||
key getAgentKey(integer agentID) | key getAgentKey(integer agentID) | ||
{ | { | ||
Line 280: | Line 271: | ||
} | } | ||
} | } | ||
//processHTTPResponse() | |||
processHTTPResponse(integer ntype, string bodyStr, list paramsli) | processHTTPResponse(integer ntype, string bodyStr, list paramsli) | ||
{ | { |
Revision as of 06:48, 14 December 2009
Bienvenid@
Hola, soy Perry Mizin y este será mi humilde intento de contribucion al proyecto "Traductor Universal de Google" creado por Hank Ramos.
El siguiente codigo fué originalmente creado por Hank Ramos, empezaré modificando algunas funciones a mi manera... No os riais
Welcome
Hello, I am Perry Mizin and this will be my humble try to contribute with the project "Universal Google Translator" created by Hank Ramos.
The next code was originally created by Hank Ramos, I will start modifiying some functions on my way... Don´t laugh
THE CODE BELOW IS NOT TESTED
<lsl> //txTxtLot() = sendTextBatch()
txTxtLot(integer txch, string txtxt) {
txtxt = llXorBase64StringsCorrect(llStringToBase64(txtxt), llStringToBase64(password)); while (llStringLength(txtxt) > 508) //If string is 509 characters or longer { llSay(txch, llGetSubString(txtxt, 0, 507)); //send 508 character chunk txtxt = llGetSubString(txtxt, 508, -1); //delete 508 character chunk } llSay(txch, txtxt); //send out any remainder chunk or original chunk //Perry Mizin Comment: I don´t understand the aim of the following if. //Hank Ramos Comment: this line serves to "trigger" the receiver not to wait for another batch. If the //message length is exactly 508 characters, the receiver things that another chunk of the message is coming. //This message serves to tell the receiver that the last chunk was the last chunk, not another regular chunk. if (llStringLength(txtxt) == 508) llSay(txch, (string)(txch*4958654)); //Hank Ramos Comment: this just flashes the color of the bottom prim to show a message was sent llMessageLinked(LINK_ALL_CHILDREN, 6634934, (string)<0.25, 0, 0.25>, "");
}
//string rxTxtLot() = string receiveTextBatch() string rxTxtLot(key rxid, string rxmsg) {
integer rxliPos; string rxtmpStr = ""; while (~llListFindList(sayCache, (list)rxid)) { rxliPos = llListFindList(sayCache, [rxid]); rxtmpStr = (rxtmpStr="") + rxtmpStr + llList2String(sayCache, rxliPos + 1); sayCache = llDeleteSubList(sayCache, rxliPos, rxliPos + 1); } rxmsg = rxtmpStr + rxmsg; rxmsg = llBase64ToString(llXorBase64StringsCorrect(rxmsg, llStringToBase64(password))); return rxmsg;
}
integer rxTxtLotBusy = FALSE; //Perry Mizin: added Busy Mode, this could fail or prevent fail
string rxTxtLot(key rxid, string rxmsg)
{
if (rxTxtLotBusy == FALSE) { rxTxtLotBusy = TRUE; integer rxliPos; string rxtmpStr = ""; if(~llListFindList(sayCache, (list)rxid)) { @rxin; rxliPos = llListFindList(sayCache, [rxid]); rxtmpStr = (rxtmpStr="") + rxtmpStr + llList2String(sayCache, rxliPos + 1); sayCache = llDeleteSubList(sayCache, rxliPos, rxliPos + 1); if(~llListFindList(sayCache, (list)rxid)) { jump rxin; } } rxmsg = rxtmpStr + rxmsg; rxmsg = llBase64ToString(llXorBase64StringsCorrect(rxmsg, llStringToBase64(password))); rxTxtLotBusy = FALSE; return rxmsg; } else { //Perry Mizin: llSaySomething? return ""; }
}
//string rxTxtLotPrv() = string receiveTextBatchPrivate() string rxTxtLotPrv(key prxid, string prxmsg) {
integer prxliPos; string prxtmpStr = ""; while (~llListFindList(sayCachePrivate, (list)prxid)) { prxliPos = llListFindList(sayCachePrivate, [prxid]); prxtmpStr = (prxtmpStr="") + prxtmpStr + llList2String(sayCachePrivate, prxliPos + 1); sayCachePrivate = llDeleteSubList(sayCachePrivate, prxliPos, prxliPos + 1); } prxmsg = prxtmpStr + prxmsg; prxmsg = llBase64ToString(llXorBase64StringsCorrect(prxmsg, llStringToBase64(password))); return prxmsg;
}
//updateTranslatorList()
updateTranslatorList()
{
integer nx; integer xliLng; list newList; string tmpStrPos; integer newMaster; //Scan and remove translators not in the area xliLng = llGetListLength(translators); for (nx = 0; nx < xliLng; nx += 2) { tmpStrPos = llList2String(llGetObjectDetails(llList2Key(translators, nx + 1), [OBJECT_POS]), 0); if ((llVecDist(llGetPos(), (vector)tmpStrPos) <= 20.0) && (tmpStrPos != "")) { newList = (newList=[]) + newList + llList2List(translators, nx, nx + 1); } } translators = newList;
// llMessageLinked(LINK_THIS, 65635544, (string)xliLng, ""); //Perry Mizin: what is this necesary for?
if (translators == []) { newMaster = 1; } else { if (enabled) { xliLng = llGetListLength(translators); newMaster = 2; for (nx = 0; nx < xliLng; nx += 2) { //llOwnerSay("Checking Priority Number(" + (string)priorityNumber + "): " + (string)llList2Integer(translators, x)); if (llList2Integer(translators, nx) > priorityNumber) { newMaster = 0; } } } else { newMaster = 0; } } if ((isMaster > 0) && (newMaster == 0)) { //We are being demoted from master to slave //Flush agentsInTranslation to master if (agentsInTranslation != []) { //Demotion Dump of agentsInTranslation to Master txTxtLot(broadcastChannel, llList2CSV([1003, llList2CSV(agentsInTranslation)])); if (isInitialized == FALSE) { return; } txTxtLot(broadcastChannel, llList2CSV([1004, options])); //error } llListenRemove(listenID); } if ((isMaster == 0) && (newMaster > 0)) { llListenRemove(listenID); listenID = llListen(0, "", "", ""); } isMaster = newMaster; llMessageLinked(LINK_THIS, 34829304, (string)isMaster, "");
}
//sendHeartbeat()
sendHeartbeat()
{
updateTranslatorList(); txTxtLot(broadcastChannel, llList2CSV([1001, priorityNumber])); //Broadcast agentList to Slaves if (isMaster == 2) { txTxtLot(broadcastChannel, llList2CSV([1002, llList2CSV(agentsInTranslation)])); }
}
//string checkLanguage() string checkLanguage(string tempString) {
if (llGetSubString(tempString, 0, 1) == "zh") { tempString = "zh-CN"; } else if (tempString == "und") { tempString = "el"; } if (~llListFindList(languageCodes, [tempString])) {
} else { tempString = ""; } tempString = llGetSubString(tempString, 0, 1); return tempString;
}
//addAgent()
addAgent(key avid, string avlan, integer chklan)
{
integer avliPos; integer idNum; if (~llListFindList(agentsInTranslation, (list)avid)) { avliPos = llListFindList(agentsInTranslation, [avid]); agentsInTranslation = llListReplaceList(agentsInTranslation, [avlan, chklan], avliPos + 1, avliPos + 2); } else { @at; idNum = llRound(llFrand(2000000)) + 1; if(~llListFindList(agentsInTranslation, (list)idNum)) {//it exists jump at; } agentsInTranslation = (agentsInTranslation=[]) + agentsInTranslation + [avid, avlan, chklan, idNum]; llMessageLinked(LINK_THIS, 64562349, avlan, avid); }
}
//string addNewAgent()
string addNewAgent(key id)
{
string speakerLanguage; if (llGetAgentSize(id) != ZERO_VECTOR) { speakerLanguage = checkLanguage(llGetAgentLanguage(id)); if (speakerLanguage == "") { speakerLanguage = "en"; addAgent(id, speakerLanguage, TRUE); } else { addAgent(id, speakerLanguage, FALSE); } } return speakerLanguage;
}
//key getAgentKey()
key getAgentKey(integer agentID)
{
if(~llListFindList(agentsInTranslation, (list)agentID)) { integer gklistPos = llListFindList(agentsInTranslation, [agentID]); return llList2Key(agentsInTranslation, gklistPos - 3); } else { return ""; }
}
//processHTTPResponse()
processHTTPResponse(integer ntype, string bodyStr, list paramsli)
{
integer spkliPos; list recepientList; key recepientID; string recepientLanguage; string languagePair; key speakerID; string speakerName; string speakerLanguage; string translatedText; string lantmpStr; integer z; integer speakerLanguageReliable; float speakerLanguageConfidence; list paramtmpli; //=================== //Process Translation //=================== if (ntype == 0) { speakerID = llList2Key(paramsli, 1); speakerName = llKey2Name(speakerID); if (speakerName == "") { speakerName = llList2String(llGetObjectDetails(speakerID, [OBJECT_NAME]), 0); } recepientList = llParseString2List(llList2String(paramsli, 2), ["@"], []); paramtmpli = llParseStringKeepNulls(llList2String(paramsli, 3), ["|"],[]); recepientLanguage = llList2String(paramtmpli, 1); languagePair = llDumpList2String(paramtmpli, ">>"); //Perform Text Cleanup z = llSubStringIndex(bodyStr, "\",\"detectedSourceLanguage\":\""); if (z != -1) { translatedText = llGetSubString(bodyStr, llSubStringIndex(bodyStr, "{\"translatedText\":\"") + 18, z); speakerLanguage = checkLanguage(llGetSubString(bodyStr, z + 28, llSubStringIndex(bodyStr, "\"}, \"responseDetails\":") - 1)); spkliPos = llListFindList(agentsInTranslation, [speakerID]); if (spkliPos >= 0) { if (speakerLanguage != llList2String(agentsInTranslation, spkliPos + 1)) { agentsInTranslation = llListReplaceList(agentsInTranslation, [TRUE], spkliPos + 2, spkliPos + 2); //Mark for recheck of actual spoken language. } } } else if (z == -1) { translatedText = llGetSubString(bodyStr, llSubStringIndex(bodyStr, "{\"translatedText\":\"") + 18, llSubStringIndex(bodyStr, "\"}, \"responseDetails\"")); } //Reverse order if Recepient Language is Hebrew or Arabic if ((recepientLanguage == "iw") || (recepientLanguage == "ar")) { lantmpStr = ""; //Perry Mizin Comment: Maybe I guess this wrong, maybe I am wrong //Perry Mizin Comment: alternative reverse order: "Hello World" could be "World Hello" //Perry Mizin Comment: reverse order: "Hello World" is "dlroW olleH" for(z = llStringLength(translatedText);z >= 0; z--) { lantmpStr = (lantmpStr="") + lantmpStr + llGetSubString(translatedText, z, z); } translatedText = lantmpStr; } lantmpStr = speakerName + "(" + languagePair + "): " + translatedText; if (showTranslation) { sendIM(speakerID, lantmpStr); } for (z = 0; z < llGetListLength(recepientList); z += 1) { recepientID = getAgentKey(llList2Integer(recepientList, z)); if (recepientID != "") { recepientLanguage = llList2String(agentsInTranslation, llListFindList(agentsInTranslation, [recepientID]) + 1); if (recepientLanguage != speakerLanguage) { sendIM(recepientID, lantmpStr); } } } return; } //=========================== //Process Language Detection //=========================== if (ntype == 1) { speakerID = llList2Key(paramsli, 1); speakerLanguageReliable = llToLower(llGetSubString(bodyStr, llSubStringIndex(bodyStr, "\",\"isReliable\":") + 15, llSubStringIndex(bodyStr, ",\"confidence\":") - 1)) == "true"; speakerLanguageConfidence = (float)llGetSubString(bodyStr, llSubStringIndex(bodyStr, ",\"confidence\":") + 14, llSubStringIndex(bodyStr, "}, \"responseDetails\":") - 1);
spkliPos = llListFindList(agentsInTranslation, [speakerID]); if (((spkliPos < 0) && (speakerLanguageReliable) || (speakerLanguageConfidence >= 0.08))) { //Analyze Data lantmpStr = checkLanguage(llToLower(llGetSubString(bodyStr, llSubStringIndex(bodyStr, "{\"language\":\"") + 13, llSubStringIndex(bodyStr, "\",\"isReliable\":") - 1))); if (lantmpStr == "") { return; } if (speakerLanguageConfidence < 0.14) { addAgent(speakerID, lantmpStr, TRUE); } else { addAgent(speakerID, lantmpStr, FALSE); } } }
} </lsl>