Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DSL for situation definition #4

Open
pereirazc opened this issue Feb 4, 2017 · 2 comments
Open

DSL for situation definition #4

pereirazc opened this issue Feb 4, 2017 · 2 comments

Comments

@pereirazc
Copy link
Contributor

A straightforward dialect for situation writing/designing to be transpiled at runtime into drl rules.

The so-famous Fever situation could be described like:

package br.ufes.lprm.scene.examples.fever

situation Fever
  when
    @febrile: Person(temperature > 37)
end
  • The situation keyword would refer to a special kind of rule with no need for an explicit consequence (RHS) which would always be internal situation life cycle management code.
  • There would be no need for a static SituationType-descendant Java class. The situation declaration provides enough information for building the situation class dynamically. The @<label> construct would represent that the binding variable maps to a class attribute <label> as a situation role.

short-term downfalls:

  • situation only file: domain rules and events would be written apart from the situations, although, defined situations could be used by any domain business rule.
@pereirazc
Copy link
Contributor Author

The scene (.scn) code:

package br.ufes.lprm.scene.examples.fever

situation Fever
  when
    @febrile: Person(temperature > 37)

transpiles to drl code:

package br.ufes.lprm.scene.examples.fever

import ...

declare Fever extends SituationType
   febrile: Person @Role("febrile")
end
rule "Fever"
@role(situation)
@type(Fever)
  when
    $febrile: Person(temperature > 37)
  then
    SituationHelper.situationDetected(drools)
end

@pereirazc
Copy link
Contributor Author

There's a way to add knowledge packages from strings into a kbuilder ResourceFactory.newByteArrayResource CommonTestMethodBase.java

PackageDescrBuilder packageBuilder = DescrFactory.newPackage();
packageBuilder
		.name("br.ufes.lprm.scene.examples.fever")
		.newDeclare().type()
			.name("Fever")
			.superType("SituationType")
				.newField("febrile")
				.type("Person")
					.newAnnotation("Role").value("febrile")
				.end()
			.end()
		.end()
		.newRule().name("Fever")
			.newAnnotation("role").value("situation")
		.end()
			.newAnnotation("type").value("Fever")
		.end()
			.lhs()
				.pattern().id("$febrile", false)
					.type("Person").constraint("temperature > 37")
				.end()
			.end()
			.rhs("SituationHelper.situationDetected(drools);")
		.end();

String rules = new DrlDumper().dump(packageBuilder.getDescr());
kbuilder.add(ResourceFactory.newByteArrayResource(rules.getBytes()), ResourceType.DRL);

@pereirazc pereirazc changed the title Situation definition dialect DSL for situation definition Feb 4, 2017
@bsunderhus bsunderhus removed their assignment Apr 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants