Welcome, Guest. Please login or register.
Kingdoms of Ahln
Pages: [1]
  Print  
Author Topic: communication parsing  (Read 226 times)
Joseph
Wanderer
*
Posts: 13


View Profile
« on: December 16, 2011, 06:18:27 pm »

Hey Justin .. I am thinking about making a few changes to the communication parsing.. please take a look at https://gist.github.com/1488853 and let me know what you think.  Not done with it yet but I think there is enough there that you can tell where I intend to go with it.  Please leave feedback +/-.  It will save me time working on it if its something you completely dislike.
Logged
Joseph
Wanderer
*
Posts: 13


View Profile
« Reply #1 on: December 17, 2011, 04:28:26 am »

Also was wondering, forgive me for being an enthusiast programmer (aka limited knowledge), is there a reason that the command lists are Sets and not Arrays?  Can you explain the benefit to me of using Sets?
Logged
Joseph
Wanderer
*
Posts: 13


View Profile
« Reply #2 on: December 18, 2011, 04:20:21 pm »

Have the test code working for say and whisper commands now, think I will clean it up and put in a few class methods to handle the command parsing before I finish w/ tell & reply.  The code is strongly commented now so that anyone can see what each part does.
Logged
Justin
Administrator
Citizen
*****
Posts: 189



View Profile
« Reply #3 on: December 18, 2011, 08:42:42 pm »

Hey Joseph, I apologize for not looking at your proposal in more depth at first. My life is quite busy and I don't do much with kams at this point in time. However, I have some feedback now...

Arrays vs. sets: it is faster to check to see if a value is in a set than in an array, particularly if the set is large.

Speaking of which, please note that all command parsing in kams begins by taking the first part of the input prior to a space (or the while thing if no spaces) and treating that as the command. Then the input is dispatched to a parsing method based on finding that command in one of the command lists. You can see that here. This means something like ::bob hey! is not going to be sent to your code unless ::bob is actually listed as a command (which it wouldn't be).

I think this approach should be maintained, because it helps keep command parsing from becoming too slow. This also means that (currently) there is no mechanism that allows shortest-match processing of commands like you are attempting with whisper.

Now that I am seeing more of it, the syntax (and the code) for your new system seems quite complex. Do you think it is something players would use instead of just emotes? (This is quite hypothetical...I don't know if anyone is using kams and actually has players.) Or the existing syntax, which allows you to add any text you want at the front of the output (I realize this is actually undocumented, oops):

Code:
>say (happily) Whee!

Happily, you exclaim, "Whee!"

In any case, have you considered using StringScanner? It might be simpler.

Logged
Joseph
Wanderer
*
Posts: 13


View Profile
« Reply #4 on: December 19, 2011, 10:57:29 am »


Quote
Hey Joseph, I apologize for not looking at your proposal in more depth at first. My life is quite busy and I don't do much with kams at this point in time. However, I have some feedback now...
Thank you greatly for the feedback, about being busy its not a problem at all, you are offering much more than I had expected.  Ill try to shoot you a pm w/ my intentions & plans when I get a few more minutes.

Quote
Arrays vs. sets: it is faster to check to see if a value is in a set than in an array, particularly if the set is large.
Sweet thanks for the information! I never knew about sets, read that they had the 'fast lookup abilities of a hash' but wasn't really sure if that would apply here.

Quote
Speaking of which, please note that all command parsing in kams begins by taking the first part of the input prior to a space (or the while thing if no spaces) and treating that as the command.

This was one of the changes I have on my ToDo list. From the 'lazy player' perspective this is one of the first things that I noticed about kams.  I intend to change command parsing to allow the player to type for example rem shirt, rather than having to type remove completely.  As part of the rewrite Ill have the command parser grab everything before the first whitespace or "common command operator" and search for an exact match.. failing an exact match for commands other than admin, issues etc I will let a simple regex find the correct command.  Yes I understand that most mudui now-a-days allow for aliasing but I wouldn't want or expect a new player to decide how they want to shorthand each command and write an alias for them all.


Quote
I think this approach should be maintained, because it helps keep command parsing from becoming too slow. This also means that (currently) there is no mechanism that allows shortest-match processing of commands like you are attempting with whisper.

Ill try it out and let you know what the processing difference is, but in reality this is a text-based game unless we create a memory leak somewhere I don't see parsing as something that will slow it down to a noticeable level.. unless lets say someone using kams manages to get 10k+ players online & scripting.

Quote
Now that I am seeing more of it, the syntax (and the code) for your new system seems quite complex. Do you think it is something players would use instead of just emotes?
Yes It does have a complex option, but it also has many very simple options.  for example just putting ? ! . at the end of a communication phrase changes the verb.  As well as things like whisper defaulting to quietly..   Ive played games w/ similar .. and less complex options before, and honestly I think that a mix is the best.. it gives something to everyone (the players that want to be able to talk simply, and the players that want to delve deeply into the roleplay and look 'cool' while they are doing it.)

Quote
Code:
>say (happily) Whee!

Happily, you exclaim, "Whee!"

Oyi nope I didn't know about that.. I will have to find that thanks for the heads up.. easier to not break something that I know exists.

Quote
In any case, have you considered using StringScanner? It might be simpler.

  Ive taken a look at it, I don't really like the way it duplicates the strings, but basically with that exception I am effectively re-inventing the wheel by doing the command parsing in a fashion similar to what strscan does.
Logged
Justin
Administrator
Citizen
*****
Posts: 189



View Profile
« Reply #5 on: December 19, 2011, 06:50:29 pm »

I think your plan for command completion sounds good Smiley
Logged
Joseph
Wanderer
*
Posts: 13


View Profile
« Reply #6 on: December 20, 2011, 10:01:24 am »

Well you were correct, with my current parsing it is pretty slow, test.rb uses my parsing method, test2 uses the parsing method currently in KAMS. First test is 30k commands, second is 300k

Quote
joseph@HP-Pro-3125-Microtower-PC:~/absurd$ ruby test.rb
2011-12-20 19:57:49 +0200
2011-12-20 19:57:50 +0200
1.619020324
joseph@HP-Pro-3125-Microtower-PC:~/absurd$ ruby test2.rb
2011-12-20 19:57:52 +0200
2011-12-20 19:57:52 +0200
0.04745924
joseph@HP-Pro-3125-Microtower-PC:~/absurd$ ruby test2.rb
2011-12-20 19:59:10 +0200
2011-12-20 19:59:10 +0200
0.468879433
joseph@HP-Pro-3125-Microtower-PC:~/absurd$ ruby test.rb
2011-12-20 19:59:12 +0200
2011-12-20 19:59:30 +0200
17.584290297
joseph@HP-Pro-3125-Microtower-PC:~/absurd$

I will see what I can do to clean that up some.  Maybe I will try w/ strscan to see if it is just the way I wrote my loops w/ tons of if thens...
« Last Edit: December 20, 2011, 10:04:51 am by Joseph » Logged
Joseph
Wanderer
*
Posts: 13


View Profile
« Reply #7 on: December 24, 2011, 11:18:42 am »

Cleaner and tons faster so far, although not finished yet. I think I found a way to make it 1.8.7 compatiable aswell (uniguruma gem) will see how well that works.

Code:
module CommandParser
input = "':happy  ::   my sword=ask  #my helm Bol command operators work."
@comm_re = /^(?:(?<action>[^:\w#=]+))(?:(?::(?!:)\s*(?<adverb>[^:=#\s]+)|(?:::\s*(?<target>(?:my\s)[^\s:=#]+))|(?:#\s*(?<direction>(?:my\s)[^\s:=#]+))|(?:=\s*(?<verb>[^\s:=#]+)))\s*)+(?<message>[^\.\?!]+(?!\z))/i
    j =  @comm_re.match(input)
    e = Hash[j.names.zip(j.captures)]
    p e
end

Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by SMF 1.1.15 | SMF © 2006-2009, Simple Machines
Terra97 design by Bloc