Re: [rules-users] Fact Names in a Model

2011-12-13 Thread Esteban Aliverti
Even if you get the packages using REST API, you still need to add them to
a kbuilder (you don't need to have multiple kbuilders. 1 kbuilder can
contain multiple packages).
What you can do if you don't want to manually add all the packages to a
kbuilder is to create a change-set, which is basically an xml pointing to
all the resources you want to add. Then, you add the change-set to the
kbuilder with ResourceType.CHANGE_SET. For more information about
change-sets, please refer to the documentation.

Best Regards  ,



Esteban Aliverti
- Developer @ http://www.plugtree.com
- Blog @ http://ilesteban.wordpress.com


On Tue, Dec 13, 2011 at 6:21 AM, srinivasasanda wrote:

> Hi Esteban,
>
> *Listing Packages*
>
>
>KnowledgeBase kbase =
> KnowledgeBaseFactory.newKnowledgeBase();
>
>  kbase.addKnowledgePackages(kbuilder1.getKnowledgePackages());
>
>  kbase.addKnowledgePackages(kbuilder2.getKnowledgePackages());
>int flag=1;
>for(KnowledgePackage kp :kbase.getKnowledgePackages())
>{
>
>
>System.out.println("Package Names
> are"+kp.getName());
> }
> The code which i had written here can possible to retrieves  the
> list of packages.Here,I added snapshots to kbuilder1,kbuilder2 and through
> kbase iam retrieving the packages list.Is it is possible to retrieve list
> of
> packages without adding package snapshots to kbuilder.???It means i think
> through repository.xml...How can i achieve that???
>
> Even i referred REST API but unable to retrieve XML nodes from it
>
>
>
>
> --
> View this message in context:
> http://drools.46999.n3.nabble.com/Fact-Names-in-a-Model-tp3572234p3581479.html
> Sent from the Drools: User forum mailing list archive at Nabble.com.
> ___
> 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] Fact Names in a Model

2011-12-12 Thread srinivasasanda
Hi Esteban,

*Listing Packages*


KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages(kbuilder1.getKnowledgePackages());
kbase.addKnowledgePackages(kbuilder2.getKnowledgePackages());
int flag=1;
for(KnowledgePackage kp :kbase.getKnowledgePackages())
{


System.out.println("Package Names are"+kp.getName());
}
 The code which i had written here can possible to retrieves  the
list of packages.Here,I added snapshots to kbuilder1,kbuilder2 and through
kbase iam retrieving the packages list.Is it is possible to retrieve list of
packages without adding package snapshots to kbuilder.???It means i think
through repository.xml...How can i achieve that???

Even i referred REST API but unable to retrieve XML nodes from it




--
View this message in context: 
http://drools.46999.n3.nabble.com/Fact-Names-in-a-Model-tp3572234p3581479.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


[rules-users] Fact Names in a Model

2011-12-12 Thread srinivasasanda
Yes Esteban,
There is a recent POST discussing it.But,I couldn't find
the answer and available API to achieve that.Any way,thanks for your
advice.I will surf the recent posts.If any update available for this dynamic
fact,please suggest me.

Thanks


--
View this message in context: 
http://drools.46999.n3.nabble.com/Fact-Names-in-a-Model-tp3572234p3578965.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] Fact Names in a Model

2011-12-12 Thread Esteban Aliverti
I'm not sure about dynamically adding fields to a type. I think there is a
recent post discussing it.

Best Regards,



Esteban Aliverti
- Developer @ http://www.plugtree.com
- Blog @ http://ilesteban.wordpress.com


On Mon, Dec 12, 2011 at 8:38 AM, srinivasasanda wrote:

> Thanks Esteban,
>
>Its working fine.Can I enhance this code by adding one more field to
> *Man(name,age)*..
>
> It means i need to add field *state* to *Model* man from this Java code.How
> can i achieve this..can you please suggest me with the code.Really thanks
> for ur suggestions till far.Please help me in this.
>
> Thanks
>
>
> --
> View this message in context:
> http://drools.46999.n3.nabble.com/Fact-Names-in-a-Model-tp3572234p3578857.html
> Sent from the Drools: User forum mailing list archive at Nabble.com.
> ___
> 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] Fact Names in a Model

2011-12-11 Thread srinivasasanda
Thanks Esteban,

Its working fine.Can I enhance this code by adding one more field to
*Man(name,age)*..

It means i need to add field *state* to *Model* man from this Java code.How
can i achieve this..can you please suggest me with the code.Really thanks
for ur suggestions till far.Please help me in this.

Thanks


--
View this message in context: 
http://drools.46999.n3.nabble.com/Fact-Names-in-a-Model-tp3572234p3578857.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


[rules-users] Fact Names in a Model

2011-12-11 Thread srinivasasanda
Thanq Esteban..I combined my code and ur suggestions.Its worked fine..I've
doubt in Enumeration list.Could you please suggest me

--
View this message in context: 
http://drools.46999.n3.nabble.com/Fact-Names-in-a-Model-tp3572234p3578842.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] Fact Names in a Model

2011-12-09 Thread Esteban Aliverti
Well, there might be a way to do what you want, but you will need to go to
the dark side of drools :) (basically means magical castings)

A KnowwledgeBase contains one or more packages, and inside the packages is
where the Declared Types live.
So, using this code (I didn't test it but it should work), you can access
all your declared types of all the packages in a knowledge base:

Set declaredFactTypes = new HashSet();
Collection knowledgePackages =
kbase.getKnowledgePackages();
for (KnowledgePackage knowledgePackage : knowledgePackages) {
//the key of this map is the simple name of the declared type
and not the fqn
Map typeDeclarations =
((KnowledgePackageImp)knowledgePackage).pkg.getTypeDeclarations();
//collect all the keys in the set
for (String type : typeDeclarations.keySet()) {
//store the fqn of the declared types to avoid name
collision
declaredFactTypes.add(knowledgePackage.getName()+"."+type);
}
}

Best Regards,


Esteban Aliverti
- Developer @ http://www.plugtree.com
- Blog @ http://ilesteban.wordpress.com


On Fri, Dec 9, 2011 at 12:43 PM, srinivasasanda wrote:

> Thanks Lauene for your response.Really Thank you very much.
>
> I've tried with this code,as u said it is being not as much as
> stable.Trying
> to work out it.By the way,Here there is no way to retrieve the fact
> names.My
> requirement is
>
> I'm having a package---*PersonDetails*
>
> In that I declared a Model called*Person*
>
> In that I declared two facts with two fields called --*Man
> (name,age) Women(name,age)*
>
> Now,My objective is to print the factnames in console.It means My output
> should be FactNames are *Man and Women*.Is it possible?
>
> How can I achieve this.Can you please suggest me please according to my
> requirement.
>
>
>
> --
> View this message in context:
> http://drools.46999.n3.nabble.com/Fact-Names-in-a-Model-tp3572234p3572703.html
> Sent from the Drools: User forum mailing list archive at Nabble.com.
> ___
> 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] Fact Names in a Model

2011-12-09 Thread srinivasasanda
Thanks Lauene for your response.Really Thank you very much.

I've tried with this code,as u said it is being not as much as stable.Trying
to work out it.By the way,Here there is no way to retrieve the fact names.My
requirement is 

I'm having a package---*PersonDetails*

In that I declared a Model called*Person*

In that I declared two facts with two fields called --*Man
(name,age) Women(name,age)*

Now,My objective is to print the factnames in console.It means My output
should be FactNames are *Man and Women*.Is it possible?

How can I achieve this.Can you please suggest me please according to my
requirement.



--
View this message in context: 
http://drools.46999.n3.nabble.com/Fact-Names-in-a-Model-tp3572234p3572703.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] Fact Names in a Model

2011-12-08 Thread Wolfgang Laun
This should contain all the code you need. Some of this is NOT from
the "stable API" although it retrieves only information that's bound
to be stable. (Another thing I keep harping about, from time to time.)
Below is a class that does some cross referencing as any serius SW
develoment would need for documentation of its DRL code, and it irks
me considerably that you have to use the "instable API" for simple
things like that.

It's working with 5.2.0, so it should do so with 5.3/4.0, but -
remember, "not stable" --  you never know. It has not been tested
extensively, e.g., for nested combinations of various flavours of
"from". It does not handle "eval" expressions and whatever goes on in
constraint expressions.

Invoke it, e.g., like this:
 RulesByClasses rbc = new RulesByClasses();
 rbc.print( kBase );

-W

//
package cc.laun.drools;

import java.io.PrintStream;
import java.util.Formatter;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.drools.KnowledgeBase;
import org.drools.base.ClassObjectType;
import org.drools.definition.KnowledgePackage;
import org.drools.definitions.impl.KnowledgePackageImp;
import org.drools.rule.Accumulate;
import org.drools.rule.Collect;
import org.drools.rule.EntryPoint;
import org.drools.rule.EvalCondition;
import org.drools.rule.Forall;
import org.drools.rule.From;
import org.drools.rule.GroupElement;
import org.drools.rule.Pattern;
import org.drools.rule.Rule;
import org.drools.spi.ObjectType;

public class RulesByClasses {
  private Formatter fmt;
  private String ruleName;
  private String packageName;
  private Map> class2rules;

  public RulesByClasses( PrintStream printStream ){
fmt = new Formatter( printStream );
  }

  public RulesByClasses(){
this( System.out );
  }

  private void register( String className ){
Set ruleSet = class2rules.get( className );
if( ruleSet == null ){
  ruleSet = new HashSet();
  class2rules.put( className, ruleSet );
}
ruleSet.add( "\"" + ruleName + "\" in " + packageName );
  }

  private void inspectCollect( Collect collect ){
inspectPattern( collect.getSourcePattern() );
inspectNestedElements( collect.getNestedElements() );
  }

  private void inspectAccumulate( Accumulate accumulate ){
inspectNestedElements( accumulate.getNestedElements() );
  }

  private void inspectFrom( From from ){
inspectNestedElements( from.getNestedElements() );
  }

  private void inspectNestedElements( List nested ){
for( Object o: nested ){
  if( o instanceof Pattern ){
inspectPattern( (Pattern)o );
  } else if( o instanceof GroupElement ){
inspectGroupElement( (GroupElement)o );
  } else if( o instanceof Forall ){
inspectForall( (Forall)o );
  } else if( o instanceof Collect ){
inspectCollect( (Collect)o );
  } else if( o instanceof Accumulate ){
inspectAccumulate( (Accumulate)o );
  } else if( o instanceof From ){
inspectFrom( (From)o );
  } else if( o instanceof EntryPoint ){
//...
  } else {
throw new IllegalStateException( "unexpected CE " + o.getClass() );
  }
}
  }

  private void inspectPattern( Pattern pattern ){
ObjectType objectType = pattern.getObjectType();
if( objectType instanceof ClassObjectType ){
  ClassObjectType classObjectType = (ClassObjectType)objectType;
  register( classObjectType.getClassName() );
}
inspectNestedElements( pattern.getNestedElements() );
  }

  private void inspectForall( Forall forall ){
inspectNestedElements( forall.getNestedElements() );
  }

  private void inspectGroupElement( GroupElement groupElement ){
for( Object o: groupElement.getChildren() ){
  if( o instanceof Pattern ){
inspectPattern( (Pattern)o );
  } else if( o instanceof GroupElement ){
inspectGroupElement( (GroupElement)o );
  } else if( o instanceof Forall ){
inspectForall( (Forall)o );
  } else if( o instanceof EvalCondition ){
// ...
  } else {
throw new IllegalStateException( "unexpected CE " + o.getClass() );
  }
}
  }

  private void inspect( KnowledgePackage kPackage ){
packageName = kPackage.getName();
for( org.drools.definition.rule.Rule ruleCopy: kPackage.getRules() ){
  ruleName = ruleCopy.getName();
  Rule rule = (Rule)((KnowledgePackageImp)kPackage).getRule( ruleName );
  inspectGroupElement( rule.getLhs() );
}
  }

  private void emit(){
for( Map.Entry> entry: class2rules.entrySet() ){
  fmt.format( "Class %s%n", entry.getKey() );
  for( String ruleNamePack: entry.getValue() ){
fmt.format( "  %s%n", ruleNamePack );
  }
}
  }

  public void print( KnowledgePackage kPackage ){
class2rules = new HashMap>();
inspect( kPackage );
emit();
  }

  public void print( KnowledgeBase kBase ){
cla

Re: [rules-users] Fact Names in a Model

2011-12-08 Thread srinivasasanda
Thank you Esteban,

   I referred API,I'm able to retrieve rule-names present in a package.But
could not able to retrieve Declarative Model names,and Facts present in that
declarative Model in that package.Here,is my code to retrieve rule names in
a package.

//.Added Kbuilder to
Collection kpackages = kbuilder2.getKnowledgePackages();
for(KnowledgePackage kpackage : kpackages) {

System.out.println(kpackage.getClass().getDeclaredClasses().toString());
for(org.drools.definition.rule.Rule rule : 
kpackage.getRules()) {
System.out.println(rule.getName());
}
}

Can I enhance this code to get Model names and Fact names(which are present
in that model).

Please help me..I'm struggling in this since last week

--
View this message in context: 
http://drools.46999.n3.nabble.com/Fact-Names-in-a-Model-tp3572234p3572275.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] Fact Names in a Model

2011-12-08 Thread Esteban Aliverti
This is the API available for that:
https://hudson.jboss.org/hudson/view/Drools%20jBPM/job/drools/lastSuccessfulBuild/artifact/drools-docs/drools-expert-docs/target/docbook/publish/en-US/html_single/index.html#d0e3750

Best Regards,



Esteban Aliverti
- Developer @ http://www.plugtree.com
- Blog @ http://ilesteban.wordpress.com


On Fri, Dec 9, 2011 at 7:46 AM, srinivasasanda wrote:

> How to get fact names present in a declarative model of a package.Could you
> please suggest me the classes available.
>
>
>
> --
> View this message in context:
> http://drools.46999.n3.nabble.com/Fact-Names-in-a-Model-tp3572234p3572234.html
> Sent from the Drools: User forum mailing list archive at Nabble.com.
> ___
> 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] Fact Names in a Model

2011-12-08 Thread srinivasasanda
How to get fact names present in a declarative model of a package.Could you
please suggest me the classes available.



--
View this message in context: 
http://drools.46999.n3.nabble.com/Fact-Names-in-a-Model-tp3572234p3572234.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users