I'm trying to wrap my head around the Java-Prolog interface library JPL. I can find plenty of examples where people query Prolog from Java for information from the knowledge base, but no examples where the knowledge base is constructed dynamically in Java. How would I do this?
Asked
Active
Viewed 485 times
2
-
1Interesting that you ask this. I am currently working on parsing a flat file using Prolog DCG and then to use JPL to call embedded Java to add the information in the flat file into a Neo4j database. I estimate it will take me about a week before I start to use the JPL. While my goal is not the same as your goal, and depending upon you goal, might be just the reverse. I will keep this question in mind when I get to JPL as creating an example for your case should be easy once I have my solution. – Guy Coder Jan 24 '19 at 05:21
-
That would be really great, thank you! I *think* I use the Prolog class static methods the more I look at this, but it's just so weird not having any relevant examples to work from. – Dylan Knowles Jan 24 '19 at 05:26
-
When you say `knowledge base is constructed dynamically in Java` you don't say where the data resides. Do you mean: 1. The data (facts) reside in Prolog and Java calls Prolog to get at the data. 2. The data is not Prolog facts and that to access the data, it must be accessed via Java for use with Prolog? – Guy Coder Jan 24 '19 at 05:26
-
1I want Java to say to Prolog "Here is an atom. It links to an object/JRef. Please remember that. Did I mention I have a rule that links to that atom? Remember that too." So, I want to use Java method calls to construct the knowledge base that I will eventually query. – Dylan Knowles Jan 24 '19 at 05:29
-
1Out of curiosity, are you aware of [Neo4j](https://neo4j.com/)? It is a [No-SQL](https://en.wikipedia.org/wiki/NoSQL) database and specifically a [graph database](https://en.wikipedia.org/wiki/Graph_database). For my purposes I need to store large amounts of related data, in the 10 to 100s of gigabytes and quickly search for series of relations. While I could use Prolog facts to do this, I don't know if Prolog would hold up with that much data and how long the queries would take. – Guy Coder Jan 24 '19 at 05:40
-
Saw that JRef is [deprecated](http://www.swi-prolog.org/packages/jpl/java_api/javadoc/jpl/package-summary.html) – Guy Coder Jan 24 '19 at 06:33
-
Of interest: JPL directory [examples](https://github.com/SWI-Prolog/packages-jpl/tree/master/examples) – Guy Coder Jan 24 '19 at 06:40
-
Prolog has a weird similarity to my use case hence why I'm investigating. Will look into neo4j though! – Dylan Knowles Jan 24 '19 at 06:47
-
Why not use the predicates for managing the database: http://www.swi-prolog.org/pldoc/man?section=dynpreds You can evaluate these from Java like you would any other query. Or am I missing your point? – User9213 Jan 24 '19 at 10:36
-
@User9213 I'm calling the methods from within Java as a Java program runs, so I can't actually use a Prolog interpreter nor read in a pre-made file. In main(), for example, I'd have a call like `Predicate p = addPredicate(...);` I've found a way to do it, I think, but now I'm stuck dealing with access violation exceptions with SWI-Prolog :/ – Dylan Knowles Jan 24 '19 at 22:24
-
1If I find time I will try to write a real answer, but I would have to setup JPL first.... For now, try to evaluate the following Prolog query from Java: `?- assertz(a(1)).`. Then, try to query, on the same Prolog instance, `?- a(X)`. If you get `1`, this means that you have succeeded in dynamically adding a fact to the Prolog database from Java. – User9213 Jan 25 '19 at 08:50