ArrangoDB - Get All Possible Path From Given Value - arangodb

I want a query to get all possible paths that start from a given vertex.
For exa. as in below image,
I want to find all paths that start from "Covid/12109" with Query.
So it returns like this
{ "_from":"Covid/12109","_to":"Covid/12110" }
{ "_from":"Covid/12110","_to":"Covid/12111" }
{ "_from":"Covid/12110","_to":"Covid/12115" }
{ "_from":"Covid/12110","_to":"Covid/12114" }
{ "_from":"Covid/12111","_to":"Covid/12115" }
{ "_from":"Covid/12111","_to":"Covid/12114" }
{ "_from":"Covid/12112","_to":"Covid/12110" }
{ "_from":"Covid/12112","_to":"Covid/12113" }
{ "_from":"Covid/12112","_to":"Covid/12114" }
And if i want to start from "Covid/12110" then it should return like this
{ "_from":"Covid/12110","_to":"Covid/12111" }
{ "_from":"Covid/12110","_to":"Covid/12115" }
{ "_from":"Covid/12110","_to":"Covid/12114" }
{ "_from":"Covid/12111","_to":"Covid/12115" }
{ "_from":"Covid/12111","_to":"Covid/12114" }
{ "_from":"Covid/12112","_to":"Covid/12110" }
{ "_from":"Covid/12112","_to":"Covid/12113" }
{ "_from":"Covid/12112","_to":"Covid/12114" }
And if i want to start from "Covid/12112" then it should return like this
{ "_from":"Covid/12112","_to":"Covid/12110" }
{ "_from":"Covid/12112","_to":"Covid/12113" }
{ "_from":"Covid/12112","_to":"Covid/12114" }
{ "_from":"Covid/12110","_to":"Covid/12111" }
{ "_from":"Covid/12110","_to":"Covid/12115" }
{ "_from":"Covid/12110","_to":"Covid/12114" }
{ "_from":"Covid/12111","_to":"Covid/12115" }
{ "_from":"Covid/12111","_to":"Covid/12114" }

Graph traversal is your friend here. There are several ways to accomplish this, but you might start by :
FOR c IN Covid
FILTER c._key == '12109'
FOR v,e IN 1..9 OUTBOUND c
`has`
OPTIONS { uniqueVertices: true }
RETURN e
The name of your edge collection ('has') is tricky because HAS is an AQL keyword (see the docs about naming things with keywords). I've enclosed this in backticks (the AQL escape char), but you could also create a named graph, which (I believe) is much more flexible.
Looking at the query:
We first find documents in the "Covid" collection that match a key. This is optional, you could also swap the "c" in the graph traversal with a document id like "Covid/12109"
FOR v,e represents "vertices" v and "edges" e to return
1..9 is the number of traversal "jumps" to perform. This can be any number (2) or range (5..27)
OUTBOUND refers to the path direction to traverse. Other options here are OUTBOUND and ANY
{ uniqueVertices: true } tells the engine to keep track of which vertices it's returned and not duplicate them on output. See the docs here
RETURN e will return edge ("has") documents. RETURN v would return vertex ("Covid") documents.

Related

How to conditional statements in action output in Bixby

Hi I want to go to another action by putting a conditional statement in the action output.
What should I do?
For example
action (~~) {
description (Validate items passed from javascript)
collect {
input (~~) {
type (~~)
min (~~) max (~~)
}
}
type(~~~)
output (items){
on-empty(items.item1){ // if items.item1 is empty.
replan { // go to case1Action.
intent {
goal : case1Action
value : ~~~~~
}
}
}else{ // else
replan { // go to case2Action.
intent {
goal : case2Action
value : ~~~~~
}
}
}
}
or I want to select the view according to the output value.(Actually this is the purpose of the question)
output (items){
if(items.item1 == "goFirstCase"){
// First case view
}else{
// Second case view
}
}
I think by "select a different view according to the output value" I presume you mean you want to change what shows on the screen? because a "view" actually is comprised of the dialog, layout, and conversation-drivers.
https://bixbydevelopers.com/dev/docs/dev-guide/developers/building-views.views
For majority of use cases, there's really only one result-view that will be used, and any of the three contents of a view can be changed based on your preferred conditions as the above answer suggests.
within a view you can have the three different components defined with these three blocks: message for dialog, render for layout, and conversation-drivers
using your example,
//in a result-view
message {
if (items.item1 == "firstCase") {
template-macro (firstCase-result-dialog) {//enter params}
}
}
render {
if (size(items) > 1) {
list-of (items) {
where-each (item) {
if (item == "firstCase") {
layout-match (item) {
mode (Summary)
}
// OR use layout-macro
layout-macro (firstCase-result-summary-thumbnail-card) {//enter params}
}
}
}
}
}
similar conditional work can be done on conversation-drivers of course.
In your case, you would not need on-empty in action, but use template-macro-def as briefly explained in https://corp.bixbydevelopers.com/dev/docs/dev-guide/developers/refining-dialog.dialog-macros
// template file one
template-macro-def (id1) {
params {
param (x) {
Type (Items) ....
}
// template file two
template-macro-def (id2) {
// param x is type Items
}
//view file
result-view {
match: Items(this)
// after some checking make sure is single item
// it is possible to use other condition like if (this.sub1 == 2)
if (exists(this.sub1)) {
template-macro (id1) {
param (x) { expression (this) }
}
}
else {
template-macro (id2) {
param (x) { expression (this) }
}
}
The above would be the recommended way to handle different views for same concept in Bixby.
on-empty in action would be used for the purpose of either replan or relax some search condition in order to avoid 0 result. Bixby does not support on-empty(key) {} syntax according to https://corp.bixbydevelopers.com/dev/docs/reference/type/action.output.on-empty and on-empty would only apply in your case if output(items) itself is empty and would not check any sub-property of items.
Another option.
instead to use 'on-empty' block, you can use 'throws - error'
in action model,
output (items) {
throws {
error (case1ActionError) {
on-catch {
replan {
intent {
goal : case1Action
value : ~~~~~
}
}
}
}
error (case2ActionError) {
on-catch {
replan {
intent {
goal : case2Action
value : ~~~~~
}
}
}
}
}
}
And, in js code,,
if (error condition1) {
throw fail.checkedError('case 1 error', 'case1ActionError')
} else if (error condition2) {
throw fail.checkedError('case 2 error', 'case2ActionError')
}
For fail, refer to https://bixbydevelopers.com/dev/docs/reference/JavaScriptAPI/fail#failcheckederrormessage-errorid-errorobj

I want to acess the value of this json object without using the key name

{
"callExpDateMap": {
"2020-03-06:2": {
"305.0": [
{
"putCall": "CALL,
}
]
}
}
}
So this is my json object.And As you can see in "callExpDateMap",there is a date("2020-03-06:2" and then there is a value("305.0").The date("2020-03-06:2") and price("305.0") values will not be the same in every response.So If I want to access the value of "putCall" (Please remember that I can't use the key of the date and the price because it keeps changing in every response), How can I do this?...I'm using nodejs.
You need to pass this JSON to a function and call that function recursively with each inner object (or value of JSON key) and when value is string just print it or use in your way.
forEach(Object.keys(jsonobj))
function myfunc(key){
if((typeof jsonobj[key])==object){
forEach(Object.keys(jsonobj[key]));
}else{
console.log(jsonobj[key])
}
}
}
You could loop over the object and get the value,
Example:
let test = {
callExpDateMap: {
"2020-03-06:2": {
"305.0": [
{
putCall: "CALL"
}
]
}
}
};
let callExpDateMap = test.callExpDateMap;
for(const dateValue in callExpDateMap) {
for(const put in callExpDateMap[dateValue]) {
console.log(callExpDateMap[dateValue][put][0]['putCall']);
}
}
or you could use Object.keys to get the value. it's simpler then the previous approach;
let obj = {
callExpDateMap: {
"2020-03-06:2": {
"305.0": [
{
putCall: "CALL"
}
]
}
}
};
let callExpDateMap = obj.callExpDateMap;
let dateKey = Object.keys(callExpDateMap);
let price = Object.keys(callExpDateMap[dateKey]);
let putCall = callExpDateMap[dateKey][price];
console.log(putCall);

How do I match a enum symbol in a result view?

I have some training examples that have the same goal, but use enums/symbols (to reduce the training examples needed.)
How can I match the symbols in a result view?
I've looked at pattern matching in the docs here: https://bixbydevelopers.com/dev/docs/dev-guide/developers/customizing-plan.match-patterns
I think this is pretty straightforward. I have an enum:
enum (sizes) {
description (drink sizes)
symbol (large)
symbol (medium)
symbol (small)
}
And some corresponding vocabulary:
vocab (sizes) {
"large" {"large", "largest", "big"}
"medium" {"medium", "normal"}
"small" {"small", "smallest", "tiny"}
}
And then for training I might have:
[g:BuyDrink] I want a (large)[v:sizes:large] drink
[g:BuyDrink] I want the (smallest)[v:sizes:small] drink
I want different result views for the two utterances, but I can't figure out the correct match pattern.
The match pattern will work for concept types. You should be able to create a layout for any variations of the value when you render the view. For example:
Action:
action (BuyDrink) {
type(Search)
description (Buy a drink (small, medium, or large))
collect {
input (size) {
type (sizes)
min (Optional) max (One)
}
}
output (sizes)
}
View:
result-view {
match {
sizes(drinkSize) {
from-output: BuyDrink(drink)
}
}
render {
if (drinkSize == 'large') {
layout-macro (large)
}
else-if (drink == 'medium') {
layout-macro (medium)
}
else {
layout-macro (small)
}
}
}
Large layout:
layout-macro-def (large) {
content {
single-line {
text(This is LARGE)
}
}
}
Medium layout:
layout-macro-def (medium) {
content {
single-line {
text(This is Medium)
}
}
}
Small layout:
layout-macro-def (small) {
content {
single-line {
text(This is small)
}
}
}

How do I get rid of all the "Warn this.name might be empty" warnings?

In my Cat.view.bxb file, I have some UI elements that are based on optional properties in the structure that have warnings attached to them.
WARN this.name might be empty
result-view{
match {
Cat (this)
}
render {
layout {
section {
content {
paragraph {
style (Title_XS)
value ("#{value(this.name)}")
}
}
}
}
}
}
The warnings serve to remind you that the UI elements you've defined will not be displayed if the optional properties are not present.
You should define an if(exists(this.name)) and define UI elements for when the optional elements are not available.
For example, your code would look something like the following:
result-view{
match {
Cat (this)
}
render {
layout {
section {
content {
if(exists(this.name)) {
paragraph {
style (Title_XS)
value ("#{value(this.name)}")
}
} else {
paragraph {
style (Title_XS)
value("No name!")
}
}
}
}
}
}
}
By doing so, you are addressing the root cause of the warning and creating a more responsive output for your users.
if (exists) works and is one way as articulated already and provides excellent context for the user. Another way that may be preferable in certain circumstances is to use the [] square brackets notation - if a section within square brackets renders null then the section is skipped. So for your example:
result-view{
match {
Cat (this)
}
render {
layout {
section {
content {
paragraph {
style (Title_XS)
value ("[#{value(this.name)}]")
}
}
}
}
}
}

Not sure how to update a struct with new information

A question concerning Bixby Studio.
I am trying to figure out how to accept text-input from the user.
I have a Filter struct with some fields such as SearchField, Genre, Platforms (Gaming consoles), and Themes (A few other entries)
By default, all of these are optional, especially with the search field. However, i would like for the user to be able to visibly see what filters are enabled, and be able to select and change their values (This values can be overwritten by NLP training, but I can't figure out how to disable the field.)
I created a result view for my filters and I've setup input-cells for selecting a specific field to modify. (In this case, SearchField.). I have been successful in redirecting to an input-view, but it seems that no matter what text I put in here, it does not save or apply to my filter.
Looking for some insight into the problem and willing to provide more information as needed.
Some of the things that I have tried in the past, seem to want take the existing context "SearchField" within the filters (which might not exist) and apply it to the new "search field". However, this doesn't work and seems to create a loop.
I've also tried to set the prompt-behavior (AlwaysSelection) in the action model for SetSearchField, but it appears to do nothing.
// Result View for Filters
result-view {
match {
Filter(this)
}
message {
template (Active Filters){
speech (Would you like to change any filters?)
}
}
render {
layout-macro (filter-details) {
param (filter) {
expression (this)
}
}
}
}
// Layout Macro
layout-macro-def(filter-details) {
params {
param (filter) {
type (Filter)
min (Required)
max (One)
}
}
content {
section {
title (Filters)
content {
input-cell {
label (Search Name)
value ("#{value(filter.name)}")
on-click {
intent {
goal: SetSearchField // <-------- Field in question
}
}
}
}
}
}
}
// Input-view for SearchField
input-view {
match {
SearchField(searchField)
}
render {
form {
elements {
text-input {
id (val)
type (SearchField)
required (true)
}
}
on-submit {
goal:SearchField
}
}
}
}
// SetSearchField action
action (SetSearchField) {
description (Sets the name in a search filter)
type (Fetch)
collect {
input (newSearchField) {
type (SearchField)
min (Required)
prompt-behavior (AlwaysSelection)
}
}
output (SearchField)
}
// SetSearchField endpoint
action-endpoint (SetSearchField) {
accepted-inputs (newSearchField)
local-endpoint ("filters/SetSearchField.js")
}
// .js file
module.exports.function = function setName (newSearchField) {
return newSearchField
}
I discovered there is a special way in accessing input form elements for input-views.
Collect input through the form -> elements, then reference them using the viv.core.FormElement(id)
input-view {
match {
SearchField(searchField)
}
render {
form {
on-submit {
goal: SearchField
value: viv.core.FormElement(text)
}
elements {
text-input {
id (text)
type (SearchField)
label (Search for: )
value("#{raw(searchField)}")
}
}
}
}
}

Resources