https://github.com/richardstartin/multi-matcher
simple rules engine
https://github.com/richardstartin/multi-matcher
classification classifier decision-table decision-tree
Last synced: 10 months ago
JSON representation
simple rules engine
- Host: GitHub
- URL: https://github.com/richardstartin/multi-matcher
- Owner: richardstartin
- License: apache-2.0
- Created: 2018-03-01T11:00:59.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2020-04-16T17:52:10.000Z (almost 6 years ago)
- Last Synced: 2025-04-15T03:03:13.428Z (10 months ago)
- Topics: classification, classifier, decision-table, decision-tree
- Language: Java
- Homepage: https://richardstartin.github.io/posts/classifying-documents
- Size: 6.52 MB
- Stars: 91
- Watchers: 1
- Forks: 9
- Open Issues: 15
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# multi-matcher
[](https://travis-ci.org/richardstartin/multi-matcher)
[](https://coveralls.io/github/richardstartin/multi-matcher?branch=master)
[](https://maven-badges.herokuapp.com/maven-central/uk.co.openkappa/bitrules)
[](https://opensource.org/licenses/Apache-2.0)
[](http://www.javadoc.io/doc/uk.co.openkappa/multi-matcher)
[](https://lgtm.com/projects/g/richardstartin/multi-matcher/alerts/)
[](https://lgtm.com/projects/g/richardstartin/multi-matcher/context:java)
I have often needed to implement tedious classification logic in data processing projects. The requirements are often ambiguous to the extent that it would be difficult to implement them even in SQL, with aspects such as fallback and overlap. This logic often ends up expressed as large blocks of nested if statements which are hard to read or modify and perform poorly. This small project aims to make such classification logic easier, and improve performance too.
# usage
Build a generic classification engine
```java
Classifier classifier = Classifier.builder(
Schema.create()
.withAttribute("productType", Product::getProductType)
.withAttribute("issueDate", Product::getIssueDate, Comparator.naturalOrder().reversed())
.withAttribute("productName", Product::getProductName)
.withAttribute("availability", Product::getAvailability)
.withAttribute("discountedPrice", value -> 0.2 * value.getPrice())
).build(Arrays.asList(
MatchingConstraint.named("rule1")
.eq("productType", "silk")
.startsWith("productName", "luxury")
.gt("discountedPrice", 1000)
.priority(0)
.classification("EXPENSIVE_LUXURY_PRODUCTS")
.build(),
MatchingConstraint.named("rule2")
.eq("productType", "caviar")
.gt("discountedPrice", 100)
.priority(1)
.classification("EXPENSIVE_LUXURY_PRODUCTS")
.build(),
MatchingConstraint.anonymous()
.eq("productName", "baked beans")
.priority(2)
.classification("CHEAP_FOOD")
.build()
)
);
```
Classify
```java
Product p = getProduct();
String classification = classifier.classification(p).orElse("UNCLASSIFIED");
```