2

For below JSON, later mention drl syntax should suffice (Although haven't tested running drl but correction would be welcome)

{
  "category": [
    {
      "nlp": [
        {
          "mainCategory": "General"
        }
      ],
      "crawler": 
        {
          "isNLP": true,
          "mainCategory": "General"
        }

    }
  ],

  "uniqueId": "5695d7dae4b047806242cfbc0"
}

Drl Rule for testing "category.nlp.mainCategory" as "General" below:

When 
$basePojo:  BasePojo($categoryList:category)
$catgory :  Category($nlpList: nlp) from $categoryList
$nlp     :  Nlp(mainCategory=="General") from   $nlpList

Then
System.out.println("Document verfied");

Question: How do I use drools fluent Java API to write the above drl for "category.nlp.mainCategory" iteration?

I saw some helpful discussion on StackOverflow discussing drools Java API to write drl rules as here

http://docs.jboss.org/drools/release/5.2.0.Final/droolsjbpm-introduction-docs/html/ch02.html#d0e124

which creates few straight constraints in above official documentation.

Kimchy
  • 501
  • 8
  • 24
  • Since you already have the rule in DRL: what would be the point of using an API for composing it? Also, I think that the "fluent API" has been dropped; it's not in Drools 6.x. – laune Sep 02 '17 at 14:43
  • Basically, I have are a requirement to automate drl writing, I am expected to create a UI by a client to create rules and on backend write drl for UI created rules. – Kimchy Sep 02 '17 at 14:46
  • hi laune, check this out https://github.com/kiegroup/drools/blob/6.3.x/drools-compiler/src/test/java/org/drools/compiler/lang/api/DescrBuilderTest.java#L451-L465 and its for drools 6.3.x – Kimchy Sep 02 '17 at 15:10
  • So, laune as per your opinion how should i achieve this workflow if not fluent api? what is this entrypoint how do use it? can entrypoint help writing above iteration? – Kimchy Sep 02 '17 at 15:37
  • 1
    This is not part of the stable API. - What workflow? The rule fires whenever the list in BasePojo contains an element where mainCategory equals 'General'. Just insert one or more BasePojo objects as facts into a session. – laune Sep 02 '17 at 15:45
  • how do i achieve above drl syntax using fluent api then? – Kimchy Sep 02 '17 at 15:51
  • 1
    I could probably show you how to write a chain of calls just like the reference you have cited, with the rule text as its result. But why do you need this if you already have the text of the rule as a string? – laune Sep 04 '17 at 06:07
  • If you need to use this fluent API you locate the source files in the Drools source, study the code and the available examples. Then you experiment a little, and after a hour or two you'll know how to do it. – laune Sep 04 '17 at 06:09
  • referenced link only shows applying direct constraint but if I wish to write iteration performing condition as shown in above manual written conditions in drl file. – Kimchy Sep 05 '17 at 17:52
  • What do you want to iterate? Insert any number of BasePojo objects and the rule fires for each Category where the nlp field has mainCategory "General". If this isn't what you want, the fluent API won't help you. You'll have to know what you want before you author rules. – laune Sep 05 '17 at 18:06
  • As mainCatgory is part of nlp Class pojo instance which is actually referenced by BasePojo. So, if I am passing on BasePojo Class instance to drl. I will have to iterate the json structure to reach nlp which is a list and test mainCategory=="Politics". I am not going to pass nlp instance directly. – Kimchy Sep 05 '17 at 18:14
  • That is how, i would be able to match mainCategory=="Politics" . Whats your way of doing it? – Kimchy Sep 05 '17 at 19:03
  • But `from $nlpList` does iterate the list `Category.nlp`. -- It's all right asking questions here, but you are expected to know a little about the topic. – laune Sep 06 '17 at 12:35
  • hi laune, thanks for the suggestion but I am actually able to perform the drl iterations and above iteration is mentioned just to get clarity on how algorithm interpret and operates on the above drl condition and LHS RHS syntaxes. So, i was actually looking at how fluent api could be used to write various iteration syntaxes as the one mentioned above. – Kimchy Sep 06 '17 at 18:17
  • If you need to use this fluent API you locate the source files in the Drools source, study the code and the available examples. Then you experiment a little, and after a hour or two you'll know how to do it. – laune Sep 07 '17 at 01:22
  • I couldn't find any example related to fluent api apart from one test case (as link also shared) and i have tested most the test cases given there and i only couldn't do was adding code to drl in casr of iteration required. – Kimchy Sep 07 '17 at 02:44
  • I haven't jumped to drools source code but i did try to google and found one test case link (as also shared with you above) and only think left is adding line of syntax to lhs in case iterations required. On my part i alredy did basic api exploring work and when i got stuck i asked question here. I would check at source code again or other way. Thanks – Kimchy Sep 07 '17 at 02:52
  • If you have some source code that almost does what you want, post it here, making it clear what is missing. – laune Sep 07 '17 at 04:57

0 Answers0