B4J Question How to make these calls to Projog?

B4JExplorer

Active Member
Licensed User
Longtime User
I have the Additional Jars defined



B4X:
    #AdditionalJar: projog-core-0.9.0.jar
    #AdditionalJar: projog-clp-0.3.0.jar



Using this page for examples


, how to make these calls and assignments?

projog.consultFile(new File("src/main/resources/test.pl"));

QueryResult r1 = projog.executeQuery("test(X,Y).");

r1.getTerm("X")

QueryStatement s1 = projog.createStatement("test(X,Y).");
 

aeric

Expert
Licensed User
Longtime User
You can refer to this example.
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
Got some bits working for you for a head start
B4X:
#Region Project Attributes
    #CommandLineArgs:
    #MergeLibraries: True
    #AdditionalJar: projog-core-0.9.0
    #AdditionalJar: projog-clp-0.3.0
#End Region

Sub Process_Globals
    Dim projog As JavaObject
End Sub

Sub AppStart (Args() As String)
    projog = (Me).As(JavaObject).RunMethodJO("newOne",Null)
    Log(projog)
   
    Dim myFile As JavaObject
    myFile = (Me).As(JavaObject).RunMethod("newFile",Array("c:/temp/test.pl"))
   
    projog.RunMethod("consultFile",Array(myFile))
   
    ' for the QueryResult
    Dim result As JavaObject
   
    result = projog.RunMethodJO("executeQuery",Array("test(X,Y)."))
    Log(result)
   
    Do While result.RunMethod("next",Null)
        Log("X= " & result.RunMethod("getTerm",Array("X")) & " Y= " & result.RunMethod("getTerm",Array("Y")))
    Loop
   
End Sub

#if java
import java.io.File;

import org.projog.api.Projog;
import org.projog.api.QueryResult;
import org.projog.api.QueryStatement;
import org.projog.core.term.Atom;

// needed to get new instance as initializNewInstance errors
    public static Projog newOne(){
        return new Projog();
    }
// needed as consultFile needs a file object not an io stream or string   
    public static File newFile(String s){
        return new File(s);
    }
#End If
 
Upvote 0
Top