The general way to use an answer format for a query is to define the attribute forQuery. Another possibility is to specify the answer format for a query is to use the answer representation field of the ASK method in the IPC interface.
The following code is an example for specifying a user-defined answer in the ASK method. This example is written in Java and uses the standard Java API of ConceptBase (see the Programmer's Manual for details).
import i5.cb.api.*;
public class CBAnswerFormat {
public static void main(String[] argv) throws Exception {
CBclient cb=new CBclient("localhost",4001,null,null);
CBanswer ans=cb.ask("find_specializations[Class/class,TRUE/ded]",
"OBJNAMES","AFParameter[bla/somevar]","Now");
System.out.println(ans.getResult());
cb.cancelMe();
}
}
In the example, a connection is made to a ConceptBase server on localhost listening on port 4001. The ask-method of the CBclient class sends a query to the server. The first argument is the query, the second argument is the format of the query (in this example, it is just one object name), the third argument is the answer representation, and the last argument is the rollback time.
The third argument, the answer representation, is usually FRAME or LABEL.
In our case, it is a parameterized answer format: AFParameter[somevalue/somevar].
This means that the result of the query will be formatted according to
the answer format AFParameter and the variable somevar
will be replaced with somevalue. The variable can be used as any other
expression, i.e. it must be enclosed in {}.
The following definition of AFParameter is an example, how
the parameter can be used in the pattern. If the parameter is not
specified, the string {somevar} will not be replaced.
Individual AFParameter in AnswerFormat with
attribute,head
hd : "<result>"
attribute,tail
tl : "</result>"
attribute,pattern
p : "
<object>
<type>{somevar}</type>
<name>{this}</name>
</object>"
end
Note, that you can use any answer format (with or without parameters) as answer representation in the ASK method.