Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 2008-06-22
6
522 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
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 
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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Article by: Nadia
Linear search (searching each index in an array one by one) works almost everywhere but it is not optimal in many cases. Let's assume, we have a book which has 42949672960 pages. We also have a table of contents. Now we want to read the content on p…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

829 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