Changing input to other words

Posted by Lucindrielle on Thu 17 Jan 2008 06:38 PM — 6 posts, 23,794 views.

#0
I have a character that uses the Imperal We, instead of "I". Problem is, sometimes I forget and use I anyway.

Is there a way to make a trigger or an alias to replace "I" if it's alone and sent the rest of the line to the world?

For example:

[say I don't know.] would send to the world as [say We don't know.]


I think it's tricky because "I" can be anywhere in the sentence and I'm not sure how to get it to leave the other commands (channels and whispers and such) and words before it and words after it alone.

Plus, there's the whole "I am" "We are" issue....

Wow, can of worms?
Amended on Thu 17 Jan 2008 06:47 PM by Lucindrielle
Australia Forum Administrator #1
This is an interesting challenge. :)

I presume you want to convert the I in "I see you" but not the I in "wine" or "pie"?

My first approach is a simple alias like this:


<aliases>
  <alias
   match="^(.+)\b(I)\b(.+)$"
   enabled="y"
   regexp="y"
   sequence="100"
  >
  <send>%1We%3</send>
  </alias>
</aliases>


This uses \b as the "world boundary" assertion, which isolates "I" to be a word on its own. I use a wildcard before and after the I (this is %1 and %3 in the send area) so I can echo back that part.

This converts:


say I see you


to:


say We see you


You can also handle changing "I am" to "We are" like this:


<aliases>
  <alias
   match="^(.+)\b(I am)\b(.+)$"
   enabled="y"
   regexp="y"
   sequence="90"
  >
  <send>%1We are%3</send>
  </alias>
</aliases>


I would make this a lower sequence (I used 90) so it gets detected first, before "I" on its own.

However I can see two problems with this simple approach:

  • It doesn't handle multiple "I" in one sentence, eg.


    say I wonder if I should eat yet

  • The word "I" is always capitalized but "we" is not necessarily, eg.


    say I see you --> say We see you
    say This is something I wonder --> say this is something we wonder



For the second problem you can probably leave "we" in lower case as people probably don't bother capitalizing the start of a sentence when typing in MUDs much.


This alias below tries to solve this with a bit of scripting.


<aliases>
  <alias
   match="^.+\bI\b.+$"
   enabled="y"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>

phrase = "%0"

phrase = (string.gsub (phrase, " I am ", " we are " ))

phrase = (string.gsub (phrase, "%a+", { ["I"] = "we" } ))

Send (phrase)

</send>
  </alias>
</aliases>


First the alias simply matches on a line with "I" in it somewhere. Then the Lua script first does a string.gsub (global substitution) to replace any instance of " I am " (note the spaces) with " we are ". By using spaces we make sure that the "I" is a full word.

Next for "I" on its own I simply used a search for one or more letters (and Lua makes a "greedy" search so you are guaranteed of a word) and then looks up the result in a small table. This table replaces "I" with "we".
Australia Forum Administrator #2
To be fussier about it, this version handles making "We" into capitals at the start of a line. To do this we need to know where what you type really starts (that is, the word "say" is not the start of the line), so we need to change the alias to match on all the ways you can talk (see below). It uses the | character as an "or" operator (ie. say or yell or chat). You can expand that to do other talking operators. Note the space after each word, as you wouldn't type "sayhello". I have also allowed for talking with the quote symbol, eg.


"hi there


In this case I assume no space.

Now what we do is the same as before, except at the end we change "we" at the start of the line (ie. "^we") to "We".

Also we have to put back the "action" word (say, chat etc.)


<aliases>
  <alias
   match="^(say |yell |chat |&quot;)(.*\bI\b.*)$"
   enabled="y"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>
phrase = "%2"

phrase = (string.gsub (phrase, "^I am ", "We are " ))

phrase = (string.gsub (phrase, " I am ", " we are " ))

phrase = (string.gsub (phrase, "%a+", { ["I"] = "we" } ))

phrase = (string.gsub (phrase, "^we ", "We " ))

Send ("%1" .. phrase)
</send>
  </alias>
</aliases>


Example:


say are you thinking what I am thinking? - I hope not

--> becomes:

say are you thinking what we are thinking? - we hope not


Amended on Thu 17 Jan 2008 07:47 PM by Nick Gammon
#3
Awesome, it works great! Thank you so much for your effort!
USA #4
Would it really matter if the "We" was supposed to be lowercase normally? I have no idea how much of a stickler you are for punctuation, but I thought that the royal pronoun for the self was always capitalized, being a proper noun. Granted, I may be totally off, since I never really payed all that much attention to the rules for nosism.
USA #5
Ok, after a bit of research, it appears I am wrong. Royal people are apparently less full of themselves than common people. They use lowercase when appropriate, whereas the common people insist they are worthy of capitals all the time. Did I ever mention I hate English?