Re: [rules-users] how to create a list obj for a rule using 'memberOf'

2010-05-10 Thread eyal edri
Thanks!

I've found another way by using 'matches'. though i don't know which one
is preferable (performance speaking..).

rule Filter File Types
 salience 100 // priority
when
 FileType( type matches (ico|gif|jpg|mov|wmv|jpeg|css|bmp|avi|swf|png) )
 then
//TODO: change to actual action
 System.out.println(ALLOW);
end


2010/5/10 Esteban Aliverti esteban.alive...@gmail.com

 Maybe you can define a global List so you would not need to add it as a
 Fact:


 *package com.test.drools*
 * *
 *import com.test.drools.Facts.FileType;*
 *
 *
 *global java.util.List allowedExtensions;*
  * *
 *rule Filter File Types*
 * *
 * **when***
 * **FileType( type memberOf allowedExtensions )*
 * **then*
 * **System.out.println(ALLOW);*
 *end*

 You will need to set the global list before inserting any Fact:
 ksession.setGlobal(allowedExtensions,somePrePopulatedList);

 Best,


 2010/5/9 eyal edri eyal.e...@gmail.com

  Hi,

 sorry for the newbi question, i'm just starting to find my way in Drools.

 i want to  write a rule that filters URLs with a certain suffix (e.g. jpg,
 gif, css, etc...).

 i read about global vars and other variables and i'm not sure what to do.

 i need to create a List with all the suffixes i want to filter, should i
 create it inside FileType?

 can you help?

 Eyal.
 ---

 here's why i had so far:


 the .drl file:

 *package com.test.drools*
 * *
 *import com.test.drools.Facts.FileType;*
 *
 *
 * *
 *rule Filter File Types*
 * *
 * **when*
 *$fileTypes : ??? *
 * **FileType( type memberOf $fileTypes )*
 * **then*
 * **System.out.println(ALLOW);*
 *end*

 here's FileType:

 package com.commtouch.drools;

 import java.net.*;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;

 public class Facts {
  // return a file type of a url
  public static class FileType {

 private String type = html;

 public FileType (URL url) {
  // get the path from the url
  //TODO: use parser to do it?
  String path = url.getPath();
  if (path != null) {
  // define regex to extract file from path
  Pattern fileRegex = Pattern.compile(([^/]+)$);
  Matcher fileMatcher = fileRegex.matcher(path);
  // get regex capure $1 (filename)
  String file = null;
  while (fileMatcher.find())
  file = fileMatcher.group(1);

  String suffix = null;
  if (file != null)
  {
  //try to extract suffix from file
  Pattern suffixRegex = Pattern.compile(\\.([^\\.]+)$);
  Matcher suffixMatcher = suffixRegex.matcher(file);
  while (suffixMatcher.find())
  suffix = suffixMatcher.group(1);
  //verify that the suffix is a valid suffix
  if (suffix != null  (suffix.length() 1  suffix.length()  6))
  setType(suffix);
  }
  }
  }

  public void setType(String type) {
  this.type = type;
  }
  public String getType() {
  return type;
  }
 }
 }


 --
 Eyal Edri

 ___
 rules-users mailing list
 rules-users@lists.jboss.org
 https://lists.jboss.org/mailman/listinfo/rules-users




 --
 

 Esteban Aliverti

 ___
 rules-users mailing list
 rules-users@lists.jboss.org
 https://lists.jboss.org/mailman/listinfo/rules-users




-- 
Eyal Edri
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] how to create a list obj for a rule using 'memberOf'

2010-05-10 Thread Wolfgang Laun
You should add '^' and '$' to avoid matching with part of the type String.
-W

2010/5/10 eyal edri eyal.e...@gmail.com

 Thanks!

 I've found another way by using 'matches'. though i don't know which one
 is preferable (performance speaking..).

 rule Filter File Types
  salience 100 // priority
 when
  FileType( type matches (ico|gif|jpg|mov|wmv|jpeg|css|bmp|avi|swf|png) )
  then
 //TODO: change to actual action
  System.out.println(ALLOW);
 end


 2010/5/10 Esteban Aliverti esteban.alive...@gmail.com

 Maybe you can define a global List so you would not need to add it as a
 Fact:


 *package com.test.drools*
 * *
 *import com.test.drools.Facts.FileType;*
 *
 *
 *global java.util.List allowedExtensions;*
  * *
 *rule Filter File Types*
 * *
 * **when***
 * **FileType( type memberOf allowedExtensions )*
 * **then*
 * **System.out.println(ALLOW);*
 *end*

 You will need to set the global list before inserting any Fact:
 ksession.setGlobal(allowedExtensions,somePrePopulatedList);

 Best,


 2010/5/9 eyal edri eyal.e...@gmail.com

  Hi,

 sorry for the newbi question, i'm just starting to find my way in Drools.

 i want to  write a rule that filters URLs with a certain suffix (e.g.
 jpg, gif, css, etc...).

 i read about global vars and other variables and i'm not sure what to do.

 i need to create a List with all the suffixes i want to filter, should i
 create it inside FileType?

 can you help?

 Eyal.
 ---

 here's why i had so far:


 the .drl file:

 *package com.test.drools*
 * *
 *import com.test.drools.Facts.FileType;*
 *
 *
 * *
 *rule Filter File Types*
 * *
 * **when*
 *$fileTypes : ??? *
 * **FileType( type memberOf $fileTypes )*
 * **then*
 * **System.out.println(ALLOW);*
 *end*

 here's FileType:

 package com.commtouch.drools;

 import java.net.*;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;

 public class Facts {
  // return a file type of a url
  public static class FileType {

 private String type = html;

 public FileType (URL url) {
  // get the path from the url
  //TODO: use parser to do it?
  String path = url.getPath();
  if (path != null) {
  // define regex to extract file from path
  Pattern fileRegex = Pattern.compile(([^/]+)$);
  Matcher fileMatcher = fileRegex.matcher(path);
  // get regex capure $1 (filename)
  String file = null;
  while (fileMatcher.find())
  file = fileMatcher.group(1);

  String suffix = null;
  if (file != null)
  {
  //try to extract suffix from file
  Pattern suffixRegex = Pattern.compile(\\.([^\\.]+)$);
  Matcher suffixMatcher = suffixRegex.matcher(file);
  while (suffixMatcher.find())
  suffix = suffixMatcher.group(1);
  //verify that the suffix is a valid suffix
  if (suffix != null  (suffix.length() 1  suffix.length()  6))
  setType(suffix);
  }
  }
  }

  public void setType(String type) {
  this.type = type;
  }
  public String getType() {
  return type;
  }
 }
 }


 --
 Eyal Edri

 ___
 rules-users mailing list
 rules-users@lists.jboss.org
 https://lists.jboss.org/mailman/listinfo/rules-users




 --
 

 Esteban Aliverti

 ___
 rules-users mailing list
 rules-users@lists.jboss.org
 https://lists.jboss.org/mailman/listinfo/rules-users




 --
 Eyal Edri

 ___
 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] how to create a list obj for a rule using 'memberOf'

2010-05-10 Thread Greg Barton
If you want to restrict to a series of literals you might check if the in 
operator is faster:

rule Filter File 
Types

salience 100 // prioritywhen

FileType( type in 
(ico,gif,jpg,mov,wmv,jpeg,css,bmp,avi,swf,png) )

then//TODO: change to actual action

System.out.println(ALLOW);

end
I don't know if in is hashed behind the scenes, but if it is it probably 
would be much faster, especially because I think mvel recompiles the regex 
behind the scenes before each evaluation.  (A dev please correct me if I'm 
wrong on that last point.)

--- On Mon, 5/10/10, eyal edri eyal.e...@gmail.com wrote:

From: eyal edri eyal.e...@gmail.com
Subject: Re: [rules-users] how to create a list obj for a rule using 'memberOf'
To: Rules Users List rules-users@lists.jboss.org
Date: Monday, May 10, 2010, 2:25 AM

Thanks!
I've found another way by using 'matches'. though i don't know which one 
is preferable (performance speaking..).
rule Filter File Types

salience 100 // prioritywhen

FileType( type matches 
(ico|gif|jpg|mov|wmv|jpeg|css|bmp|avi|swf|png) )

then//TODO: change to actual action

System.out.println(ALLOW);

end

2010/5/10 Esteban Aliverti esteban.alive...@gmail.com


Maybe you can define a global List so you would not need to add it as a Fact:



package com.test.drools 

import com.test.drools.Facts.FileType;
global java.util.List allowedExtensions;



 rule Filter File Types   

when                



FileType( type memberOf allowedExtensions )



thenSystem.out.println(ALLOW);



end
You will need to set the global list before inserting any Fact: 
ksession.setGlobal(allowedExtensions,somePrePopulatedList);




Best,

2010/5/9 eyal edri eyal.e...@gmail.com




Hi,
sorry for the newbi question, i'm just starting to find my way in Drools.
i want to  write a rule that filters URLs with a certain suffix (e.g. jpg, gif, 
css, etc...).






i read about global vars and other variables and i'm not sure what to do.
i need to create a List with all the suffixes i want to filter, should i create 
it inside FileType? 






can you help?
Eyal.---
here's why i had so far:

the .drl file:






package com.test.drools import com.test.drools.Facts.FileType;






 rule Filter File Types

when

                $fileTypes : ???    FileType( type memberOf 
$fileTypes )





thenSystem.out.println(ALLOW);





end
here's FileType:
package com.commtouch.drools;


import java.net.*;import java.util.regex.Matcher;

import java.util.regex.Pattern;
public class Facts {

// return a file type of a url

public static class FileType {


private String type = html;






public FileType (URL url) {

// get the path from the url

//TODO: use parser to do it?

String path = url.getPath();

if (path != null) {

// define regex to extract file from path

Pattern fileRegex = Pattern.compile(([^/]+)$);

Matcher fileMatcher = fileRegex.matcher(path);

    // get regex capure $1 (filename)





String file = null;

    while (fileMatcher.find()) 





     file = fileMatcher.group(1);





    

    String suffix = null;





    if (file != null)





    {





    //try to extract suffix from file





    Pattern suffixRegex = 
Pattern.compile(\\.([^\\.]+)$);





Matcher suffixMatcher = 
suffixRegex.matcher(file);

while (suffixMatcher.find()) 

     suffix = suffixMatcher.group(1);





//verify that the suffix is a valid 
suffix 

if (suffix != null  (suffix.length() 
1  suffix.length()  6))

setType(suffix);

    }





}   





}


public void setType(String type) {





this.type = type;

}   

public String getType() {

return type;

}   }





}

-- 
Eyal Edri



___

rules-users mailing list

rules-users@lists.jboss.org

https://lists.jboss.org/mailman/listinfo/rules-users





-- 

[rules-users] how to create a list obj for a rule using 'memberOf'

2010-05-09 Thread eyal edri
Hi,

sorry for the newbi question, i'm just starting to find my way in Drools.

i want to  write a rule that filters URLs with a certain suffix (e.g. jpg,
gif, css, etc...).

i read about global vars and other variables and i'm not sure what to do.

i need to create a List with all the suffixes i want to filter, should i
create it inside FileType?

can you help?

Eyal.
---

here's why i had so far:


the .drl file:

*package com.test.drools*
* *
*import com.test.drools.Facts.FileType;*
*
*
* *
*rule Filter File Types*
* *
* **when*
*$fileTypes : ??? *
* **FileType( type memberOf $fileTypes )*
* **then*
* **System.out.println(ALLOW);*
*end*

here's FileType:

package com.commtouch.drools;

import java.net.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Facts {
 // return a file type of a url
 public static class FileType {

private String type = html;

public FileType (URL url) {
 // get the path from the url
 //TODO: use parser to do it?
 String path = url.getPath();
 if (path != null) {
 // define regex to extract file from path
 Pattern fileRegex = Pattern.compile(([^/]+)$);
 Matcher fileMatcher = fileRegex.matcher(path);
 // get regex capure $1 (filename)
 String file = null;
 while (fileMatcher.find())
 file = fileMatcher.group(1);

 String suffix = null;
 if (file != null)
 {
 //try to extract suffix from file
 Pattern suffixRegex = Pattern.compile(\\.([^\\.]+)$);
 Matcher suffixMatcher = suffixRegex.matcher(file);
 while (suffixMatcher.find())
 suffix = suffixMatcher.group(1);
 //verify that the suffix is a valid suffix
 if (suffix != null  (suffix.length() 1  suffix.length()  6))
 setType(suffix);
 }
 }
 }

 public void setType(String type) {
 this.type = type;
 }
 public String getType() {
 return type;
 }
}
}


-- 
Eyal Edri
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] how to create a list obj for a rule using 'memberOf'

2010-05-09 Thread Esteban Aliverti
Maybe you can define a global List so you would not need to add it as a
Fact:


*package com.test.drools*
* *
*import com.test.drools.Facts.FileType;*
*
*
*global java.util.List allowedExtensions;*
* *
*rule Filter File Types*
* *
* **when***
* **FileType( type memberOf allowedExtensions )*
* **then*
* **System.out.println(ALLOW);*
*end*

You will need to set the global list before inserting any Fact:
ksession.setGlobal(allowedExtensions,somePrePopulatedList);

Best,


2010/5/9 eyal edri eyal.e...@gmail.com

 Hi,

 sorry for the newbi question, i'm just starting to find my way in Drools.

 i want to  write a rule that filters URLs with a certain suffix (e.g. jpg,
 gif, css, etc...).

 i read about global vars and other variables and i'm not sure what to do.

 i need to create a List with all the suffixes i want to filter, should i
 create it inside FileType?

 can you help?

 Eyal.
 ---

 here's why i had so far:


 the .drl file:

 *package com.test.drools*
 * *
 *import com.test.drools.Facts.FileType;*
 *
 *
 * *
 *rule Filter File Types*
 * *
 * **when*
 *$fileTypes : ??? *
 * **FileType( type memberOf $fileTypes )*
 * **then*
 * **System.out.println(ALLOW);*
 *end*

 here's FileType:

 package com.commtouch.drools;

 import java.net.*;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;

 public class Facts {
  // return a file type of a url
  public static class FileType {

 private String type = html;

 public FileType (URL url) {
  // get the path from the url
  //TODO: use parser to do it?
  String path = url.getPath();
  if (path != null) {
  // define regex to extract file from path
  Pattern fileRegex = Pattern.compile(([^/]+)$);
  Matcher fileMatcher = fileRegex.matcher(path);
  // get regex capure $1 (filename)
  String file = null;
  while (fileMatcher.find())
  file = fileMatcher.group(1);

  String suffix = null;
  if (file != null)
  {
  //try to extract suffix from file
  Pattern suffixRegex = Pattern.compile(\\.([^\\.]+)$);
  Matcher suffixMatcher = suffixRegex.matcher(file);
  while (suffixMatcher.find())
  suffix = suffixMatcher.group(1);
  //verify that the suffix is a valid suffix
  if (suffix != null  (suffix.length() 1  suffix.length()  6))
  setType(suffix);
  }
  }
  }

  public void setType(String type) {
  this.type = type;
  }
  public String getType() {
  return type;
  }
 }
 }


 --
 Eyal Edri

 ___
 rules-users mailing list
 rules-users@lists.jboss.org
 https://lists.jboss.org/mailman/listinfo/rules-users




-- 


Esteban Aliverti
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users