Class: Sfp::Axiom

Inherits:
Hash
  • Object
show all
Defined in:
lib/sfp/sas_translator.rb

Overview

A class for Grounded Axiom

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAxiom

Returns a new instance of Axiom.



2013
2014
2015
# File 'lib/sfp/sas_translator.rb', line 2013

def initialize
	@id = Sfp::SasTranslator.next_axiom_id
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



2011
2012
2013
# File 'lib/sfp/sas_translator.rb', line 2011

def id
  @id
end

#targetObject

Returns the value of attribute target.



2011
2012
2013
# File 'lib/sfp/sas_translator.rb', line 2011

def target
  @target
end

Instance Method Details

#to_sObject



2017
2018
2019
# File 'lib/sfp/sas_translator.rb', line 2017

def to_s
	return 'axiom#' + @id.to_s
end

#to_sas(root, variables) ⇒ Object

Raises:

  • (Exception)


2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
# File 'lib/sfp/sas_translator.rb', line 2021

def to_sas(root, variables)
	prevails = select { |var,param| param.post.nil? }
	preposts = select { |var,param| !param.post.nil? }
	raise Exception, "Invalid axiom: total preposts > 1" if preposts.length > 1
	raise Exception, "Invalid axiom: total preposts <= 0" if preposts.length <= 0

	sas = "begin_rule"
	sas += "\n#{prevails.length}"
	prevails.each { |var,param| sas += "\n" + param.to_sas(root, variables) }
	preposts.each { |var,param| sas += "\n" + param.to_sas(root, variables) }
	sas += "\nend_rule"
	return sas
end