Added dynamic configuration printing to output grammars.
authorYeGoblynQueenne@splinter <ep50@uni.brighton.ac.uk>
Mon, 29 Aug 2016 08:27:27 +0000 (11:27 +0300)
committerYeGoblynQueenne@splinter <ep50@uni.brighton.ac.uk>
Mon, 29 Aug 2016 08:27:27 +0000 (11:27 +0300)
* Dynamic config options increasingly look like just a short version of
  the full config options- since I've stopped using them actually
  dynamically a while ago now.

lib/project_utilities.pl
lib/term_utilities.pl
tree_learning/grammar_printing.pl

index e894c83..b1f02b3 100644 (file)
@@ -19,6 +19,7 @@
                    ,sanitised_user_input/2
                    ,sanitised_edge/2
                    ,dynamic_configuration/0
+                   ,dynamic_configuration/1
                    ,current_configuration/0
                    ,current_configuration/1
                    ,training_and_test_sets/2
@@ -717,6 +718,7 @@ sanitised_vertex(V,V_):-
        ,!.
 
 
+
 %!     dynamic_configuration is det.
 %
 %      Print to the console configuration options that can be modified
@@ -724,13 +726,27 @@ sanitised_vertex(V,V_):-
 %
 %      This is only meant to be used during console sessions and as
 %      such doesn't print to a file. For keeping a log of the current
-%      configuration consider using current_configuration/1 or the Swi
-%      Prolog built-in protocol/0.
+%      configuration changes consider using dynamic_configuration/1 or
+%      the Swi Prolog built-in protocol/0. For full configuration
+%      options use current_configuration/[1,0]
 %
 dynamic_configuration:-
+       dynamic_configuration(user_output).
+
+
+
+%!     dynamic_configuration(+Stream) is det.
+%
+%      Print dynamic configuration options to the given Stream.
+%
+%      Use this to include short configuration information with output
+%      grammars.
+%
+dynamic_configuration(Stream):-
        configuration_options(Os)
        ,findall(O-Vs
                ,(member(O-Vs,Os)
+                % @TODO: this is now relevant to all testing.
                 % Only show gnf-related options when they're relevant.
                 ,(   (    O == production_arity
                      ;    O == evaluation_parsing_time_limit
@@ -746,12 +762,17 @@ dynamic_configuration:-
                      ,N \= 0
                  ;   true
                  )
+                % Only show lexicalisation strategy when it's 'true'.
+                ,(   O == lexicalisation_strategy
+                 ->  Vs = [true]
+                 ;   true
+                 )
                 ,length(Vs, A)
                 ,functor(T,O,A)
                 ,predicate_property(configuration:T,dynamic)
                 )
                ,Os_)
-       ,print_configuration_options(user_output,Os_)
+       ,print_configuration_options(Stream,Os_)
        ,output_file_name(grammar, OF)
        ,format('Grammar output file:~n ~w~n',[OF]).
 
@@ -809,13 +830,17 @@ configuration_options(Options):-
 %
 %      Print the given list of configuration Options to Stream.
 %
+%      Options are printed each in its own line preceded by the Prolog
+%      line comment character, '%' and a single space character.
+%
 print_configuration_options(Stream,Options):-
-               forall(member(Option-Values, Options)
-              ,(format(Stream, '~w ~w ', [Option,=])
-               ,print_list(Values, ' - ')
-               ,nl
-               )
-              ).
+       forall(member(Option-Values, Options)
+             ,(format(Stream, '% ~w ~w ', [Option,=])
+              ,print_list(Stream,Values, ' - ')
+              ,nl(Stream)
+              )
+             )
+       ,nl(Stream).
 
 
 
index d9ed761..dfb9a17 100644 (file)
@@ -10,6 +10,7 @@
                         ,ord_add_elements/3\r
                         ,permute/2\r
                         ,print_list/2\r
+                        ,print_list/3\r
                         ,remove_duplicates/2\r
                         ,subsequence/5\r
                         ,subsequence/6\r
@@ -430,24 +431,35 @@ permute([X|Rest], L) :-
     select(X, L, L1).\r
 \r
 \r
-%!     print_list(+List,+Delimiter) is det.\r
+\r
+%!     print_list(+Delimiter) is det.\r
 %\r
-%      Prints each element of List followed by Delimiter, except for\r
-%      the last element, which is printed without Delimiter.\r
+%      Prints to user_output stream each element of List followed by\r
+%       Delimiter, except for the last element which is printed on its\r
+%      own.\r
+%\r
+%      Pass Delimiter = '\n' to print each element in a new line.\r
+print_list(L,D):-\r
+       print_list(user_output,L,D).\r
+\r
+\r
+\r
+%!     print_list(+Stream,+List,+Delimiter) is det.\r
+%\r
+%      Prints to the given Stream each element of List followed by Delimiter,\r
+%       except for the last element, which is printed without Delimiter.\r
 %\r
 %      Can be used to print lists neatly separated by commas or\r
 %      whitespace without the square brackets.\r
 %\r
 %      Pass Delimiter = '\n' to print each element in its own line.\r
 %\r
-%      @TODO: please move to libs.\r
-%\r
-print_list([L], _):-\r
-       write(L).\r
-print_list([L|List],Delimiter):-\r
-       write(L)\r
-       ,write(Delimiter)\r
-       ,print_list(List, Delimiter).\r
+print_list(S,[L], _):-\r
+       write(S,L).\r
+print_list(S,[L|List],Delimiter):-\r
+       write(S,L)\r
+       ,write(S,Delimiter)\r
+       ,print_list(S,List,Delimiter).\r
 \r
 \r
 \r
index 2f068f2..7f993af 100644 (file)
@@ -8,7 +8,8 @@
 :-use_module(skeleton_transformation, [corpus_productions/2]).
 :-use_module(lib(load_libs), [file_name_module_name/2
                             ,start_symbol/1
-                            ,training_and_test_sets/2]).
+                            ,training_and_test_sets/2
+                            ,dynamic_configuration/1]).
 
 /** <module> Predicates for printing an induced grammar.
 
@@ -181,6 +182,7 @@ print_grammar_file(dcg, Grammar_module_name, Stream, S, Ps):-
        ,format(Stream, '~w~w~w~w~w~n'
               ,[':-module(',Grammar_module_name,',',[S//N],').'])
        ,write(Stream, '\n')
+       ,dynamic_configuration(Stream)
        ,forall(member(P, Ps), print_term(Stream, p, P)).
 
 print_grammar_file(tags, Grammar_module_name, Stream, S, Ps):-