Révision 743 tmp/org.txm.ca.core/src/org/txm/ca/core/functions/CA.java

CA.java (revision 743)
44 44
import org.txm.core.results.TXMParameters;
45 45
import org.txm.lexicaltable.core.functions.LexicalTable;
46 46
import org.txm.statsengine.core.StatException;
47
import org.txm.utils.logger.Log;
47 48

  
48 49
/**
49 50
 * Correspondence Analysis of a lexical table.
......
72 73
	String[] coltitles; // of the colinfo table
73 74

  
74 75
	String pattern = "(cos2|contrib) (([0-9]+\\.[0-9]+)|([0-9]+))";
75
	
76

  
76 77
	/** The rownames. */
77 78
	String[] rownames = null;
78 79

  
......
85 86
	/** The use Factomine R: change this only if you want to use the default R CA package. */
86 87
	boolean useFactoMineR = true;
87 88

  
88
	
89
	
90
	
89

  
90

  
91

  
91 92
	/**
92 93
	 * First dimension.
93 94
	 */
......
99 100
	 */
100 101
	@Parameter(key=CAPreferences.SECOND_DIMENSION, type=Parameter.RENDERING)
101 102
	protected int secondDimension = 2;
102
	
103

  
103 104
	/**
104 105
	 * To show/hide individuals.
105 106
	 */
......
117 118
	 */
118 119
	@Parameter(key=CAPreferences.SHOW_POINT_SHAPES, type=Parameter.RENDERING)
119 120
	protected boolean showPointShapes;
120
	
121
	
122
	
123
	
121

  
122

  
123

  
124

  
124 125
	/**
125 126
	 * Creates a new empty CA.
126 127
	 *
......
138 139

  
139 140
	@Override
140 141
	protected boolean _compute() throws Exception {
141
		
142
		if (this.useFactoMineR) {
143
			this.r_ca = new FactoMineRCA(this.getLexicalTable().getData());
142
		try {
143
			if (this.useFactoMineR) {
144
				this.r_ca = new FactoMineRCA(this.getLexicalTable().getData());
145
			}
146
			else {
147
				this.r_ca = new org.txm.ca.core.statsengine.r.functions.CA(this.getLexicalTable().getData());
148
			}
149

  
150
			this.r_ca.compute();
151

  
152
			// in case the lexical table changes
153
			this.getColNames();
154
			// in case the lexical table changes
155
			this.getRowNames();
156

  
157
			return true;
158
		} catch(Exception e) {
159
			System.out.println("Error: CA not computed: "+e);
160
			Log.printStackTrace(e);
161
			return false;
144 162
		}
145
		else {
146
			this.r_ca = new org.txm.ca.core.statsengine.r.functions.CA(this.getLexicalTable().getData());
147
		}
148
		
149
		this.r_ca.compute();
150
		
151
		 // in case the lexical table changes
152
		this.getColNames();
153
		 // in case the lexical table changes
154
		this.getRowNames();
155
		
156
		return true;
157 163

  
158 164
	}
159 165

  
......
165 171
		else {
166 172
			System.out.println("Columns filter malformed follow this pattern " + pattern);
167 173
		}
168
		
174

  
169 175
		if (row.matches(pattern)) {
170 176
			this.rowfilter = row;
171 177
		}
......
637 643
		return this.r_ca.getRowsMass();
638 644
	}
639 645

  
640
//	/**
641
//	 * step 1.
642
//	 *
643
//	 * @throws StatException the stat exception
644
//	 * @throws CqiClientException the cqi client exception
645
//	 */
646
//	public boolean stepLexicalTable() throws Exception
647
//	{
648
//		table = LexicalTableFactory.getLexicalTable(partition, pAnalysisProperty, fmin);
649
//		if (table == null) {
650
//			System.out.println("Error: Lexical table is null.");
651
//			return false;
652
//		}
653
//		partition.addResult(table);
654
//		table.addResult(this);
655
//		
656
//		return true;
657
//	}
646
	//	/**
647
	//	 * step 1.
648
	//	 *
649
	//	 * @throws StatException the stat exception
650
	//	 * @throws CqiClientException the cqi client exception
651
	//	 */
652
	//	public boolean stepLexicalTable() throws Exception
653
	//	{
654
	//		table = LexicalTableFactory.getLexicalTable(partition, pAnalysisProperty, fmin);
655
	//		if (table == null) {
656
	//			System.out.println("Error: Lexical table is null.");
657
	//			return false;
658
	//		}
659
	//		partition.addResult(table);
660
	//		table.addResult(this);
661
	//		
662
	//		return true;
663
	//	}
658 664

  
659
//	/**
660
//	 * step 2.
661
//	 */
662
//	public boolean stepSortTableLexical()
663
//	{
664
//		try {
665
//			table.getData().filter(vmax, fmin);
666
//		} catch (Exception e) {
667
//			System.out.println("Error: "+e.getLocalizedMessage());
668
//			org.txm.utils.logger.Log.printStackTrace(e);
669
//			return false;
670
//		}
671
//		return true;
672
//	}
665
	//	/**
666
	//	 * step 2.
667
	//	 */
668
	//	public boolean stepSortTableLexical()
669
	//	{
670
	//		try {
671
	//			table.getData().filter(vmax, fmin);
672
	//		} catch (Exception e) {
673
	//			System.out.println("Error: "+e.getLocalizedMessage());
674
	//			org.txm.utils.logger.Log.printStackTrace(e);
675
	//			return false;
676
	//		}
677
	//		return true;
678
	//	}
673 679

  
674 680
	/**
675 681
	 * Gets the second dimension.
......
695 701
	}
696 702

  
697 703

  
698
	
704

  
699 705
	/**
700 706
	 * Get the singular values as array.
701 707
	 *
......
786 792
		return sum;
787 793
	}
788 794

  
789
	
795

  
790 796
	/**
791 797
	 * Exports CA R data to a file
792 798
	 *
......
819 825
		return rez;
820 826
	}
821 827

  
822
	
828

  
823 829
	/**
824 830
	 * Checks if the CA uses the FactoMineR R package.
825 831
	 * @return <code>true</code> if the CA uses the FactoMineR R package otherwise <code>false</code>
......
838 844
				&& this.firstDimension != this.secondDimension
839 845
				;
840 846
	}
841
	
847

  
842 848
	@Override
843 849
	public boolean saveParameters() {
844 850
		// nothing to do

Formats disponibles : Unified diff