//package hu.birot.OTKit.runableExamples;

import hu.birot.OTKit.dataType.*;
import hu.birot.OTKit.otBuildingBlocks.*;
import hu.birot.OTKit.grammarExamples.StringGrammar;

/**
 * Create a tableau for a string grammar.
 * @see hu.birot.OTKit.grammarExamples.StringGrammar
 * @author <a href="http://www.birot.hu">Tamas Biro</a>
 *
 */
public class Tableau {
	
	public static void main(String[] arg) {
		StringGrammar G = new StringGrammar(4, 4, "OT");
		
		G.hierarchy.setRank("No0 >> No1 >> No2 >> No3");
		G.hierarchy.sortByRank();
		
		int[] array = {0,0,0,0};
		Form uf = G.StrForm(array);
		
		System.out.println(tableau(G, uf));
	}

	/**
	 * This String gives you the character(s) to be used to
	 * divide the columns of the tableau. By default, it is
	 * " | ", but you may want to change it to " & " if you 
	 * wish to use the output in LaTeX. 
	 */
	public static String Divider = " | ";
	
	/**
	 * This String gives you the character(s) following the
	 * first column of the tableau. By default, it is
	 * " | ", but you may want to change it to " & " if you 
	 * wish to use the output in LaTeX. 
	 */
	public static String FirstDivider = " || ";
	
	/**
	 * <p>This static method returns a String containing
	 * the tableau generated by Grammar G using underlying
	 * form uf.</p>
	 *  
	 * <p>The set of candidates generated by G.gen 
	 * from uf must be finite 
	 * (refer to method G.gen.allCandidates(uf)).
	 * Method G.hierarchy.sortedByRank() is used to
	 * define the ranking: make sure you call the method
	 * G.hierarchy.sortByRank() before employing this method.</p>
	 *  
	 * @param G Grammar generating the tableau.
	 * @param uf Underlying form from which the tablea is generated.
	 * @return A string containing the corresponding tableau.
	 */
	public static String tableau(Grammar G, Form uf) {
		
	       String tableau = "/" + uf.toString() + "/" + FirstDivider ;
	        for(int j=G.hierarchy.sortedByRank().length-1; j>-1; j--) {
	        	tableau += G.hierarchy.sortedByRank()[j].name() + Divider;
	        }
	        tableau += "\n";
	        tableau += "---------------------------------------------------------- \n";
	                   
	        for(Candidate cand : G.gen.allCandidates(uf)) {
	        	tableau += "[" + cand.sf + "]" + FirstDivider;
	            for(int j=G.hierarchy.sortedByRank().length-1; j>-1; j--) {
	            	tableau += G.hierarchy.sortedByRank()[j].value(cand) + Divider;
	            }
	            tableau += "\n";
	        }
	        
	        return tableau;
	}
	
}

