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

Feat/serialize to fix #182 #183

Merged
merged 5 commits into from
Apr 12, 2021
Merged

Conversation

newm4n
Copy link
Member

@newm4n newm4n commented Apr 12, 2021

Added capability to Store a KnowledgeBase into stream of bytes using io.Writer and read them back using io.Reader.
I hope, this will enable user to store huge KnowledgeBase rule-set into a binary file and
read that file back into KnowledgeBase when the application start in a much faster way.

To write a KnowledgeBase already loaded in KnowledgeLibrary

func (lib *KnowledgeLibrary) StoreKnowledgeBaseToWriter(writer io.Writer, name, version string) error 

The name and version should be existing in the knowledge library.

To read a byte stream back using reader into KnowledgeLibrary

func (lib *KnowledgeLibrary) LoadKnowledgeBaseFromReader(reader io.Reader, overwrite bool) (retKb *KnowledgeBase, retErr error)

Or, if you're a hacking kind of guy, you can see example/Serialization_test.go to see how you can marshal/unmarshal a KnowlegeBase by hand.

I have not add any documentation to help user on how to do this. Help is greatly apreciated.

Oh another thing, if you use an io.Writer and io.Reader as they are, the binary size is inflated 10x-20x fold due to lots of indexing happening for the rete and generated keys, etc. So, you can wrap those Writer/Reader with archive/zip counterpart.

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

Successfully merging this pull request may close these issues.

1 participant