https://github.com/qvdk/prolamb4j
Java & SWI-Prolog AWS lambda runtime
https://github.com/qvdk/prolamb4j
Last synced: 4 months ago
JSON representation
Java & SWI-Prolog AWS lambda runtime
- Host: GitHub
- URL: https://github.com/qvdk/prolamb4j
- Owner: qvdk
- License: gpl-3.0
- Created: 2024-08-13T21:09:45.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2024-08-14T09:44:48.000Z (10 months ago)
- Last Synced: 2025-01-13T02:27:25.863Z (5 months ago)
- Language: Dockerfile
- Size: 16.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# Prolamb4J
Java bootstrap for the AWS Lambda provided runtime with the integration of the SWI-Prolog library.
This allows to handle easily a Java-based lambda that query a prolog engine.
## How to use?
Since Prolamb4J extends AWS lambda base image for Java, you can follow the official documentation on how to [Deploy Java Lambda functions with container images - Using an AWS base image for Java](https://docs.aws.amazon.com/lambda/latest/dg/java-image.html#java-image-instructions)
Then, you have to base your Dockerfile from the Prolamb4J image.
Replace
```
FROM public.ecr.aws/lambda/java:21
```
by
```
FROM qvdk/prolambd4j:9.3.8-java21
```Add JLP library in your `pom.xml`.
```xml
com.github.SWI-Prolog
packages-jpl
V9.3.8```
Write your own handler.
```java
public class App implements RequestHandler, Map> {@Override
public Map handleRequest(Map input, Context context) {
// Consulting the Prolog database from its text file
Query q1 = new Query("load_files", new Term[] { new Atom("test.pl") });
System.out.println("Loading test.pl " + (q1.hasSolution() ? "succeeded" : "failed"));String who = input.get("payload");
Variable X = new Variable("X");
Query q2 = new Query("descendent_of", new Term[] { X, new Atom(who) });String output = "The descendents of " + who + ":";
java.util.Map[] solutions = q2.allSolutions();
for (int i = 0; i < solutions.length; i++) {
System.out.println("X = " + solutions[i].get("X"));
output += " " + solutions[i].get("X");
}// return what you want...
return Map.of("payload", output);
}
}
```
See [JLP tutorials](https://jpl7.org/TutorialJavaCallsProlog) for more samples.Test locally.
```
~ curl "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{"payload":"ralf"}'
{"payload":"The descendents of ralf: joe mary steve"}%
```