Search code examples
javadroolskie

How to read drl file by using drools API? Is there any function in drools that can parse drl file into some value or other formats?


I am trying to visualize some drl file not using drools workbench(or business central). I've found the function to create drl file by passing value. However, I can't find the way to do opposite thing.

I expect to parse the existed drl file into some value or other format that can be easily used in my Vue project. At the moment I am looking for it in Drools souce code but can't find it.

I don't want to use drools workbench because it's not convenient enough to use. But if there are some functions or libraries in its souce code, please let me know. It's also very helpful.

I am using drools 7.0.0.final now.

Thanks for reading my question, if you have any idea, please help me.


Solution

  • I'm not sure about what you're trying to achieve, but let me give you some hints.

    The org.drools.compiler.compiler.DrlParser in the drools-compiler module will parse the DRL and generate the PackageDescr, pretty much an AST of the rule file. Take a look at org.drools.compiler.compiler.DrlParserTest for an example.

    The org.drools.compiler.builder.impl.KnowledgeBuilderImpl will create the *Impl* classes which are used by the runtime of Drools.

    Alternatively you can take a look at the drools-model-compiler module, in which theres a compiler org.drools.modelcompiler.builder.ModelBuilderImpl that compiles *Descrs into a Java DSL we created recently, the executable model. see org.drools.modelcompiler.CompilerTest and org.drools.modelcompiler.PatternDSLTest

    Let me know if it helps.

    Good luck