Is there a way to return a result from a walker without reporting it using jaseci
Question:
Is there a way to return a result from a walker without reporting it using jaseci.
because when you report stuff in general it queues up in the final report which we don’t need.
report: [
{"response": "xyz"}
];
instead of
report: [
"jdsjdbjs",
"dndkfndkfn",
{"response": "xyz"}
];
it messes up with picking out records
Answers:
Depending on your use case there are two solutions:
- If you need to return something from a walker to its caller, you can use
has anchor
in the walker being called. This will be "return" value of the walker spawn statement. For example,
walker B {
has anchor X;
X = 5;
}
walker A {
Y = spawn here walker::B;
}
In this example, Y
will be assigned the value of 5
when walker B finishes walking.
- If you are using the same walker in different scenarios where sometimes you need it to report and sometimes you don’t. What I usually do is to just create a parameter for the walker, something like
if_report
and just report when it is set to True.
Seems like it would be nice if Jac had some more language features around this but you can check out "report custom" support. Its described here https://docs.jaseci.org/docs/docs/Developing_with_JAC/Language_Features/report_custom.html (docs arn’t very good atm). Also keep in mind that once you set report:custom
= that exact jsonized object will be reported after the run. (You wont get the full walker dictionary that includes "report", "success", etc etc.
Also note the last executed report:custom
will be the only report returned.
Here are some examples:
walker cust_report{
report:custom = {'a': 'b'};
}
walker cust_report_neutralize{ # this walker will report nothing
report:custom = {'a': 'b'};
report:custom = null;
}
walker disengage_report{ # this walker will report {'a': 'b'}
disengage report:custom = {'a': 'b'};
report:custom = null;
}
Is there a way to return a result from a walker without reporting it using jaseci.
because when you report stuff in general it queues up in the final report which we don’t need.
report: [
{"response": "xyz"}
];
instead of
report: [
"jdsjdbjs",
"dndkfndkfn",
{"response": "xyz"}
];
it messes up with picking out records
Depending on your use case there are two solutions:
- If you need to return something from a walker to its caller, you can use
has anchor
in the walker being called. This will be "return" value of the walker spawn statement. For example,
walker B {
has anchor X;
X = 5;
}
walker A {
Y = spawn here walker::B;
}
In this example, Y
will be assigned the value of 5
when walker B finishes walking.
- If you are using the same walker in different scenarios where sometimes you need it to report and sometimes you don’t. What I usually do is to just create a parameter for the walker, something like
if_report
and just report when it is set to True.
Seems like it would be nice if Jac had some more language features around this but you can check out "report custom" support. Its described here https://docs.jaseci.org/docs/docs/Developing_with_JAC/Language_Features/report_custom.html (docs arn’t very good atm). Also keep in mind that once you set report:custom
= that exact jsonized object will be reported after the run. (You wont get the full walker dictionary that includes "report", "success", etc etc.
Also note the last executed report:custom
will be the only report returned.
Here are some examples:
walker cust_report{
report:custom = {'a': 'b'};
}
walker cust_report_neutralize{ # this walker will report nothing
report:custom = {'a': 'b'};
report:custom = null;
}
walker disengage_report{ # this walker will report {'a': 'b'}
disengage report:custom = {'a': 'b'};
report:custom = null;
}