Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions artefact/lib/artefact/cypher.ex
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,21 @@ defmodule Artefact.Cypher do
"(#{id}#{label_str} #{prop_str})"
end

defp effective_labels(labels, nil), do: labels
defp effective_labels(labels, base_label), do: Enum.uniq(labels ++ [base_label])
defp effective_labels(labels, nil), do: pascal_case(labels)
defp effective_labels(labels, base_label), do: pascal_case(Enum.uniq(labels ++ [base_label]))

defp pascal_case(labels) when is_list(labels) do
Enum.map(labels, &pascal_case(&1))
end

defp pascal_case(label) when is_binary(label) do
# split by spaces, captialise first letter only and join
String.split(label, " ") |> Enum.map_join(&capitalize_first(&1))
end

def capitalize_first(<<first::utf8, rest::binary>>) do
String.upcase(<<first::utf8>>) <> rest
end

defp rel_pattern(%Artefact.Relationship{type: type, properties: props}) do
prop_str = props_to_cypher(props)
Expand Down
4 changes: 2 additions & 2 deletions artefact/test/artefact_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -688,8 +688,8 @@ defmodule ArtefactTest do
assert length(a.graph.nodes) == 8
end

test "base_label is ArtefactHarmonise", %{artefact: a} do
assert a.base_label == "ArtefactHarmonise"
test "base_label is Artefact Harmonise", %{artefact: a} do
assert a.base_label == "Artefact Harmonise"
end

test "has compose, harmonise, Binding, guards and outcomes", %{artefact: a} do
Expand Down
2 changes: 1 addition & 1 deletion artefact/test/data/artefact_harmonise/arrows.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"base_label":"ArtefactHarmonise","nodes":[{"caption":"","id":"n0","labels":["Operation","ArtefactHarmonise"],"position":{"x":-300,"y":-150},"properties":{"meaning":"Disjoint union; nodes reindexed to avoid id collision","name":"compose","uuid":"019da93e-ef0c-774e-b2f5-385d9da61db9"},"style":{}},{"caption":"","id":"n1","labels":["Operation","ArtefactHarmonise"],"position":{"x":300,"y":-150},"properties":{"meaning":"Merge bound nodes; lower uuid wins identity, labels unioned, left-wins properties","name":"harmonise","uuid":"019da93e-ef0c-7f46-bcc5-34b814ba0a3b"},"style":{}},{"caption":"","id":"n2","labels":["Mechanism","ArtefactHarmonise"],"position":{"x":600,"y":-150},"properties":{"meaning":"Declares node equivalence; auto-detected by shared uuid or injected explicitly","name":"Binding","uuid":"019da93e-ef0c-7f50-a41b-c37bef7a232d"},"style":{}},{"caption":"","id":"n3","labels":["Outcome","ArtefactHarmonise"],"position":{"x":-300,"y":150},"properties":{"meaning":"Graphs side by side; label-based implicit relationships","name":"Disjoint","uuid":"019da93e-ef0c-7257-b962-6b8a46a8e712"},"style":{}},{"caption":"","id":"n4","labels":["Outcome","ArtefactHarmonise"],"position":{"x":300,"y":150},"properties":{"meaning":"Bound nodes fused; relationships deduplicated by from/type/to, left-wins properties","name":"Merged","uuid":"019da93e-ef0c-75ed-95d2-e805513d2b7d"},"style":{}},{"caption":"","id":"n5","labels":["Guard","ArtefactHarmonise"],"position":{"x":0,"y":350},"properties":{"meaning":"Artefact cannot be harmonised with itself","name":"SameUUID","uuid":"019da93e-ef0c-7cda-90d3-e34bf1541ddb"},"style":{}},{"caption":"","id":"n6","labels":["Guard","ArtefactHarmonise"],"position":{"x":600,"y":150},"properties":{"meaning":"Artefacts from the same base_label family cannot be harmonised","name":"SameBaseLabel","uuid":"019da93e-ef0c-733d-9971-662b0d380c11"},"style":{}},{"caption":"","id":"n7","labels":["Struct","ArtefactHarmonise"],"position":{"x":0,"y":-350},"properties":{"name":"Artefact","uuid":"019da897-f2e0-74b2-ab91-4d68115d4f71"},"style":{}}],"relationships":[{"fromId":"n7","id":"r0","properties":{},"style":{},"toId":"n0","type":"HAS_OPERATION"},{"fromId":"n7","id":"r1","properties":{},"style":{},"toId":"n1","type":"HAS_OPERATION"},{"fromId":"n1","id":"r2","properties":{},"style":{},"toId":"n2","type":"REQUIRES"},{"fromId":"n0","id":"r3","properties":{},"style":{},"toId":"n3","type":"PRODUCES"},{"fromId":"n1","id":"r4","properties":{},"style":{},"toId":"n4","type":"PRODUCES"},{"fromId":"n1","id":"r5","properties":{},"style":{},"toId":"n5","type":"RAISES_ON"},{"fromId":"n1","id":"r6","properties":{},"style":{},"toId":"n6","type":"RAISES_ON"}],"style":{},"title":"ArtefactHarmonise","uuid":"019da93f-1f64-744c-aefa-4ecbf75358c3"}
{"base_label":"Artefact Harmonise","nodes":[{"caption":"","id":"n0","labels":["Operation","Artefact Harmonise"],"position":{"x":-300,"y":-150},"properties":{"meaning":"Disjoint union; nodes reindexed to avoid id collision","name":"compose","uuid":"019da93e-ef0c-774e-b2f5-385d9da61db9"},"style":{}},{"caption":"","id":"n1","labels":["Operation","Artefact Harmonise"],"position":{"x":300,"y":-150},"properties":{"meaning":"Merge bound nodes; lower uuid wins identity, labels unioned, left-wins properties","name":"harmonise","uuid":"019da93e-ef0c-7f46-bcc5-34b814ba0a3b"},"style":{}},{"caption":"","id":"n2","labels":["Mechanism","Artefact Harmonise"],"position":{"x":600,"y":-150},"properties":{"meaning":"Declares node equivalence; auto-detected by shared uuid or injected explicitly","name":"Binding","uuid":"019da93e-ef0c-7f50-a41b-c37bef7a232d"},"style":{}},{"caption":"","id":"n3","labels":["Outcome","Artefact Harmonise"],"position":{"x":-300,"y":150},"properties":{"meaning":"Graphs side by side; label-based implicit relationships","name":"Disjoint","uuid":"019da93e-ef0c-7257-b962-6b8a46a8e712"},"style":{}},{"caption":"","id":"n4","labels":["Outcome","Artefact Harmonise"],"position":{"x":300,"y":150},"properties":{"meaning":"Bound nodes fused; relationships deduplicated by from/type/to, left-wins properties","name":"Merged","uuid":"019da93e-ef0c-75ed-95d2-e805513d2b7d"},"style":{}},{"caption":"","id":"n5","labels":["Guard","Artefact Harmonise"],"position":{"x":0,"y":350},"properties":{"meaning":"Artefact cannot be harmonised with itself","name":"SameUUID","uuid":"019da93e-ef0c-7cda-90d3-e34bf1541ddb"},"style":{}},{"caption":"","id":"n6","labels":["Guard","Artefact Harmonise"],"position":{"x":600,"y":150},"properties":{"meaning":"Artefacts from the same base_label family cannot be harmonised","name":"SameBaseLabel","uuid":"019da93e-ef0c-733d-9971-662b0d380c11"},"style":{}},{"caption":"","id":"n7","labels":["Struct","Artefact Harmonise"],"position":{"x":0,"y":-350},"properties":{"name":"Artefact","uuid":"019da897-f2e0-74b2-ab91-4d68115d4f71"},"style":{}}],"relationships":[{"fromId":"n7","id":"r0","properties":{},"style":{},"toId":"n0","type":"HAS_OPERATION"},{"fromId":"n7","id":"r1","properties":{},"style":{},"toId":"n1","type":"HAS_OPERATION"},{"fromId":"n1","id":"r2","properties":{},"style":{},"toId":"n2","type":"REQUIRES"},{"fromId":"n0","id":"r3","properties":{},"style":{},"toId":"n3","type":"PRODUCES"},{"fromId":"n1","id":"r4","properties":{},"style":{},"toId":"n4","type":"PRODUCES"},{"fromId":"n1","id":"r5","properties":{},"style":{},"toId":"n5","type":"RAISES_ON"},{"fromId":"n1","id":"r6","properties":{},"style":{},"toId":"n6","type":"RAISES_ON"}],"style":{},"title":"Artefact Harmonise","uuid":"019da93f-1f64-744c-aefa-4ecbf75358c3"}
Loading