javaprologswi-prologjpl

JPL7, list of strings in prolog-query


i have a prolog-query which needs an array as atom:

searchEventsOnCategory(Categories,Events) Categories is a list of strings.

Example input: searchEventsOnCategory(['Bar','Disco'],Events)

Output: Event = [listOfEvents]

searchEventsOnCategory(Categories,Events):-
    findall([X,V], event(X,_,_,V), List),
    compareCategories(List,Categories,Events1),
    Events = Events1.

My java-code is:

public ArrayList<String> getEventsByPrologWithCategories(ArrayList<String> Categories){
    ArrayList<String> events = new ArrayList<String>();

    //(Persons,Budget,Categories,Events)
    Variable X = new Variable("X");
    Compound V = new Compound("[Bar]");

    Query q4 =
            new Query(
                "searchEventsOnCategory",
                new Term[] {V,X}
            );

    ... 

    return events;

}

How i have to devine V, that prolog get the V as a list of Strings?


Solution

  • Instead of Compound, you should use Term

    Variable X = new Variable("X");
    
    Term t = Util.textToTerm("[Bar]");
    
    Query q4 =
        new Query(
            "searchEventsOnCategory",
            new Term[] {t,X}
            );