How about:

```ruby
def get_form_elements(transition)
  semantics = defined?(transition.semantics) ? transition.semantics : {}
  semantics.values.each_with_object({}) do |semantic, h|
    elements = if semantic.semantics.any?
       semantic.semantics.values.map { |fsemantic| get_control(transition.name, fsemantic) }.reduce(&:deep_merge)
     else
        get_control(transition.name, semantic)
     end
     h.deep_merge!(elements)
  end
end
```