Author Topic: [Source Code] Grammar Code [UPDATES ON NEW POST]  (Read 4503 times)

this is not stupid or anything but you've made it so that it covers everything and i bet you whenever i say lol or something, i wouldn't want an ! at the end...

Oh thank you Brian Smithers :)

This is client-sided right


yes
Then it's useless

Would like a server-sided add-on that auto adds a . and makes the first letter a capital one
But I'm too lazy right now to do it myself :s


if(isPackage(grammar))
   deactivatepackage(grammar);
package grammar
{
   function NMH_Type::send(%this)
   {
      if(strStr(NMH_Channel.getValue(),"SAY: ") == -1)
      {
         if(firstLetter(%this.getValue()) $= "/")
            return parent::send(%this);
         commandToServer('MessageSent',simpleGrammar(%this.getValue()));
         commandToSErver('stopTalking');
         canvas.popDialog(newMessageHud);
         NMH_Type.setValue("");
      }
      else
      if(strStr(NMH_Channel.getValue(),"TEAM: ") == -1)
      {
         if(firstLetter(%this.getValue()) $= "/")
            return parent::send(%this);
         commandToServer('TeamMessageSent',simpleGrammar(%this.getValue()));
         commandToSErver('stopTalking');
         canvas.popDialog(newMessageHud);
         NMH_Type.setValue("");     
      }
   }
};
ActivatePackage(grammar);

function firstLevelWords(%str)
{
   for(%i=0;%i<getWordCount(%str);%i++)
   {
      %word[%i] = getWord(%str,%i);
      switch$(%word[%i])
      {
         case "dont":
            %word[%i] = "don't";
         case "i":
            %word[%i] = "I";
         case "ive":
            %word[%i] = "I've";
         case "whatchya":
            %word[%i] = "what do you";
         case "wat":
            %word[%i] = "what";
         case "whats":
            %word[%i] = "what's";
         case "isnt":
            %word[%i] = "isn't";
         case "im":
            %word[%i] = "I'm";
         case "its":
            %word[%i] = "it's";
         case "wasnt":
            %word[%i] = "wasn't";
         case "couldnt":
            %word[%i] = "couldn't";
         case "wouldve":
            %word[%i] = "would've";
         case "kik":
            %word[%i] = "lol":
         case "ill":
            %word[%i] = "I'll";
         case "stil":
            %word[%i] = "still";
         case "probaly":
            %word[%i] = "probably";
         case "probs":
            %word[%i] = "probably";
         case "intersting":
            %word[%i] = "intresting";
         case "bord":
            %word[%i] = "bored";
         case "se":
            %word[%i] = "see";
         case "catually":
            %word[%i] = "actually";
         case "actualy":
            %word[%i] = "actually";
         case "lest":
            %word[%i] = "lets";
         case "somthig":
            %word[%i] = "something";
         case "poeple":
            %word[%i] = "people";
         case "H,,":
            %word[%i] = "Hmm";
         case "vant":
            %word[%i] = "can't";
         case "wont":
            %word[%i] = "won't";
         case "nothig":
            %word[%i] = "nothing";
         case "siht":
            %word[%i] = "stuff";
         case "letme":
            %word[%i] = "let me";
         case "tht":
            %word[%i] = "that";
         case "thta":
            %word[%i] = "that";
         case "blokc":
            %word[%i] = "block";
         case "cant":
            %word[%i] = "can't";
         case "sylvandor":
            %word[%i] = "sylvanor";
         case "hsot":
            %word[%i] = "host";
         case "alot":
            %word[%i] = "a lot";
      }
      if(%nstr $= "")
      {
         %nstr = %word[%i];
      }
      else
      {
         %nstr = %nstr SPC %word[%i];
      }
   }
   return %nstr;
}
function secondLevelWords(%str)
{
   for(%i=0;%i<getWordCount(%str);%i++)
   {
      %word[%i] = getWord(%str,%i);
      if(getSubStr(%word[%i],0,3) $= "Hmm" && lastLetter(%word[%i]) !$= "f")
         %word[%i] = "Hmm...";
      %word[%i] = nameCheck(%word[%i]);
      if(%nstr $= "")
      {
         %nstr = %word[%i];
      }
      else
      {
         %nstr = %nstr SPC %word[%i];
      }
   }
   return %nstr;
}
function firstLetter(%str)
{
   return getSubStr(%str,0,1);
}
function restLetters(%str)
{
   return getSubStr(%str,1,strLen(%str));
}
function lastLetter(%str)
{
   return getSubStr(%str,strlen(%str) - 1,strLen(%str));
}
function capitols(%str)
{
   return strUpr(firstLetter(%str)) @ restLetters(%str);
}
function nameCheck(%word)
{
   for(%i = 0; %i < NPL_List.rowCount(); %i++)
   {
      %list = NPL_List.getRowText(%i);
      %name = getField(%list, 1);
      if(%name $= %word)
         %word = strUpr(getSubStr(%word,0,1)) @ getSubStr(%word,1,strLen(%word));
   }
   return %word;
}
function butCheck(%str)
{
   if(firstWord(%str) $= "but")
      return restWords(%str);
   else
      return %str;
}
function periods(%str)
{
   if(strLen(%str) <= 3)
      return %str;
   %per = ". , ? ; \" ! * : ( )";
   for(%i=0;%i<getWordCount(%per);%i++)
   {
      if(lastLetter(%str) $= getWord(%per,%i))
         %y = 1;
   }
   %blacklist = ":D D: :( :C :) :( ;( ;) :-) 8) 8( >: <: :> :< C:";
   for(%i=0;%i<getWordCount(%blacklist);%i++)
   {
      if(lastWord(%str) $= getWord(%blacklist,%i))
         %y = 1;
   }
   if(%y == 0)
   {
      switch$(strlwr(firstWord(%str)))
      {
         case "what":
            %str = %str @ "?";
         case "why":
            %str = %str @ "?";
         case "where":
            %str = %str @ "?";
         case "how":
            %str = %str @ "?";
         case "who":
            %str = %str @ "?";
         case "lol":
            %str = %str @ "!";
         case "rofl":
            %str = %str @ "!";
         default:
            %str = %str @ ".";
      }
   }
   return %str;
}
function thirdLevelWords(%str)
{
   %fstr = strLwr(%str);
   if(%pos = strPos(%fstr,"id"))
   {
      switch$(getWord(%fstr,%pos))
      {
         case "bl":
            return;
         case "blockland":
            return;
         default:
            %str = getWords(%str,0,%pos - 1) SPC "i'd" SPC getWords(%pos + 1,strLen(%str));
      }
   }
   if(%pos = strPos(%fstr,"ill"))
   {
      if(getSubStr(periods(%str),strLen(periods(%str)) - 1,periods(%str)) !$= "?")
      {
         %str = getWord(%str,0,%pos - 1) SPC "i'll" SPC getWords(%pos, + 1,strLen(%str));
      }
   }
   return %str;
}

function simpleGrammar(%str)
{
   %str = butCheck(%str);
   %str = firstLevelWords(%str);
   %str = secondLevelWords(%str);
   %str = thirdLevelWordS(%str);
   %str = periods(%str);
   %str = capitols(%str);
   return %str;
}


updated, not tested though.


if(isPackage(grammar))
   deactivatepackage(grammar);
package grammar
{
   function NMH_Type::send(%this)
   {
      if(strStr(NMH_Channel.getValue(),"SAY: ") == -1)
      {
         if(firstLetter(%this.getValue()) $= "/")
            return parent::send(%this);
         commandToServer('MessageSent',simpleGrammar(%this.getValue()));
         commandToSErver('stopTalking');
         canvas.popDialog(newMessageHud);
         NMH_Type.setValue("");
      }
      else
      if(strStr(NMH_Channel.getValue(),"TEAM: ") == -1)
      {
         if(firstLetter(%this.getValue()) $= "/")
            return parent::send(%this);
         commandToServer('TeamMessageSent',simpleGrammar(%this.getValue()));
         commandToSErver('stopTalking');
         canvas.popDialog(newMessageHud);
         NMH_Type.setValue("");     
      }
   }
};
ActivatePackage(grammar);

function firstLevelWords(%str)
{
   for(%i=0;%i<getWordCount(%str);%i++)
   {
      %word[%i] = getWord(%str,%i);
      switch$(%word[%i])
      {
         case "dont":
            %word[%i] = "don't";
         case "i":
            %word[%i] = "I";
         case "ive":
            %word[%i] = "I've";
         case "whatchya":
            %word[%i] = "what do you";
         case "wat":
            %word[%i] = "what";
         case "whats":
            %word[%i] = "what's";
         case "isnt":
            %word[%i] = "isn't";
         case "im":
            %word[%i] = "I'm";
         case "its":
            %word[%i] = "it's";
         case "wasnt":
            %word[%i] = "wasn't";
         case "couldnt":
            %word[%i] = "couldn't";
         case "wouldve":
            %word[%i] = "would've";
         case "kik":
            %word[%i] = "lol":
         case "ill":
            %word[%i] = "I'll";
         case "stil":
            %word[%i] = "still";
         case "probaly":
            %word[%i] = "probably";
         case "probs":
            %word[%i] = "probably";
         case "intersting":
            %word[%i] = "intresting";
         case "bord":
            %word[%i] = "bored";
         case "se":
            %word[%i] = "see";
         case "catually":
            %word[%i] = "actually";
         case "actualy":
            %word[%i] = "actually";
         case "lest":
            %word[%i] = "lets";
         case "somthig":
            %word[%i] = "something";
         case "poeple":
            %word[%i] = "people";
         case "H,,":
            %word[%i] = "Hmm";
         case "vant":
            %word[%i] = "can't";
         case "wont":
            %word[%i] = "won't";
         case "nothig":
            %word[%i] = "nothing";
         case "siht":
            %word[%i] = "stuff";
         case "letme":
            %word[%i] = "let me";
         case "tht":
            %word[%i] = "that";
         case "thta":
            %word[%i] = "that";
         case "blokc":
            %word[%i] = "block";
         case "cant":
            %word[%i] = "can't";
         case "sylvandor":
            %word[%i] = "sylvanor";
         case "hsot":
            %word[%i] = "host";
         case "alot":
            %word[%i] = "a lot";
      }
      if(%nstr $= "")
      {
         %nstr = %word[%i];
      }
      else
      {
         %nstr = %nstr SPC %word[%i];
      }
   }
   return %nstr;
}
function secondLevelWords(%str)
{
   for(%i=0;%i<getWordCount(%str);%i++)
   {
      %word[%i] = getWord(%str,%i);
      if(getSubStr(%word[%i],0,3) $= "Hmm" && lastLetter(%word[%i]) !$= "f")
         %word[%i] = "Hmm...";
      %word[%i] = nameCheck(%word[%i]);
      if(%nstr $= "")
      {
         %nstr = %word[%i];
      }
      else
      {
         %nstr = %nstr SPC %word[%i];
      }
   }
   return %nstr;
}
function firstLetter(%str)
{
   return getSubStr(%str,0,1);
}
function restLetters(%str)
{
   return getSubStr(%str,1,strLen(%str));
}
function lastLetter(%str)
{
   return getSubStr(%str,strlen(%str) - 1,strLen(%str));
}
function capitols(%str)
{
   return strUpr(firstLetter(%str)) @ restLetters(%str);
}
function nameCheck(%word)
{
   for(%i = 0; %i < NPL_List.rowCount(); %i++)
   {
      %list = NPL_List.getRowText(%i);
      %name = getField(%list, 1);
      if(%name $= %word)
         %word = strUpr(getSubStr(%word,0,1)) @ getSubStr(%word,1,strLen(%word));
   }
   return %word;
}
function butCheck(%str)
{
   if(firstWord(%str) $= "but")
      return restWords(%str);
   else
      return %str;
}
function periods(%str)
{
   if(strLen(%str) <= 3)
      return %str;
   %per = ". , ? ; \" ! * : ( )";
   for(%i=0;%i<getWordCount(%per);%i++)
   {
      if(lastLetter(%str) $= getWord(%per,%i))
         %y = 1;
   }
   %blacklist = ":D D: :( :C :) :( ;( ;) :-) 8) 8( >: <: :> :< C:";
   for(%i=0;%i<getWordCount(%blacklist);%i++)
   {
      if(lastWord(%str) $= getWord(%blacklist,%i))
         %y = 1;
   }
   if(%y == 0)
   {
      switch$(strlwr(firstWord(%str)))
      {
         case "what":
            %str = %str @ "?";
         case "why":
            %str = %str @ "?";
         case "where":
            %str = %str @ "?";
         case "how":
            %str = %str @ "?";
         case "who":
            %str = %str @ "?";
         case "lol":
            %str = %str @ "!";
         case "rofl":
            %str = %str @ "!";
         default:
            %str = %str @ ".";
      }
   }
   return %str;
}
function thirdLevelWords(%str)
{
   %fstr = strLwr(%str);
   if(%pos = strPos(%fstr,"id"))
   {
      switch$(getWord(%fstr,%pos))
      {
         case "bl":
            return;
         case "blockland":
            return;
         default:
            %str = getWords(%str,0,%pos - 1) SPC "i'd" SPC getWords(%pos + 1,strLen(%str));
      }
   }
   if(%pos = strPos(%fstr,"ill"))
   {
      if(getSubStr(periods(%str),strLen(periods(%str)) - 1,periods(%str)) !$= "?")
      {
         %str = getWord(%str,0,%pos - 1) SPC "i'll" SPC getWords(%pos, + 1,strLen(%str));
      }
   }
   return %str;
}

function simpleGrammar(%str)
{
   %str = butCheck(%str);
   %str = firstLevelWords(%str);
   %str = secondLevelWords(%str);
   %str = thirdLevelWordS(%str);
   %str = periods(%str);
   %str = capitols(%str);
   return %str;
}


updated, not tested though.
Contains an error report. You may wan't to test it out yourself,
http://dl.dropbox.com/u/79071525/Client_Grammar2.zip

whatchya =/= what do you

wan't
I lol'd

Also don't quote the entire text block you dummy

:P
tu mahnie dolan peapul hear
tish miyt bea neated

Well, This could be helpful with the dumbass people, BUT there are times with this that will make the non dumbasses look like dumbasses

Post a screenshot of it happening to you

this would replace "how are you doing?" with "How? are you doing?", wouldn't it.

this would replace "how are you doing?" with "How? are you doing?", wouldn't it.
no
not at all lol.

It's somewhat intelligent, switches out only space delimited words and adds punctuation only to the end of strings. It's still essentially useless though.

no
not at all lol.
Really, because upon examination of the periods function, it looks like it would...
I could be wrong though, I havn't actually run the script.

wanted to point out "lest" is a word, but kalphiter did a good job clearing up that sutff