[rules-users] Rule Templates and Array Handling
Hi All, I'm trying to determine if it's possible to process arrays of data using Rule Templates. An example of what I'm trying to accomplish. Spreadsheet of rules, with one of the columns being valid colors. Valid colors contains comma separated data and is variable length. For example It might contain: Blue, Green, Red or Blue, or Red, Green, Purple, Silver Any number of entries. I then need to process incoming fact values against this list of colors, using either CONTAINS or IN. For example: template header desc valid_colors[] package org.drools.examples.templates global com.sample.Product product; template ColorTestTemplate rule ColorRule_@{row.rowNumber} when product1 : Product (Color in @{valid_colors}); then product1.setDesc(@{desc}); end end template I know the following doesn't work: product1 : Product (Color in @{valid_colors}); However, I wanted to depict what I'm trying to accomplish. The challenge is with valid_colors being a variable length array, I can't refer to the individual values using constants i.e. valid_colors0, valid_colors1, valid_colors3, etc to build my array list. ie Color in (@{valid_colors0}, @{valid_colors1}, @{valid_colors2}) Is there a way to iterate through a variable length array in a template? Any thoughts on how I could build an array list i.e. (Blue, Green, Red) when the column contains a variable length array? Thanks in advance, Jason___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Rule Templates and Array Handling
In the spreadsheet (with class Country) you would have a column such as: CONDITION Country name in ( $param ) Test whether name is one from a given set Austria, Germany, Switzerland France, Canada, Belgium This is the generated rule: rule InTest_18 when $country: Country(name in ( Austria,Germany,Switzerland )) then System.out.println( German is spoken ); end You should be able to retrofit the template from this. (Why do you need a template when you have a spreadsheet?) -W On 14/06/2013, Jason Allen jason.al...@data-sign.com wrote: Hi All, I'm trying to determine if it's possible to process arrays of data using Rule Templates. An example of what I'm trying to accomplish. Spreadsheet of rules, with one of the columns being valid colors. Valid colors contains comma separated data and is variable length. For example It might contain: Blue, Green, Red or Blue, or Red, Green, Purple, Silver Any number of entries. I then need to process incoming fact values against this list of colors, using either CONTAINS or IN. For example: template header desc valid_colors[] package org.drools.examples.templates global com.sample.Product product; template ColorTestTemplate rule ColorRule_@{row.rowNumber} when product1 : Product (Color in @{valid_colors}); then product1.setDesc(@{desc}); end end template I know the following doesn't work: product1 : Product (Color in @{valid_colors}); However, I wanted to depict what I'm trying to accomplish. The challenge is with valid_colors being a variable length array, I can't refer to the individual values using constants i.e. valid_colors0, valid_colors1, valid_colors3, etc to build my array list. ie Color in (@{valid_colors0}, @{valid_colors1}, @{valid_colors2}) Is there a way to iterate through a variable length array in a template? Any thoughts on how I could build an array list i.e. (Blue, Green, Red) when the column contains a variable length array? Thanks in advance, Jason ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Rule Templates and Array Handling
Thanks for the reply Wolfgang. I chose to use the template because I liked the idea of separating the rule definition from the rule data. Just seemed intuitive to me. Overall, I'm new to Drools, so not sure if that is the best choice or not. I think your approach works if my spreadsheet has all the items separated with commas and double quotes. Because then it's just referring to the field as a simple string field, not an array of values. When the field is in the spreadsheet as: Austria, Germany, Switzerland it needs to be handled as an array, otherwise it will build the generated rule as: Country(name in (Austria, Germany, Switzerland)) and fail compile because it's missing the quotes. If you use @{country}) it will put (Austria, Germany, Switzerland), when you really need (Austria, Germany, Switzerland) Maybe I'll just embed the double quotes in the spreadsheet and call it a day, instead of fighting the field as an array of values. If you have any other thoughts, let me know! Thanks, Jason. On Jun 14, 2013, at 1:33 PM, Wolfgang Laun wolfgang.l...@gmail.com wrote: In the spreadsheet (with class Country) you would have a column such as: CONDITION Country name in ( $param ) Test whether name is one from a given set Austria, Germany, Switzerland France, Canada, Belgium This is the generated rule: rule InTest_18 when $country: Country(name in ( Austria,Germany,Switzerland )) then System.out.println( German is spoken ); end You should be able to retrofit the template from this. (Why do you need a template when you have a spreadsheet?) -W On 14/06/2013, Jason Allen jason.al...@data-sign.com wrote: Hi All, I'm trying to determine if it's possible to process arrays of data using Rule Templates. An example of what I'm trying to accomplish. Spreadsheet of rules, with one of the columns being valid colors. Valid colors contains comma separated data and is variable length. For example It might contain: Blue, Green, Red or Blue, or Red, Green, Purple, Silver Any number of entries. I then need to process incoming fact values against this list of colors, using either CONTAINS or IN. For example: template header desc valid_colors[] package org.drools.examples.templates global com.sample.Product product; template ColorTestTemplate rule ColorRule_@{row.rowNumber} when product1 : Product (Color in @{valid_colors}); then product1.setDesc(@{desc}); end end template I know the following doesn't work: product1 : Product (Color in @{valid_colors}); However, I wanted to depict what I'm trying to accomplish. The challenge is with valid_colors being a variable length array, I can't refer to the individual values using constants i.e. valid_colors0, valid_colors1, valid_colors3, etc to build my array list. ie Color in (@{valid_colors0}, @{valid_colors1}, @{valid_colors2}) Is there a way to iterate through a variable length array in a template? Any thoughts on how I could build an array list i.e. (Blue, Green, Red) when the column contains a variable length array? Thanks in advance, Jason ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Rule Templates and Array Handling
If you are expanding the template with data taken from anywhere you have the option of processing that data before you pass it to the expander. Section 2.5.2., Expanding a Template, explains how to do this. This is the option you have for implementing specific processing. The problem with data in a spreadsheet is that it doesn't have much of a data type along with it, so an entry such as x,y,z could be any of these: one string value, a list of numbers, a list of three string values, with quotes omitted, a list of enums, and so on. -W On 14/06/2013, Jason Allen jason.al...@data-sign.com wrote: Thanks for the reply Wolfgang. I chose to use the template because I liked the idea of separating the rule definition from the rule data. Just seemed intuitive to me. Overall, I'm new to Drools, so not sure if that is the best choice or not. I think your approach works if my spreadsheet has all the items separated with commas and double quotes. Because then it's just referring to the field as a simple string field, not an array of values. When the field is in the spreadsheet as: Austria, Germany, Switzerland it needs to be handled as an array, otherwise it will build the generated rule as: Country(name in (Austria, Germany, Switzerland)) and fail compile because it's missing the quotes. If you use @{country}) it will put (Austria, Germany, Switzerland), when you really need (Austria, Germany, Switzerland) Maybe I'll just embed the double quotes in the spreadsheet and call it a day, instead of fighting the field as an array of values. If you have any other thoughts, let me know! Thanks, Jason. On Jun 14, 2013, at 1:33 PM, Wolfgang Laun wolfgang.l...@gmail.com wrote: In the spreadsheet (with class Country) you would have a column such as: CONDITION Country name in ( $param ) Test whether name is one from a given set Austria, Germany, Switzerland France, Canada, Belgium This is the generated rule: rule InTest_18 when $country: Country(name in ( Austria,Germany,Switzerland )) then System.out.println( German is spoken ); end You should be able to retrofit the template from this. (Why do you need a template when you have a spreadsheet?) -W On 14/06/2013, Jason Allen jason.al...@data-sign.com wrote: Hi All, I'm trying to determine if it's possible to process arrays of data using Rule Templates. An example of what I'm trying to accomplish. Spreadsheet of rules, with one of the columns being valid colors. Valid colors contains comma separated data and is variable length. For example It might contain: Blue, Green, Red or Blue, or Red, Green, Purple, Silver Any number of entries. I then need to process incoming fact values against this list of colors, using either CONTAINS or IN. For example: template header desc valid_colors[] package org.drools.examples.templates global com.sample.Product product; template ColorTestTemplate rule ColorRule_@{row.rowNumber} when product1 : Product (Color in @{valid_colors}); then product1.setDesc(@{desc}); end end template I know the following doesn't work: product1 : Product (Color in @{valid_colors}); However, I wanted to depict what I'm trying to accomplish. The challenge is with valid_colors being a variable length array, I can't refer to the individual values using constants i.e. valid_colors0, valid_colors1, valid_colors3, etc to build my array list. ie Color in (@{valid_colors0}, @{valid_colors1}, @{valid_colors2}) Is there a way to iterate through a variable length array in a template? Any thoughts on how I could build an array list i.e. (Blue, Green, Red) when the column contains a variable length array? Thanks in advance, Jason ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Rule Templates and Array Handling
Thanks Wolfgang. I think I see what you're saying. If I need to do any complex prep, simply process it first, then build a collection of POJO objects for expansion by the drools template. I also understand what you're saying about spreadsheets. Most of this is just proof of concept I'm doing…I think you're right in maintaining the rule data somewhere else…i.e. database. Thanks again for your help. -Jason On Jun 14, 2013, at 3:01 PM, Wolfgang Laun wolfgang.l...@gmail.com wrote: If you are expanding the template with data taken from anywhere you have the option of processing that data before you pass it to the expander. Section 2.5.2., Expanding a Template, explains how to do this. This is the option you have for implementing specific processing. The problem with data in a spreadsheet is that it doesn't have much of a data type along with it, so an entry such as x,y,z could be any of these: one string value, a list of numbers, a list of three string values, with quotes omitted, a list of enums, and so on. -W On 14/06/2013, Jason Allen jason.al...@data-sign.com wrote: Thanks for the reply Wolfgang. I chose to use the template because I liked the idea of separating the rule definition from the rule data. Just seemed intuitive to me. Overall, I'm new to Drools, so not sure if that is the best choice or not. I think your approach works if my spreadsheet has all the items separated with commas and double quotes. Because then it's just referring to the field as a simple string field, not an array of values. When the field is in the spreadsheet as: Austria, Germany, Switzerland it needs to be handled as an array, otherwise it will build the generated rule as: Country(name in (Austria, Germany, Switzerland)) and fail compile because it's missing the quotes. If you use @{country}) it will put (Austria, Germany, Switzerland), when you really need (Austria, Germany, Switzerland) Maybe I'll just embed the double quotes in the spreadsheet and call it a day, instead of fighting the field as an array of values. If you have any other thoughts, let me know! Thanks, Jason. On Jun 14, 2013, at 1:33 PM, Wolfgang Laun wolfgang.l...@gmail.com wrote: In the spreadsheet (with class Country) you would have a column such as: CONDITION Country name in ( $param ) Test whether name is one from a given set Austria, Germany, Switzerland France, Canada, Belgium This is the generated rule: rule InTest_18 when $country: Country(name in ( Austria,Germany,Switzerland )) then System.out.println( German is spoken ); end You should be able to retrofit the template from this. (Why do you need a template when you have a spreadsheet?) -W On 14/06/2013, Jason Allen jason.al...@data-sign.com wrote: Hi All, I'm trying to determine if it's possible to process arrays of data using Rule Templates. An example of what I'm trying to accomplish. Spreadsheet of rules, with one of the columns being valid colors. Valid colors contains comma separated data and is variable length. For example It might contain: Blue, Green, Red or Blue, or Red, Green, Purple, Silver Any number of entries. I then need to process incoming fact values against this list of colors, using either CONTAINS or IN. For example: template header desc valid_colors[] package org.drools.examples.templates global com.sample.Product product; template ColorTestTemplate rule ColorRule_@{row.rowNumber} when product1 : Product (Color in @{valid_colors}); then product1.setDesc(@{desc}); end end template I know the following doesn't work: product1 : Product (Color in @{valid_colors}); However, I wanted to depict what I'm trying to accomplish. The challenge is with valid_colors being a variable length array, I can't refer to the individual values using constants i.e. valid_colors0, valid_colors1, valid_colors3, etc to build my array list. ie Color in (@{valid_colors0}, @{valid_colors1}, @{valid_colors2}) Is there a way to iterate through a variable length array in a template? Any thoughts on how I could build an array list i.e. (Blue, Green, Red) when the column contains a variable length array? Thanks in advance, Jason ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users