Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 530
  • Last Modified:

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

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
kennethfine
Asked:
kennethfine
  • 3
  • 2
1 Solution
 
Jaime OlivaresSoftware ArchitectCommented:
well, indeed correct term is "state machines".
There are lots of good examples at codeproject.com, search for the 'state machine' keywords
0
 
kennethfineAuthor Commented:

Thanks. Can someone give an explanation? I read the Wikipedia articles on both "state diagrams" and "state machines" and found them unsatisfying.
0
 
Christopher KileCommented:
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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
kennethfineAuthor Commented:
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
 
Christopher KileCommented:
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
 
kennethfineAuthor Commented:
Thanks. I was most interested in "theory" here and your post provided an excellent introduction. Much appreciated!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now