#NEWLINE# def get_domain( self ) : #NEWLINE# #INDENT# '\n        Adds domain of each variable to the network.\n\n        Example\n        -------\n        >>> writer = UAIWriter(model)\n        >>> writer.get_domain()\n        ' #NEWLINE# if isinstance ( self . model , BayesianModel ) : #NEWLINE# #INDENT# cpds = self . model . get_cpds ( ) #NEWLINE# cpds . sort ( key = ( lambda x : x . variable ) ) #NEWLINE# domain = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for cpd in self : #NEWLINE# #INDENT# domain [ cpd . variable ] = str ( cpd . variable_card ) #NEWLINE# #UNINDENT# return domain #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( self . model , MarkovModel ) : #NEWLINE# #INDENT# factors = self . model . get_factors ( ) #NEWLINE# domain = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for factor in factors : #NEWLINE# #INDENT# variables = factor . variables #NEWLINE# for var in variables : #NEWLINE# #INDENT# if ( var not in domain ) : #NEWLINE# #INDENT# domain [ var ] = str ( factor . get_cardinality ( [ var ] ) [ var ] ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return domain #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise TypeError ( 'Model must be an instance of Markov or Bayesian model.' )