Solved

Please teach me about how to implement state diagrams in C#

Posted on 2008-06-22
6
521 Views
Last Modified: 2008-06-24
This is not homework.

I am interested in scanning large amounts of textual content for many different search terms of interest.

I am told that using a "state diagram" is an efficient method to do this. I don't know if this is true and indeed it is likely that I will use a prebuilt product to do this. However, I would like to learn this as a matter of principle.

I would like it very much if you could show me a C# implementation of a state diagram. It would also help if you could comment the code and advise what state diagrams are and are not good for. Most helpful if you can teach me what you know.

thank you!

0
Comment
Question by:kennethfine
  • 3
  • 2
6 Comments
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 21843477
well, indeed correct term is "state machines".
There are lots of good examples at codeproject.com, search for the 'state machine' keywords
0
 
LVL 6

Author Comment

by:kennethfine
ID: 21843737

Thanks. Can someone give an explanation? I read the Wikipedia articles on both "state diagrams" and "state machines" and found them unsatisfying.
0
 
LVL 23

Accepted Solution

by:
Christopher Kile earned 500 total points
ID: 21847965
A "state" is simply the list of descriptions of your current situation.  Your clothes are dirty, your kitchen sink is filled with dishes, and you're running late.  An "event" occurs, such as "doing the dishes".  Your state is now "clothes are dirty, kitchen sink is empty, and you're running later than you were."

Don't complicate the idea of states too much.  Keep clear in your head that states are mundane lists of what is.  I made the mistake of overcomplicating on my first attempt at designing a state machine that determined what the remainder of dividing a binary number by 3 would be; my state machine "worked", but I had eleven states - of course, there are naturally only three states, those being remainder 0, remainder 1, and remainder 2.

You will have to describe every possible state for your system if you're building a state machine.  You also need to describe, for a given state, what state you will be in for each possible event that can change the given state to another state (some events, like "call your buddy to find out when the game is tonight", don't change the state at all; some events such as "burn the house down because you don't want to clean it" are not permitted events and require exception handling (such as police restraint and fire suppression)).

When you're processing text, sometimes simple state machines are not enough.  Compiling source code to something that can run on a computer is a typical example, as this frequently requires a "pushdown automaton" where one state machine is "pushed" onto a stack while another state machine is tested to see whether it can process the remainder of the text or not, with the idea of picking the state machine from an available list that process the greatest amount of the remaining text while not leaving text that cannot be processed by any available state machine.

Thus, simply learning about state machines may not solve your problem.  What sort of text processing are you trying to do?
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 6

Author Comment

by:kennethfine
ID: 21851454
Thanks very much for your time, cpkilekofp. I am first just interested in learning in these general concepts and your message is very helpful in that regard.

I am interested in matching large groups of short terms against a large collection of content. My best bet as a production thing will probably be to use a prebuilt indexing solution that exposes an API and work against that. However, it would be interesting to learn efficient ways of doing the same work "by hand" for instances where I don't want to work against an index or don't have an index.
0
 
LVL 23

Expert Comment

by:Christopher Kile
ID: 21856381
Hmmmmm....there is no general case for efficient ways of doing it "by hand."  The problem is sensitively dependent on the format of your data, and free-form text is the worst case.

Have you experimented with regular expressions?  Matching a regular expression to your input as you read it is a common way of generating an event.
0
 
LVL 6

Author Comment

by:kennethfine
ID: 21856445
Thanks. I was most interested in "theory" here and your post provided an excellent introduction. Much appreciated!
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The greatest common divisor (gcd) of two positive integers is their largest common divisor. Let's consider two numbers 12 and 20. The divisors of 12 are 1, 2, 3, 4, 6, 12 The divisors of 20 are 1, 2, 4, 5, 10 20 The highest number among the c…
When there is a disconnect between the intentions of their creator and the recipient, when algorithms go awry, they can have disastrous consequences.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question