Révision 3753

TXM/trunk/bundles/org.txm.conllu.core/src/org/txm/conllu/core/function/UDTreeSearch.java (revision 3753)
61 61
		return matchingSentencesToMatches != null;
62 62
	}
63 63
	
64
	public boolean isDrawn() {
64
	public boolean canBeDrawn() {
65 65
		return matchingSentencesToMatches != null;
66 66
	}
67 67
	
......
72 72
	@Override
73 73
	public boolean toSVG(File svgFile, int sent, int sub, List<String> T,  List<String> NT) {
74 74
		
75
		if (!isDrawn()) return false; // no result
75
		if (!canBeDrawn()) return false; // no result
76 76
		try {
77 77

  
78 78
			org.txm.objects.Match matchingSentence = this.matchingSentencesKeys.get(sent);
TXM/trunk/bundles/org.txm.treesearch.core/src/org/txm/treesearch/function/TreeSearch.java (revision 3753)
16 16
import org.txm.searchengine.cqp.corpus.CQPCorpus;
17 17
import org.txm.searchengine.cqp.corpus.WordProperty;
18 18
import org.txm.treesearch.preferences.TreeSearchPreferences;
19
import org.txm.utils.logger.Log;
19 20

  
20 21
public abstract class TreeSearch extends TXMResult {
21
	
22

  
22 23
	protected CQPCorpus corpus;
23
	
24

  
24 25
	/**
25 26
	 * from 0 to N-1 sentences
26 27
	 */
27 28
	@Parameter(key = TXMPreferences.INDEX, type = Parameter.RENDERING)
28 29
	protected int pIndex;
29
	
30

  
30 31
	/**
31 32
	 * from 0 to N-1 sentence subgraphs
32 33
	 */
......
35 36

  
36 37
	@Parameter(key = TXMPreferences.QUERY)
37 38
	protected IQuery pQuery;
38
	
39

  
39 40
	@Parameter(key = TreeSearchPreferences.TFEATURE)
40 41
	protected List<String> T;
41
	
42

  
42 43
	@Parameter(key = TreeSearchPreferences.NTFEATURE)
43 44
	protected List<String> NT;
44
	
45

  
45 46
	@Parameter(key = TreeSearchPreferences.VISUALISATION)
46 47
	protected String pVisualisation;
47
	
48 48

  
49

  
49 50
	public TreeSearch(CQPCorpus corpus) {
50
		
51

  
51 52
		this(null, corpus);
52 53
	}
53
	
54

  
54 55
	public TreeSearch(String parentNodePath) {
55
		
56

  
56 57
		this(parentNodePath, null);
57 58
	}
58
	
59

  
59 60
	public TreeSearch(String parentNodePath, CQPCorpus corpus) {
60
		
61

  
61 62
		super(parentNodePath, corpus);
62 63
	}
63
	
64

  
64 65
	@Override
65 66
	public boolean canCompute() {
66
		
67

  
67 68
		return corpus != null; // && pQuery != null && pQuery.length() > 0; // if pQuery is empty/null set a default query
68 69
	}
69
	
70

  
70 71
	public abstract String[] getAvailableNTProperties();
71
	
72

  
72 73
	public abstract String[] getAvailableTProperties();
73
	
74

  
74 75
	public CQPCorpus getCorpus() {
75
		
76

  
76 77
		return corpus;
77 78
	}
78
	
79

  
79 80
	@Override
80 81
	public String getDetails() {
81
		
82

  
82 83
		if (pQuery != null) {
83 84
			return pQuery.toString();
84 85
		}
85 86
		return "no query";
86 87
	}
87
	
88

  
88 89
	@Override
89 90
	public String getName() {
90
		
91

  
91 92
		if (pQuery != null) {
92 93
			return pQuery.toString();
93 94
		}
94 95
		return "no query";
95 96
	}
96
	
97

  
97 98
	public abstract int getNMatchingSentences();
98
	
99

  
99 100
	public abstract int getNSubMatch();
100
	
101

  
101 102
	public abstract int getTotalSubMatch();
102
	
103

  
103 104
	public final List<String> getNT() {
104 105
		return NT;
105 106
	}
106
	
107

  
107 108
	public abstract String getQuery();
108
	
109

  
109 110
	@Override
110 111
	public String getSimpleName() {
111
		
112

  
112 113
		if (pQuery != null) {
113 114
			return pQuery.toString();
114 115
		}
115 116
		return "no query";
116 117
	}
117
	
118

  
118 119
	public String getComputingStartMessage() {
120
		
119 121
		return NLS.bind("Rendering {0} Syntactic Tree...", this.getSelector().getEngine());
120 122
	}
121
	
123

  
124
	public String getComputingDoneMessage() {
125
		
126
		int n = this.getNMatchingSentences();
127
		
128
		if (n > 0) {
129
			return ""+n+" matching sentence"+(n > 1?"s":"");
130
		} else {
131
			return "No matching sentence.";
132
		}
133
	}
134

  
135

  
136

  
122 137
	public final List<String> getT() {
123 138
		return T;
124 139
	}
125
	
140

  
126 141
	@Override
127 142
	public final boolean loadParameters() throws Exception {
128
		
143

  
129 144
		this.T = new ArrayList<>();
130 145
		String values = getStringParameterValue(TreeSearchPreferences.TFEATURE);
131 146

  
132 147
		if (values != null && !values.isEmpty() && values.length() > 0) {
133 148
			this.T.addAll(Arrays.asList(values.split(",")));
134 149
		}
135
		
150

  
136 151
		this.NT = new ArrayList<>();
137 152
		values = getStringParameterValue(TreeSearchPreferences.TFEATURE);
138 153

  
139 154
		if (values != null && !values.isEmpty() && values.length() > 0) {
140 155
			this.NT.addAll(Arrays.asList(values.split(",")));
141 156
		}
142
		
157

  
143 158
		String squery = getStringParameterValue(TreeSearchPreferences.QUERY);
144 159
		if (squery != null && !squery.isEmpty() && squery.length() > 0) {
145 160
			this.pQuery = IQuery.fromPrefString(squery);
146 161
		}
147
		
162

  
148 163
		return _loadParameters();
149 164
	}
150
	
165

  
151 166
	@Override
152 167
	public boolean saveParameters() throws Exception {
153
		
168

  
154 169
		if (pQuery != null) {
155 170
			this.saveParameter(TreeSearchPreferences.QUERY, IQuery.toPrefString(pQuery));
156 171
		}
157
		
172

  
158 173
		this.saveParameter(TreeSearchPreferences.TFEATURE, StringUtils.join(this.T, ","));
159
		
174

  
160 175
		this.saveParameter(TreeSearchPreferences.NTFEATURE, StringUtils.join(this.NT, ","));
161
		
176

  
162 177
		return true;
163 178
	}
164
	
179

  
165 180
	public abstract boolean _loadParameters() throws Exception;
166
	
181

  
167 182
	public abstract boolean hasSubMatchesStrategy();
168
	
183

  
169 184
	@Override
170 185
	public abstract boolean setParameters(TXMParameters parameters);
171
	
186

  
172 187
	public abstract boolean toSVG(File svgFile, int sent, int sub, List<String> T, List<String> nT2);
173 188

  
174 189
	public abstract boolean isReady();
......
177 192

  
178 193
	public abstract boolean isComputed();
179 194

  
180
	public abstract boolean isDrawn();
195
	public abstract boolean canBeDrawn();
181 196

  
182 197
	public abstract String getEngine();
183 198

  
184 199
	public abstract TreeSearchSelector getSelector();
185
	
200

  
186 201
	public abstract String[] getTextAndWordIDSOfCurrentSentence() throws Exception;
187
	
202

  
188 203
	public abstract String getIconPath();
189 204

  
190
	public int getCurrentMatchIndex() {
191
		
205
	public final int getCurrentMatchIndex() {
206

  
192 207
		return pIndex;
193 208
	}
194 209

  
195
	public int getCurrentSubMatchIndex() {
196
		
210
	public final int getCurrentSubMatchIndex() {
211

  
197 212
		return this.pSubIndex;
198 213
	}
199 214

  
......
210 225
	public String getVisualisation() {
211 226
		return pVisualisation;
212 227
	}
213
	
228

  
214 229
}
TXM/trunk/bundles/org.txm.treesearch.rcp/src/org/txm/treesearch/editor/TreeSearchEditor.java (revision 3753)
517 517
//			if (ts.hasSubMatchesStrategy()) subCounterLabel.setText(Messages.NoSubGraph);
518 518
		}
519 519
		
520
		if (!ts.isDrawn()) {
520
		if (!ts.canBeDrawn()) {
521 521
			sentSpinner.setSelection(ts.getCurrentMatchIndex());
522 522
			sentSpinner.setMaximum(ts.getNMatchingSentences());
523 523
			// if (ts.hasSubMatchesStrategy()) {
......
606 606
				subSpinner.setMaximum(ts.getNSubMatch());
607 607
				subSpinner.refresh();
608 608
				reloadGraph();
609
				Log.warning(""+ts.getNMatchingSentences()+" matching sentence(s) for "+ts.getTotalSubMatch()+" matches.");
610 609
			} else {
611
				Log.warning("No matching sentence.");
612 610
				svgPanel.setText("");
613 611
				sentSpinner.setEnabled(false);
614 612
				subSpinner.setEnabled(false);
TXM/trunk/bundles/org.txm.tigersearch.rcp/src/org/txm/function/tigersearch/TIGERSearch.java (revision 3753)
67 67
		return tsresult != null;
68 68
	}
69 69
	
70
	public boolean isDrawn() {
70
	public boolean canBeDrawn() {
71 71
		
72 72
		return tsresult != null && T != null && NT != null;
73 73
	}
TXM/trunk/bundles/org.txm.tigersearch.rcp/src/org/txm/searchengine/ts/TIGERSearchEngine.java (revision 3753)
282 282

  
283 283
		return new TIGERSelection(query, result2);
284 284
	}
285

  
285
	
286 286
	@Override
287 287
	public Query newQuery() {
288 288
		return new TIGERQuery();
......
362 362

  
363 363
		File master = new File(sourceDirectory, driverFilename);
364 364
		if (!master.exists()) {
365
			File[] xmlFiles = sourceDirectory.listFiles(new FileFilter() {
366
				public boolean accept(File file) {
367
					if (file.isDirectory()) return false;
368
					if (file.isHidden()) return false;
369
					String filename = file.getName();
370
					if (filename.equals("import.xml")) return false;
371
					if (!filename.endsWith(".xml")) return false;
372

  
373
					return true;
374
				}
375
			});
376

  
377
			if (xmlFiles == null) {
365
//			File[] xmlFiles = sourceDirectory.listFiles(new FileFilter() {
366
//				public boolean accept(File file) {
367
//					if (file.isDirectory()) return false;
368
//					if (file.isHidden()) return false;
369
//					String filename = file.getName();
370
//					if (filename.equals("import.xml")) return false;
371
//					if (!filename.endsWith(".xml")) return false;
372
//
373
//					return true;
374
//				}
375
//			});
376
//
377
//			if (xmlFiles == null) {
378 378
				System.out.println("No master file found in: "+sourceDirectory);
379 379
				return false;
380
			}
381
			master = xmlFiles[0];
380
//			}
381
//			master = xmlFiles[0];
382 382
		}
383 383
		String uri = master.getAbsolutePath(); // TIGER corpus source root file
384 384
		File tigerBinDir = new File(tigerDir, corpusName);
TXM/trunk/bundles/org.txm.tigersearch.rcp/src/org/txm/tigersearch/commands/ImportTIGERAnnotations.java (revision 3753)
28 28
package org.txm.tigersearch.commands;
29 29

  
30 30
import java.io.File;
31
import java.io.FileNotFoundException;
32 31
import java.io.IOException;
33
import java.io.RandomAccessFile;
34
import java.nio.MappedByteBuffer;
35
import java.nio.channels.FileChannel;
36 32

  
37 33
import org.apache.log4j.BasicConfigurator;
38 34
import org.eclipse.core.commands.AbstractHandler;
......
43 39
import org.eclipse.swt.SWT;
44 40
import org.eclipse.swt.widgets.DirectoryDialog;
45 41
import org.eclipse.ui.handlers.HandlerUtil;
46
import org.txm.searchengine.cqp.AbstractCqiClient;
47
import org.txm.searchengine.cqp.CQPSearchEngine;
48 42
import org.txm.searchengine.cqp.clientExceptions.CqiClientException;
49 43
import org.txm.searchengine.cqp.clientExceptions.UnexpectedAnswerException;
50 44
import org.txm.searchengine.cqp.corpus.CQPCorpus;
51 45
import org.txm.searchengine.cqp.corpus.MainCorpus;
52 46
import org.txm.searchengine.cqp.serverException.CqiServerError;
53
import org.txm.searchengine.ts.InternalCorpusQueryManagerLocal2;
54 47
import org.txm.searchengine.ts.TIGERSearchEngine;
55 48
import org.txm.searchengine.ts.TSCorpus;
56
import org.txm.searchengine.ts.TSCorpusManager;
57
import org.txm.utils.ConsoleProgressBar;
49
import org.txm.tigersearch.preferences.TigerSearchPreferences;
58 50
import org.txm.utils.DeleteDir;
59 51
import org.txm.utils.io.FileCopy;
60 52
import org.txm.utils.io.IOUtils;
61 53
import org.txm.utils.logger.Log;
62 54

  
63
import ims.tiger.corpus.Sentence;
64
import ims.tiger.corpus.T_Node;
65
import ims.tiger.index.reader.Index;
66 55
import ims.tiger.index.reader.IndexException;
67 56
import ims.tiger.index.writer.IndexBuilderErrorHandler;
68 57
import ims.tiger.index.writer.SimpleErrorHandler;
69 58
import ims.tiger.index.writer.XMLIndexing;
70 59
import ims.tiger.query.api.QueryIndexException;
71
import ims.tiger.query.processor.CorpusQueryProcessor;
72 60

  
73 61
/**
74 62
 * Import TIGERSearch annotations into a TXM corpus
......
81 69
 */
82 70
public class ImportTIGERAnnotations extends AbstractHandler {
83 71
	
84
	public static final String ID = "org.txm.rcp.commands.function.ComputeTSIndex"; //$NON-NLS-1$
85
	
86 72
	/*
87 73
	 * (non-Javadoc)
88 74
	 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
......
119 105
			}
120 106
			
121 107
			if (new File(tigerCorpusDirectory, "word.lexicon").exists() && new File(tigerCorpusDirectory, "corpus_config.xml").exists()) {
122
				// ok this is a TIGERSearch binary corpus
108
				// ok this is a TIGERSearch binary corpus, use it
123 109
			}
124 110
			else {
125
				
126 111
				// need to build a TIGERSearch binary corpus
127 112
				File tigerBinaryCorpusDirectory = new File(tigerCorpusDirectory, "tiger");
128
				if (!buildTIGERCorpus(mainCorpus, tigerCorpusDirectory, tigerBinaryCorpusDirectory)) {
113
				if (!buildTIGERBinaryCorpus(mainCorpus, tigerCorpusDirectory, tigerBinaryCorpusDirectory)) {
129 114
					Log.warning("Aborting annotation importation.");
130 115
					return null;
131 116
				}
......
133 118
			}
134 119
			
135 120
			try {
136
				return importAnnotations(mainCorpus, tigerCorpusDirectory, "editionId");
121
				return importTIGERBinaryCorpus(mainCorpus, tigerCorpusDirectory, "editionId");
137 122
			}
138 123
			catch (Exception e) {
139 124
				e.printStackTrace();
......
146 131
		}
147 132
	}
148 133
	
149
	private boolean buildTIGERCorpus(MainCorpus corpus, File sourceDirectory, File tigerDir) {
134
	public static boolean buildTIGERBinaryCorpus(MainCorpus corpus, File sourceDirectory, File tigerDir) {
135
		
150 136
		tigerDir.mkdirs();
151 137
		
152 138
		File configfile = new File(tigerDir, "tigersearch.logprop");
......
155 141
		}
156 142
		
157 143
		BasicConfigurator.configure();
158
		File master = new File(sourceDirectory, "main.xml");
159
		if (!master.exists()) master = new File(sourceDirectory, "master.xml");
144
		File master = new File(sourceDirectory, TigerSearchPreferences.DRIVER_FILENAME);
160 145
		
161 146
		if (!master.exists()) {
162
			Log.warning("Error: Can't create TIGERSearch corpus: no main or master file found in " + sourceDirectory);
147
			Log.warning("Error: Can't create TIGERSearch corpus: driver file found: " + master);
163 148
			return false;
149
		} else {
150
			Log.warning("Using the driver file found: " + master+". Be sure text order is the same as the CQP corpus!");
164 151
		}
152
		
165 153
		String uri = master.getAbsolutePath(); // TIGER corpus source root file
166 154
		File tigerBinDir = new File(tigerDir, corpus.getName());
167 155
		tigerBinDir.mkdirs();
......
211 199
	 * @throws IOException
212 200
	 * @throws UnexpectedAnswerException
213 201
	 */
214
	public static int importAnnotations(MainCorpus corpus, File tigerCorpusDirectory, String wordIdAttribute) throws IndexException, QueryIndexException, UnexpectedAnswerException, IOException,
202
	public static int importTIGERBinaryCorpus(MainCorpus corpus, File tigerCorpusDirectory, String wordIdAttribute) throws IndexException, QueryIndexException, UnexpectedAnswerException, IOException,
215 203
			CqiServerError,
216 204
			CqiClientException {
217 205
		
218

  
219
		
220 206
		File tigerDirectory = new File(corpus.getProjectDirectory(), "tiger");
221 207
		File tigerCorpusExistingDirectory = new File(tigerDirectory, corpus.getName());
222 208
		DeleteDir.deleteDirectory(tigerCorpusExistingDirectory);

Formats disponibles : Unified diff