Skip to content
This repository has been archived by the owner on Sep 20, 2021. It is now read-only.

Interpreted rule should be available in JSON format #1

Closed
bthibault opened this issue Oct 29, 2013 · 13 comments
Closed

Interpreted rule should be available in JSON format #1

bthibault opened this issue Oct 29, 2013 · 13 comments

Comments

@bthibault
Copy link

serialize(
Hoa\Ruler::interprete(
'logged(user) and group in ("customer", "guest") and points > 30'
)

This might be good for storing in a relational db, but for those of us using NoSql db like Mongo, It would be nice to get a JSON encoded rule model ...

@stephpy
Copy link
Member

stephpy commented Oct 29, 2013

Hi, i don't understand why json would be better than a raw text, you could insert it in a text field.

encode/decode json of a php code (Hoa\Ruler::interprete) return a php code is really difficult ...
encode/decode json a serialization of a phpcode is really difficult too ...

I'm not sure to see the benefits to implement this feature.

@bthibault
Copy link
Author

Hi stephpy,

The benefit would be interoperation with nosql querying language, in querying rules and rule sets.

See Rule Language here: https://code.google.com/p/jsonrules/wiki/RuleLanguage

If we had a JSON rule we could query through db something like - ( psuedocode ) db.rules.find( {"conditions": { "and" OR "or" } , "action": changeBackground " }});

You can do this kind of querying with with the raw text command, but it becomes much more powerful to offload this advanced querying to the db.

In my mind its better to always store a structured language , than raw english language

@Hywan
Copy link
Member

Hywan commented Oct 29, 2013

Hello :-),

So you want only a serializer, not a unserializer? And you want to respect the Json Rules specification?

@bthibault
Copy link
Author

Serializer would be nice, it could just use the current rule formatting, the Rule Language was just an example, I don't think it is a widely adopted format.

An unserializer isn't necessary right away. I can store the actual raw command as stephpy suggested to execute the rule.

I could also build an unserializer, if someone gets me started on the serializer, but i'm not quite familiar with the framework yet.

Thanks

@hoaproject
Copy link
Collaborator

I have a question. The goal here is not to serialize or unserialize the rule model but only to compile the model into JSON, in order to use it in some database engine. Ok. But how will you execute the rule in the database engine? Does the JSON rules format is supported by such engines? You have mentionned the JSON rules format as an example. Are there others?

@Hywan
Copy link
Member

Hywan commented Nov 18, 2013

@bthibault ping?

@bthibault
Copy link
Author

Hi there,

So let me walk you through my work flow.

  1. Creating a JS web front to allow a user to create a rule see - https://github.com/joshuamcginnis/rules-builder
  2. User can create multiple rules, so store each rule in a rules table tied to one piece of data and assign a priority for conflict resolution.
  3. The rule should be stored in the DB as json, so it can be easily queried, and pulled out of the db and back into the GUI form for editing.
  4. My thought was I could then translate that json to the 'natural language' Hoa ruler uses and store that command as well for processing by Hoa.

So maybe that helps clarify, I just need a consistent way to build , store, query rules. Really the missing piece is translating Hoa rules to a formatted, structured definition I can use and store (JSON (or XML))

Does that help clarify the issue?

@Hywan
Copy link
Member

Hywan commented Nov 19, 2013

If the goal is to translate rules into JSON, then the only thing one has to do is to create a new visitor, such as Visitor/Disassembly.php (Visitor/Asserter.php or Visitor/Compiler.php can also be inspiring).

Next questions are:

  • is it part of Hoa to create and maintain such a visitor?
  • is this JSON structure standard?
  • is it widespread?

Cheers :-).

@bthibault
Copy link
Author

  1. This is something you'll have to decide, I'm don't know enough about your plan or mission to provide any help with that.
  2. This structure is not standard, but I think it is standard to store rules as JSON ( see Nools http://c2fo.github.io/nools/)
  3. JSON and MongoDb are extremely widespread with web companies now, and mySQL is taking a back seat.

Either way. I'm going forward with Hoa/Ruler, Nools, or JBoss Drools. If I use Hoa/Ruler I will write a Visitor for JSON

Thanks
BT

@Hywan
Copy link
Member

Hywan commented Nov 26, 2013

@bthibault It is part of Hoa to promote and propose a strong implementation of standards, but it seems like even one standard does not exists actually. This is a problem :-). Do you have a study about the usage of such serializations?

Aside to that, it is easy to write an Hoathis that extends Hoa\Ruler. Hoathis partly aims at containing non-standard implementations, which is what we seem to do here. I request the opinion of @stephpy in particular :-).

@bthibault
Copy link
Author

http://ruleml.org/ here is a standard Rule definition. Thanks

@stephpy
Copy link
Member

stephpy commented Dec 3, 2013

I'm agree with you @Hywan, Rules could be stored in different formats.
I guess we shouldn't create visitors for all theses formats on Hoa\Ruler but on a dedicated library.

@Hywan
Copy link
Member

Hywan commented Sep 28, 2014

Can we close this issue?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

3 participants