I have a question based on your reply below (I also started a thread but
figured maybe we can continue the reference to what you said below). I
understand the code you typed below, but I have a question. What if I want
to create multiple KnowledgeBase objects and feed them the "same"
KnowledgePackages that I have in memory? Is that legal? Is there anything
against that? I am trying to do that in my code and after some time one of
my newly created KnowledgeBases (usually after 20 or so creations of
KnowledgeBases) just gets stuck on the addKnowledgePackages call and never
returns from it!! Any idea what that may be? Any hint or suggestion on how I
want to go about creating multiple knowledge bases but share the same set of
pre-compiled rules (knowledge packages)?
Thanks in advance.
Wolfgang Laun-2 wrote:
This is what you might do:
KnowledgeBase kBase = KnowledgeBaseFactory.newKnowledgeBase();
KnowledgeBuilder kBuilder =
KnowledgeBuilderFactory.newKnowledgeBuilder();
kBuilder.add( ResourceFactory.newFileResource( "Movie.drl" ),
ResourceType.DRL );
if( kBuilder.hasErrors() ){
for( KnowledgeBuilderError err: kBuilder.getErrors() ){
System.out.println( err.toString() );
}
throw new IllegalStateException( "DRL errors" );
}
OutputStream os = new FileOutputStream( "Movie.pkg" );
ObjectOutputStream oos = new ObjectOutputStream( os );
oos.writeObject( kBuilder.getKnowledgePackages() );
// And now, from the file containing the binary knowlewdge packages:
InputStream is = new FileInputStream( "Movie.pkg" );
ObjectInputStream ois = new ObjectInputStream( is );
@SuppressWarnings("unchecked")
Collection<KnowledgePackage> kpkgs =
(Collection<KnowledgePackage>)
ois.readObject();
ois.close();
kBase.addKnowledgePackages( kpkgs );
-W
2009/5/2 Perumaal Krishnaraj <perumaal.k(a)gmail.com>
> Hello Everybody,
> I'm a newbie to Drools, so please excuse me, if question is very
> fundamental.
> I'm not using drools with eclipse or brms.
> I would like to convert the drl file which I had created using a text
> editor to the binary form ie. in pkg format (serialized), which can be
> used
> im my Java application.
>
> Is there a tool, or a code snippet which gives me an idea as to how this
> is
> done.
>
> Regards,
> kp
>
>
>
>
> _______________________________________________
> rules-users mailing list
> rules-users(a)lists.jboss.org
>
https://lists.jboss.org/mailman/listinfo/rules-users
>
>
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
--
View this message in context:
http://n3.nabble.com/drl-to-pkg-tp58983p96934.html
Sent from the Drools - User mailing list archive at
Nabble.com.