Solved

RegEx vs If condition while using VB.Net

Posted on 2004-10-11
7
611 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
[X]
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
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 84

Expert Comment

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

Author Comment

by:LanWorks
ID: 12283384
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
ID: 12284480
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 11

Expert Comment

by:pratap_r
ID: 12284737
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
ID: 12285291
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
ID: 12285663
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
ID: 12292975
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
This is about my first experience with programming Arduino.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

697 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