Révision 1960

tmp/org.txm.concordance.core/src/org/txm/concordance/core/r/ConcordanceRTransformer.java (revision 1960)
1
package org.txm.concordance.core.r;
2

  
3
import org.txm.concordance.core.functions.Concordance;
4
import org.txm.concordance.core.functions.Line;
5
import org.txm.core.results.TXMResult;
6
import org.txm.statsengine.r.core.RTransformer;
7
import org.txm.statsengine.r.core.RWorkspace;
8
import org.txm.statsengine.r.core.exceptions.RWorkspaceException;
9

  
10
public class ConcordanceRTransformer extends RTransformer<Concordance> {
11

  
12
	/** The noconc. */
13
	protected static int noconc = 1;
14

  
15
	/** The prefix r. */
16
	protected static String prefixR = "Concordances"; //$NON-NLS-1$
17
	
18
	@Override
19
	public Concordance fromRtoTXM(String symbol) throws RWorkspaceException {
20
		// TODO Auto-generated method stub
21
		return null;
22
	}
23

  
24
	@Override
25
	public String fromTXMtoR(TXMResult o) throws RWorkspaceException {
26
		
27
		if (!(o instanceof Concordance)) return null;
28
		
29
		Concordance conc = (Concordance)o;
30
		
31
		String symbol = prefixR+ noconc++;
32
		String[] refs = new String[conc.getNLines()];
33
		String[] lefts = new String[conc.getNLines()];
34
		String[] keywords = new String[conc.getNLines()];
35
		String[] rights = new String[conc.getNLines()];
36

  
37
		int i = 0;
38
		try {
39
			for (Line line : conc.getLines(0, conc.getNLines())) {
40
				refs[i] = line.getViewRef().toString();
41
				lefts[i] = line.leftContextToString();
42
				keywords[i] = line.keywordToString();
43
				rights[i] = line.rightContextToString();
44
				i++;
45
			}
46
		} catch (Exception e) {
47
			org.txm.utils.logger.Log.printStackTrace(e);
48
			return null; //$NON-NLS-1$
49
		}
50

  
51
		RWorkspace rw = RWorkspace.getRWorkspaceInstance();
52
		rw.addVectorToWorkspace("concrefs", refs); //$NON-NLS-1$
53
		rw.addVectorToWorkspace("conclefts", lefts); //$NON-NLS-1$
54
		rw.addVectorToWorkspace("conckeywords", keywords); //$NON-NLS-1$
55
		rw.addVectorToWorkspace("concrights", rights); //$NON-NLS-1$
56

  
57
		rw.eval(symbol+ "<- matrix(data = c(concrefs, conclefts, conckeywords, concrights), nrow = "+conc.getNLines()+", ncol = 4)"); //$NON-NLS-1$ //$NON-NLS-2$
58
		rw.eval("colnames("+symbol+" ) <- c('refs', 'leftcontext', 'keyword', 'rightcontext')"); //$NON-NLS-1$ //$NON-NLS-2$
59
		rw.eval(symbol+ "<- list(data="+symbol //$NON-NLS-1$
60
				+ ", leftcontext="+conc.getLeftContextSize() //$NON-NLS-1$
61
				+ ", rightcontext="+conc.getRightContextSize() //$NON-NLS-1$
62
				//+ ", query=\""+conc.query.getQueryString()+"\""
63
				+ ")"); //$NON-NLS-1$
64

  
65
		return symbol;
66
	}
67

  
68
}
0 69

  
tmp/org.txm.concordance.core/plugin.xml (revision 1960)
7 7
            class="org.txm.concordance.core.preferences.ConcordancePreferences">
8 8
      </initializer>
9 9
   </extension>
10
         <extension
11
         point="org.txm.statsengine.r.core.RTransformer">
12
      <transfert
13
            class="org.txm.concordance.core.r.ConcordanceRTransformer"
14
            type="org.txm.concordance.core.functions.Concordance">
15
      </transfert>
16
   </extension>
10 17

  
11 18
</plugin>
tmp/org.txm.cooccurrence.core/plugin.xml (revision 1960)
8 8
      </initializer>
9 9
   </extension>
10 10

  
11
      <extension
12
         point="org.txm.statsengine.r.core.RTransformer">
13
      <transfert
14
            class="org.txm.cooccurrence.core.r.CooccurrencesRTransformer"
15
            type="org.txm.cooccurrence.core.functions.Cooccurrence">
16
      </transfert>
17
   </extension>
18

  
11 19
</plugin>
tmp/org.txm.cooccurrence.core/src/org/txm/cooccurrence/core/r/CooccurrencesRTransformer.java (revision 1960)
1
package org.txm.cooccurrence.core.r;
2

  
3
import org.txm.cooccurrence.core.functions.Cooccurrence;
4
import org.txm.cooccurrence.core.functions.Cooccurrence.CLine;
5
import org.txm.core.results.TXMResult;
6
import org.txm.statsengine.r.core.RTransformer;
7
import org.txm.statsengine.r.core.RWorkspace;
8
import org.txm.statsengine.r.core.exceptions.RWorkspaceException;
9

  
10
public class CooccurrencesRTransformer extends RTransformer<Cooccurrence>{
11

  
12
	/** The noconc. */
13
	protected static int nocooc = 1;
14

  
15
	/** The prefix r. */
16
	protected static String prefixR = "Cooccurrences"; //$NON-NLS-1$
17
	
18
	@Override
19
	public Cooccurrence fromRtoTXM(String symbol) throws RWorkspaceException {
20
		return null;
21
	}
22

  
23
	@Override
24
	public String fromTXMtoR(TXMResult o) throws RWorkspaceException {
25
		
26
		if (!(o instanceof Cooccurrence)) return null;
27
		
28
		Cooccurrence cooc = (Cooccurrence)o;
29
		
30
		String symbol = prefixR+nocooc;
31

  
32
		String[] occ = new String[cooc.getLines().size()];
33
		int[] freq = new int[cooc.getLines().size()];
34
		int[] cofreq = new int[cooc.getLines().size()];
35
		double[] score = new double[cooc.getLines().size()];
36
		double[] dist = new double[cooc.getLines().size()];
37

  
38
		int i = 0;
39
		for (CLine line : cooc.getLines()) {
40
			occ[i] = line.occ;
41
			freq[i] = line.freq;
42
			cofreq[i] = line.nbocc;
43
			score[i] = line.score;
44
			dist[i] = line.distmoyenne;
45
			i++;
46
		}
47
		
48
		RWorkspace rw = RWorkspace.getRWorkspaceInstance();
49
		rw.addVectorToWorkspace("coococc", occ); //$NON-NLS-1$
50
		rw.addVectorToWorkspace("coocfreq", freq); //$NON-NLS-1$
51
		rw.addVectorToWorkspace("cooccofreq", cofreq); //$NON-NLS-1$
52
		rw.addVectorToWorkspace("coocscore", score); //$NON-NLS-1$
53
		rw.addVectorToWorkspace("coocmeandist", dist); //$NON-NLS-1$
54
		
55
		rw.eval(symbol+ "<- matrix(data = c(coocfreq, cooccofreq, coocscore, coocmeandist), nrow = "+cooc.getLines().size()+", ncol = 4)"); //$NON-NLS-1$ //$NON-NLS-2$
56
		rw.eval("rownames("+symbol+" ) <- coococc"); //$NON-NLS-1$ //$NON-NLS-2$
57
		rw.eval("colnames("+symbol+" ) <- c('freq', 'cofreq', 'score', 'dist')"); //$NON-NLS-1$ //$NON-NLS-2$
58
		rw.eval(symbol+ "<- list(data="+symbol //$NON-NLS-1$
59
				//+ ", leftcontext="+this.leftContextSize
60
				//+ ", rightcontext="+this.rightContextSize
61
				//+ ", query=\""+this.query.getQueryString()+"\""
62
				+ ")"); //$NON-NLS-1$
63

  
64
		nocooc++;
65
		return symbol;
66
	}
67
}
0 68

  
tmp/org.txm.searchengine.cqp.core/src/org/txm/searchengine/cqp/corpus/Property.java (revision 1960)
31 31
import java.util.List;
32 32

  
33 33
import org.apache.commons.lang.StringUtils;
34
import org.txm.core.messages.TXMCoreMessages;
34 35
import org.txm.core.preferences.TXMPreferences;
35 36
import org.txm.searchengine.cqp.clientExceptions.CqiClientException;
37
import org.txm.utils.logger.Log;
36 38

  
37 39

  
38 40
/**
......
124 126
		return (this.getQualifiedName().compareTo((p).getQualifiedName()));
125 127
	}
126 128
	
127
	
128 129
	/**
129 130
	 * Converts the specified string to a list of Property from the specified Corpus.
130 131
	 * @param corpus
......
135 136
	public static List<? extends Property> stringToProperties(CQPCorpus corpus, String str) {
136 137
		ArrayList<Property> properties = new ArrayList<Property>();
137 138
		
138
		if (str == null) {
139
		if (str == null || corpus == null) {
139 140
			return properties;
140 141
		}
141 142

  
......
147 148
					properties.add(p);
148 149
				}
149 150
			} catch (CqiClientException e) {
150
				// TODO Auto-generated catch block
151
				e.printStackTrace();
151
				Log.warning(TXMCoreMessages.bind("** No property {0} found in the {1} corpus: {2}", s, corpus, e));
152
				Log.printStackTrace(e);
152 153
			}
153 154
		}
154 155
		return properties;
155 156
	}
156 157

  
157

  
158 158
	/**
159 159
	 * Converts the specified list of Property to a string.
160 160
	 * 
......
174 174
		
175 175
		return StringUtils.join(names, TXMPreferences.LIST_SEPARATOR);
176 176
	}
177
	
178 177
}
tmp/org.txm.statsengine.r.rcp/src/org/txm/statsengine/r/rcp/handlers/SendToRCommand.java (revision 1960)
142 142
			RTransformer<? extends TXMResult> transformer = rengine.getTransformers().get(o.getClass().getName());
143 143
			return transformer.fromTXMtoR(o);
144 144
		} else {
145
			Log.info(NLS.bind("{0} cannot be copied in thr R workspace", o.getSimpleName()));
146 145
			return null;
147 146
		}
148 147
	//TODO: MD: create the SendToRCommands commands in all plugins that manage the following TXMResult classes
tmp/org.txm.statsengine.r.rcp/plugin.xml (revision 1960)
140 140
                  <reference
141 141
                        definitionId="OneCorpusSelected">
142 142
                  </reference>
143
                  <reference
144
                        definitionId="OnePartitionIndexSelected">
145
                  </reference>
143 146
               </or>
144 147
            </visibleWhen>
145 148
         </command>
......
172 175
                  <reference
173 176
                        definitionId="OneCorpusSelected">
174 177
                  </reference>
178
                  <reference
179
                        definitionId="OnePartitionIndexSelected">
180
                  </reference>
175 181
               </or>
176 182
            </visibleWhen>
177 183
         </command>
......
204 210
                  <reference
205 211
                        definitionId="OneCorpusSelected">
206 212
                  </reference>
213
                  <reference
214
                        definitionId="OnePartitionIndexSelected">
215
                  </reference>
207 216
               </or>
208 217
            </visibleWhen>
209 218
         </command>
tmp/org.txm.progression.core/src/org/txm/progression/core/r/ProgressionRTransformer.java (revision 1960)
1
package org.txm.progression.core.r;
2

  
3
import org.txm.core.results.TXMResult;
4
import org.txm.progression.core.functions.Progression;
5
import org.txm.statsengine.r.core.RTransformer;
6
import org.txm.statsengine.r.core.exceptions.RWorkspaceException;
7

  
8
public class ProgressionRTransformer extends RTransformer<Progression> {
9

  
10
	@Override
11
	public Progression fromRtoTXM(String symbol) throws RWorkspaceException {
12
		return null;
13
	}
14

  
15
	@Override
16
	public String fromTXMtoR(TXMResult o) throws RWorkspaceException {
17

  
18
		if (!(o instanceof Progression)) return null;
19
		
20
		return null;
21
	}
22

  
23
}
0 24

  
tmp/org.txm.index.core/plugin.xml (revision 1960)
11 11
      <extension
12 12
         point="org.txm.statsengine.r.core.RTransformer">
13 13
      <transfert
14
            class="org.txm.index.core.r.LexiconRTransformer"
15
            type="org.txm.index.core.functions.Lexicon">
16
      </transfert>
17
      <transfert
14 18
            class="org.txm.index.core.r.IndexRTransformer"
15 19
            type="org.txm.index.core.functions.Index">
16 20
      </transfert>
21
      <transfert
22
            class="org.txm.index.core.r.ParitionIndexRTransformer"
23
            type="org.txm.index.core.functions.PartitionIndex">
24
      </transfert>
17 25
   </extension>
18 26

  
19 27
</plugin>
tmp/org.txm.index.core/src/org/txm/index/core/r/ParitionIndexRTransformer.java (revision 1960)
1
package org.txm.index.core.r;
2

  
3
import java.util.ArrayList;
4
import java.util.List;
5

  
6
import org.txm.core.results.TXMResult;
7
import org.txm.index.core.functions.Line;
8
import org.txm.index.core.functions.PartitionIndex;
9
import org.txm.statsengine.r.core.RTransformer;
10
import org.txm.statsengine.r.core.RWorkspace;
11
import org.txm.statsengine.r.core.exceptions.RWorkspaceException;
12

  
13
public class ParitionIndexRTransformer extends RTransformer<PartitionIndex> {
14

  
15
	/** The novoc. */
16
	protected static int novoc = 1;
17

  
18
	/** The prefix r. */
19
	protected static String prefixR = "PartitionIndex"; //$NON-NLS-1$
20

  
21
	
22
	public ParitionIndexRTransformer() {
23
		// TODO Auto-generated constructor stub
24
	}
25

  
26
	@Override
27
	public PartitionIndex fromRtoTXM(String symbol) {
28
		return null;
29
	}
30

  
31
	/**
32
	 * As r matrix.
33
	 *
34
	 * @return the string
35
	 * @throws RWorkspaceException the r workspace exception
36
	 */
37
	@Override
38
	public String fromTXMtoR(TXMResult o) throws RWorkspaceException {
39
		if (!(o instanceof PartitionIndex)) return null;
40
		
41
		PartitionIndex index = (PartitionIndex)o;
42
		
43
		String symbol = prefixR+novoc;
44

  
45
		ArrayList<String> colnames = new ArrayList<String>();
46
		List<String> partnames = index.getPartnames();
47
		
48
		colnames.add("F"); //$NON-NLS-1$
49
		colnames.addAll(partnames);
50
		
51
		//System.out.println("cols: "+colnames);
52
		List<Line> lines = index.getAllLines();
53
		String[] keywords = new String[lines.size()];
54

  
55
		int[] freq = new int[lines.size()];
56
		ArrayList<int[]> partfreqs = new ArrayList<int[]>(partnames.size());
57
		for (int j = 0; j < partnames.size(); j++) {
58
			partfreqs.add(new int[lines.size()]);
59
		}
60
		
61
		for (int i = 0 ; i < lines.size() ; i++) {
62
			Line line = lines.get(i);
63
			freq[i] = line.getFrequency(); 
64
			keywords[i] = line.toString();
65
			for (int j = 0; j < partnames.size(); j++) {
66
				partfreqs.get(j)[i] = line.getFrequency(j);
67
			}
68
		}
69

  
70
		RWorkspace rw = RWorkspace.getRWorkspaceInstance();
71
		for (int j = 0; j < partnames.size(); j++) {
72
			rw.addVectorToWorkspace("vocpartfreqs"+j, partfreqs.get(j)); //$NON-NLS-1$
73
		}
74
		rw.addVectorToWorkspace("vocfreq", freq); //$NON-NLS-1$
75
		rw.addVectorToWorkspace("vockeywords", keywords); //$NON-NLS-1$
76
		rw.addVectorToWorkspace("voccolnames", colnames.toArray(new String[colnames.size()])); //$NON-NLS-1$
77

  
78
		int ncol = 1 + partnames.size();
79

  
80
		int nrow = lines.size();
81
		String partscmd = ""; //$NON-NLS-1$
82
		for (int j = 0; j < partnames.size(); j++) {
83
			partscmd +=", vocpartfreqs"+j; //$NON-NLS-1$
84
		}
85
		rw.eval(symbol+ "<- matrix(data = c(vocfreq"+partscmd+"), nrow = "+nrow+", ncol = "+ncol+")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
86
		rw.eval("colnames("+symbol+" ) <- voccolnames"); //$NON-NLS-1$ //$NON-NLS-2$
87
		rw.eval("rownames("+symbol+" ) <- vockeywords"); //$NON-NLS-1$ //$NON-NLS-2$
88
		rw.eval(symbol+ "<- list(data="+symbol+")"); //$NON-NLS-1$ //$NON-NLS-2$
89

  
90
		novoc++;
91
		return symbol;
92
	}
93
}
0 94

  
tmp/org.txm.index.core/src/org/txm/index/core/r/LexiconRTransformer.java (revision 1960)
1
package org.txm.index.core.r;
2

  
3
import java.util.ArrayList;
4
import java.util.List;
5

  
6
import org.txm.core.results.TXMResult;
7
import org.txm.index.core.functions.Lexicon;
8
import org.txm.index.core.functions.Line;
9
import org.txm.statsengine.r.core.RTransformer;
10
import org.txm.statsengine.r.core.RWorkspace;
11
import org.txm.statsengine.r.core.exceptions.RWorkspaceException;
12

  
13
public class LexiconRTransformer extends RTransformer<Lexicon> {
14

  
15
	/** The novoc. */
16
	protected static int novoc = 1;
17

  
18
	/** The prefix r. */
19
	protected static String prefixR = "Lexicon"; //$NON-NLS-1$
20

  
21
	
22
	public LexiconRTransformer() {
23
		// TODO Auto-generated constructor stub
24
	}
25

  
26
	@Override
27
	public Lexicon fromRtoTXM(String symbol) {
28
		// TODO Auto-generated method stub
29
		return null;
30
	}
31

  
32
	/**
33
	 * As r matrix.
34
	 *
35
	 * @return the string
36
	 * @throws RWorkspaceException the r workspace exception
37
	 */
38
	@Override
39
	public String fromTXMtoR(TXMResult o) throws RWorkspaceException {
40
		if (!(o instanceof Lexicon)) return null;
41
		
42
		Lexicon index = (Lexicon)o;
43
		
44
		String symbol = prefixR+novoc;
45

  
46
		ArrayList<String> colnames = new ArrayList<String>();
47

  
48
		colnames.add("F"); //$NON-NLS-1$
49
		
50
		//System.out.println("cols: "+colnames);
51
		List<Line> lines = index.getAllLines();
52
		String[] keywords = new String[lines.size()];
53

  
54
		int[] freq = new int[lines.size()];
55

  
56
		for (int i = 0 ; i < lines.size() ; i++) {
57
			Line line = lines.get(i);
58
			freq[i] = line.getFrequency(); 
59
			keywords[i] = line.toString();
60
		}
61

  
62
		RWorkspace rw = RWorkspace.getRWorkspaceInstance();
63
		rw.addVectorToWorkspace("vocfreq", freq); //$NON-NLS-1$
64
		rw.addVectorToWorkspace("vockeywords", keywords); //$NON-NLS-1$
65
		rw.addVectorToWorkspace("voccolnames", colnames.toArray(new String[colnames.size()])); //$NON-NLS-1$
66

  
67
		int ncol = 1;
68

  
69
		int nrow = lines.size();
70
		String partscmd = ""; //$NON-NLS-1$
71
		
72
		rw.eval(symbol+ "<- matrix(data = c(vocfreq"+partscmd+"), nrow = "+nrow+", ncol = "+ncol+")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
73
		rw.eval("colnames("+symbol+" ) <- voccolnames"); //$NON-NLS-1$ //$NON-NLS-2$
74
		rw.eval("rownames("+symbol+" ) <- vockeywords"); //$NON-NLS-1$ //$NON-NLS-2$
75
		rw.eval(symbol+ "<- list(data="+symbol+")"); //$NON-NLS-1$ //$NON-NLS-2$
76

  
77
		novoc++;
78
		return symbol;
79
	}
80
}
0 81

  
tmp/org.txm.index.core/src/org/txm/index/core/functions/Index.java (revision 1960)
471 471
	 * @return the corpus
472 472
	 */
473 473
	public CQPCorpus getCorpus() {
474
		if (this.parent instanceof CQPCorpus) {
475
			return (CQPCorpus) this.parent;
476
		} else {
477
			return null;
478
		}
474
		return (CQPCorpus) this.parent;
479 475
	}
480 476

  
481 477
	@Override

Formats disponibles : Unified diff