Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/badetitou/moose2graphjson
Import and export MooseModel in a JSON format that is easy to use with Neo4J
https://github.com/badetitou/moose2graphjson
metamodel moose neo4j
Last synced: about 1 month ago
JSON representation
Import and export MooseModel in a JSON format that is easy to use with Neo4J
- Host: GitHub
- URL: https://github.com/badetitou/moose2graphjson
- Owner: badetitou
- License: mit
- Created: 2020-02-05T16:26:45.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2024-05-28T17:47:07.000Z (7 months ago)
- Last Synced: 2024-05-29T08:48:34.103Z (7 months ago)
- Topics: metamodel, moose, neo4j
- Language: Smalltalk
- Homepage:
- Size: 102 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Moose2GraphJson
I can export and import any MooseModel in a json format adapted for graph database
## Install
### Stable version
```smalltalk
Metacello new
githubUser: 'badetitou' project: 'Moose2GraphJson' commitish: 'v1.0.0' path: 'src';
baseline: 'Moose2GraphJson';
load
```### Last version
```smalltalk
Metacello new
githubUser: 'badetitou' project: 'Moose2GraphJson' commitish: 'main' path: 'src';
baseline: 'Moose2GraphJson';
load
```## Export a model
```smalltalk
'D:/test.json' asFileReference writeStreamDo: [ :stream | (M2GJExporter on: stream) writeMooseModel: aMooseModel ]
```## Import a model
```smalltalk
(M2GJImporter on: 'D:/ref/to/model.json' asFileReference readStream)
model: MooseModel new;
yourself.
importer import.
importer model name
```## Import in neo4j
You can load the generated json file with this command
```db
CALL apoc.load.json('file:///test-graph.json') YIELD value
WITH value.nodes AS nodes, value.relationships AS rels
UNWIND nodes AS n
CALL apoc.create.node(n.labels, apoc.map.setKey(n.properties, 'id', n.id)) YIELD node
WITH rels, apoc.map.fromPairs(COLLECT([n.id, node])) AS nMap
UNWIND rels AS r
WITH r, nMap[TOSTRING(r.startNode)] AS startNode, nMap[TOSTRING(r.endNode)] AS endNode
WHERE startNode IS NOT NULL and endNode IS NOT NULL
CALL apoc.create.relationship(startNode, r.type, r.properties, endNode) YIELD rel
RETURN rel
```## JSON model format
## Goal
Import and Export Fame model the following format
```json
{
"name":"modelName",
"nodes": [
{
"id": 3510982,
"labels": ["FAMIX.Class"],
"properties": { "isStub": false, "isInterface": false, "numberOfLinesOfCode": 0, "name": "a" }
},
{
"id": 3510983,
"labels": ["FAMIX.Attribute"],
"properties": { "name": "a1", "hasClassScope": false, "numberOfLinesOfCode": -1, "isStub": false }
},
{
"id": 3510984,
"labels": ["FAMIX.Attribute"],
"properties": { "name": "a2", "hasClassScope": false, "numberOfLinesOfCode": -1, "isStub": false }
}
],
"relationships": [
{ "type": "parentType", "startNode": 3510983, "endNode": 3510982, "properties": {} },
{ "type": "parentType", "startNode": 3510984, "endNode": 3510982, "properties": {} }
]
}
```