Solved

RegEx vs If condition while using VB.Net

Posted on 2004-10-11
7
608 Views
Last Modified: 2012-08-14
I have an application where I have to allow the users to modify and add criteria to populate multiple fields of a report (we're is a production assembly line environment).  In a simplified version:  We produce 1000 customized widgets a day.  Each widget requires different parts and or actions and the report is to tell each of the 20 stations what part or action they need to do. Since we have 20 production lines and each customized widget requires about 500 parts and/or actions , I need a way to take the schedule (Input 1) and compare it to a bill of material for each part in the schedule (Input 2) and apply rules (either regex or if conditions) to create a 50 column report.  The 1st column has the Serial Number and the other columns have the anwser to the rules.  So to summarize: for each serial number in Input1, I'll be looking at every part and description in the Bill of material (Input2) and filling in the blanks of the report (we do not make a column for all 500 parts ... just the parts that make it customized)

Now the question:  Since I have so much data to process (1000 widgets with 500 parts) and each column may require up to 20 coditions (rules), am I better to store the rules as regex expressions and cycle thru it that way OR am I better to store the rules as discreet if/and/or conditions and dynamically create the rules while I cycle thru the list.
0
Comment
Question by:LanWorks
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 84

Expert Comment

by:ozo
Comment Utility
Could you give some examples of the type of conditions you will be testing?
0
 

Author Comment

by:LanWorks
Comment Utility
Example: the user would specify that for Model numbers that do not start with 38 and have the last 2 digits of the component being any of these (X1,X2,X3,X4,X5,SS,SA,SB,ETC..) then include the component part number in the 8th column and the 23rd column.   The next rule after that might be that if there is something in column 8, and the component="99sx3" then include the componet in column 9 (remember I have to test every line of the Bill of Ladeb for every model)

This is an sample of the 1st 37 characters (out of 250 characters) for 3 of the rows of data (input 2):
09/01/04  38AxD  99Sx1  SEALER,long
09/01/04  39AxD  99Sx2  SEALER,long
09/01/04  39AxD  99Sx3  SEALER,xlong

The question at  http://www.experts-exchange.com/Programming/Q_21163802.html explained is a little differently

0
 
LVL 6

Expert Comment

by:etmendz
Comment Utility
You can use a series of If conditions and then use RegEx as the tool for your If statements if necessary. To be exact, you can actually create 1 If entry per column with rules. This should keep maintenance simpler as well. For example:

If IsColumn2Rule1Ok() Then
 If IsColumn2Rule2Ok() Then
  ...
 Else
  ...
 End If
End If

If IsColumn6Rule1Ok() Then
 ...
End If

...

The IsColumn#Rule#Ok methods may contain your RegEx tests and other tests necessary to meet a specific rule.

So what do you need? A result set (SqlDataReader) and your IsColumn#Rule#Ok methods to process per column. RegEx is just a tool here when needed.

Have fun...
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 11

Expert Comment

by:pratap_r
Comment Utility
LanWorks,

since you are using VB.Net its easier for you to go with Regex, my suggestion would be to store these rules in a seperate file database or xml file (whatever you need) rather than hardcoding it in the program. this way you can add the rules dynamically without having to recompile everytime.. also your number of lines of code will be less.. maintainance will be easy too..

let me know if you need help with the logic

Enjoy!
Pratap
0
 
LVL 6

Expert Comment

by:etmendz
Comment Utility
Hmmm... pratap_r has an interesting point somehow though I can't imagine how a new rule can be automatically supported in a program without re-compiling. In this case, I am seeing the rule as a condition which triggers an action.

- Given an If, you fill up its body with actions. So if there is a new rule in the database, it is still likely that you'll need to recompile in order to define the action for the new rule. Consider also when a rule is a nested If structure...

- Given an If, its actions may be unique in form and style. So if there are new actions to a new rule, you'd still need to recompile in order to support the new rule's new action.

But, given your experience, you can identify and pre-build known "action patterns" into methods.

So if you have time, you can start abstracting early and then invent a data-driven engine as suggested by pratap_r. He is of course correct in saying that this may be easier to maintain... More likely, you only need to re-compile when a new "action pattern" is required...

Have fun.
0
 
LVL 11

Accepted Solution

by:
pratap_r earned 500 total points
Comment Utility
Right, in a typical production environment as lanworks suggests its not that high end processing that is required and the number of outcomes is possibly predefined.. its just the way of how to get it which differs.. in the given scenario the requirement is to get the part number, but how,when and where we get this part number will be specified in the rules... this does not require recompilation. its just a way of storing a pattern in a file or someplace and using that to filter out the inputs.. the result is your part number.. or a predefined output.. now if you want the output to be processed through a logic its a whole different scenario.

in a project i did for a client, we were required to match a set of rules and based on the outcome generate reports (or emails basically) and further they wanted a custom rule entry where they will have an option of puting their own code in.. now we dint want them to keep compiling their code, so we had two options give them a rule engine, something on the terms of a python interface or go for plugins (compiled code).. the client being comfortable with plugins we went with the plugin model.. each time they require special processing to be done on an output they will provide an additional custom component which they will plugin to the main framework.. sounds ok? :-) no recompilation to the main program and no affecting production schedules..

Enjoy!
Pratap
0
 

Author Comment

by:LanWorks
Comment Utility
I started the project today using pure RegEx.  The logic went as follows:
1) Cycle thru each line of the Bill of Material (BOM)
2) ... concatenate the fields into a long string (to make it easier to RegEx search)
3) ... Cycle thru each RegEx rule looking for a match
4) ... if regex found a match, then look in the rules "Action" table
5) .... after I find the ruleAction, I find what needs to be updated with what info and extract it and write

I then changed horses and started writting it using If conditions:
1) Cycle thru each line of the Bill of Material (BOM)
2) ... Cycle thru each If_Condition rule looking for a match
3) ... If all of the If_Conditions for a rule set matched, the look in the rules "Action" table
4) ...  after I find the ruleAction, I find what needs to be updated with what info and extract it and write

The If_Conditions are easier to write (RegEx is just hard), and I save the string concatenate.  But I plan to take advantage of RegEx where they have a string of OR CONDITIONS (such as the last 2 digits equal to CA or CB or CC or CD or CE or CF) because Regex can drop the search to (CA|CB|CC|CD|CE|CF)

So the bottom line is that I will have a fully table driven application that has extensive rules that will not need to be recompiled.  I have not finished the project so I'm obviously optimistic, but at least I finally decided which way to go.

Thank all for their input


0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
for loop with Set 4 45
noX challenge 17 75
How does Google get such fast response times? 5 119
Regular expressions Exclude patter 3 8
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
A short article about problems I had with the new location API and permissions in Marshmallow
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now