Revision 306

tmp/org.txm.statsengine.r.core/src/org/txm/statsengine/r/core/RserveWatcher.java (revision 306)
1
// Copyright © 2010-2013 ENS de Lyon.
2
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of
3
// Lyon 2, University of Franche-Comté, University of Nice
4
// Sophia Antipolis, University of Paris 3.
5
// 
6
// The TXM platform is free software: you can redistribute it
7
// and/or modify it under the terms of the GNU General Public
8
// License as published by the Free Software Foundation,
9
// either version 2 of the License, or (at your option) any
10
// later version.
11
// 
12
// The TXM platform is distributed in the hope that it will be
13
// useful, but WITHOUT ANY WARRANTY; without even the implied
14
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15
// PURPOSE. See the GNU General Public License for more
16
// details.
17
// 
18
// You should have received a copy of the GNU General
19
// Public License along with the TXM platform. If not, see
20
// http://www.gnu.org/licenses.
21
// 
22
// 
23
// 
24
// $LastChangedDate:$
25
// $LastChangedRevision:$
26
// $LastChangedBy:$ 
27
//
28
package org.txm.statsengine.r.core;
29

  
30
import org.txm.statsengine.r.core.exceptions.RWorkspaceException;
31
import org.txm.utils.Watcher;
32

  
33
// TODO: Auto-generated Javadoc
34
/**
35
 * The Class RserveWatcher.
36
 */
37
//FIXME: not used ?
38
public class RserveWatcher extends Watcher	{
39

  
40
	
41
	/**
42
	 * Instantiates a new rserve watcher.
43
	 */
44
	public RserveWatcher()
45
	{
46
		this.processname = "RSERVE"; //$NON-NLS-1$
47
	}
48
	
49
	/* (non-Javadoc)
50
	 * @see org.txm.Watcher#check()
51
	 */
52
	@Override
53
	protected boolean check() {
54
		RWorkspace rw;
55
		try {
56
			rw = RWorkspace.getRWorkspaceInstance();
57
		} catch (RWorkspaceException e1) {
58
			System.out.println("Rserve watcher encounter an error: "+e1); //$NON-NLS-1$
59
			return false;
60
		}
61
		
62
		if (rw == null)
63
		{
64
			return false;
65
		}
66
		else
67
		{
68
			try {
69
				rw.eval("print(\"test\")"); //$NON-NLS-1$
70
			} catch (Exception e) {
71
				System.out.println("Rserve watcher encounter an error: "+e); //$NON-NLS-1$
72
				return false;
73
			}
74
		}
75
		return true;
76
	}
77

  
78
	/* (non-Javadoc)
79
	 * @see org.txm.Watcher#restart()
80
	 */
81
	@Override
82
	protected boolean restart() {
83
		return Toolbox.restartStatEngine(true);
84
	}
85
}
tmp/CQP/bin/cqpserver.init (revision 306)
1
host *;               # allow access from any host (including localhost)
2

  
3
# users must login with name "anonymous" and explicit "" as password!
4
user anonymous "";
tmp/org.txm.index.rcp/src/org/txm/index/rcp/adapters/IndexRAdaptor.java (revision 306)
1
package org.txm.index.rcp.adapters;
2

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

  
7
import org.txm.index.core.functions.Index;
8
import org.txm.index.core.functions.Line;
9
import org.txm.statsengine.r.core.RWorkspace;
10
import org.txm.statsengine.r.core.exceptions.RWorkspaceException;
11
import org.txm.statsengine.r.rcp.handlers.RAdaptor;
12

  
13
/**
14
 * Create a R object from an Index
15
 * 
16
 * The class stores the symbols and sended results in 2 static objects : symbols and sended
17
 * 
18
 * @author mdecorde
19
 *
20
 */
21
public class IndexRAdaptor extends RAdaptor {
22

  
23
	
24
	/** The novoc. */
25
	protected static int no_index = 1;
26

  
27
	/** The prefix r. */
28
	protected static String prefixR = "Index"; //$NON-NLS-1$
29
	
30
	/**
31
	 * @return the R symbol
32
	 * 
33
	 * @throws RWorkspaceException the r workspace exception
34
	 */
35
	public String sendToR(Index index) throws RWorkspaceException {
36
		
37
		if (sended.containsKey(index)) {
38
			return sended.get(index);
39
		}
40
		
41
		String symbol = prefixR+no_index;
42

  
43
		ArrayList<String> colnames = new ArrayList<String>();
44

  
45
		colnames.add("F"); //$NON-NLS-1$
46
		List<String> partnames = index.getPartnames();
47
		if (partnames.size() > 1)
48
			for (int j = 0; j < partnames.size(); j++)
49
				colnames.add(partnames.get(j)); 
50

  
51
		//System.out.println("cols: "+colnames);
52

  
53
		List<Line> lines = index.getAllLines();
54
		String[] keywords = new String[lines.size()];
55

  
56
		int[] freq = new int[lines.size()];
57
		ArrayList<int[]> partfreqs = new ArrayList<int[]>(partnames.size());
58
		if (partnames.size() > 1)
59
			for (int j = 0; j < partnames.size(); j++)
60
				partfreqs.add(new int[lines.size()]);
61

  
62
		for (int i = 0 ; i < lines.size() ; i++) 
63
		{
64
			Line ligne = lines.get(i);
65
			freq[i] = ligne.getFrequency(); 
66
			keywords[i] = ligne.toString();
67
			if (partnames.size() > 1)
68
				for (int j = 0; j < partnames.size(); j++)
69
				{
70
					partfreqs.get(j)[i] = ligne.getFrequency(j);
71
				}
72

  
73
		}
74

  
75
		RWorkspace rw = RWorkspace.getRWorkspaceInstance();
76
		if (partnames.size() > 1)
77
			for (int j = 0; j < partnames.size(); j++)
78
				rw.addVectorToWorkspace("vocpartfreqs"+j, partfreqs.get(j)); //$NON-NLS-1$
79
		rw.addVectorToWorkspace("vocfreq", freq); //$NON-NLS-1$
80
		rw.addVectorToWorkspace("vockeywords", keywords); //$NON-NLS-1$
81
		rw.addVectorToWorkspace("voccolnames", colnames.toArray(new String[colnames.size()])); //$NON-NLS-1$
82

  
83
		int ncol = 1;
84
		if (partnames.size() > 1)
85
			ncol += partnames.size();
86

  
87
		int nrow = lines.size();
88
		String partscmd = ""; //$NON-NLS-1$
89
		if (partnames.size() > 1)
90
			for (int j = 0; j < partnames.size(); j++)
91
				partscmd +=", vocpartfreqs"+j; //$NON-NLS-1$
92

  
93
		rw.eval(symbol+ "<- matrix(data = c(vocfreq"+partscmd+"), nrow = "+nrow+", ncol = "+ncol+")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
94
		rw.eval("colnames("+symbol+" ) <- voccolnames"); //$NON-NLS-1$ //$NON-NLS-2$
95
		rw.eval("rownames("+symbol+" ) <- vockeywords"); //$NON-NLS-1$ //$NON-NLS-2$
96
		rw.eval(symbol+ "<- list(data="+symbol+")"); //$NON-NLS-1$ //$NON-NLS-2$
97

  
98
		no_index++;
99
		
100
		sended.put(index, symbol);
101
		symbols.put(symbol, index);
102
		
103
		return symbol;
104
	}
105
}
0 106

  
tmp/org.txm.index.rcp/plugin.xml (revision 306)
108 108
         </with>
109 109
      </definition>
110 110
   </extension>
111
   <extension
112
         point="org.txm.statengine.r.rcp.sendtor">
113
      <sendtorcommand></sendtorcommand>
114
   </extension>
111 115

  
112 116
</plugin>
tmp/org.txm.index.rcp/META-INF/MANIFEST.MF (revision 306)
6 6
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
7 7
Require-Bundle: org.txm.core;bundle-version="0.7.0",
8 8
 org.txm.index.core;bundle-version="1.0.0",
9
 org.txm.statsengine.r.rcp,
9 10
 org.eclipse.ui;bundle-version="3.106.1",
10 11
 org.eclipse.core.runtime;bundle-version="3.10.0",
11 12
 org.txm.rcp,
12 13
 org.txm.statsengine.r.core;bundle-version="1.0.0",
13
 org.txm.statsengine.r.rcp,
14 14
 org.eclipse.core.expressions;bundle-version="3.4.600"
15 15
Export-Package: org.txm.index.rcp.adapters,
16 16
 org.txm.index.rcp.editors,
tmp/org.txm.index.core/src/org/txm/index/core/functions/Index.java (revision 306)
116 116
	/** proxy to get the string values of cqp tokens. */
117 117
	//private Map<Property, CqpDataProxy> cache;
118 118

  
119
	/** The symbol. */
120
	private String symbol;
121

  
122 119
	
123 120
	/** The properties to process. */
124 121
	HashSet<String> propertiesToProcess;
......
892 889
		return altered;
893 890
	}
894 891

  
895
	/** The novoc. */
896
	protected static int novoc = 1;
897

  
898
	/** The prefix r. */
899
	protected static String prefixR = "Index"; //$NON-NLS-1$
900

  
901 892
	/**
902
	 * As r matrix.
903
	 *
904
	 * @return the string
905
	 * @throws RWorkspaceException the r workspace exception
906
	 */
907
	public String asRMatrix() throws RWorkspaceException {
908
		symbol = prefixR+novoc;
909

  
910
		ArrayList<String> colnames = new ArrayList<String>();
911

  
912
		colnames.add("F"); //$NON-NLS-1$
913
		if (partnames.size() > 1)
914
			for (int j = 0; j < partnames.size(); j++)
915
				colnames.add(partnames.get(j)); 
916

  
917
		//System.out.println("cols: "+colnames);
918

  
919
		String[] keywords = new String[this.lines.size()];
920

  
921
		int[] freq = new int[this.lines.size()];
922
		ArrayList<int[]> partfreqs = new ArrayList<int[]>(partnames.size());
923
		if (partnames.size() > 1)
924
			for (int j = 0; j < partnames.size(); j++)
925
				partfreqs.add(new int[this.lines.size()]);
926

  
927
		for (int i = 0 ; i < lines.size() ; i++) 
928
		{
929
			Line ligne = lines.get(i);
930
			freq[i] = ligne.getFrequency(); 
931
			keywords[i] = ligne.toString();
932
			if (partnames.size() > 1)
933
				for (int j = 0; j < partnames.size(); j++)
934
				{
935
					partfreqs.get(j)[i] = ligne.getFrequency(j);
936
				}
937

  
938
		}
939

  
940
		RWorkspace rw = RWorkspace.getRWorkspaceInstance();
941
		if (partnames.size() > 1)
942
			for (int j = 0; j < partnames.size(); j++)
943
				rw.addVectorToWorkspace("vocpartfreqs"+j, partfreqs.get(j)); //$NON-NLS-1$
944
		rw.addVectorToWorkspace("vocfreq", freq); //$NON-NLS-1$
945
		rw.addVectorToWorkspace("vockeywords", keywords); //$NON-NLS-1$
946
		rw.addVectorToWorkspace("voccolnames", colnames.toArray(new String[colnames.size()])); //$NON-NLS-1$
947

  
948
		int ncol = 1;
949
		if (partnames.size() > 1)
950
			ncol += partnames.size();
951

  
952
		int nrow = lines.size();
953
		String partscmd = ""; //$NON-NLS-1$
954
		if (partnames.size() > 1)
955
			for (int j = 0; j < partnames.size(); j++)
956
				partscmd +=", vocpartfreqs"+j; //$NON-NLS-1$
957

  
958
		rw.eval(symbol+ "<- matrix(data = c(vocfreq"+partscmd+"), nrow = "+nrow+", ncol = "+ncol+")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
959
		rw.eval("colnames("+symbol+" ) <- voccolnames"); //$NON-NLS-1$ //$NON-NLS-2$
960
		rw.eval("rownames("+symbol+" ) <- vockeywords"); //$NON-NLS-1$ //$NON-NLS-2$
961
		rw.eval(symbol+ "<- list(data="+symbol+")"); //$NON-NLS-1$ //$NON-NLS-2$
962

  
963
		novoc++;
964
		return symbol;
965
	}
966

  
967
	/**
968
	 * Gets the symbol.
969
	 *
970
	 * @return the symbol
971
	 */
972
	public String getSymbol()
973
	{
974
		return symbol;
975
	}
976

  
977
	/**
978 893
	 * If the index has been build with corpus + property, the method returns the lexicon used.
979 894
	 *
980 895
	 * @return the lexicon
tmp/org.txm.statsengine.r.rcp/plugin.xml (revision 306)
1 1
<?xml version="1.0" encoding="UTF-8"?>
2 2
<?eclipse version="3.4"?>
3 3
<plugin>
4
   <extension-point id="org.txm.statengine.r.rcp.sendtor" name="SendToRCommand" schema="schema/org.txm.statengine.r.rcp.sendtor.exsd"/>
4 5
   <extension
5 6
         point="org.eclipse.ui.preferencePages">
6 7
      <page
......
33 34
            name="%command.name.46">
34 35
      </command>
35 36
               <command
36
            defaultHandler="org.txm.statsengine.r.rcp.handlers.SendToR"
37
            defaultHandler="org.txm.statsengine.r.rcp.handlers.SendToRCommand"
37 38
            id="SendToR"
38 39
            name="%command.name.53">
39 40
      </command>
tmp/org.txm.statsengine.r.rcp/META-INF/MANIFEST.MF (revision 306)
9 9
 org.eclipse.core.runtime;bundle-version="3.10.0",
10 10
 org.eclipse.ui;bundle-version="3.106.1",
11 11
 org.txm.rcp;bundle-version="0.7.8"
12
Export-Package: org.txm.statsengine.r.rcp.views
12
Export-Package: org.txm.statsengine.r.rcp.handlers,
13
 org.txm.statsengine.r.rcp.messages,
14
 org.txm.statsengine.r.rcp.perspectives,
15
 org.txm.statsengine.r.rcp.preferences,
16
 org.txm.statsengine.r.rcp.views
13 17
Bundle-Vendor: Textometrie.org
tmp/org.txm.statsengine.r.rcp/schema/org.txm.statengine.r.rcp.sendtor.exsd (revision 306)
1
<?xml version='1.0' encoding='UTF-8'?>
2
<!-- Schema file written by PDE -->
3
<schema targetNamespace="org.txm.statsengine.r.rcp" xmlns="http://www.w3.org/2001/XMLSchema">
4
<annotation>
5
      <appinfo>
6
         <meta.schema plugin="org.txm.statsengine.r.rcp" id="org.txm.statengine.r.rcp.sendtor" name="SendToRCommand"/>
7
      </appinfo>
8
      <documentation>
9
         An extension point to add commands that create R object using a TXMResult object
10
      </documentation>
11
   </annotation>
12

  
13
   <element name="extension">
14
      <annotation>
15
         <appinfo>
16
            <meta.element />
17
         </appinfo>
18
      </annotation>
19
      <complexType>
20
         <choice minOccurs="1" maxOccurs="unbounded">
21
            <element ref="sendtorcommand"/>
22
         </choice>
23
         <attribute name="point" type="string" use="required">
24
            <annotation>
25
               <documentation>
26
                  
27
               </documentation>
28
            </annotation>
29
         </attribute>
30
         <attribute name="id" type="string">
31
            <annotation>
32
               <documentation>
33
                  
34
               </documentation>
35
            </annotation>
36
         </attribute>
37
         <attribute name="name" type="string">
38
            <annotation>
39
               <documentation>
40
                  
41
               </documentation>
42
               <appinfo>
43
                  <meta.attribute translatable="true"/>
44
               </appinfo>
45
            </annotation>
46
         </attribute>
47
      </complexType>
48
   </element>
49

  
50
   <element name="sendtorcommand">
51
      <complexType>
52
         <attribute name="class" type="string">
53
            <annotation>
54
               <documentation>
55
                  
56
               </documentation>
57
               <appinfo>
58
                  <meta.attribute kind="java" basedOn="org.txm.statsengine.r.rcp.handlers.SendToRCommand:"/>
59
               </appinfo>
60
            </annotation>
61
         </attribute>
62
      </complexType>
63
   </element>
64

  
65
   <annotation>
66
      <appinfo>
67
         <meta.section type="since"/>
68
      </appinfo>
69
      <documentation>
70
         [Enter the first release in which this extension point appears.]
71
      </documentation>
72
   </annotation>
73

  
74
   <annotation>
75
      <appinfo>
76
         <meta.section type="examples"/>
77
      </appinfo>
78
      <documentation>
79
         [Enter extension point usage example here.]
80
      </documentation>
81
   </annotation>
82

  
83
   <annotation>
84
      <appinfo>
85
         <meta.section type="apiinfo"/>
86
      </appinfo>
87
      <documentation>
88
         [Enter API information here.]
89
      </documentation>
90
   </annotation>
91

  
92
   <annotation>
93
      <appinfo>
94
         <meta.section type="implementation"/>
95
      </appinfo>
96
      <documentation>
97
         [Enter information about supplied implementation of this extension point.]
98
      </documentation>
99
   </annotation>
100

  
101

  
102
</schema>
0 103

  
tmp/org.txm.statsengine.r.rcp/src/org/txm/statsengine/r/rcp/TXMRServeWatcher.java (revision 306)
1
// Copyright © 2010-2013 ENS de Lyon.
2
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of
3
// Lyon 2, University of Franche-Comté, University of Nice
4
// Sophia Antipolis, University of Paris 3.
5
// 
6
// The TXM platform is free software: you can redistribute it
7
// and/or modify it under the terms of the GNU General Public
8
// License as published by the Free Software Foundation,
9
// either version 2 of the License, or (at your option) any
10
// later version.
11
// 
12
// The TXM platform is distributed in the hope that it will be
13
// useful, but WITHOUT ANY WARRANTY; without even the implied
14
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15
// PURPOSE. See the GNU General Public License for more
16
// details.
17
// 
18
// You should have received a copy of the GNU General
19
// Public License along with the TXM platform. If not, see
20
// http://www.gnu.org/licenses.
21
// 
22
// 
23
// 
24
// $LastChangedDate:$
25
// $LastChangedRevision:$
26
// $LastChangedBy:$ 
27
//
28
package org.txm.statsengine.r.rcp;
29

  
30
import org.eclipse.jface.dialogs.MessageDialog;
31
import org.eclipse.swt.widgets.Display;
32
import org.txm.rcpapplication.Messages;
33
import org.txm.rcpapplication.views.corpora.CorporaView;
34
import org.txm.statsengine.r.core.RserveWatcher;
35

  
36
// TODO: Auto-generated Javadoc
37
/**
38
 * Watch if RServe is running
39
 */
40
@Deprecated
41
public class TXMRServeWatcher extends RserveWatcher{
42
	
43
	/** The parent. */
44
	private Display parent;
45

  
46
	/**
47
	 * Instantiates a new tXMR serve watcher.
48
	 *
49
	 * @param parent the parent
50
	 */
51
	TXMRServeWatcher(Display parent)
52
	{
53
		this.parent = parent;
54
	}
55
	
56
	/* (non-Javadoc)
57
	 * @see org.txm.RserveWatcher#restart()
58
	 */
59
	@Override
60
	public boolean restart()
61
	{
62
		parent.syncExec(new Runnable(){
63
		      @Override
64
			public void run(){
65
		    	  MessageDialog d =
66
					    new MessageDialog(
67
					      parent.getActiveShell(),
68
					      Messages.TXMRServeWatcher_0,
69
					      null,
70
					      Messages.TXMRServeWatcher_1,
71
					      MessageDialog.ERROR,
72
					      new String[] { Messages.TXMRServeWatcher_2 },
73
					      0);
74
					    d.open();
75
		      }
76
		    });
77
		
78
		boolean ret = super.restart();
79
		
80
		parent.syncExec(new Runnable(){
81
		      @Override
82
			public void run(){
83
		    	  MessageDialog d =
84
					    new MessageDialog(
85
					      parent.getActiveShell(),
86
					      Messages.TXMRServeWatcher_3,
87
					      null,
88
					      Messages.TXMRServeWatcher_4,
89
					      MessageDialog.ERROR,
90
					      new String[] { Messages.TXMRServeWatcher_2 },
91
					      0);
92
					    d.open();
93
		      }
94
		    });
95
		
96
		if (ret)
97
		{
98
			parent.syncExec(new Runnable(){
99
			      @Override
100
				public void run(){
101
			    	  CorporaView.reload();
102
			      }
103
			    });
104
		}
105
		
106
		return ret;
107
	}
108
}
tmp/org.txm.statsengine.r.rcp/src/org/txm/statsengine/r/rcp/handlers/SendToR.java (revision 306)
1
// Copyright © 2010-2013 ENS de Lyon.
2
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of
3
// Lyon 2, University of Franche-Comté, University of Nice
4
// Sophia Antipolis, University of Paris 3.
5
// 
6
// The TXM platform is free software: you can redistribute it
7
// and/or modify it under the terms of the GNU General Public
8
// License as published by the Free Software Foundation,
9
// either version 2 of the License, or (at your option) any
10
// later version.
11
// 
12
// The TXM platform is distributed in the hope that it will be
13
// useful, but WITHOUT ANY WARRANTY; without even the implied
14
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15
// PURPOSE. See the GNU General Public License for more
16
// details.
17
// 
18
// You should have received a copy of the GNU General
19
// Public License along with the TXM platform. If not, see
20
// http://www.gnu.org/licenses.
21
// 
22
// 
23
// 
24
// $LastChangedDate:$
25
// $LastChangedRevision:$
26
// $LastChangedBy:$ 
27
//
28
package org.txm.statsengine.r.rcp.handlers;
29

  
30
import java.util.List;
31

  
32
import org.eclipse.core.commands.ExecutionEvent;
33
import org.eclipse.core.commands.ExecutionException;
34
import org.eclipse.core.runtime.IProgressMonitor;
35
import org.eclipse.core.runtime.IStatus;
36
import org.eclipse.core.runtime.Status;
37
import org.eclipse.jface.viewers.IStructuredSelection;
38
import org.eclipse.ui.IEditorPart;
39
import org.eclipse.ui.IEditorReference;
40
import org.eclipse.ui.IWorkbenchPage;
41
import org.eclipse.ui.IWorkbenchWindow;
42
import org.eclipse.ui.handlers.HandlerUtil;
43
import org.eclipse.ui.internal.Workbench;
44
import org.txm.ca.core.functions.CA;
45
import org.txm.cooccurrence.core.functions.Cooccurrence;
46
import org.txm.cooccurrence.rcp.editors.CooccurrencesEditor;
47
import org.txm.functions.concordances.Concordance;
48
import org.txm.functions.referencer.Referencer;
49
import org.txm.index.core.functions.Index;
50
import org.txm.index.rcp.editors.IndexEditor;
51
import org.txm.lexicaltable.core.statsengine.data.LexicalTable;
52
import org.txm.lexicaltable.rcp.editors.LexicalTableEditor;
53
import org.txm.lexicaltable.rcp.editors.LexicalTableEditor2;
54
import org.txm.lexicon.core.corpusengine.cqp.Lexicon;
55
import org.txm.progression.core.functions.Progression;
56
import org.txm.rcp.handlers.BaseAbstractHandler;
57
import org.txm.rcpapplication.JobsTimer;
58
import org.txm.rcpapplication.commands.editor.CustomizableEditor;
59
import org.txm.rcpapplication.editors.concordances.ConcordancesEditor;
60
import org.txm.rcpapplication.editors.referencer.ReferencerEditor;
61
import org.txm.rcpapplication.utils.JobHandler;
62
import org.txm.rcpapplication.views.corpora.CorporaView;
63
import org.txm.searchengine.cqp.corpus.Corpus;
64
import org.txm.specificities.core.functions.SpecificitesResult;
65
import org.txm.specificities.rcp.editors.SpecificitiesTableEditor;
66
import org.txm.statsengine.core.data.Vector;
67
import org.txm.statsengine.r.rcp.messages.RUIMessages;
68
import org.txm.statsengine.r.rcp.views.RVariablesView;
69

  
70
// TODO: Auto-generated Javadoc
71
/**
72
 * Delete the selection: TXMObjects and results code for the results must be
73
 * added manually here @ author mdecorde.
74
 */
75
public class SendToR extends BaseAbstractHandler {
76

  
77
	/* (non-Javadoc)
78
	 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
79
	 */
80
	@Override
81
	public Object execute(ExecutionEvent event) throws ExecutionException {
82

  
83
		
84
		if(!super.checkStatsEngine())	{
85
			return null;
86
		}
87
		
88
		IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event);
89
		
90
		final List list = selection.toList();
91
		JobHandler jobhandler = new JobHandler(RUIMessages.SendToR_0+ list) {
92
				@Override
93
				protected IStatus run(IProgressMonitor monitor) {
94
					this.runInit(monitor);
95
					try {
96
						JobsTimer.start();
97
						monitor.beginTask(RUIMessages.SendToR_0+ list, 100);
98
						int delta = 100 / list.size();
99
						//System.out.println(selection.toList());
100
						for(Object o : list)
101
							try {
102
								monitor.subTask(RUIMessages.SendToR_0+ o);
103
								this.acquireSemaphore();
104
								send(o);
105
								this.releaseSemaphore();
106
								
107
								monitor.worked(delta);
108
								
109
							} catch (Exception e) {
110
								// TODO Auto-generated catch block
111
								org.txm.rcpapplication.utils.Logger.printStackTrace(e);
112
							}
113
	
114
						monitor.subTask(RUIMessages.SendToR_3);
115
						this.syncExec(new Runnable() {
116
							@Override
117
							public void run() {
118
								CorporaView.refresh();
119
								RVariablesView.reload();
120
							}
121
						});
122
					} catch (ThreadDeath td) {
123
						return Status.CANCEL_STATUS;
124
					} finally {
125
						monitor.done();
126
						JobsTimer.stopAndPrint();
127
					}
128
					return Status.OK_STATUS;
129
				}
130
			};
131
			jobhandler.startJob();
132
		
133
		
134
			return null;
135
	}
136

  
137
	/**
138
	 * Send.
139
	 *
140
	 * @param o the o
141
	 * @throws Exception the exception
142
	 */
143
	public static void send(Object o) throws Exception {
144

  
145
		if (o instanceof Lexicon) 
146
		{
147
			Lexicon lex = (Lexicon) o;
148
			Vector v = lex.asVector();
149
			lex.setSymbol(v.getSymbol());
150

  
151
			System.out.println(lex.getName()+" >> "+lex.getSymbol()); //$NON-NLS-1$
152
		}  else if (o instanceof Corpus) {
153
			Corpus corpus = (Corpus) o;
154
			String symbol = corpus.SendToR();
155

  
156
			System.out.println(corpus.getName()+" >> "+symbol); //$NON-NLS-1$
157
		} else if (o instanceof Concordance) {
158
			Concordance conc = (Concordance) o;
159
			String symbol = conc.asRMatrix();
160

  
161
			System.out.println(conc.getName()+" >> "+conc.getSymbol()); //$NON-NLS-1$
162
		} else if (o instanceof Referencer) {
163
			Referencer referencer = (Referencer) o;
164
			String symbol = referencer.asRMatrix();
165

  
166
			System.out.println(referencer.getName()+" >> "+referencer.getSymbol()); //$NON-NLS-1$
167
		} else if (o instanceof Cooccurrence) {
168
			Cooccurrence cooc = (Cooccurrence) o;
169
			String symbol = cooc.asRMatrix();
170

  
171
			System.out.println(cooc.getName()+" >> "+cooc.getSymbol()); //$NON-NLS-1$
172
		} else if (o instanceof Index) {
173
			Index voc = (Index) o;
174
			voc.asRMatrix();
175
			
176
			System.out.println(voc.getName()+" >> "+voc.getSymbol()); //$NON-NLS-1$
177
		}
178
	}
179

  
180
	/**
181
	 * Close the editors which uses an Object.
182
	 *
183
	 * @param o the object used by an editor
184
	 */
185
	
186
	// FIXME: this method should only contains one test on TXMEditor.getResult() and moved to non-R code/plug-in
187
	public static void closeEditorOfSelection(Object o)
188
	{
189
		if (o != null) {
190
			//get all editors
191
			//check editor class
192
			//test if object used dispose editor if necessary
193
			if (o instanceof Concordance)
194
			{
195
				for(IWorkbenchPage page : getPages())
196
				{
197
					for(IEditorReference editorref : page.getEditorReferences())
198
					{
199
						IEditorPart editor = editorref.getEditor(false);
200

  
201
						if (editor instanceof ConcordancesEditor)
202
							if (((Concordance)o).equals(((ConcordancesEditor)editor).getConcordance()))
203
								editor.getEditorSite().getPage().closeEditor(editor, true);
204
					}
205
				}
206
			}
207
			else if (o instanceof Cooccurrence)
208
			{
209
				for(IWorkbenchPage page : getPages())
210
				{
211
					for(IEditorReference editorref : page.getEditorReferences())
212
					{
213
						IEditorPart editor = editorref.getEditor(false);
214

  
215
						if (editor instanceof CooccurrencesEditor)
216
							if (o.equals(((CooccurrencesEditor)editor).getCooc()))
217
								editor.getEditorSite().getPage().closeEditor(editor, true);
218
					}
219
				}
220
			}
221
			else if (o instanceof CA)
222
			{
223
				for(IWorkbenchPage page : getPages())
224
				{
225
					for(IEditorReference editorref : page.getEditorReferences())
226
					{
227
						IEditorPart editor = editorref.getEditor(false);
228
						if (editor instanceof CAEditor)
229
							if (o.equals(((CAEditor)editor).getCA()))
230
								editor.getEditorSite().getPage().closeEditor(editor, true);
231
					}
232
				}
233
			}
234
			else if (o instanceof SpecificitesResult)
235
			{
236
				for(IWorkbenchPage page : getPages())
237
				{
238
					for(IEditorReference editorref : page.getEditorReferences())
239
					{
240
						IEditorPart editor = editorref.getEditor(false);
241
						if (editor instanceof SpecificitiesTableEditor)
242
							if (o.equals(((SpecificitiesTableEditor)editor).getSpecificitiesResult()))
243
								editor.getEditorSite().getPage().closeEditor(editor, true);
244
					}
245
				}
246
			}
247
			else if (o instanceof Index)
248
			{
249
				for(IWorkbenchPage page : getPages())
250
				{
251
					for(IEditorReference editorref : page.getEditorReferences())
252
					{
253
						IEditorPart editor = editorref.getEditor(false);
254
						if (editor instanceof IndexEditor)
255
						{
256
							if (o.equals(((IndexEditor)editor).getIndex()))
257
								editor.getEditorSite().getPage().closeEditor(editor, true);
258
						}
259
					}
260
				}
261
			}
262
			else if (o instanceof LexicalTable)
263
			{
264
				for(IWorkbenchPage page : getPages())
265
				{
266
					for(IEditorReference editorref : page.getEditorReferences())
267
					{
268
						IEditorPart editor = editorref.getEditor(false);
269
						if (editor instanceof LexicalTableEditor)
270
							if (o.equals(((LexicalTableEditor2)editor).getLexicalTable()))
271
								editor.getEditorSite().getPage().closeEditor(editor, true);
272
					}
273
				}
274
			}
275
			else if (o instanceof Referencer)
276
			{
277
				for(IWorkbenchPage page : getPages())
278
				{
279
					for(IEditorReference editorref : page.getEditorReferences())
280
					{
281
						IEditorPart editor = editorref.getEditor(false);
282
						if (editor instanceof ReferencerEditor)
283
							if (o.equals(((ReferencerEditor)editor).getReferencer()))
284
								editor.getEditorSite().getPage().closeEditor(editor, true);
285
					}
286
				}
287
			} 
288
			else if (o instanceof Progression) 
289
			{
290
				Progression rep = (Progression)o;
291
				for(IWorkbenchPage page : getPages())
292
				{
293
					for(IEditorReference editorref : page.getEditorReferences())
294
					{
295
						IEditorPart editor = editorref.getEditor(false);
296
						if (editor instanceof CustomizableEditor)
297
						{	
298
							Object source = ((CustomizableEditor)editor).getSource();
299
							if (source != null && source instanceof Progression)
300
								if (rep.equals(source))
301
									editor.getEditorSite().getPage().closeEditor(editor, true);
302
						}
303
					}
304
				}
305
			}
306
		}
307

  
308
	}
309

  
310
	/**
311
	 * Gets the pages.
312
	 *
313
	 * @return the pages
314
	 */
315
	private static IWorkbenchPage[] getPages()
316
	{
317
		for(IWorkbenchWindow win : Workbench.getInstance().getWorkbenchWindows())
318
		{
319
			return win.getPages();
320
		}
321
		return new IWorkbenchPage[0];
322
	}
323
}
tmp/org.txm.statsengine.r.rcp/src/org/txm/statsengine/r/rcp/handlers/RAdaptor.java (revision 306)
1
package org.txm.statsengine.r.rcp.handlers;
2

  
3
import java.util.HashMap;
4

  
5
import org.txm.core.results.TXMResult;
6

  
7
public class RAdaptor {
8
	
9
	protected HashMap<String, TXMResult> symbols = new HashMap<String, TXMResult>();
10
	protected HashMap<TXMResult, String> sended = new HashMap<TXMResult, String>();
11
	
12
	
13
	public static String sendToR(TXMResult result) {
14
		return "";
15
	}
16

  
17
	/**
18
	 * Get the symbols created.
19
	 *
20
	 * @return the symbol
21
	 */
22
	public HashMap<String, TXMResult> getSymbols()
23
	{
24
		return symbols;
25
	}
26

  
27
	/**
28
	 * Gets the indexes who have a symbol.
29
	 *
30
	 * @return the symbol
31
	 */
32
	public HashMap<TXMResult, String> getSendedTXMResults()
33
	{
34
		return sended;
35
	}
36
}
0 37

  
tmp/org.txm.statsengine.r.rcp/src/org/txm/statsengine/r/rcp/handlers/SendToRCommand.java (revision 306)
1
// Copyright © 2010-2013 ENS de Lyon.
2
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of
3
// Lyon 2, University of Franche-Comté, University of Nice
4
// Sophia Antipolis, University of Paris 3.
5
// 
6
// The TXM platform is free software: you can redistribute it
7
// and/or modify it under the terms of the GNU General Public
8
// License as published by the Free Software Foundation,
9
// either version 2 of the License, or (at your option) any
10
// later version.
11
// 
12
// The TXM platform is distributed in the hope that it will be
13
// useful, but WITHOUT ANY WARRANTY; without even the implied
14
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15
// PURPOSE. See the GNU General Public License for more
16
// details.
17
// 
18
// You should have received a copy of the GNU General
19
// Public License along with the TXM platform. If not, see
20
// http://www.gnu.org/licenses.
21
// 
22
// 
23
// 
24
// $LastChangedDate:$
25
// $LastChangedRevision:$
26
// $LastChangedBy:$ 
27
//
28
package org.txm.statsengine.r.rcp.handlers;
29

  
30
import java.util.List;
31

  
32
import org.eclipse.core.commands.ExecutionEvent;
33
import org.eclipse.core.commands.ExecutionException;
34
import org.eclipse.core.runtime.IProgressMonitor;
35
import org.eclipse.core.runtime.IStatus;
36
import org.eclipse.core.runtime.Status;
37
import org.eclipse.jface.viewers.IStructuredSelection;
38
import org.eclipse.ui.handlers.HandlerUtil;
39
import org.txm.core.results.TXMResult;
40
import org.txm.rcp.handlers.BaseAbstractHandler;
41
import org.txm.rcpapplication.JobsTimer;
42
import org.txm.rcpapplication.utils.JobHandler;
43
import org.txm.rcpapplication.views.corpora.CorporaView;
44
import org.txm.statsengine.r.rcp.messages.RUIMessages;
45
import org.txm.statsengine.r.rcp.views.RVariablesView;
46

  
47
/**
48
 * Commands that creates a R object using a TXMResult.
49
 * 
50
 * 
51
 * 
52
 * @author mdecorde.
53
 */
54
public abstract class SendToRCommand extends BaseAbstractHandler {
55

  
56
	/* (non-Javadoc)
57
	 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
58
	 */
59
	@Override
60
	public Object execute(ExecutionEvent event) throws ExecutionException {
61

  
62
		if(!super.checkStatsEngine())	{
63
			return null;
64
		}
65

  
66
		IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelection(event);
67

  
68
		final List list = selection.toList();
69
		JobHandler jobhandler = new JobHandler(RUIMessages.SendToR_0+ list) {
70
			@Override
71
			protected IStatus run(IProgressMonitor monitor) {
72
				this.runInit(monitor);
73
				try {
74
					JobsTimer.start();
75
					
76
					monitor.beginTask(RUIMessages.SendToR_0+ list, 100);
77
					int delta = 100 / list.size();
78
					for(Object o : list) {
79
						if (o instanceof TXMResult) {
80
							try {
81
								monitor.subTask(RUIMessages.SendToR_0+ o);
82
								this.acquireSemaphore();
83
								send((TXMResult)o);
84
								this.releaseSemaphore();
85

  
86
								monitor.worked(delta);
87

  
88
							} catch (Exception e) {
89
								System.out.println("Failed to send to R: "+o);
90
								org.txm.rcpapplication.utils.Logger.printStackTrace(e);
91
							}
92
						}
93
					}
94
					
95
					monitor.subTask(RUIMessages.SendToR_3);
96
					this.syncExec(new Runnable() {
97
						@Override
98
						public void run() {
99
							CorporaView.refresh();
100
							RVariablesView.reload();
101
						}
102
					});
103
				} catch (ThreadDeath td) {
104
					return Status.CANCEL_STATUS;
105
				} finally {
106
					monitor.done();
107
					JobsTimer.stopAndPrint();
108
				}
109
				return Status.OK_STATUS;
110
			}
111
		};
112
		jobhandler.startJob();
113

  
114

  
115
		return null;
116
	}
117

  
118
	/**
119
	 * Static method to create a R object from a TXMResult
120
	 *
121
	 * @param o the o
122
	 * @throws Exception the exception
123
	 */
124
	public abstract void send(TXMResult o) throws Exception;
125
	
126
	//TODO: create the SendToRCommands commands in all plugins that manage the following TXMResult classes
127
	/*{
128

  
129
		if (o instanceof Lexicon) 
130
		{
131
			Lexicon lex = (Lexicon) o;
132
			Vector v = lex.asVector();
133
			lex.setSymbol(v.getSymbol());
134

  
135
			System.out.println(lex.getName()+" >> "+lex.getSymbol()); //$NON-NLS-1$
136
		}  else if (o instanceof Corpus) {
137
			Corpus corpus = (Corpus) o;
138
			String symbol = corpus.SendToR();
139

  
140
			System.out.println(corpus.getName()+" >> "+symbol); //$NON-NLS-1$
141
		} else if (o instanceof Concordance) {
142
			Concordance conc = (Concordance) o;
143
			String symbol = conc.asRMatrix();
144

  
145
			System.out.println(conc.getName()+" >> "+conc.getSymbol()); //$NON-NLS-1$
146
		} else if (o instanceof Referencer) {
147
			Referencer referencer = (Referencer) o;
148
			String symbol = referencer.asRMatrix();
149

  
150
			System.out.println(referencer.getName()+" >> "+referencer.getSymbol()); //$NON-NLS-1$
151
		} else if (o instanceof Cooccurrence) {
152
			Cooccurrence cooc = (Cooccurrence) o;
153
			String symbol = cooc.asRMatrix();
154

  
155
			System.out.println(cooc.getName()+" >> "+cooc.getSymbol()); //$NON-NLS-1$
156
		} else if (o instanceof Index) {
157
			Index voc = (Index) o;
158
			voc.asRMatrix();
159

  
160
			System.out.println(voc.getName()+" >> "+voc.getSymbol()); //$NON-NLS-1$
161
		}
162
	}
163
	 */
164
}
0 165

  
tmp/org.txm.core/src/java/org/txm/core/preferences/TXMPreferences.java (revision 306)
40 40
	// FIXME: here we must use a ProjectScope when we use IProject for the corporas of TXM
41 41
	public static IScopeContext scope = InstanceScope.INSTANCE;
42 42
	
43
	
44 43
	/**
45 44
	 * Alternative nodes to look up when getting a preference.
46 45
	 */
47 46
	public static ArrayList<String> alternativeNodesQualifiers = new ArrayList<String>();
48
	
49
	
50
	
47

  
51 48
	/**
52 49
	 * Stores a pairs of key / value in a local node dedicated to the specified result. The node qualifier is generated by the <code>Object.toString()</code> method.
53 50
	 * @param result
tmp/org.txm.core/src/java/org/txm/core/results/ITXMResult.java (revision 306)
9 9
 * @author sjacquot
10 10
 *
11 11
 */
12
//FIXME: this interface has been created to manage the result baed on interface AND implementation, for example: interface LexicalTable.
12
//FIXME: this interface has been created to manage the result based on interface AND implementation, for example: interface LexicalTable.
13 13
// need to see if it's useful or not.
14 14
public interface ITXMResult {
15 15

  
tmp/org.txm.core/src/groovy/org/txm/macroproto/partition/CreatePartitionByNumericMetadataMacro.groovy (revision 306)
1 1
// STANDARD DECLARATIONS
2 2
package org.txm.macroproto.partition
3 3

  
4
import org.kohsuke.args4j.*
5

  
6 4
import groovy.transform.Field
7 5

  
6
import org.kohsuke.args4j.*
8 7
import org.txm.rcpapplication.swt.widget.parameters.*
9
import org.txm.searchengine.cqp.corpus.*
10
import org.txm.utils.logger.Log;
11 8
import org.txm.rcpapplication.views.*
12
import org.txm.stat.engine.r.RWorkspace
13
import org.txm.Toolbox
9
import org.txm.searchengine.cqp.corpus.*
14 10

  
15 11
//BEGINNING OF PARAMETERS
16 12
def corpus = corpusViewSelection
tmp/org.txm.core/src/groovy/org/txm/macroproto/SelectBanal.groovy (revision 306)
1 1
package org.txm.macroproto;
2
import groovy.transform.Field
3

  
4
import org.kohsuke.args4j.*
2 5
import org.txm.*
3 6
import org.txm.functions.ca.*
7
import org.txm.functions.specificities.*
8
import org.txm.rcpapplication.swt.widget.parameters.*
4 9
import org.txm.searchengine.cqp.clientExceptions.*
5 10
import org.txm.searchengine.cqp.corpus.*
6 11
import org.txm.searchengine.cqp.corpus.query.*
7
import org.txm.stat.StatException
8 12
import org.txm.stat.data.*
9 13
import org.txm.stat.engine.r.*
10
import org.txm.functions.specificities.*
11
import org.kohsuke.args4j.*
12
import groovy.transform.Field
13
import org.txm.rcpapplication.swt.widget.parameters.*
14 14

  
15 15
//TODO: temporary uncommented
16 16
//if (!(corpusViewSelection instanceof SpecificitesResult)) {
tmp/org.txm.core/src/groovy/org/txm/test/HelloWorldR.groovy (revision 306)
33 33
// $LastChangedRevision:$
34 34
// $LastChangedBy:$ 
35 35
//
36
import org.txm.stat.engine.r.RWorkspace
37 36

  
38 37
// TODO: Auto-generated Javadoc
39 38
/* (non-Javadoc)
tmp/org.txm.core/src/groovy/org/txm/test/ExecuteRscript.groovy (revision 306)
31 31
// $LastChangedRevision:$
32 32
// $LastChangedBy:$ 
33 33
//
34
import org.txm.stat.engine.r.RWorkspace
35 34
// import org.txm.rcpapplication.commands.*
36 35
// uncomment for test
37 36

  
tmp/org.txm.core/src/groovy/org/txm/test/SomeRCode.groovy (revision 306)
32 32
//
33 33
package org.txm.test
34 34

  
35
import org.rosuda.REngine.REXP;
36
import org.txm.Toolbox;
37
import org.txm.stat.engine.r.RWorkspace;
35
import org.txm.statsengine.r.core.RWorkspace
38 36

  
37

  
39 38
// TODO: Auto-generated Javadoc
40 39
/* (non-Javadoc)
41 40
 * @see groovy.lang.Script#run()
tmp/org.txm.core/src/groovy/org/txm/macro/r/PlotSpecifMacro.groovy (revision 306)
26 26
// $LastChangedBy:$ 
27 27
//
28 28

  
29
import groovy.transform.Field
30

  
31
import java.lang.invoke.MethodHandleImpl.BindCaller.T
32

  
29 33
import org.kohsuke.args4j.*
30
import groovy.transform.Field
34
import org.txm.Toolbox
35
import org.txm.rcpapplication.commands.*
31 36
import org.txm.rcpapplication.swt.widget.parameters.*
32
import org.txm.rcpapplication.commands.*
33
import org.txm.Toolbox
34
import org.txm.stat.engine.r.RWorkspace
35 37

  
36 38
/**
37 39
 * 

Also available in: Unified diff