Skip to content

Commit

Permalink
jq: cleanPath and treeAddAttrs
Browse files Browse the repository at this point in the history
  • Loading branch information
bogovicj committed Nov 8, 2023
1 parent 4c5f020 commit 2d7f5d4
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/main/resources/n5.jq
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ def hasDims: .attributes | has("dimensions");

def flattenTree: .. | select( type == "object" and has("path")) | del(.children);

def cleanPath: . | sub("^\\.(?<x>.*)\\/.+"; "\(.x)"; "g");

def parentPath: if length <= 1 then "" elif length == 2 then .[0] else .[0:-1] | map(select( . != "children")) | join("/") end;

def attrPaths: paths | select(.[-1] == "attributes");
Expand Down Expand Up @@ -293,6 +295,11 @@ def getSubTree( $path ): getpath( $path | toTreePath );
def moveSubTree( $srcPath; $dstPath ): getSubTree( $srcPath ) as $subTree | setpath( $dstPath | toTreePath; $subTree )
| delpaths([$srcPath | toTreePath]);

def treeAddAttrs( $path; $attrs ):
($path | toTreePath | . + ["attributes"]) as $p |
getpath( $p ) as $currentAttrs |
setpath( $p; $currentAttrs + $attrs );

def canonicalAxis( $type; $lbl; $unit ): {
"type" : $type,
"label" : $lbl,
Expand Down

0 comments on commit 2d7f5d4

Please sign in to comment.