How to Create a 3 level graph using NEO4J using JSON Array of Objects - neo4j

I want to create a graph using neo4j which gives me a graph of the terms in the "JavaScript" array of the following JSON data, along with relationships pointing to unique "relatedTerms" nodes.
Here is my JSON data:
{
"JavaScript": [
{
"termName": "asm.js",
"link": "/terms/javascript/asmjs",
"info": "A subset of JavaScript. Effectively describes a safe virtual machine for memory-unsafe languages like C or C++. It can be used as a low-level, efficient target language for compilers.",
"relatedTerms": [
{
"name": "JavaScript",
"link": "/terms/go_to_term/549"
},
{
"name": "C",
"link": "/terms/go_to_term/470"
},
{
"name": "C++",
"link": "/terms/go_to_term/860"
},
{
"name": "compilers",
"link": "/terms/go_to_term/390"
}
],
"category": "JavaScript"
},
{
"termName": "Cycle.js",
"link": "/terms/javascript/cyclejs",
"info": "JavaScript framework for a predictable code. Builds on functional and reactive streams. Describes an app as a simple function taking an event stream as input and outputting an event stream.",
"relatedTerms": [
{
"name": "JavaScript",
"link": "/terms/go_to_term/549"
}
],
"category": "JavaScript"
},
{
"termName": "Derby",
"link": "/terms/javascript/derby",
"info": "Server component which is written on top of Node.js. It's is a server-side application with rich real-time data synchronization technology such used in google docs.",
"relatedTerms": [
{
"name": "Node.js",
"link": "/terms/go_to_term/595"
}
],
"category": "JavaScript"
},
{
"termName": "Express.js",
"link": "/terms/javascript/expressjs",
"info": "Lightweight, efficient middleware and routing framework. Express.js is best known as another quarter of the MEAN (MongoDB, Express, AngularJS and Node) software stack, and is the most popular Node.js framework.",
"relatedTerms": [
{
"name": "MEAN",
"link": "/terms/go_to_term/361"
},
{
"name": "MongoDB",
"link": "/terms/go_to_term/868"
},
{
"name": "AngularJS",
"link": "/terms/go_to_term/47"
},
{
"name": "Node",
"link": "/terms/go_to_term/595"
}
],
"category": "JavaScript"
},
{
"termName": "Flow",
"link": "/terms/javascript/flow",
"info": "A static type checker for JavaScript. Integrates with the code editor by checking changes and analyzing correctness of the code. Provides context as to what is wrong with the code.",
"relatedTerms": [
{
"name": "JavaScript",
"link": "/terms/go_to_term/549"
}
],
"category": "JavaScript"
},
{
"termName": "Hapi",
"link": "/terms/javascript/hapi",
"info": "Web framework for building web applications, APIs and services. Hapi was created around the idea that configuration is better than code, that business logic must be isolated from the transport layer.",
"relatedTerms": [
{
"name": "APIs",
"link": "/terms/go_to_term/206"
}
],
"category": "JavaScript"
},
{
"termName": "Koa",
"link": "/terms/javascript/koa",
"info": "Callback-less, lightweight middleware framework for Node.js to build efficient web applications and APIs. Koa.js efficiently uses generators to deal with callbacks and increase error-handling capabilities.",
"relatedTerms": [
{
"name": "Node.js",
"link": "/terms/go_to_term/595"
},
{
"name": "API",
"link": "/terms/go_to_term/206"
}
],
"category": "JavaScript"
},
{
"termName": "MEAN",
"link": "/terms/javascript/mean",
"info": "A full stack JavaScript solution that refers to the first letters of the four components of a solution for building dynamic websites: MongoDB, a NoSQL database; Express.js, a web applications framework; Angular.js, a JavaScript MVC framework for web apps; Node.js, a software platform for scalable server-side and networking applications.",
"relatedTerms": [
{
"name": "JavaScript",
"link": "/terms/go_to_term/549"
},
{
"name": "MongoDB",
"link": "/terms/go_to_term/868"
},
{
"name": "NoSQL",
"link": "/terms/go_to_term/951"
},
{
"name": "Express.js",
"link": "/terms/go_to_term/392"
},
{
"name": "Angular.js",
"link": "/terms/go_to_term/47"
},
{
"name": "MVC",
"link": "/terms/go_to_term/201"
},
{
"name": "Node.js",
"link": "/terms/go_to_term/595"
}
],
"category": "JavaScript"
},
{
"termName": "Meteor",
"link": "/terms/javascript/meteor",
"info": "JavaScript framework built on top of Node.js with MongoDB as its database driver. With Node.js and Meteor, you’re using JavaScript everywhere, and data is synced through the use of WebSockets, a protocol that allows an interactive communication between server and browser.",
"relatedTerms": [
{
"name": "Node.js",
"link": "/terms/go_to_term/595"
},
{
"name": "MongoDB",
"link": "/terms/go_to_term/868"
},
{
"name": "JavaScript",
"link": "/terms/go_to_term/549"
},
{
"name": "WebSockets",
"link": "/terms/go_to_term/1046"
}
],
"category": "JavaScript"
},
{
"termName": "Node.js",
"link": "/terms/javascript/nodejs",
"info": "One of the most popular JavaScript frameworks which eases the work of building web applications. By far the fastest growing language in use. Runs on Windows, Linux, and Mac OS. The use of Node.js is mainly for full stack, front-end and back-end.",
"relatedTerms": [
{
"name": "JavaScript",
"link": "/terms/go_to_term/549"
},
{
"name": "Windows",
"link": "/terms/go_to_term/1373"
},
{
"name": "Linux",
"link": "/terms/go_to_term/558"
},
{
"name": "Node.js",
"link": "/terms/go_to_term/595"
}
],
"category": "JavaScript"
},
{
"termName": "Oracle JET",
"link": "/terms/javascript/oracle_jet",
"info": "Oracle JavaScript Extension Toolkit. A modular toolkit based on modern JavaScript, CSS3 and HTML5 design and development principles. Created for developers who work on applications that consume and interact with Oracle products and services.",
"relatedTerms": [
],
"category": "JavaScript"
},
{
"termName": "Restify",
"link": "/terms/javascript/restify",
"info": "A Node.js module built specifically to enable to build correct REST web services. It borrows heavily from express as that is more or less the de facto API for writing web applications on top of Node.js.",
"relatedTerms": [
{
"name": "Node.js",
"link": "/terms/go_to_term/595"
},
{
"name": "REST",
"link": "/terms/go_to_term/524"
},
{
"name": "API",
"link": "/terms/go_to_term/206"
}
],
"category": "JavaScript"
},
{
"termName": "Sails",
"link": "/terms/javascript/sails",
"info": "Sails.js wraps express and provides another higher level for doing things like connecting to the DB, auto-generating input pages, etc. Especially suitable for creating chat apps or multiplayer games.",
"relatedTerms": [
{
"name": "DB",
"link": "/terms/go_to_term/415"
}
],
"category": "JavaScript"
},
{
"termName": "Seneca",
"link": "/terms/javascript/seneca",
"info": "Microservices toolkit for Node.js. Helps to write an organized code that can be scaled and deployed at any time. Organizes the business logic of an app.",
"relatedTerms": [
{
"name": "Node.js",
"link": "/terms/go_to_term/595"
}
],
"category": "JavaScript"
}
]
}
My Expected Result looks like:
The following is my Query:
CALL apoc.load.json("file:///js.json") YIELD value
UNWIND value.JavaScript AS item
FOREACH(js IN item |
CREATE(cat:Category{name:js.termName})
FOREACH(rt in item.relatedTerms|
CREATE(rtt:RelatedTerms{name:rt.name})
MERGE (cat)-[r:RELATESTO]->(rtt)))
And here is my Actual Result:

Try switching the CREATE statements for MERGE statements. In Cypher, MERGE will check to see if a pattern exists and create it if it does not. CREATE will create a new pattern every time, even if a pattern like it already exists in the graph.
CALL apoc.load.json("file:///js.json") YIELD value
UNWIND value.JavaScript AS item
MERGE (cat:Category {name:item.termName})
WITH cat, item
UNWIND item.relatedTerms AS subitem
MERGE (rt:RelatedTerm {name:subitem.name})
MERGE (cat)-[:RELATES_TO]->(rt)
RETURN *

Related

How to create zoom like response in slack bot message using block kit?

I have used zoom integration with slack. When I send /zoom command the bot responds with a new meeting link in a box layout that looks really good.
Note the bordered box below "Call"
However I am not able to create similar box layout with border and section in my own slack bot. Which block kit syntax should I use to achieve the same design?
At max what I am able to achieve is like the below:
I did not find any relevant example in the documentation as well.
There are multiple ways suggested in slack's official documentation to format Messages in responses.
For instance:
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Hello, Assistant to the Regional Manager Dwight! *Michael Scott* wants to know where you'd like to take the Paper Company investors to dinner tonight.\n\n *Please select a restaurant:*"
}
},
{
"type": "divider"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Farmhouse Thai Cuisine*\n:star::star::star::star: 1528 reviews\n They do have some vegan options, like the roti and curry, plus they have a ton of salad stuff and noodles can be ordered without meat!! They have something for everyone here"
},
"accessory": {
"type": "image",
"image_url": "https://s3-media3.fl.yelpcdn.com/bphoto/c7ed05m9lC2EmA3Aruue7A/o.jpg",
"alt_text": "alt text for image"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Kin Khao*\n:star::star::star::star: 1638 reviews\n The sticky rice also goes wonderfully with the caramelized pork belly, which is absolutely melt-in-your-mouth and so soft."
},
"accessory": {
"type": "image",
"image_url": "https://s3-media2.fl.yelpcdn.com/bphoto/korel-1YjNtFtJlMTaC26A/o.jpg",
"alt_text": "alt text for image"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Ler Ros*\n:star::star::star::star: 2082 reviews\n I would really recommend the Yum Koh Moo Yang - Spicy lime dressing and roasted quick marinated pork shoulder, basil leaves, chili & rice powder."
},
"accessory": {
"type": "image",
"image_url": "https://s3-media2.fl.yelpcdn.com/bphoto/DawwNigKJ2ckPeDeDM7jAg/o.jpg",
"alt_text": "alt text for image"
}
},
{
"type": "divider"
},
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": "Farmhouse",
"emoji": true
},
"value": "click_me_123"
},
{
"type": "button",
"text": {
"type": "plain_text",
"text": "Kin Khao",
"emoji": true
},
"value": "click_me_123",
"url": "https://google.com"
},
{
"type": "button",
"text": {
"type": "plain_text",
"text": "Ler Ros",
"emoji": true
},
"value": "click_me_123",
"url": "https://google.com"
}
]
}
]}
You can use these components to design your own experience in response.
Further reading: https://api.slack.com/messaging/composing
I think the elements you are referring to are produced by the Call API
It doesn't seem that it is an available block for use in message building.

DTDL - How to create object for location (lat,long)?

I have DTDL model similar to below. I can use Json as string and store lat,long values. But,
How I can store lat,long array of locations using objects.
{
"#id": "dtmi:DigitalTwins:BasicInfra;2",
"#type": "Interface",
"displayName": "BasicInfra interface model",
"#context": "dtmi:dtdl:context;2",
"contents": [
{
"#type": "Property",
"name": "name",
"schema": "string"
},
{
"#type": "Property",
"name": "location",
"description": "Polygon/PolyLine Format Location",
"schema": {
"#type": "Object",
"fields": [
{
"name": "x",
"schema": "double"
},
{
"name": "y",
"schema": "double"
}
]
}
},
{
"#type": "Relationship",
"name": "contains"
}
]
}
Thanks for posting this question.
We got a response from Microsoft's Product Team.
At the moment, we don't support arrays in properties.
Please follow Azure Digital Twins updates, blogs, and announcements to get latest information on upcoming features. Also Product Updates page.

Slack API invalid_block

I'm building a simple slack bot and I am playing with the checkboxes element.
When I return the following from my API in a JSON response to a slash-command I get an error failed with the error "invalid_blocks", however, when I put this in the block-kit-builder it works perfectly (including "sending to slack" button)
Any ideas why this is failing when I run my slash command - and is it possible to see more detailed error messages from slack?
{
"blocks": [
{
"elements": [
{
"style": "primary",
"text": {
"emoji": true,
"text": "Create new TODO list",
"type": "plain_text"
},
"type": "button",
"value": "value"
},
{
"style": "primary",
"text": {
"emoji": true,
"text": "Help",
"type": "plain_text"
},
"type": "button",
"value": "value"
}
],
"type": "actions"
},
{
"text": {
"text": "Today",
"type": "mrkdwn"
},
"type": "section"
},
{
"elements": [
{
"initial_options": [
{
"text": {
"text": "Get Into the garden",
"type": "mrkdwn"
},
"value": "foo"
}
],
"options": [
{
"text": {
"text": "Get Into the garden",
"type": "mrkdwn"
},
"value": "foo"
}
],
"type": "checkboxes"
},
{
"style": "primary",
"text": {
"emoji": true,
"text": "Add new Task",
"type": "plain_text"
},
"type": "button",
"value": "value"
}
],
"type": "actions"
}
],
"type": "home"
}
I am using the Slack Web API. I was getting the similar error. After a lot of looking around, here's how I solved it.
import json
blocks = [{...}]
payload = {
"blocks": json.dumps(blocks)
}
You will then send this payload.
in the api, the "blocks" parameter need to be string type. Did you convert it to string or you use it as a JSON ?
https://api.slack.com/methods/chat.postMessage
In the Block Kit Builder, the data is a JSON with a blocks key.
In the Slack API, the blocks param is only the list of JSON objects.
blocks = [
{
"text": {
"text": "Its the list of your blocks",
"type": "mrkdwn"
},
"type": "section"
}
]
text = 'Alternative data in text'
client.chat_postMessage(channel=channel_id, blocks=blocks, text=text)
Another cause of this problem seems to be too many blocks being returned. I can't find any documentation about this whatsoever, but personal experience seems to indicate about 20 blocks is the maximum.
An alternative is to return fewer blocks, with paging actions -- paging works well with the "replace" message so that the content being paged through does not result in many separate messages.
It appears that not all valid elements in block kit tool can be posted as a message, despite the fact that message preview works fine in the Block Tool.
In my case, the code failed when I included an input block and passed when i removed it. The input block was generated by the Block Kit tool.
{
"type": "input",
"element": {
"type": "plain_text_input",
"action_id": "plain_text_input-action"
},
"label": {
"type": "plain_text",
"text": "Feedback",
"emoji": true
}
}
The error was
{'ok': False, 'error': 'invalid_blocks'}
Also, although the documentation for python says you need to urlEncode the JSON-based array, there is no example, and it is incorrect. https://api.slack.com/methods/chat.postMessage
You can see on line 29 in the SDK test code below that blocks= takes a regular list of dicts not a string.
https://github.com/slackapi/python-slack-sdk/blob/c9dc6aa0907a72c16cf36aa15e7e80031a9fdce2/integration_tests/samples/basic_usage/sending_a_message.py

DWG to DGN conversion using Design Automation API

Is there any possibility for conversion from dwg to dgn using forge design automation api? If yes then what will be the best way to do that? Any suggestion would be helpful.
Yes, you can use the -DGNEXPORT command in your script to accomplish this.
I was trying to get a concrete codes for this question as it requires some tricks and support of seed file on Design Automation. By engineer team's help, now it is working.
Assume we test with Postman. If you are working with v2 of Design Automation, the scripts below demo the usage.
Activity:
{
"HostApplication": "",
"RequiredEngineVersion": "23.1",
"Parameters": {
"InputParameters": [{
"Name": "HostDwg",
"LocalFileName": "$(HostDwg)"
}],
"OutputParameters": [{
"Name": "Result",
"LocalFileName": "result.dgn"
}]
},
"Instruction": {
"CommandLineParameters": null,
"Script":"(command \"_-DGNEXPORT\" \"_V8\" (strcat (getvar \"DWGPREFIX\")
\"result.dgn\") \"_Master\" \"Standard\" (strcat (getvar \"LOCALROOTPREFIX\")
\"Template\\\\V8-Imperial-Seed3D.dgn\"))\n"
},
"Version": 1,
"Id": "CreateActByLISP"
}
WorkItem:
{
"#odata.type": "#ACES.Models.WorkItem",
"Arguments": {
"InputArguments": [
{
"Resource": "http://forge-test.oss-cn-shanghai.aliyuncs.com/test.dwg",
"Name": "HostDwg",
"StorageProvider": "Generic"
}
],
"OutputArguments": [
{
"Name": "Result",
"StorageProvider": "Generic",
"HttpVerb": "POST",
"Resource": null
}
]
},
"ActivityId": "CreateActByLISP",
"Id": ""
}
If working with v3 of Design Automation, the script would be as below. Note: the engine needs 23.1 (Autodesk.AutoCAD+23_1)
Activity
{
"commandLine": [
"$(engine.path)\\accoreconsole.exe /i $(args[HostDwg].path) /s $(settings[script].path)"
],
"parameters": {
"HostDwg": {
"verb": "get",
"description": "Host drawing to be loaded into acad.",
"localName": "$(HostDwg)"
},
"Result": {
"verb": "post",
"description": "Results",
"localName": "result.dgn"
}
},
"engine": "Autodesk.AutoCAD+23_1",
"appbundles": [],
"settings": {
"script": {
"value": "(command \"_-DGNEXPORT\" \"_V8\" (strcat (getvar \"DWGPREFIX\") \"result.dgn\") \"_Master\" \"Standard\" (strcat (getvar \"LOCALROOTPREFIX\") \"Template\\\\V8-Imperial-Seed3D.dgn\"))\n"
}
},
"description": "PlotToPdf for all layouts.",
"id": "myexportdgn"
}
WorkItem:
{
"activityId": "{{your nick name}}.myexportdgn+{{activity alias}}",
"arguments": {
"HostDwg": {
"url": "http://forge-test.oss-cn-shanghai.aliyuncs.com/test.dwg"
},
"Result": {
"verb": "put",
"url": "<your upload url>"
}
}
}

Using YQL to get Options Data

Using the YQL console I did:
select * from yahoo.finance.options where symbol="FB"
but I got the following result in JSON. There is no data in the optionsChain. Based on other posts I believe the request to be formatted correctly. How do I get the data that should be in the options chain? Is this out of date or am I missing something? Thanks in advance.
{
"query": {
"count": 1,
"created": "2015-01-10T17:26:16Z",
"lang": "en-US",
"diagnostics": {
"url": [
{
"execution-start-time": "0",
"execution-stop-time": "71",
"execution-time": "71",
"content": "http://www.datatables.org/yahoo/finance/yahoo.finance.options.xml"
},
{
"execution-start-time": "74",
"execution-stop-time": "1620",
"execution-time": "1546",
"content": "http://finance.yahoo.com/q/op?s=FB"
}
],
"publiclyCallable": "true",
"log": [
"results.length(): 0",
"no elements"
],
"javascript": {
"execution-start-time": "74",
"execution-stop-time": "1647",
"execution-time": "1573",
"instructions-used": "11272",
"table-name": "yahoo.finance.options"
},
"user-time": "1648",
"service-time": "1537",
"build-version": "0.2.278"
},
"results": {
"optionsChain": {
"symbol": "FB"
}
}
}
}
Lots of people having problems with this myself included.
After looking around I found out that Google's Option information is also available via JSON.
It's no good for production environments as it's unsupported and really just a function of how there site operates, but if your interested I did a tutorial with full sample code on it. Even better it's REST based so can be consumed fairly easily in any language.
Google Stock Option Chain Data

Resources