Skip to content

JimRoepcke/Rules

Repository files navigation

Rules

Version License Platform

Rules provides a simple forward-chaining inference rule engine that is configurable at runtime.

When you provide a set of known facts, and a set of rules, inferred facts can be determined.

For example:

  • known fact: the sky is blue
  • rule: if the sky is blue, then the weather is sunny
  • inferrable fact: the weather is sunny

You you make much more complicated rules than this, which are based on more facts, even based on inferred facts.

For example:

  • known fact: the sky is blue

  • known fact: the season is summer

  • rule: if the sky is blue, then the weather is sunny

  • rule: if true, the beach is empty (this is a fallback rule)

  • rule: if the weather is sunny and the season is summer, then the beach is full

  • inferred fact: the beach is full

  • known fact: the season is autumn

  • inferred fact: the beach is empty

Rules can be specified using a simple textual format, and can be decoded from JSON to load into a Brain.

This repo also contains a TextRulesToJSON command-line program for macOS that can convert a text file with human-readable rules to JSON. As the Rule type in Rules conforms to Swift's Decodable protocol, this makes it easy to import rules into an application. TextRulesToJSON can also lint the rules to help ensure they are valid before they are converted to JSON.

Example

The Example project only exists for unit tests. To run them, clone the repo, and run pod install from the Example directory first.

Requirements

  • Xcode 10.0
  • Swift 4.2

Installation

Rules is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'Rules'

Rules is also available as a Swift Package. See the Rules/Package.swift file for more information.

Author

Jim Roepcke, [email protected]

License

Rules is available under the MIT license. See the LICENSE file for more info.

About

Rule Engine for Swift

Resources

License

Stars

Watchers

Forks

Packages

No packages published