Related
I have my data set up in cosmos DB gremlin API. I am trying to write a query that can starting at a given vertex, gives all the edges with labels and properties in both directions, and the vertices with their properties, with a loop count of lets say 2. I am running the following queries.
Data to be setup
g.addV('item').property('id','1').property('name', 'item1')
g.addV('item').property('id','2').property('name', 'item2')
g.addV('item').property('id','3').property('name', 'item3')
g.addV('item').property('id','4').property('name', 'item4')
g.addV('item').property('id','5').property('name', 'item5')
g.addV('item').property('id','6').property('name', 'item6')
g.addV('item').property('id','7').property('name', 'item7')
g.addV('report').property('id','8').property('name', 'report1')
g.addV('report').property('id','9').property('name', 'report2')
g.addV('folder').property('id','10').property('name', 'folder1')
g.addV('server').property('id','11').property('name', 'server1')
g.V('1').addE('hasParent').to(g.V('2'))
g.V('1').addE('hasParent').to(g.V('3'))
g.V('2').addE('hasParent').to(g.V('4'))
g.V('5').addE('hasParent').to(g.V('6'))
g.V('4').addE('hasParent').to(g.V('5'))
g.V('7').addE('hasParent').to(g.V('5'))
g.V('8').addE('hasParent').to(g.V('9'))
g.V('8').addE('hasParent').to(g.V('9'))
g.V('8').addE('belongsTo').to(g.V('10'))
g.V('10').addE('belongsTo').to(g.V('11'))
query: g.V('id','1').repeat(bothE().dedup().otherV()).times(2).path()
response:
[
{
"labels": [
[],
[],
[],
[],
[]
],
"objects": [
{
"id": "1",
"label": "item",
"type": "vertex",
"properties": {
"name": [
{
"id": "1|name",
"value": "item1"
}
]
}
},
{
"id": "a6b02073-68f8-4d53-8af0-54739eaaeaa0",
"label": "hasParent",
"type": "edge",
"inVLabel": "item",
"outVLabel": "item",
"inV": "2",
"outV": "1"
},
{
"id": "2",
"label": "item",
"type": "vertex",
"properties": {
"name": [
{
"id": "2|name",
"value": "item2"
}
]
}
},
{
"id": "c8722748-3899-4a2c-afe4-6f13b6c1f8d5",
"label": "hasParent",
"type": "edge",
"inVLabel": "item",
"outVLabel": "item",
"inV": "4",
"outV": "2"
},
{
"id": "4",
"label": "item",
"type": "vertex",
"properties": {
"name": [
{
"id": "4|name",
"value": "item4"
}
]
}
}
]
},
{
"labels": [
[],
[],
[],
[],
[]
],
"objects": [
{
"id": "1",
"label": "item",
"type": "vertex",
"properties": {
"name": [
{
"id": "1|name",
"value": "item1"
}
]
}
},
{
"id": "a6b02073-68f8-4d53-8af0-54739eaaeaa0",
"label": "hasParent",
"type": "edge",
"inVLabel": "item",
"outVLabel": "item",
"inV": "2",
"outV": "1"
},
{
"id": "2",
"label": "item",
"type": "vertex",
"properties": {
"name": [
{
"id": "2|name",
"value": "item2"
}
]
}
},
{
"id": "a6b02073-68f8-4d53-8af0-54739eaaeaa0",
"label": "hasParent",
"type": "edge",
"inVLabel": "item",
"outVLabel": "item",
"inV": "2",
"outV": "1"
},
{
"id": "1",
"label": "item",
"type": "vertex",
"properties": {
"name": [
{
"id": "1|name",
"value": "item1"
}
]
}
}
]
},
{
"labels": [
[],
[],
[],
[],
[]
],
"objects": [
{
"id": "1",
"label": "item",
"type": "vertex",
"properties": {
"name": [
{
"id": "1|name",
"value": "item1"
}
]
}
},
{
"id": "2f0c5890-3fa5-4d7d-8ada-910e5419750f",
"label": "hasParent",
"type": "edge",
"inVLabel": "item",
"outVLabel": "item",
"inV": "3",
"outV": "1"
},
{
"id": "3",
"label": "item",
"type": "vertex",
"properties": {
"name": [
{
"id": "3|name",
"value": "item3"
}
]
}
},
{
"id": "2f0c5890-3fa5-4d7d-8ada-910e5419750f",
"label": "hasParent",
"type": "edge",
"inVLabel": "item",
"outVLabel": "item",
"inV": "3",
"outV": "1"
},
{
"id": "1",
"label": "item",
"type": "vertex",
"properties": {
"name": [
{
"id": "1|name",
"value": "item1"
}
]
}
}
]
}
]
This is giving me the desired output, but has a lot of repetitions, i am guessing because it prints the path as it traverses. How can I modify this query to return the smallest possible json output? Just return the vertices and edges once. I am using cosmosDB gremlin APIs if that makes any difference.
Response needed: just a list of vertices and edges needed for painting this graph.
Your example as-is doesn't produce the same output that I see in your question - I get just one path:
gremlin> g.V('id','1').repeat(bothE().dedup().otherV()).times(2).path()
==>[v[1],e[11][1-hasParent->2],v[2],e[13][2-hasParent->4],v[4]]
I'm not sure if that's some mistake in your data script but I think I get the gist of what you are asking from your output. I can recreate a situation of duplication by doing an emit() on the repeat() to include all paths in the output:
gremlin> g.V('id','1').repeat(bothE().dedup().otherV()).emit().times(2).path()
==>[v[1],e[11][1-hasParent->2],v[2]]
==>[v[1],e[12][1-hasParent->3],v[3]]
==>[v[1],e[11][1-hasParent->2],v[2],e[13][2-hasParent->4],v[4]]
Now I have some duplication of vertices/edges in the resulting output. If you just want a unique list of all those objects, just unfold() each Path and dedup():
gremlin> g.V('id','1').repeat(bothE().dedup().otherV()).emit().times(2).path().unfold().dedup()
==>v[1]
==>e[11][1-hasParent->2]
==>v[2]
==>e[12][1-hasParent->3]
==>v[3]
==>e[13][2-hasParent->4]
==>v[4]
This is a bit of an interesting pattern in a sense because it provides an easy way to produce a subgraph for Gremlin Language Variants and graph systems that don't support subgraph() step.
Vega is available as CDN script that can be included in HTML & used directly in js code.
But, how to proceed if we wish to use the same with generic web components built with polymer or StencilJS. including CDN js is not a good idea there.
Is there any way to include vega as npm module in such projects ?
have a look at this fiddle it is a native webComponent using vega:
<script src="https://cdn.jsdelivr.net/npm/vega#5"></script>
<script src="https://cdn.jsdelivr.net/npm/vega-lite#3"></script>
<script src="https://cdn.jsdelivr.net/npm/vega-embed#4"></script>
<script type="module">
const barChart = {
"$schema": "https://vega.github.io/schema/vega/v5.json",
"width": 400,
"height": 200,
"padding": 5,
"data": [
{
"name": "table",
"values": [
{"category": "A", "amount": 28},
{"category": "B", "amount": 55},
{"category": "C", "amount": 43},
{"category": "D", "amount": 91},
{"category": "E", "amount": 81},
{"category": "F", "amount": 53},
{"category": "G", "amount": 19},
{"category": "H", "amount": 87}
]
}
],
"signals": [
{
"name": "tooltip",
"value": {},
"on": [
{"events": "rect:mouseover", "update": "datum"},
{"events": "rect:mouseout", "update": "{}"}
]
}
],
"scales": [
{
"name": "xscale",
"type": "band",
"domain": {"data": "table", "field": "category"},
"range": "width",
"padding": 0.05,
"round": true
},
{
"name": "yscale",
"domain": {"data": "table", "field": "amount"},
"nice": true,
"range": "height"
}
],
"axes": [
{ "orient": "bottom", "scale": "xscale" },
{ "orient": "left", "scale": "yscale" }
],
"marks": [
{
"type": "rect",
"from": {"data":"table"},
"encode": {
"enter": {
"x": {"scale": "xscale", "field": "category"},
"width": {"scale": "xscale", "band": 1},
"y": {"scale": "yscale", "field": "amount"},
"y2": {"scale": "yscale", "value": 0}
},
"update": {
"fill": {"value": "steelblue"}
},
"hover": {
"fill": {"value": "red"}
}
}
},
{
"type": "text",
"encode": {
"enter": {
"align": {"value": "center"},
"baseline": {"value": "bottom"},
"fill": {"value": "#333"}
},
"update": {
"x": {"scale": "xscale", "signal": "tooltip.category", "band": 0.5},
"y": {"scale": "yscale", "signal": "tooltip.amount", "offset": -2},
"text": {"signal": "tooltip.amount"},
"fillOpacity": [
{"test": "datum === tooltip", "value": 0},
{"value": 1}
]
}
}
}
]
}
class VegaElement extends HTMLElement {
constructor() {
super()
this.innerHTML = "<div id='view'></div>"
}
connectedCallback() {
vegaEmbed( '#view', barChart ); }
}
customElements.define('vega-element', VegaElement);
</script>
<vega-element></vega-element>
Trying to transcript audio from Telegram voice message but I got "unable to transcode data stream audio/opus -> audio/x-float-array" error from watson's speech to text node.
I'm using Node-Red on Raspberry to simply transcript audio from Telegram voice message with node-red-contrib-telegrambot and node-red-node-watson.
With text messages, my code works as a charm.
With Voice Messages, I got "unable to transcode data stream audio/opus -> audio/x-float-array" error from watson's speech to text node.
node-red flow images I don't have enough reputation point to post images :(
JSON flow export
[
{
"id": "b4106ec1.63dd58",
"type": "tab",
"label": "Telegram",
"disabled": false,
"info": ""
},
{
"id": "d1198164.e38f68",
"type": "telegram receiver",
"z": "b4106ec1.63dd58",
"name": "FMWatsonBot",
"bot": "5f347711.7876d8",
"saveDataDir": "",
"x": 110,
"y": 100,
"wires": [
[
"f4b4ab25.5dde18",
"f5d126df.5b6928"
],
[]
]
},
{
"id": "c6ec445d.0840d8",
"type": "telegram sender",
"z": "b4106ec1.63dd58",
"name": "Send2Telegram",
"bot": "5f347711.7876d8",
"x": 780,
"y": 80,
"wires": [
[]
]
},
{
"id": "f4b4ab25.5dde18",
"type": "debug",
"z": "b4106ec1.63dd58",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"x": 290,
"y": 60,
"wires": []
},
{
"id": "f5d126df.5b6928",
"type": "function",
"z": "b4106ec1.63dd58",
"name": "Save chat context",
"func": "msg.chatId = msg.payload.chatId;\nmsg.type = msg.payload.type;\nmsg.content = msg.payload.content;\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 230,
"y": 160,
"wires": [
[
"c3d1a92d.227568"
]
]
},
{
"id": "276cfad7.cef62e",
"type": "function",
"z": "b4106ec1.63dd58",
"name": "Set Chat Context",
"func": "msg.payload = {\n chatId : msg.chatId,\n topic : msg.type,\n type : \"message\",\n content : msg.payload};\nreturn msg;\n",
"outputs": 1,
"noerr": 0,
"x": 730,
"y": 220,
"wires": [
[
"c6ec445d.0840d8"
]
]
},
{
"id": "c3d1a92d.227568",
"type": "switch",
"z": "b4106ec1.63dd58",
"name": "Check msg type",
"property": "type",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "message",
"vt": "str"
},
{
"t": "eq",
"v": "voice",
"vt": "str"
},
{
"t": "else"
}
],
"checkall": "true",
"repair": false,
"outputs": 3,
"x": 300,
"y": 240,
"wires": [
[
"e8452a44.f967c8"
],
[
"6aea6224.578d8c"
],
[]
]
},
{
"id": "e8452a44.f967c8",
"type": "function",
"z": "b4106ec1.63dd58",
"name": "Echo message",
"func": "msg.payload = {\n chatId : msg.chatId,\n topic : \"Text Echo\",\n type : msg.type,\n content : msg.content};\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 540,
"y": 80,
"wires": [
[
"c6ec445d.0840d8"
]
]
},
{
"id": "6aea6224.578d8c",
"type": "change",
"z": "b4106ec1.63dd58",
"name": "Set voice URL",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "payload.weblink",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 440,
"y": 300,
"wires": [
[
"fc7b1590.557c"
]
]
},
{
"id": "493d1bac.216d3c",
"type": "change",
"z": "b4106ec1.63dd58",
"name": "Set transcription",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "transcription",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 680,
"y": 300,
"wires": [
[
"276cfad7.cef62e"
]
]
},
{
"id": "fc7b1590.557c",
"type": "watson-speech-to-text",
"z": "b4106ec1.63dd58",
"name": "S2T",
"alternatives": 1,
"speakerlabels": false,
"smartformatting": false,
"lang": "en-GB",
"langhidden": "en-GB",
"langcustom": "NoCustomisationSetting",
"langcustomhidden": "",
"custom-weight": "0.5",
"band": "BroadbandModel",
"bandhidden": "BroadbandModel",
"keywords": "",
"keywords-threshold": "0.5",
"word-confidence": false,
"password": "",
"apikey": "#########CHANGED VALUE TO POST###########",
"payload-response": false,
"streaming-mode": false,
"streaming-mute": true,
"auto-connect": false,
"discard-listening": false,
"disable-precheck": false,
"default-endpoint": true,
"service-endpoint": "https://stream.watsonplatform.net/speech-to-text/api",
"x": 530,
"y": 360,
"wires": [
[
"493d1bac.216d3c"
]
]
},
{
"id": "5f347711.7876d8",
"type": "telegram bot",
"z": "",
"botname": "FMWatsonBot",
"usernames": "",
"chatids": "",
"baseapiurl": "",
"updatemode": "polling",
"pollinterval": "300",
"bothost": "",
"localbotport": "8443",
"publicbotport": "8443",
"privatekey": "",
"certificate": "",
"verboselogging": false
}
]
Any hint?
Thanks in advance
Ferruccio
It boils down to how you are fetching the audio from Telegram. Check the answer to this related question - https://developer.ibm.com/answers/questions/424777/help-how-do-i-use-speech-to-text-with-my-telegram/
which shows how to build the url to send through to the Speech to text node.
Update: Flow perfectly works with telegram node v4.4.0, but fails with new version 5.1.5
So, it's not a problem regarding Speech to Text node.
I have no problems creating GTM variables from 'simple' dataLayer,
example:
"transactionEntity": "ORDER",
"transactionId": "193552702",
But can't understand how to take values from array.
Basically i need to take ID value from these dataLayer table:
"transactionProducts": [
{
"id": "5",
"sku": "black-handbag",
"price": 170,
"priceexcludingtax": "0.00",
"tax": "0.00",
"taxrate": 0,
"type": "bundle",
"category": "",
"quantity": 1
},
{
"id": "3",
"sku": "red-handbag",
"price": 120,
"priceexcludingtax": "0.00",
"tax": "0.00",
"taxrate": 0,
"type": "bundle",
"category": "",
"quantity": 1
}
],
And to pass them to FB pixel using this format:
content_ids: ['5', '3'],
If you have datalayer like that:
<script>
dataLayer.push({
'ecommerce': {
"transactionProducts": [
{
"id": "5",
"sku": "black-handbag",
"price": 170,
"priceexcludingtax": "0.00",
"tax": "0.00",
"taxrate": 0,
"type": "bundle",
"category": "",
"quantity": 1
},
{
"id": "3",
"sku": "red-handbag",
"price": 120,
"priceexcludingtax": "0.00",
"tax": "0.00",
"taxrate": 0,
"type": "bundle",
"category": "",
"quantity": 1
}
]
}
});
</script>
And you want to create variable which will return array of IDs ['5', '3']
Then you need to create two variables:
1) Name: transactionProducts
Type: Data Layer Variable
Data Layer Variable Name: ecommerce.transactionProducts
2) Name: transactionProductsIds
Type: Custom JavaScript
Custom JavaScript: function () { return {{transactionProducts}}.map(function(a) {return a.id;}); }
And then you can use your second variable transactionProductsIds to receive IDs
I've a JSON object as follows which is most of the time having no specific structures. This been created from the client side using jquery and sending to the server side via AJAX.
{
"items": {
"1": [{
"text": "Man",
"itemID": "1",
"checked": 1,
"sequence": 1,
"matchingtext": "",
"weight": 0
}, {
"text": "goat",
"itemID": "2",
"checked": 0,
"sequence": 2,
"matchingtext": "",
"weight": 0
}, {
"text": "dog",
"itemID": "3",
"checked": 0,
"sequence": 3,
"matchingtext": "",
"weight": 0
}],
"2": [{
"text": "pizza",
"itemID": "1",
"checked": 1,
"sequence": 1,
"matchingtext": "",
"weight": 0
}, {
"text": "horse",
"itemID": "2",
"checked": 0,
"sequence": 2,
"matchingtext": "",
"weight": 0
}, {
"text": "paper",
"itemID": "3",
"checked": 0,
"sequence": 3,
"matchingtext": "",
"weight": 0
}]
},
"wbmode": "dd",
"wbanswertype": "sc"
}
Since its not having any specific structure I cant de-serialize it using some structured classes.
So how can I traverse across all the objects of items such as in this case 1 and 2
I would recommend using the JSON.NET library (available via NuGet). Once you add reference to it in your project and import the library to your class, you can traverse through the JSON structure like this:
Dim jsonString = "{""items"":{""1"":[{""text"":""Man"",""itemID"":""1"",""checked"":1,""sequence"":1,""matchingtext"":"""",""weight"":0},{""text"":""goat"",""itemID"":""2"",""checked"":0,""sequence"":2,""matchingtext"":"""",""weight"":0},{""text"":""dog"",""itemID"":""3"",""checked"":0,""sequence"":3,""matchingtext"":"""",""weight"":0}],""2"":[{""text"":""pizza"",""itemID"":""1"",""checked"":1,""sequence"":1,""matchingtext"":"""",""weight"":0},{""text"":""horse"",""itemID"":""2"",""checked"":0,""sequence"":2,""matchingtext"":"""",""weight"":0},{""text"":""paper"",""itemID"":""3"",""checked"":0,""sequence"":3,""matchingtext"":"""",""weight"":0}]},""wbmode"":""dd"",""wbanswertype"":""sc""}"
Dim j As JObject = JObject.Parse(jsonString)
For Each item As JProperty In j.Item("items")
Dim itemObjects As JToken = item.Value
For Each i As JObject In itemObjects
For Each p In i
Debug.Print(p.Key.ToString & " = " & p.Value.ToString)
Next
Next
Next