Révision 2243

tmp/org.txm.searchengine.cqp.core/src/org/txm/searchengine/cqp/corpus/MainCorpus.java (revision 2243)
127 127
		}
128 128

  
129 129
		HashMap<String, MainCorpus> corpora = CorpusManager.getCorpusManager().getCorpora();
130
		if (corpora.get(this.pID) != null && corpora.get(this.pID) != this) {
130
		if (CorpusManager.getCorpusManager().hasCorpus(this)) {
131 131
			Log.severe(NLS.bind("** The \"{0}\" MainCorpus object in the \"{1}\" project can not be computed: another one with the same CQP identifier has already been computed.", this.pID, this.getProjectDirectory()));
132 132
			return false;
133 133
		}
134
		corpora.put(this.pID, this);
134
		CorpusManager.getCorpusManager().add(this);
135 135

  
136 136
		this.dataDirectory = new File(getProjectDirectory(), "data/"+getID());
137 137
		this.registryFile = new File(getProjectDirectory(), "registry/"+getID().toLowerCase());
......
154 154
			}
155 155
			
156 156
			CQPSearchEngine.getCqiClient().load_a_system_corpus(this.registryFile.getParent(), this.pID);
157
			
157 158
			corpora.put(this.pID, this); // register the corpus
158 159
		} catch(Exception e) {
159 160
			Log.severe("MainCorpus not loaded: "+e);
......
165 166

  
166 167
		return true;
167 168
	}
169
	
170
	@Override
171
	public void onProjectClose() {
172
		try {
173
			if (hasBeenComputedOnce && this.pID != null) {
174
				CorpusManager.getCorpusManager().deleteCorpus(this);
175
			}
176
		} catch (Exception e) {
177
			// TODO Auto-generated catch block
178
			e.printStackTrace();
179
		}
180
	}
168 181

  
169 182
	/* (non-Javadoc)
170 183
	 * @see org.txm.searchengine.cqp.corpus.Corpus#load()
tmp/org.txm.searchengine.cqp.core/src/org/txm/searchengine/cqp/corpus/query/QueryPart.java (revision 2243)
32 32

  
33 33
import static org.txm.searchengine.cqp.corpus.query.CqpQueryConstant.*;
34 34

  
35
// TODO: Auto-generated Javadoc
36 35
/**
37
 * A query that extract a part from a corpus.
36
 * A query that select a structured subcorpus from a corpus.
38 37
 * 
39 38
 * @author Jean Philippe Magué
40 39
 * @author sloiseau
......
42 41
public class QueryPart extends CQLQuery {
43 42

  
44 43
	/** The structure. */
45
	private StructuralUnit structure;
44
	protected StructuralUnit structure;
46 45

  
47 46
	/** The property. */
48
	private StructuralUnitProperty property;
47
	protected StructuralUnitProperty property;
49 48

  
50 49
	/** The value. */
51
	private String value;
50
	protected String value;
52 51

  
53 52
	/**
54 53
	 * Instantiates a new query part.
......
66 65
		this.property = property;
67 66
		this.value = value;
68 67
		
69
		String tag = structure.getName() + TAG_ATTRIBUTE_SEPARATOR + property.getName();
70
		String label = "a"; //$NON-NLS-1$
71
		StringBuffer query = new StringBuffer();
72
		query.append(REGION_MACRO + START_MACRO_ARGS);
73
		query.append(tag + MACRO_ARGS_SEPARATOR + label + END_MACRO_ARGS);
74
		query.append(START_GLOBAL_CONSTRAINT + label + DOT + tag + EQUALS
75
				+ START_DOUBLE_QUOTE + value + END_DOUBLE_QUOTE);
76
		queryString = query.toString();
68
//		String tag = structure.getName() + TAG_ATTRIBUTE_SEPARATOR + property.getName();
69
//		String label = "a"; //$NON-NLS-1$
70
//		StringBuffer query = new StringBuffer();
71
//		query.append(REGION_MACRO + START_MACRO_ARGS);
72
//		query.append(tag + MACRO_ARGS_SEPARATOR + label + END_MACRO_ARGS);
73
//		query.append(START_GLOBAL_CONSTRAINT + label + DOT + tag + EQUALS
74
//				+ START_DOUBLE_QUOTE + value + END_DOUBLE_QUOTE);
75
//		queryString = query.toString();
76
		
77
		if ("text".equals(structure.getName())) { // optimisation only for the text structure
78
			queryString = "<"+property.getFullName()+"=\""+CQLQuery.addBackSlash(value)+"\">[] expand to "+structure.getName();
79
		} else {
80
			queryString = "[_."+property.getFullName()+"=\""+CQLQuery.addBackSlash(value)+"\"] expand to "+structure.getName();
81
		}
77 82
	}
78 83

  
84
	public StructuralUnit getStructure() {
85
		return structure;
86
	}
87

  
88
	public StructuralUnitProperty getProperty() {
89
		return property;
90
	}
91

  
92
	public String getValue() {
93
		return value;
94
	}
95

  
79 96
//	/*
80 97
//	 * (non-Javadoc)
81 98
//	 * 
tmp/org.txm.searchengine.cqp.core/src/org/txm/searchengine/cqp/corpus/CorpusManager.java (revision 2243)
219 219
	 *
220 220
	 * @param corpus the corpus
221 221
	 */
222
	public static void deleteCorpus(MainCorpus corpus) {
222
	public void deleteCorpus(MainCorpus corpus) {
223 223
		if (corpora != null)
224
			corpora.remove(corpus);
224
			corpora.remove(corpus.getID());
225 225
		if (CQPSearchEngine.isInitialized()) {
226 226
			try {
227 227
				CQPSearchEngine.getCqiClient().dropCorpus(corpus.getID());
......
231 231
			}
232 232
		}
233 233
	}
234

  
235
	public boolean hasCorpus(MainCorpus mainCorpus) {
236
		if (corpora != null) {
237
			return corpora.containsKey(mainCorpus.getID());
238
		}
239
		return false;
240
	}
241
	
242
	public void add(MainCorpus mainCorpus) {
243
		if (corpora != null) {
244
			corpora.put(mainCorpus.getID(), mainCorpus);
245
		}
246
	}
234 247
}
tmp/org.txm.searchengine.cqp.core/src/org/txm/searchengine/cqp/corpus/Partition.java (revision 2243)
136 136

  
137 137
		Log.fine(NLS.bind(SearchEngineCoreMessages.info_creatingNewPartition, this.getParent(), this.userName));
138 138
		long start = System.currentTimeMillis();
139
		
140
		if (monitor != null) monitor.beginTask("Building parts...", pQueries.size());
141
		
139 142
		for (int i = 0; i < pQueries.size(); i++) {
140 143
			String queryS = pQueries.get(i);
141 144

  
......
147 150
				partName = "-"; //$NON-NLS-1$
148 151
			}
149 152
			new Part(this, partName, queryS);
153
			if (monitor != null) monitor.worked(1);
150 154
		}
151 155
		long end = System.currentTimeMillis();
152 156
		Log.fine(NLS.bind(SearchEngineCoreMessages.info_partitionCreatedInXMs, this.userName, (end - start)));
......
233 237
		for (String value : pValues) {
234 238
			String partName = value.replace("\\",""); //$NON-NLS-1$ //$NON-NLS-2$
235 239
			pPartNames.add(partName);
236
			CQLQuery query = new QueryPart(pProperty.getStructuralUnit(), pProperty, CQLQuery.addBackSlash(value));
240
			CQLQuery query = new QueryPart(pProperty.getStructuralUnit(), pProperty, CQLQuery.addBackSlash(value)); // second option is faster
241
			
237 242
			pQueries.add(query.getQueryString());
238 243
		}
239 244

  
......
246 251

  
247 252
		// Parts already created
248 253
		if (this.getParts().size() > 0) {
254
			
255
			if (monitor != null) monitor.beginTask("Building parts...", this.getParts().size());
249 256
			//FIXME: temporary fix, compute all the children parts
250 257
			List<Part> parts = (List<Part>)getChildren(Part.class);
251 258
			for (int i = 0; i < parts.size(); i++) {
252 259
				parts.get(i).compute();
260
				if (monitor != null) monitor.worked(1);
253 261
			}
254 262
		}
255 263
		else {

Formats disponibles : Unified diff