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

Gramamr Code by Brian Smith
What
It does some spelling mistakes and a few other grammar stuff

Why
Well while it does teach some horrid coding habits, it also has a bunch of things that can help out anyone.

Credits
Brian Smith
8437
Brian Smithers
smith8437
block8437
ya' know.

Code
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 "id":
            %word[%i] = "I'd";
         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";
      }
      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 simpleGrammar(%str)
{
   %str = butCheck(%str);
   %str = firstLevelWords(%str);
   %str = secondLevelWords(%str);
   %str = periods(%str);
   %str = capitols(%str);
   return %str;
}

Check my post for the new source code.

If you use this ever, please credit me.
« Last Edit: May 12, 2012, 05:25:39 PM by Brian Smithers »

I do not understand the point of this.

I do not understand the point of this.
i saw the punctation topic and it reminded me of this so i decided i'd release it in coding help because it has a few useful things in it.

Person: What is your Blockland I'd?
Person: Sorry I meant Blockland I'd?
Person: wtf?

Person: Is this guy I'll?
Person: wtf, I'll as in sick

Person: The robot cannot see it's feet
Person: wtf I said it's

Person: see is my favorite country
Person: SWEDEN

Person: What heeft hij gedaan?
Person: Stupid filter replaced "wat". Stupid Brian hates Dutch people.

I bet you had fun dreaming those up ^

This is really only a big ass check for a bunch of different things that might be a spelling mistake

I bet you had fun dreaming those up ^
I tried to insert humor, the only legitimate use for "wat" that I could think of was in Dutch.


commandToServer('MessageSent',simpleGrammar(%this.getValue()));
         commandToSErver('stopTalking');
         canvas.popDialog(newMessageHud);
         NMH_Type.setValue("");

Instead, you can just do NMH_Type.setValue(%newGrammarMessage); and parent the code, instead of overwriting. Same for the team function.

I agree with Kalphiter though, there is no point in this..

I completely agree, this will only cause more misunderstandings, if you ACTUALLY want to make a grammar corrector, you will need to make a language processor.

Also
it teaches some horrid coding habits
Gramamr Code?
I lol'd so hard

He want use his script allow fix on my grammer while on the server.

He want use his script allow fix on my grammer while on the server.
nah doesn't do anything like word rearranging it seems

your spelling is generally fine so this wouldn't really make grammatical fixes

He want use his script allow fix on my grammer while on the server.
THIS kinda crap needs language processing.

I would use this on my server to prevent some really obnoxious spelling errors. e.g. some people call the tank turret a 'turrent'.

But like Ipquarx said, most grammer checking would require language processing.

Of all the things to include, you don't do 'alot' -> 'a lot'.