Révision 347
tmp/org.txm.para.core/src/org/txm/para/core/Activator.java (revision 347) | ||
---|---|---|
1 |
package org.txm.para.core; |
|
2 |
|
|
3 |
import org.eclipse.ui.plugin.AbstractUIPlugin; |
|
4 |
import org.osgi.framework.BundleContext; |
|
5 |
|
|
6 |
/** |
|
7 |
* The activator class controls the plug-in life cycle |
|
8 |
*/ |
|
9 |
public class Activator extends AbstractUIPlugin { |
|
10 |
|
|
11 |
// The plug-in ID |
|
12 |
public static final String PLUGIN_ID = "org.txm.para.core"; //$NON-NLS-1$ |
|
13 |
|
|
14 |
// The shared instance |
|
15 |
private static Activator plugin; |
|
16 |
|
|
17 |
/** |
|
18 |
* The constructor |
|
19 |
*/ |
|
20 |
public Activator() { |
|
21 |
} |
|
22 |
|
|
23 |
/* |
|
24 |
* (non-Javadoc) |
|
25 |
* @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) |
|
26 |
*/ |
|
27 |
public void start(BundleContext context) throws Exception { |
|
28 |
super.start(context); |
|
29 |
plugin = this; |
|
30 |
} |
|
31 |
|
|
32 |
/* |
|
33 |
* (non-Javadoc) |
|
34 |
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) |
|
35 |
*/ |
|
36 |
public void stop(BundleContext context) throws Exception { |
|
37 |
plugin = null; |
|
38 |
super.stop(context); |
|
39 |
} |
|
40 |
|
|
41 |
/** |
|
42 |
* Returns the shared instance |
|
43 |
* |
|
44 |
* @return the shared instance |
|
45 |
*/ |
|
46 |
public static Activator getDefault() { |
|
47 |
return plugin; |
|
48 |
} |
|
49 |
|
|
50 |
} |
|
0 | 51 |
tmp/org.txm.para.core/src/org/txm/para/functions/package.html (revision 347) | ||
---|---|---|
1 |
<html> |
|
2 |
<body> |
|
3 |
<p>Prototype of aligned edition browser</p> |
|
4 |
</body> |
|
5 |
</html> |
|
0 | 6 |
tmp/org.txm.para.core/src/org/txm/para/functions/ParaCell.java (revision 347) | ||
---|---|---|
1 |
package org.txm.para.functions; |
|
2 |
|
|
3 |
public class ParaCell { |
|
4 |
public String CCG, CCD, CG, keyword, CD, ref; |
|
5 |
public ParaCell(String CCG, String CG, String keyword, String CD, String CCD, String ref) |
|
6 |
{ |
|
7 |
this.CCG = CCG; |
|
8 |
this.CG = CG; |
|
9 |
this.CD = CD; |
|
10 |
this.CCD = CCD; |
|
11 |
this.keyword = keyword; |
|
12 |
this.ref = ref; |
|
13 |
} |
|
14 |
/* (non-Javadoc) |
|
15 |
* @see java.lang.Object#toString() |
|
16 |
*/ |
|
17 |
@Override |
|
18 |
public String toString() { |
|
19 |
return ref + ": " + CCG + ">" + CG + "|" + keyword + "|" + CD + "<" + CCD; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ |
|
20 |
} |
|
21 |
} |
|
0 | 22 |
tmp/org.txm.para.core/src/org/txm/para/functions/ParallelContexts.java (revision 347) | ||
---|---|---|
1 |
package org.txm.para.functions; |
|
2 |
|
|
3 |
import groovy.lang.IntRange; |
|
4 |
|
|
5 |
import java.io.IOException; |
|
6 |
import java.util.ArrayList; |
|
7 |
import java.util.Collections; |
|
8 |
import java.util.HashMap; |
|
9 |
import java.util.LinkedHashMap; |
|
10 |
import java.util.List; |
|
11 |
|
|
12 |
import org.txm.Toolbox; |
|
13 |
import org.txm.searchengine.cqp.AbstractCqiClient; |
|
14 |
import org.txm.searchengine.cqp.clientExceptions.CqiClientException; |
|
15 |
import org.txm.searchengine.cqp.corpus.Corpus; |
|
16 |
import org.txm.searchengine.cqp.corpus.CorpusManager; |
|
17 |
import org.txm.searchengine.cqp.corpus.Property; |
|
18 |
import org.txm.searchengine.cqp.corpus.QueryResult; |
|
19 |
import org.txm.searchengine.cqp.corpus.StructuralUnitProperty; |
|
20 |
import org.txm.searchengine.cqp.corpus.query.Match; |
|
21 |
import org.txm.searchengine.cqp.corpus.query.Query; |
|
22 |
import org.txm.searchengine.cqp.serverException.CqiServerError; |
|
23 |
|
|
24 |
public class ParallelContexts { |
|
25 |
|
|
26 |
ArrayList<String> queries; |
|
27 |
String struct; |
|
28 |
ArrayList<Corpus> corpora; |
|
29 |
ArrayList<String> props; |
|
30 |
ArrayList<String> refs; |
|
31 |
ArrayList<Integer> CGs; |
|
32 |
ArrayList<Integer> CDs; |
|
33 |
ArrayList<Boolean> participates; |
|
34 |
|
|
35 |
// TODO : manage |
|
36 |
HashMap<String, Match[]> keywordsStartsEnds = new HashMap<String, Match[]>(); |
|
37 |
HashMap<String, ParaCell[]> keywordsStrings = new HashMap<String, ParaCell[]>(); |
|
38 |
ArrayList<String> segKeys; |
|
39 |
private String structprop; |
|
40 |
|
|
41 |
public ParallelContexts(ArrayList<String> queries, String struct, String structprop, ArrayList<Corpus> corpora, |
|
42 |
ArrayList<String> props, ArrayList<String> refs, |
|
43 |
ArrayList<Integer> CGs, ArrayList<Integer> CDs, |
|
44 |
ArrayList<Boolean> participates) throws CqiClientException, IOException, CqiServerError |
|
45 |
{ |
|
46 |
this.queries = queries; |
|
47 |
this.corpora = corpora; |
|
48 |
this.struct = struct; |
|
49 |
this.structprop = structprop; |
|
50 |
this.props = props; |
|
51 |
this.refs = refs; |
|
52 |
this.CGs = CGs; |
|
53 |
this.CDs = CDs; |
|
54 |
this.participates = participates; |
|
55 |
|
|
56 |
for (int num = 0; num < corpora.size() ; num++) { |
|
57 |
if (!participates.get(num)) |
|
58 |
continue; |
|
59 |
Corpus corpus = corpora.get(num); |
|
60 |
//String lang = corpus.getLang(); |
|
61 |
String query = queries.get(num); |
|
62 |
System.out.println(corpus.getName()+" query: "+query); |
|
63 |
QueryResult result = corpus.query(new Query(query), "TMP", true); |
|
64 |
|
|
65 |
try { |
|
66 |
List<Match> matches = result.getMatches(); |
|
67 |
int[] positions = result.getStarts(); |
|
68 |
|
|
69 |
StructuralUnitProperty align_id = corpus.getStructuralUnit(struct).getProperty(structprop); |
|
70 |
System.out.println("struct: "+struct+" prop: "+structprop+" -> "+align_id); |
|
71 |
int[] struct_pos = Toolbox.getCqiClient().cpos2Struc(align_id.getQualifiedName(), positions); |
|
72 |
String[] struct_ids = Toolbox.getCqiClient().struc2Str(align_id.getQualifiedName(), struct_pos); |
|
73 |
|
|
74 |
// fill allsegments |
|
75 |
for (int i = 0 ; i < struct_ids.length ; i++) { |
|
76 |
String id = struct_ids[i]; |
|
77 |
if (!keywordsStartsEnds.containsKey(id)) { |
|
78 |
keywordsStartsEnds.put(id, new Match[corpora.size()]); |
|
79 |
keywordsStrings.put(id, new ParaCell[corpora.size()]); |
|
80 |
} |
|
81 |
keywordsStartsEnds.get(id)[num] = matches.get(i); // take the first one |
|
82 |
} |
|
83 |
} catch(Exception e) { |
|
84 |
System.out.println("Result is NULL ! "+e.toString()); |
|
85 |
org.txm.utils.logger.Log.printStackTrace(e); |
|
86 |
} |
|
87 |
} |
|
88 |
|
|
89 |
//sort allsegments |
|
90 |
segKeys = new ArrayList<String>(keywordsStartsEnds.keySet()); |
|
91 |
Collections.sort(segKeys); |
|
92 |
System.out.println("segKeys : "+segKeys.size()); |
|
93 |
} |
|
94 |
|
|
95 |
/** |
|
96 |
* @return the keywordsStartsEnds |
|
97 |
*/ |
|
98 |
public HashMap<String, Match[]> getKeywordsStartsEnds() { |
|
99 |
return keywordsStartsEnds; |
|
100 |
} |
|
101 |
|
|
102 |
/** |
|
103 |
* @return the keywordsStrings |
|
104 |
* @throws CqiServerError |
|
105 |
* @throws IOException |
|
106 |
* @throws CqiClientException |
|
107 |
*/ |
|
108 |
public HashMap<String, ParaCell[]> getKeywordsStrings() throws CqiClientException, IOException, CqiServerError { |
|
109 |
return getKeywordsStrings(0, segKeys.size()); |
|
110 |
} |
|
111 |
|
|
112 |
/** |
|
113 |
* @return the keywordsStrings |
|
114 |
* @throws CqiClientException |
|
115 |
* @throws CqiServerError |
|
116 |
* @throws IOException |
|
117 |
*/ |
|
118 |
public LinkedHashMap<String, ParaCell[]> getKeywordsStrings(int from, int to) throws CqiClientException, IOException, CqiServerError { |
|
119 |
if (from < 0 ) from = 0; |
|
120 |
if (to > segKeys.size()) to = segKeys.size(); |
|
121 |
|
|
122 |
LinkedHashMap<String, ParaCell[]> rez = new LinkedHashMap<String, ParaCell[]>(); |
|
123 |
getMissingValues(from, to); |
|
124 |
if (segKeys.size()>0) { |
|
125 |
for (int i = from ; i < to ; i++) |
|
126 |
rez.put(segKeys.get(i), keywordsStrings.get(segKeys.get(i))); |
|
127 |
//System.out.println("getKeywordsStrings [REZ="+rez+"]"); |
|
128 |
} else { |
|
129 |
System.out.println("getKeywordsStrings - NO SEG KEYS !!"); |
|
130 |
} |
|
131 |
|
|
132 |
return rez; |
|
133 |
} |
|
134 |
|
|
135 |
private void getMissingValues(int from , int to) throws CqiClientException, IOException, CqiServerError |
|
136 |
{ |
|
137 |
AbstractCqiClient cqiClient = CorpusManager.getCorpusManager().getCqiClient(); |
|
138 |
if (segKeys.size()>0){ |
|
139 |
String segquery = "<"+struct+"_"+structprop+"=\""; //\"]"; |
|
140 |
for (int i = from ; i < to ; i++) { |
|
141 |
segquery += segKeys.get(i)+"|"; |
|
142 |
} |
|
143 |
segquery = segquery.substring(0, segquery.length() -1 ); |
|
144 |
segquery += "\">[]"; |
|
145 |
System.out.println("align_seg_query : "+segquery); |
|
146 |
|
|
147 |
// loop over corpus to minimize the number of queries |
|
148 |
for (int nocorpus = 0; nocorpus < corpora.size() ; nocorpus++) { |
|
149 |
Corpus corpus = corpora.get(nocorpus); |
|
150 |
int MAXPOSITION = corpus.getSize(); |
|
151 |
StructuralUnitProperty align_id = corpus.getStructuralUnit(struct).getProperty(structprop); |
|
152 |
Property prop = corpus.getProperty(props.get(nocorpus)); |
|
153 |
//PropertyHashMap<CqpDataProxy> proxies = CorpusManager.getCorpusManager().getCorpusProxies(corpus); |
|
154 |
int iCG = CGs.get(nocorpus); |
|
155 |
int iCD = CDs.get(nocorpus); |
|
156 |
//System.out.println("iCG "+iCG+" iCD "+iCD); |
|
157 |
//CqpDataProxy wordp = cqiClient.get(prop); |
|
158 |
String[] split = refs.get(nocorpus).split("_", 2); |
|
159 |
//System.out.println("refs : "+refs); |
|
160 |
StructuralUnitProperty ref = null; |
|
161 |
if (split.length == 2) |
|
162 |
ref = corpus.getStructuralUnit(split[0]).getProperty(split[1]); |
|
163 |
|
|
164 |
// get the seg that actually are in the corpus |
|
165 |
QueryResult resul2t = corpus.query(new Query(segquery), "TMP", true); |
|
166 |
int[] struct_starts = resul2t.getStarts(); |
|
167 |
int[] struct_pos = Toolbox.getCqiClient().cpos2Struc(align_id.getQualifiedName(), struct_starts); |
|
168 |
String[] struct_ids = Toolbox.getCqiClient().struc2Str(align_id.getQualifiedName(), struct_pos); |
|
169 |
|
|
170 |
//System.out.println("segs: "+Arrays.toString(struct_ids)); |
|
171 |
|
|
172 |
// get ref if asked |
|
173 |
String[] ref_values = null; |
|
174 |
if (ref != null) { |
|
175 |
int[] struct_pos2 = Toolbox.getCqiClient().cpos2Struc(ref.getQualifiedName(), struct_starts); |
|
176 |
ref_values = Toolbox.getCqiClient().struc2Str(ref.getQualifiedName(), struct_pos2); |
|
177 |
} |
|
178 |
//System.out.println("ref values: "+Arrays.toString(ref_values)); |
|
179 |
|
|
180 |
// get the words values of segs |
|
181 |
QueryResult result = corpus.query(new Query(segquery+"+</"+struct+">"), "TMP", false); |
|
182 |
List<Match> matches = result.getMatches(); |
|
183 |
//System.out.println("seg matches: "+matches); |
|
184 |
ArrayList<Integer> positions = new ArrayList<Integer>(); |
|
185 |
for (Match m : matches) { |
|
186 |
groovy.lang.IntRange range = (IntRange) m.getRange(); |
|
187 |
|
|
188 |
int minpos = range.get(0); |
|
189 |
int maxpos = range.get(range.size()-1); |
|
190 |
//System.out.println("range size "+range.size()+" minpos "+minpos+" maxpos "+maxpos); |
|
191 |
//int n = 0; |
|
192 |
for (int i = iCG ; i > 0 ; i--) { |
|
193 |
if (minpos - i >= 0) { |
|
194 |
positions.add(minpos - i); |
|
195 |
//System.out.println("CG add "+(minpos-i)); |
|
196 |
} |
|
197 |
} |
|
198 |
positions.addAll(range); |
|
199 |
//System.out.println("add "+range); |
|
200 |
for (int i = 1 ; i <= iCD ; i++) { |
|
201 |
if (maxpos+i < MAXPOSITION) { |
|
202 |
positions.add(maxpos + i); |
|
203 |
//System.out.println("CD add "+(maxpos+i)); |
|
204 |
} |
|
205 |
} |
|
206 |
} |
|
207 |
|
|
208 |
int[] cpos = new int[positions.size()]; |
|
209 |
for (int i = 0 ; i < positions.size() ; i++) |
|
210 |
cpos[i] = positions.get(i); |
|
211 |
|
|
212 |
List<String> words = cqiClient.getSingleData(prop, cpos); |
|
213 |
//System.out.println("words: "+(words)); |
|
214 |
|
|
215 |
int wordIterator = 0; |
|
216 |
//System.out.println("loop"); |
|
217 |
for (int i = 0 ; i < struct_ids.length ; i++) // for each seg actually in the corpus |
|
218 |
{ |
|
219 |
if (keywordsStrings.get(struct_ids[i])[nocorpus] != null) |
|
220 |
continue; // this cell has already been computed |
|
221 |
if (wordIterator >= words.size()) |
|
222 |
break; // no more words to process |
|
223 |
Match m = matches.get(i); |
|
224 |
|
|
225 |
Match keyWordMatch = keywordsStartsEnds.get(struct_ids[i])[nocorpus]; |
|
226 |
//System.out.println("wordIterator "+wordIterator+" str "+words.get(wordIterator)+ " str2 "+words.get(wordIterator+1)+" pos "+cpos[wordIterator]+" seg no "+i+" match "+m+" keyword "+keyWordMatch); |
|
227 |
//if ((m.getStart() - cpos[wordIterator]) < iCG) System.out.println("WARNING CG"); |
|
228 |
String CCG="", CG ="", keyword="", CD="", CCD="", refValue = ""; |
|
229 |
int state = 1; // 0 CCG, 1 CG 2 keyword 3 CD 4 CCD |
|
230 |
int previouspos = -1; |
|
231 |
while (wordIterator < cpos.length |
|
232 |
&& cpos[wordIterator] <= m.getEnd() + iCD |
|
233 |
&& previouspos <= cpos[wordIterator]) |
|
234 |
{ // concat word value |
|
235 |
int pos = cpos[wordIterator]; |
|
236 |
previouspos = pos ; |
|
237 |
//if (keyWordMatch != null) { |
|
238 |
if (pos < m.getStart()) |
|
239 |
state = 0; |
|
240 |
else if (keyWordMatch != null && pos < keyWordMatch.getStart()) |
|
241 |
state = 1; |
|
242 |
else if (keyWordMatch != null && pos <= keyWordMatch.getEnd()) |
|
243 |
state = 2; |
|
244 |
else if (pos <= m.getEnd()) |
|
245 |
state = 3; |
|
246 |
else |
|
247 |
state = 4; |
|
248 |
//} |
|
249 |
switch (state) { |
|
250 |
case 0: |
|
251 |
CCG += words.get(wordIterator)+" "; break; |
|
252 |
case 1: |
|
253 |
CG += words.get(wordIterator)+" "; break; |
|
254 |
case 2: |
|
255 |
keyword += words.get(wordIterator)+" "; break; |
|
256 |
case 3: |
|
257 |
CD += words.get(wordIterator)+" "; break; |
|
258 |
case 4: |
|
259 |
CCD += words.get(wordIterator)+" "; break; |
|
260 |
} |
|
261 |
wordIterator++; |
|
262 |
} |
|
263 |
|
|
264 |
if (ref_values != null) { |
|
265 |
refValue = ref_values[i]; |
|
266 |
//System.out.println("ref: "+refValue); |
|
267 |
} |
|
268 |
|
|
269 |
// set ParaCell |
|
270 |
ParaCell cell = new ParaCell(CCG, CG, keyword, CD, CCD, refValue); |
|
271 |
keywordsStrings.get(struct_ids[i])[nocorpus] = cell; |
|
272 |
} |
|
273 |
} |
|
274 |
} |
|
275 |
} |
|
276 |
|
|
277 |
/** |
|
278 |
* @return the segKeys |
|
279 |
*/ |
|
280 |
public ArrayList<String> getSegKeys() { |
|
281 |
return segKeys; |
|
282 |
} |
|
283 |
|
|
284 |
/** |
|
285 |
* @return the queries |
|
286 |
*/ |
|
287 |
public ArrayList<String> getQueries() { |
|
288 |
return queries; |
|
289 |
} |
|
290 |
|
|
291 |
/** |
|
292 |
* @return the struct |
|
293 |
*/ |
|
294 |
public String getStruct() { |
|
295 |
return struct; |
|
296 |
} |
|
297 |
|
|
298 |
/** |
|
299 |
* @return the corpora |
|
300 |
*/ |
|
301 |
public ArrayList<Corpus> getCorpora() { |
|
302 |
return corpora; |
|
303 |
} |
|
304 |
|
|
305 |
/** |
|
306 |
* @return the props |
|
307 |
*/ |
|
308 |
public ArrayList<String> getProps() { |
|
309 |
return props; |
|
310 |
} |
|
311 |
|
|
312 |
/** |
|
313 |
* @return the refs |
|
314 |
*/ |
|
315 |
public ArrayList<String> getRefs() { |
|
316 |
return refs; |
|
317 |
} |
|
318 |
|
|
319 |
/** |
|
320 |
* @return the cGs |
|
321 |
*/ |
|
322 |
public ArrayList<Integer> getCGs() { |
|
323 |
return CGs; |
|
324 |
} |
|
325 |
|
|
326 |
/** |
|
327 |
* @return the cDs |
|
328 |
*/ |
|
329 |
public ArrayList<Integer> getCDs() { |
|
330 |
return CDs; |
|
331 |
} |
|
332 |
|
|
333 |
/** |
|
334 |
* @return the participates |
|
335 |
*/ |
|
336 |
public ArrayList<Boolean> getParticipates() { |
|
337 |
return participates; |
|
338 |
} |
|
339 |
|
|
340 |
/* (non-Javadoc) |
|
341 |
* @see java.lang.Object#hashCode() |
|
342 |
*/ |
|
343 |
@Override |
|
344 |
public int hashCode() { |
|
345 |
final int prime = 31; |
|
346 |
int result = 1; |
|
347 |
result = prime * result + ((CDs == null) ? 0 : CDs.hashCode()); |
|
348 |
result = prime * result + ((CGs == null) ? 0 : CGs.hashCode()); |
|
349 |
result = prime * result + ((corpora == null) ? 0 : corpora.hashCode()); |
|
350 |
result = prime * result |
|
351 |
+ ((participates == null) ? 0 : participates.hashCode()); |
|
352 |
result = prime * result + ((props == null) ? 0 : props.hashCode()); |
|
353 |
result = prime * result + ((queries == null) ? 0 : queries.hashCode()); |
|
354 |
result = prime * result + ((refs == null) ? 0 : refs.hashCode()); |
|
355 |
result = prime * result + ((struct == null) ? 0 : struct.hashCode()); |
|
356 |
return result; |
|
357 |
} |
|
358 |
|
|
359 |
/* (non-Javadoc) |
|
360 |
* @see java.lang.Object#equals(java.lang.Object) |
|
361 |
*/ |
|
362 |
@Override |
|
363 |
public boolean equals(Object obj) { |
|
364 |
if (this == obj) |
|
365 |
return true; |
|
366 |
if (obj == null) |
|
367 |
return false; |
|
368 |
if (getClass() != obj.getClass()) |
|
369 |
return false; |
|
370 |
ParallelContexts other = (ParallelContexts) obj; |
|
371 |
if (CDs == null) { |
|
372 |
if (other.CDs != null) |
|
373 |
return false; |
|
374 |
} else if (!CDs.equals(other.CDs)) |
|
375 |
return false; |
|
376 |
if (CGs == null) { |
|
377 |
if (other.CGs != null) |
|
378 |
return false; |
|
379 |
} else if (!CGs.equals(other.CGs)) |
|
380 |
return false; |
|
381 |
if (corpora == null) { |
|
382 |
if (other.corpora != null) |
|
383 |
return false; |
|
384 |
} else if (!corpora.equals(other.corpora)) |
|
385 |
return false; |
|
386 |
if (participates == null) { |
|
387 |
if (other.participates != null) |
|
388 |
return false; |
|
389 |
} else if (!participates.equals(other.participates)) |
|
390 |
return false; |
|
391 |
if (props == null) { |
|
392 |
if (other.props != null) |
|
393 |
return false; |
|
394 |
} else if (!props.equals(other.props)) |
|
395 |
return false; |
|
396 |
if (queries == null) { |
|
397 |
if (other.queries != null) |
|
398 |
return false; |
|
399 |
} else if (!queries.equals(other.queries)) |
|
400 |
return false; |
|
401 |
if (refs == null) { |
|
402 |
if (other.refs != null) |
|
403 |
return false; |
|
404 |
} else if (!refs.equals(other.refs)) |
|
405 |
return false; |
|
406 |
if (struct == null) { |
|
407 |
if (other.struct != null) |
|
408 |
return false; |
|
409 |
} else if (!struct.equals(other.struct)) |
|
410 |
return false; |
|
411 |
return true; |
|
412 |
} |
|
413 |
|
|
414 |
/* (non-Javadoc) |
|
415 |
* @see java.lang.Object#toString() |
|
416 |
*/ |
|
417 |
@Override |
|
418 |
public String toString() { |
|
419 |
return "ParallelContexts [queries=" + queries + ", struct=" + struct |
|
420 |
+ ", corpora=" + corpora + ", props=" + props + ", refs=" |
|
421 |
+ refs + ", CGs=" + CGs + ", CDs=" + CDs + ", participates=" |
|
422 |
+ participates + "]"; |
|
423 |
} |
|
424 |
} |
|
0 | 425 |
tmp/org.txm.para.core/src/org/txm/para/functions/ParaBrowser.java (revision 347) | ||
---|---|---|
1 |
package org.txm.para.functions; |
|
2 |
|
|
3 |
import java.util.ArrayList; |
|
4 |
import java.util.HashMap; |
|
5 |
import java.util.LinkedHashMap; |
|
6 |
import java.util.List; |
|
7 |
import java.util.Map; |
|
8 |
|
|
9 |
import org.txm.core.results.TXMResult; |
|
10 |
import org.txm.functions.ReferencePattern; |
|
11 |
import org.txm.searchengine.cqp.CqpDataProxy; |
|
12 |
import org.txm.searchengine.cqp.clientExceptions.CqiClientException; |
|
13 |
import org.txm.searchengine.cqp.corpus.MainCorpus; |
|
14 |
import org.txm.searchengine.cqp.corpus.Property; |
|
15 |
import org.txm.searchengine.cqp.corpus.QueryResult; |
|
16 |
import org.txm.searchengine.cqp.corpus.StructuralUnit; |
|
17 |
import org.txm.searchengine.cqp.corpus.StructuralUnitProperty; |
|
18 |
import org.txm.searchengine.cqp.corpus.query.Match; |
|
19 |
import org.txm.searchengine.cqp.corpus.query.Query; |
|
20 |
import org.txm.searchengine.cqp.corpus.query.QueryPart; |
|
21 |
import org.txm.utils.Pair; |
|
22 |
import org.txm.utils.i18n.LangFormater; |
|
23 |
|
|
24 |
public class ParaBrowser extends TXMResult { |
|
25 |
|
|
26 |
/** |
|
27 |
* Gets the nextor previous. |
|
28 |
* |
|
29 |
* @param unit the unit |
|
30 |
* @param property the property |
|
31 |
* @param value the value |
|
32 |
* @param isNext the is next |
|
33 |
* @return the nextor previous |
|
34 |
*/ |
|
35 |
public String getNextOrPrevious(MainCorpus corpus, StructuralUnit unit, |
|
36 |
StructuralUnitProperty property, String value, boolean isNext) { |
|
37 |
String next = ""; |
|
38 |
Query query = null; |
|
39 |
System.out.println("GET NEXT or PREVIOUS : " + value + " unit " + unit |
|
40 |
+ " property " + property + " next? " + isNext); |
|
41 |
if (isNext) { |
|
42 |
query = new Query("<" + unit.getName() + "_id=\"" + value |
|
43 |
+ "\">[]+</" + unit.getName() + ">[]"); |
|
44 |
} else { |
|
45 |
query = new Query("<" + unit.getName() + ">[]+" + "</" |
|
46 |
+ unit.getName() + "><" + unit.getName() + "_id=\"" + value |
|
47 |
+ "\">[]+"); |
|
48 |
} |
|
49 |
Property text_id = unit.getProperty("id"); //$NON-NLS-1$ |
|
50 |
// System.out.println("text_id = unit "+unit+" get props de id"); |
|
51 |
// System.out.println("Query : "+query); |
|
52 |
if (property != null) { |
|
53 |
// List<Line> lines; |
|
54 |
int nLines; |
|
55 |
|
|
56 |
ReferencePattern referencePattern = new ReferencePattern(); |
|
57 |
referencePattern.addProperty(text_id); |
|
58 |
|
|
59 |
QueryResult queryResult; |
|
60 |
try { |
|
61 |
Map<Property, List<List<String>>> wordPropValues = new HashMap<Property, List<List<String>>>(); |
|
62 |
|
|
63 |
queryResult = corpus.query(query, query.getQueryString().replace( |
|
64 |
" ", "_") |
|
65 |
+ "_parallel", false); |
|
66 |
nLines = queryResult.getNMatch(); // get number of tokens |
|
67 |
// System.out.println("nLines : "+nLines); |
|
68 |
// lines = new ArrayList<Line>(); |
|
69 |
|
|
70 |
List<Match> matches = null; |
|
71 |
if (nLines > 0) |
|
72 |
matches = queryResult.getMatches(0, nLines - 1); // get the |
|
73 |
// indexes |
|
74 |
// sequences |
|
75 |
// of |
|
76 |
// result's |
|
77 |
// tokens |
|
78 |
else |
|
79 |
matches = new ArrayList<Match>(); |
|
80 |
|
|
81 |
List<Integer> beginingOfKeywordsPositions = new ArrayList<Integer>(); |
|
82 |
List<Integer> lengthOfKeywords = new ArrayList<Integer>(); |
|
83 |
// keywordsViewPropValues = new HashMap<Property, |
|
84 |
// List<List<String>>>(); |
|
85 |
int nb = 0; |
|
86 |
for (int j = 0; j < nLines; j++) { |
|
87 |
Match match = matches.get(j); |
|
88 |
beginingOfKeywordsPositions.add(match.getStart()); // get |
|
89 |
// the first |
|
90 |
// index |
|
91 |
lengthOfKeywords.add(match.getEnd() - match.getStart() + 1);// get |
|
92 |
// the last index |
|
93 |
nb = match.getEnd() - match.getStart() + 1; |
|
94 |
} |
|
95 |
|
|
96 |
if (!isNext) { |
|
97 |
nb = 1; |
|
98 |
} |
|
99 |
|
|
100 |
// get all reference values of all lines |
|
101 |
for (Property prop : referencePattern) { |
|
102 |
// List<List<String>> propVals = cache.get(prop).getData( |
|
103 |
// beginingOfKeywordsPositions, |
|
104 |
// Collections.nCopies(beginingOfKeywordsPositions |
|
105 |
// .size(), nb)); |
|
106 |
// // for the first word = 1 |
|
107 |
// // for the last word = nb |
|
108 |
// |
|
109 |
// for (List<String> propVal : propVals) { |
|
110 |
// for (String str : propVal) { |
|
111 |
// // System.out.println("Next = "+str); |
|
112 |
// next = str; |
|
113 |
// } |
|
114 |
// } |
|
115 |
} |
|
116 |
|
|
117 |
} catch (CqiClientException e1) { |
|
118 |
org.txm.utils.logger.Log.printStackTrace(e1); |
|
119 |
} |
|
120 |
} |
|
121 |
return next; |
|
122 |
} |
|
123 |
|
|
124 |
|
|
125 |
/** |
|
126 |
* Gets the text region. |
|
127 |
* |
|
128 |
* @param unit the unit |
|
129 |
* @param property the property |
|
130 |
* @param value the value |
|
131 |
* @return the text region |
|
132 |
*/ |
|
133 |
public Pair<String, QueryResult> getTextRegion(MainCorpus corpus, StructuralUnit unit, |
|
134 |
StructuralUnitProperty property, String value) { |
|
135 |
Query query = new QueryPart(unit, property, value); |
|
136 |
System.out.println("GET REGION : " + value); |
|
137 |
|
|
138 |
String text = ""; |
|
139 |
|
|
140 |
if (property != null) { |
|
141 |
LinkedHashMap<String, Integer> counts; |
|
142 |
// List<Line> lines; |
|
143 |
int nLines; |
|
144 |
|
|
145 |
CqpDataProxy cache; |
|
146 |
try { |
|
147 |
cache = new CqpDataProxy(null, corpus.getProperty("word")); // TODO: not null |
|
148 |
} catch (CqiClientException e1) { |
|
149 |
org.txm.utils.logger.Log.printStackTrace(e1); |
|
150 |
return new Pair<String, QueryResult>( |
|
151 |
"error can't get word property", null); |
|
152 |
} |
|
153 |
|
|
154 |
// get the cqp result of the query |
|
155 |
QueryResult result; |
|
156 |
try { |
|
157 |
result = corpus.query(query, query.getQueryString().replace(" ", |
|
158 |
"_") |
|
159 |
+ "_parallel", false); |
|
160 |
nLines = result.getNMatch(); // get number of tokens |
|
161 |
System.out.println("nMatchs : " + nLines); |
|
162 |
// lines = new ArrayList<Line>(); |
|
163 |
|
|
164 |
List<Match> matches = null; |
|
165 |
if (nLines > 0) |
|
166 |
matches = result.getMatches(0, nLines - 1); // get the |
|
167 |
// indexes |
|
168 |
// sequences of |
|
169 |
// result's |
|
170 |
// tokens |
|
171 |
else |
|
172 |
matches = new ArrayList<Match>(); |
|
173 |
|
|
174 |
List<Integer> beginingOfKeywordsPositions = new ArrayList<Integer>(); |
|
175 |
List<Integer> lengthOfKeywords = new ArrayList<Integer>(); |
|
176 |
// keywordsViewPropValues = new HashMap<Property, |
|
177 |
// List<List<String>>>(); |
|
178 |
|
|
179 |
for (int j = 0; j < nLines; j++) { |
|
180 |
Match match = matches.get(j); |
|
181 |
beginingOfKeywordsPositions.add(match.getStart()); // get |
|
182 |
// the |
|
183 |
// first |
|
184 |
// index |
|
185 |
lengthOfKeywords.add(match.getEnd() - match.getStart() + 1);// get |
|
186 |
// the |
|
187 |
// last |
|
188 |
// index |
|
189 |
} |
|
190 |
|
|
191 |
List<List<String>> propVals = cache.getData( |
|
192 |
beginingOfKeywordsPositions, lengthOfKeywords); |
|
193 |
for (List<String> prop : propVals) { |
|
194 |
text += "\n\n"; |
|
195 |
for (String str : prop) { |
|
196 |
text += str + " "; |
|
197 |
// System.out.println("Region word = "+str); |
|
198 |
} |
|
199 |
} |
|
200 |
} catch (CqiClientException e) { |
|
201 |
org.txm.utils.logger.Log.printStackTrace(e); |
|
202 |
return new Pair<String, QueryResult>("error", null); |
|
203 |
} |
|
204 |
return new Pair<String, QueryResult>(LangFormater.format(text, corpus |
|
205 |
.getAttribute("lang")), result); |
|
206 |
} |
|
207 |
// return keywordsViewPropValues; |
|
208 |
return new Pair<String, QueryResult>("error no property", null); |
|
209 |
} |
|
210 |
|
|
211 |
|
|
212 |
@Override |
|
213 |
public String getName() { |
|
214 |
// TODO Auto-generated method stub |
|
215 |
return null; |
|
216 |
} |
|
217 |
|
|
218 |
|
|
219 |
@Override |
|
220 |
public String getSimpleName() { |
|
221 |
// TODO Auto-generated method stub |
|
222 |
return null; |
|
223 |
} |
|
224 |
|
|
225 |
|
|
226 |
@Override |
|
227 |
public String getDetails() { |
|
228 |
// TODO Auto-generated method stub |
|
229 |
return null; |
|
230 |
} |
|
231 |
|
|
232 |
|
|
233 |
@Override |
|
234 |
public void clean() { |
|
235 |
// TODO Auto-generated method stub |
|
236 |
|
|
237 |
} |
|
238 |
} |
|
0 | 239 |
tmp/org.txm.para.core/build.properties (revision 347) | ||
---|---|---|
1 |
source.. = src/ |
|
2 |
output.. = bin/ |
|
3 |
bin.includes = META-INF/,\ |
|
4 |
. |
|
0 | 5 |
tmp/org.txm.para.core/.settings/org.eclipse.jdt.core.prefs (revision 347) | ||
---|---|---|
1 |
eclipse.preferences.version=1 |
|
2 |
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled |
|
3 |
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 |
|
4 |
org.eclipse.jdt.core.compiler.compliance=1.6 |
|
5 |
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error |
|
6 |
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error |
|
7 |
org.eclipse.jdt.core.compiler.source=1.6 |
|
0 | 8 |
tmp/org.txm.para.core/.classpath (revision 347) | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<classpath> |
|
3 |
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/> |
|
4 |
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> |
|
5 |
<classpathentry kind="src" path="src"/> |
|
6 |
<classpathentry kind="output" path="bin"/> |
|
7 |
</classpath> |
|
0 | 8 |
tmp/org.txm.para.core/META-INF/MANIFEST.MF (revision 347) | ||
---|---|---|
1 |
Manifest-Version: 1.0 |
|
2 |
Bundle-ManifestVersion: 2 |
|
3 |
Bundle-Name: Core |
|
4 |
Bundle-SymbolicName: org.txm.para.core |
|
5 |
Bundle-Version: 1.0.0.qualifier |
|
6 |
Bundle-Activator: org.txm.para.core.Activator |
|
7 |
Require-Bundle: org.txm.core;bundle-version="0.7.0", |
|
8 |
org.eclipse.ui, |
|
9 |
org.eclipse.core.runtime |
|
10 |
Bundle-RequiredExecutionEnvironment: JavaSE-1.6 |
|
11 |
Bundle-ActivationPolicy: lazy |
|
12 |
Export-Package: org.txm.para.functions |
|
0 | 13 |
tmp/org.txm.para.core/.project (revision 347) | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<projectDescription> |
|
3 |
<name>org.txm.para.core</name> |
|
4 |
<comment></comment> |
|
5 |
<projects> |
|
6 |
</projects> |
|
7 |
<buildSpec> |
|
8 |
<buildCommand> |
|
9 |
<name>org.eclipse.jdt.core.javabuilder</name> |
|
10 |
<arguments> |
|
11 |
</arguments> |
|
12 |
</buildCommand> |
|
13 |
<buildCommand> |
|
14 |
<name>org.eclipse.pde.ManifestBuilder</name> |
|
15 |
<arguments> |
|
16 |
</arguments> |
|
17 |
</buildCommand> |
|
18 |
<buildCommand> |
|
19 |
<name>org.eclipse.pde.SchemaBuilder</name> |
|
20 |
<arguments> |
|
21 |
</arguments> |
|
22 |
</buildCommand> |
|
23 |
</buildSpec> |
|
24 |
<natures> |
|
25 |
<nature>org.eclipse.pde.PluginNature</nature> |
|
26 |
<nature>org.eclipse.jdt.core.javanature</nature> |
|
27 |
</natures> |
|
28 |
</projectDescription> |
|
0 | 29 |
Formats disponibles : Unified diff