DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workkloads.

Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Build a DIY AI Model Hosting Platform With vLLM
  • Evolution of Recommendation Systems: From Legacy Rules Engines to Machine Learning
  • Personalized Search Optimization Using Semantic Models and Context-Aware NLP for Improved Results
  • Introduction to Polymorphism With Database Engines in NoSQL Using Jakarta NoSQL

Trending

  • Chaos Engineering for Microservices
  • SQL Server Index Optimization Strategies: Best Practices with Ola Hallengren’s Scripts
  • Analyzing “java.lang.OutOfMemoryError: Failed to create a thread” Error
  • How to Convert Between PDF and TIFF in Java

Prolog as a Rule Engine

Prolog is a general-purpose logic programming language. With some work, you can turn it into your very own rules engine.

By 
Faustine Padit user avatar
Faustine Padit
·
Jun. 23, 17 · Tutorial
Likes (5)
Comment
Save
Tweet
Share
6.3K Views

Join the DZone community and get the full member experience.

Join For Free

I was challenged by my team lead in my previous company to create a Java application module that will be integrated into our current POC project to act as a rule engine. The idea is to have a module that will prove if the given URL is malicious, benign, or suspicious given all the information pertaining to the URL such as registrant, IP location, URL pattern, etc.

I started the formal development given the business requirements and as I went through development trying to hard code all the conditions using if-else statements, I realized that the code I was writing was not going to be effective. Then, I asked myself, "What if there’s a sudden change in the condition that needs to be implemented?" The first thing that came to my mind is to externalized those conditions that can be written inside a file or config. Eventually, I stopped the development right then and there and thought of something that would address my problem.

I began searching the web and came to existing rule engine applications like Drools and JRules, but I was hesitant because I didn't know how these technologies work and I really wanted to create my own that would satisfy the requirements. I’m aware that I should not repeat myself (DRY principle) in doing things that are already there, but I wanted to put my idea to the challenge.

Prolog

Eventually, I came to Prolog, a general-purpose logic programming language associated with artificial intelligence and computational linguistics. The program logic is expressed in terms of relations, represented as facts and rules.

Now let's try to give a brief explanation what "facts" and "rules" mean. I'll try to keep it simple so that we can get the idea of how we can use Prolog as a rule engine.

Facts

Clauses with empty bodies are called facts. An example of a fact is:

domain("example.com").
ip("192.168.1.1").
registrant.email("sample@domain.com").
reputation.score(88).

Rules

A rule is in the form of:

Head :- Body.

Let's try to create our three rules: malicious, benign, and suspicious.

We could say that a domain is malicious if it belongs to the registrant sample@domain.com.

malicious :- registrant.email("sample@domain.com").

We could say that a domain is benign if it does not belong to the registrant sample@domain.com. We use negation here. (We could add more to the body of our rule to increase our confidence in our rule)

benign :- not(registrant.email("sample@domain.com")),reputation.score(SCORE),SCORE>70.

We could say that a domain is suspicious if the domain is not malicious and not benign.

suspicious :- not(malicious),not(benign).

Now that we already have our facts and rules, we can now proceed.

I'm using the TuProlog IDE so that we can test our rules based on the facts given.

Image title

Image title

Image title

You can view the source code here for your reference. 

P.S. Sorry for the coding — this was created during my second year in my IT career.

Prolog Engine

Opinions expressed by DZone contributors are their own.

Related

  • Build a DIY AI Model Hosting Platform With vLLM
  • Evolution of Recommendation Systems: From Legacy Rules Engines to Machine Learning
  • Personalized Search Optimization Using Semantic Models and Context-Aware NLP for Improved Results
  • Introduction to Polymorphism With Database Engines in NoSQL Using Jakarta NoSQL

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!