Method: ActiveFacts::Metamodel::Verbaliser#elided_objectification

Defined in:
lib/activefacts/vocabulary/verbaliser.rb

#elided_objectification(next_step, fact_type, last_is_contractable, next_node) ⇒ Object



642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
# File 'lib/activefacts/vocabulary/verbaliser.rb', line 642

def elided_objectification(next_step, fact_type, last_is_contractable, next_node)
  if last_is_contractable
    # Choose a reading that's contractable against the previous step, if possible
    reading = fact_type.all_reading_by_ordinal.
      detect do |reading|
 # Only contract a negative reading if we want one
 (!next_step.is_disallowed || !reading.is_negative == !next_step.is_disallowed) and
		reading_starts_with_node(reading, next_node)
      end
  end
  last_is_contractable = false unless reading
  reading ||= fact_type.preferred_reading(next_step.is_disallowed) || fact_type.preferred_reading

  # Find which role occurs last in the reading, and which Variable is attached
  reading.text =~ /\{(\d)\}[^{]*\Z/
  last_role_ref = reading.role_sequence.all_role_ref_in_order[$1.to_i]
  exit_node = @variables.detect{|jn| jn.all_play.detect{|jr| jr.role == last_role_ref.role}}
  exit_step = nil

	debug :query, "Stepping over an objectification to #{exit_node.object_type.name} requires eliding the other implied steps" do
	  count = 0
	  while other_step =
	    @steps.
 detect{|js|
		debug :query, "Considering step '#{js.fact_type.default_reading}'"
		next unless js.is_objectification_step

		# REVISIT: This test is too weak: We need to ensure that the same variables are involved, not just the same object types:
		next unless js.input_play.variable.object_type == fact_type.entity_type || js.output_play.variable.object_type == fact_type.entity_type
		exit_step = js if js.output_play.variable == exit_node
		true
 }
	    debug :query, "Emitting objectified FT allows deleting #{other_step.describe}"
	    step_completed(other_step)
  #          raise "The objectification of '#{fact_type.default_reading}' should not cause the deletion of more than #{fact_type.all_role.size} other steps" if (count += 1) > fact_type.all_role.size
	  end
	end

	[ reading, exit_step ? exit_step.input_play.variable : exit_node, exit_step, last_is_contractable]
end