Revision 345

tmp/org.txm.groovy.core/.settings/org.eclipse.ltk.core.refactoring.prefs (revision 345)
1
eclipse.preferences.version=1
2
org.eclipse.ltk.core.refactoring.enable.project.refactoring.history=false
0 3

  
tmp/org.txm.groovy.core/.settings/org.eclipse.jdt.groovy.core.prefs (revision 345)
1
eclipse.preferences.version=1
2
groovy.compiler.level=23
0 3

  
tmp/org.txm.groovy.core/.classpath (revision 345)
4 4
	<classpathentry kind="src" path="src/groovy"/>
5 5
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
6 6
	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
7
	<classpathentry exported="true" kind="con" path="GROOVY_SUPPORT"/>
8
	<classpathentry exported="true" kind="con" path="GROOVY_DSL_SUPPORT"/>
7
	<classpathentry kind="con" path="GROOVY_DSL_SUPPORT"/>
9 8
	<classpathentry kind="output" path="bin"/>
10 9
</classpath>
tmp/org.txm.groovy.core/src/groovy/org/txm/test/Concordances.groovy (revision 345)
37 37
import org.txm.Toolbox
38 38
import org.txm.searchengine.cqp.corpus.*
39 39
import org.txm.searchengine.cqp.corpus.query.*
40
import org.txm.functions.concordances.*
41
import org.txm.functions.concordances.comparators.*
40
import org.txm.concordances.functions.*
41
import org.txm.concordances.functions.comparators.*
42 42
import org.txm.functions.ReferencePattern
43 43

  
44 44
	// get the DISCOURS corpus
tmp/org.txm.groovy.core/src/groovy/org/txm/test/ReleaseFunctionsValidation.groovy (revision 345)
3 3
//import org.txm.functions.*
4 4
//import org.txm.functions.ca.*
5 5
//import org.txm.functions.classification.*
6
//import org.txm.functions.concordances.*
7
//import org.txm.functions.concordances.comparators.*
6
//import org.txm.concordances.functions.*
7
//import org.txm.concordances.functions.comparators.*
8 8
//import org.txm.functions.cooccurrences.Cooccurrence
9 9
//import org.txm.functions.diagnostic.*
10 10
//import org.txm.functions.index.*
tmp/org.txm.groovy.core/src/groovy/org/txm/test/CQPBenchmark.groovy (revision 345)
4 4
//import org.txm.functions.*
5 5
////import org.txm.functions.ca.*
6 6
////import org.txm.functions.classification.CAH
7
//import org.txm.functions.concordances.*
8
//import org.txm.functions.concordances.comparators.*
7
//import org.txm.concordances.functions.*
8
//import org.txm.concordances.functions.comparators.*
9 9
//import org.txm.functions.cooccurrences.*
10 10
//import org.txm.functions.diagnostic.*
11 11
//import org.txm.functions.index.*
tmp/org.txm.groovy.core/src/groovy/org/txm/export/ParaConc.groovy (revision 345)
30 30
import org.txm.Toolbox
31 31
import org.txm.searchengine.cqp.corpus.*
32 32
import org.txm.searchengine.cqp.corpus.query.*
33
import org.txm.functions.concordances.*
34
import org.txm.functions.concordances.comparators.*
33
import org.txm.concordances.functions.*
34
import org.txm.concordances.functions.comparators.*
35 35
import org.txm.functions.ReferencePattern
36 36

  
37 37
////// PARAMETERS //////
tmp/org.txm.groovy.core/src/groovy/org/txm/export/MultipleConcordances.groovy (revision 345)
53 53
import org.txm.Toolbox
54 54
import org.txm.searchengine.cqp.corpus.*
55 55
import org.txm.searchengine.cqp.corpus.query.*
56
import org.txm.functions.concordances.*
57
import org.txm.functions.concordances.comparators.*
56
import org.txm.concordances.functions.*
57
import org.txm.concordances.functions.comparators.*
58 58
import org.txm.functions.ReferencePattern
59 59

  
60 60
//PARAMETRES
tmp/org.txm.groovy.core/src/groovy/org/txm/export/ConcordancesExport_discours.groovy (revision 345)
43 43
import org.txm.Toolbox
44 44
import org.txm.searchengine.cqp.corpus.*
45 45
import org.txm.searchengine.cqp.corpus.query.*
46
import org.txm.functions.concordances.*
47
import org.txm.functions.concordances.comparators.*
46
import org.txm.concordances.functions.*
47
import org.txm.concordances.functions.comparators.*
48 48
import org.txm.functions.ReferencePattern
49 49

  
50 50
// TODO: Auto-generated Javadoc
tmp/org.txm.groovy.core/src/groovy/org/txm/export/ConcordancesExport.groovy (revision 345)
36 36
import org.txm.Toolbox
37 37
import org.txm.searchengine.cqp.corpus.*
38 38
import org.txm.searchengine.cqp.corpus.query.*
39
import org.txm.functions.concordances.*
40
import org.txm.functions.concordances.comparators.*
39
import org.txm.concordances.functions.*
40
import org.txm.concordances.functions.comparators.*
41 41
import org.txm.functions.ReferencePattern
42 42

  
43 43
// TODO: Auto-generated Javadoc
tmp/org.txm.groovy.core/src/groovy/org/txm/importer/hyperprince/AnalyzeAlignement.groovy (revision 345)
48 48
import java.util.ArrayList;
49 49
import javax.xml.stream.*;
50 50

  
51
import org.txm.functions.concordances.comparators.NullComparator;
51
import org.txm.concordances.functions.comparators.NullComparator;
52 52

  
53 53

  
54 54
// TODO: Auto-generated Javadoc
tmp/org.txm.groovy.core/src/groovy/org/txm/macro/annotation/BuildWordPropTableMacro.groovy (revision 345)
29 29
import org.txm.Toolbox
30 30
import org.txm.searchengine.cqp.corpus.*
31 31
import org.txm.searchengine.cqp.corpus.query.*
32
import org.txm.functions.concordances.*
33
import org.txm.functions.concordances.comparators.*
32
import org.txm.concordances.functions.*
33
import org.txm.concordances.functions.comparators.*
34 34
import org.txm.functions.ReferencePattern
35 35
import org.kohsuke.args4j.*
36 36
import groovy.transform.Field
tmp/org.txm.groovy.core/src/groovy/org/txm/scripts/i18n/GetStringsFromPropertiesFile.groovy (revision 345)
1
package org.txm.scripts.i18n;
2

  
3
import java.io.BufferedReader;
4
import java.io.File;
5
import java.io.FileInputStream;
6
import java.io.InputStreamReader;
7
import java.util.LinkedList;
8

  
9
import org.txm.utils.io.IOUtils;
10

  
11
File newProjectMessagesPackage= new File(System.getProperty("user.home"), "workspace079/org.txm.concordance.core/src/org/txm/concordances/messages");
12
File oldProjectMessagesPackage= new File(System.getProperty("user.home"), "workspace079/org.txm.core/src/java/org/txm/core/messages")
13
File newNLSClassFile = new File(newProjectMessagesPackage, "ConcordanceMessages.java");
14
File oldNLSClassFile = new File(oldProjectMessagesPackage, "TBXMessages.java");
15
def langs = ["_fr", "", "_ru"]
16
for (def lang : langs) {
17
	println "LANG=$lang"
18
	Properties oldProperties = new Properties();
19
	File oldMessageFile = new File(oldProjectMessagesPackage, "messages${lang}.properties")
20
	oldProperties.load(IOUtils.getReader(oldMessageFile, "UTF-8"));
21
	Properties newProperties = new Properties();
22
	File newMessageFile = new File(newProjectMessagesPackage, "messages${lang}.properties")
23
	if (newMessageFile.exists())
24
		newProperties.load(IOUtils.getReader(newMessageFile, "UTF-8"));
25
		
26
	newNLSClassFile.getText("UTF-8").findAll("public static String [^;]+;") { key ->
27
		key = key.substring(21, key.length()-1)
28
		
29
		if (oldProperties.get(key) == null) {
30
			println "Key $key is missing from old messages file: "+oldMessageFile.getName()
31
			newProperties.put(key, "MISSING")
32
		} else {
33
			if (newProperties.get(key) != null) {
34
				println "update $key = "+oldProperties.get(key)
35
			} else {
36
				println "add $key = "+oldProperties.get(key)
37
			}
38
			newProperties.put(key, oldProperties.get(key))
39
		}
40
	}
41
	newProperties.store(IOUtils.getWriter(newMessageFile, "UTF-8"), "created/updated with GetStringsFromPropertiesFile.groovy")
42
	println "Done"		
43
}
tmp/org.txm.cooccurrence.rcp/src/org/txm/cooccurrence/rcp/handlers/ComputeCooccurrences.java (revision 345)
35 35
import org.eclipse.ui.IWorkbenchPage;
36 36
import org.eclipse.ui.IWorkbenchWindow;
37 37
import org.txm.Toolbox;
38
import org.txm.concordances.functions.Concordance;
38 39
import org.txm.cooccurrence.core.functions.Cooccurrence;
39 40
import org.txm.cooccurrence.core.preferences.CooccurrencePreferences;
40 41
import org.txm.cooccurrence.rcp.editors.CooccurrenceEditorInput;
41 42
import org.txm.cooccurrence.rcp.editors.CooccurrencesEditor;
42 43
import org.txm.core.preferences.TXMPreferences;
43
import org.txm.functions.concordances.Concordance;
44 44
import org.txm.rcp.handlers.BaseAbstractHandler;
45 45
import org.txm.rcp.Messages;
46 46
import org.txm.rcp.StatusLine;
tmp/org.txm.cooccurrence.core/src/org/txm/cooccurrence/core/functions/Cooccurrence.java (revision 345)
42 42
import java.util.Set;
43 43

  
44 44
import org.rosuda.REngine.REXPMismatchException;
45
import org.txm.concordances.functions.Concordance;
46
import org.txm.concordances.functions.Line;
45 47
import org.txm.cooccurrence.core.functions.comparators.CLineComparator;
46 48
import org.txm.cooccurrence.core.messages.CooccurrenceCoreMessages;
47 49
import org.txm.functions.Function;
48
import org.txm.functions.concordances.Concordance;
49
import org.txm.functions.concordances.Line;
50 50
import org.txm.index.core.functions.Index;
51 51
import org.txm.lexicaltable.core.functions.LexicalTable;
52 52
import org.txm.lexicaltable.core.functions.LexicalTableFactory;
......
89 89
	String referenceCorpus;
90 90

  
91 91
	/** The conclines. */
92
	List<org.txm.functions.concordances.Line> conclines;
92
	List<org.txm.concordances.functions.Line> conclines;
93 93

  
94 94
	/** The corpus. */
95 95
	Corpus corpus;
tmp/org.txm.core/src/java/org/txm/core/messages/TXMCoreMessages.java (revision 345)
47 47
	public static String CatalogManager_0;
48 48
	public static String CatalogManager_1;
49 49
	public static String Catalog_0;
50
	public static String CompositeComparator_0;
51
	public static String Concordance_0;
52
	public static String Concordance_1;
53
	public static String Concordance_12;
54
	public static String Concordance_13;
55
	public static String Concordance_14;
56
	public static String Concordance_15;
57
	public static String Concordance_16;
58
	public static String Concordance_17;
59
	public static String Concordance_18;
60
	public static String Concordance_19;
61
	public static String Concordance_2;
62
	public static String Concordance_3;
63
	public static String Concordance_4;
64
	public static String Concordance_5;
65
	public static String Concordance_6;
66
	public static String Concordance_7;
67
	public static String Concordance_8;
68 50
	public static String Contrasts_0;
69 51
	public static String Convert5To6_1;
70 52
	public static String Convert5To6_10;
......
158 140
	public static String InternalView_7;
159 141
	public static String LEXICON;
160 142
	public static String LEXICON_ADDED;
161
	public static String LexicographicKeywordComparator_0;
162
	public static String LexicographicLeftContextComparator_0;
163
	public static String LexicographicRightContextComparator_0;
164 143
	public static String MATRIX_ADDED_TO_WORKSPACE;
165 144
	public static String MainCorpus_0;
166 145
	public static String MainCorpus_1;
......
181 160
	public static String NetCqiClient_97;
182 161
	public static String NetCqiServer_0;
183 162
	public static String NetCqiServer_1;
184
	public static String NullComparator_0;
185 163
	public static String PACKAGE_LOADED;
186 164
	public static String PARTITION_CREATED;
187 165
	public static String PART_CREATED;
......
234 212
	public static String Project_7;
235 213
	public static String Project_8;
236 214
	public static String Project_9;
237
	public static String PropertiesReferenceComparator_0;
238 215
	public static String QUERY;
239 216
	public static String QUERYING_PARTITION;
240 217
	public static String QueryIndex_2;
tmp/org.txm.core/META-INF/MANIFEST.MF (revision 345)
13 13
 org.eclipse.persistence.jpa;bundle-version="2.6.0",
14 14
 javax.persistence;bundle-version="2.1.0",
15 15
 org.eclipse.persistence.jpa.jpql;bundle-version="2.6.0",
16
 org.txm.statsengine.r.core;bundle-version="1.0.0"
16
 org.txm.statsengine.r.core;bundle-version="1.0.0",
17
 org.txm.annotation.core;bundle-version="1.0.0"
17 18
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
18 19
Export-Package: EDU.oswego.cs.dl.util.concurrent,
19 20
 EDU.oswego.cs.dl.util.concurrent.misc,
......
229 230
 org.sqlite.jdbc4,
230 231
 org.sqlite.util,
231 232
 org.txm,
232
 org.txm.annotation,
233
 org.txm.annotation.conversion,
234
 org.txm.annotation.repository,
235
 org.txm.annotation.storage.temporary,
236 233
 org.txm.annotation.temporary,
237 234
 org.txm.core.messages,
238 235
 org.txm.core.preferences,
tmp/org.txm.progression.rcp/src/org/txm/progression/rcp/chartsengine/events/ProgressionEventCallBack.java (revision 345)
20 20
import org.jfree.chart.entity.ChartEntity;
21 21
import org.txm.chartsengine.rcp.events.EventCallBack;
22 22
import org.txm.chartsengine.rcp.events.ZoomAndPanCallBack;
23
import org.txm.functions.concordances.comparators.LineComparator;
23
import org.txm.concordances.functions.comparators.LineComparator;
24 24
import org.txm.objects.Edition;
25 25
import org.txm.objects.Page;
26 26
import org.txm.objects.Text;
tmp/org.txm.concordance.core/META-INF/MANIFEST.MF (revision 345)
4 4
Bundle-SymbolicName: org.txm.concordance.core
5 5
Bundle-Version: 1.0.0.qualifier
6 6
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
7
Require-Bundle: org.txm.core
8
Export-Package: org.txm.functions.concordances,
9
 org.txm.functions.concordances.comparators
7
Require-Bundle: org.txm.core,
8
 org.txm.annotation.core;bundle-version="1.0.0"
9
Export-Package: org.txm.concordances.functions,
10
 org.txm.concordances.functions.comparators
tmp/org.txm.concordance.core/src/TestConcordance.java (revision 345)
5 5
import java.util.Arrays;
6 6
import java.util.List;
7 7

  
8
import org.txm.concordances.functions.Concordance;
9
import org.txm.concordances.functions.comparators.LexicographicKeywordComparator;
10
import org.txm.concordances.functions.comparators.LexicographicLeftContextComparator;
11
import org.txm.concordances.functions.comparators.LexicographicRightContextComparator;
12
import org.txm.concordances.functions.comparators.LineComparator;
13
import org.txm.concordances.functions.comparators.NullComparator;
14
import org.txm.concordances.functions.comparators.PropertiesReferenceComparator;
8 15
import org.txm.functions.ReferencePattern;
9
import org.txm.functions.concordances.Concordance;
10
import org.txm.functions.concordances.comparators.LexicographicKeywordComparator;
11
import org.txm.functions.concordances.comparators.LexicographicLeftContextComparator;
12
import org.txm.functions.concordances.comparators.LexicographicRightContextComparator;
13
import org.txm.functions.concordances.comparators.LineComparator;
14
import org.txm.functions.concordances.comparators.NullComparator;
15
import org.txm.functions.concordances.comparators.PropertiesReferenceComparator;
16 16
import org.txm.searchengine.cqp.corpus.Corpus;
17 17
import org.txm.searchengine.cqp.corpus.CorpusManager;
18 18
import org.txm.searchengine.cqp.corpus.Property;
tmp/org.txm.concordance.core/src/org/txm/concordances/messages/messages.properties (revision 345)
1
#created/updated with GetStringsFromPropertiesFile.groovy
2
#Mon Jul 03 14:53:55 CEST 2017
3
LexicographicLeftContextComparator_0=Left context
4
NullComparator_0=None
5
Concordance_8=Failed to get texts limits\: 
6
Concordance_7=\ results
7
PropertiesReferenceComparator_0=References
8
Concordance_6=Retrieving 
9
Concordance_5=
10
Concordance_4=Failed to remove QueryResult from CQP\: 
11
Concordance_3=\ results retrieved in 
12
Concordance_2=undefined
13
Concordance_1=** Failed to retrieve text_id property from lines
14
Concordance_0=\ 
15
CompositeComparator_0=Composite\: 
16
LexicographicRightContextComparator_0=Right context
17
LexicographicKeywordComparator_0=Keyword
18
Concordance_19=Context
19
Concordance_18=
20
Concordance_17=Reference
21
Concordance_16=RightContext
22
Concordance_15=Keyword
23
Concordance_14=LeftContext
24
Concordance_13=Reference
25
Concordance_12=** Failed to export Concordance\: 
0 26

  
tmp/org.txm.concordance.core/src/org/txm/concordances/messages/ConcordanceMessages.java (revision 345)
1
package org.txm.concordances.messages;
2

  
3
import org.eclipse.osgi.util.NLS;
4
import org.txm.utils.messages.Utf8NLS;
5

  
6
/**
7
 * Toolbox core messages.
8
 * 
9
 * @author mdecorde
10
 * @author sjacquot
11
 *
12
 */
13
public class ConcordanceMessages extends NLS {
14

  
15
	private static final String BUNDLE_NAME = "org.txm.concordances.messages"; //$NON-NLS-1$
16

  
17
	public static String Concordance_0;
18
	public static String Concordance_1;
19
	public static String Concordance_12;
20
	public static String Concordance_13;
21
	public static String Concordance_14;
22
	public static String Concordance_15;
23
	public static String Concordance_16;
24
	public static String Concordance_17;
25
	public static String Concordance_18;
26
	public static String Concordance_19;
27
	public static String Concordance_2;
28
	public static String Concordance_3;
29
	public static String Concordance_4;
30
	public static String Concordance_5;
31
	public static String Concordance_6;
32
	public static String Concordance_7;
33
	public static String Concordance_8;
34
	public static String CompositeComparator_0;
35
	public static String PropertiesReferenceComparator_0;
36
	public static String LexicographicLeftContextComparator_0;
37
	public static String LexicographicKeywordComparator_0;
38
	public static String LexicographicRightContextComparator_0;
39
	public static String NullComparator_0;
40
	
41
	static {
42
		// initialize resource bundle
43
		Utf8NLS.initializeMessages(BUNDLE_NAME, ConcordanceMessages.class);
44
	}
45
}
0 46

  
tmp/org.txm.concordance.core/src/org/txm/concordances/messages/messages_ru.properties (revision 345)
1
#created/updated with GetStringsFromPropertiesFile.groovy
2
#Mon Jul 03 14:53:55 CEST 2017
3
LexicographicLeftContextComparator_0=MISSING
4
NullComparator_0=MISSING
5
Concordance_8=MISSING
6
Concordance_7=MISSING
7
PropertiesReferenceComparator_0=MISSING
8
Concordance_6=MISSING
9
Concordance_5=MISSING
10
Concordance_4=MISSING
11
Concordance_3=MISSING
12
Concordance_2=MISSING
13
Concordance_1=MISSING
14
Concordance_0=MISSING
15
CompositeComparator_0=MISSING
16
LexicographicRightContextComparator_0=MISSING
17
LexicographicKeywordComparator_0=MISSING
18
Concordance_19=MISSING
19
Concordance_18=MISSING
20
Concordance_17=MISSING
21
Concordance_16=MISSING
22
Concordance_15=MISSING
23
Concordance_14=MISSING
24
Concordance_13=MISSING
25
Concordance_12=MISSING
0 26

  
tmp/org.txm.concordance.core/src/org/txm/concordances/messages/messages_fr.properties (revision 345)
1
#created/updated with GetStringsFromPropertiesFile.groovy
2
#Mon Jul 03 14:53:55 CEST 2017
3
LexicographicLeftContextComparator_0=Contexte gauche
4
NullComparator_0=Aucun
5
Concordance_8=Echec de la récupération des limites de texte \: 
6
Concordance_7=\ résultats
7
PropertiesReferenceComparator_0=Références
8
Concordance_6=Récupération 
9
Concordance_5=MISSING
10
Concordance_4=Echec de la suppression du QueryResult de CQP\: 
11
Concordance_3=\ résultats obtenus en 
12
Concordance_2=indéfini
13
Concordance_1=** Echec de récupération de la propriété 'text_id' des lignes 
14
Concordance_0=\ 
15
CompositeComparator_0=Composé \: 
16
LexicographicRightContextComparator_0=Contexte droit
17
LexicographicKeywordComparator_0=Pivot
18
Concordance_19=Contexte
19
Concordance_18=MISSING
20
Concordance_17=Référence
21
Concordance_16=ContexteDroit
22
Concordance_15=Pivot
23
Concordance_14=ContexteGauche
24
Concordance_13=Référence
25
Concordance_12=** Echec de l'exportation de la concordance \: 
0 26

  
tmp/org.txm.concordance.core/src/org/txm/concordances/functions/Concordance.java (revision 345)
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: 2016-11-29 16:47:07 +0100 (Tue, 29 Nov 2016) $
25
// $LastChangedRevision: 3349 $
26
// $LastChangedBy: mdecorde $ 
27
//
28
package org.txm.concordances.functions;
29

  
30
import java.io.BufferedOutputStream;
31
import java.io.BufferedWriter;
32
import java.io.File;
33
import java.io.FileOutputStream;
34
import java.io.IOException;
35
import java.io.OutputStreamWriter;
36
import java.io.UnsupportedEncodingException;
37
import java.io.Writer;
38
import java.util.ArrayList;
39
import java.util.Arrays;
40
import java.util.Collections;
41
import java.util.Comparator;
42
import java.util.HashMap;
43
import java.util.HashSet;
44
import java.util.List;
45
import java.util.Map;
46

  
47
import org.txm.annotation.Annotation;
48
import org.txm.annotation.AnnotationManager;
49
import org.txm.annotation.repository.AnnotationType;
50
import org.txm.annotation.repository.TypedValue;
51
import org.txm.concordances.functions.comparators.LineComparator;
52
import org.txm.concordances.messages.ConcordanceMessages;
53
//import org.txm.core.messages.ConcordanceMessages;
54
import org.txm.functions.Function;
55
import org.txm.functions.Reference;
56
import org.txm.functions.ReferencePattern;
57
import org.txm.searchengine.cqp.AbstractCqiClient;
58
import org.txm.searchengine.cqp.MemCqiClient;
59
import org.txm.searchengine.cqp.clientExceptions.CqiClientException;
60
import org.txm.searchengine.cqp.corpus.Corpus;
61
import org.txm.searchengine.cqp.corpus.CorpusManager;
62
import org.txm.searchengine.cqp.corpus.Property;
63
import org.txm.searchengine.cqp.corpus.QueryResult;
64
import org.txm.searchengine.cqp.corpus.StructuralUnit;
65
import org.txm.searchengine.cqp.corpus.query.Match;
66
import org.txm.searchengine.cqp.corpus.query.Query;
67
import org.txm.searchengine.cqp.serverException.CqiServerError;
68
import org.txm.statsengine.r.core.RWorkspace;
69
import org.txm.statsengine.r.core.exceptions.RWorkspaceException;
70
import org.txm.utils.logger.Log;
71

  
72
// TODO: Auto-generated Javadoc
73
/**
74
 * The Class Concordance.
75
 * 
76
 * @author jmague, mdecorde
77
 */
78
public class Concordance extends Function {
79

  
80
	/**
81
	 * The Enum Format.
82
	 */
83
	public enum Format {
84
		/** The CONCORDANCE. */
85
		CONCORDANCE, 
86
		/** The CONTEXT. */
87
		CONTEXT
88
	};
89

  
90
	/** The lines. */
91
	private List<Line> lines;
92

  
93
	/** The query result. */
94
	private QueryResult queryResult;
95

  
96
	/** The view properties. */
97
	private List<Property> viewProperties; // contains all the view properties
98
	// needed
99
	/** The left c view properties. */
100
	private List<Property> leftCViewProperties;
101

  
102
	/** The right c view properties. */
103
	private List<Property> rightCViewProperties;
104

  
105
	/** The keyword view properties. */
106
	private List<Property> keywordViewProperties;
107

  
108
	/** The analysis property. */
109
	private List<Property> leftAnalysisProperties;
110

  
111
	/** The right c analysis property. */
112
	private List<Property> rightAnalysisProperties;
113

  
114
	/** The keyword analysis property. */
115
	private List<Property> keywordAnalysisProperties;
116

  
117
	/** The n lines. */
118
	private int nLines;
119

  
120
	/** The right context size. */
121
	private int rightContextSize;
122

  
123
	/** The left context size. */
124
	private int leftContextSize;
125

  
126
	/** The corpus. */
127
	private Corpus corpus;
128

  
129
	/** The reference pattern. */
130
	private ReferencePattern refViewPattern;
131
	private ReferencePattern refAnalysePattern;
132

  
133
	/** The cache. */
134
	//private Map<Property, CqpDataProxy> cache;
135

  
136
	/** The query. */
137
	private Query query;
138

  
139
	/** The symbol. */
140
	private String symbol;
141

  
142
	/** The writer. */
143
	private Writer writer;
144

  
145
	/**
146
	 * Creates a new concordance and compute it.
147
	 *
148
	 * @param corpus The corpus on which apply the query
149
	 * @param query The query defining the keywords
150
	 * @param analysisProperty The property used to sort the lines
151
	 * @param viewProperties The property used to print the lines
152
	 * @param referencePattern the reference pattern
153
	 * @param leftContextSize The size in words of the left context
154
	 * @param rightContextSize The size in words of the right context
155
	 * @throws CqiClientException the cqi client exception
156
	 */
157
	public Concordance(Corpus corpus, Query query, Property analysisProperty,
158
			List<Property> viewProperties, ReferencePattern referencePattern, ReferencePattern refAnalysePattern,
159
			int leftContextSize, int rightContextSize)
160
					throws CqiClientException {
161

  
162
		super(corpus);
163
		// set concordance parameters
164
		this.corpus = corpus;
165
		this.query = query;
166
		this.leftAnalysisProperties = Arrays.asList(analysisProperty); // same analysis property
167
		this.rightAnalysisProperties = Arrays.asList(analysisProperty);
168
		this.keywordAnalysisProperties = Arrays.asList(analysisProperty);
169
		this.viewProperties = viewProperties; // same view property for left, right context and keyword
170
		this.leftCViewProperties = viewProperties;
171
		this.rightCViewProperties = viewProperties;
172
		this.keywordViewProperties = viewProperties;
173
		this.updateViewPropertiesList();
174
		this.refViewPattern = referencePattern;
175
		this.refAnalysePattern = refAnalysePattern;
176
		this.leftContextSize = leftContextSize;
177
		this.rightContextSize = rightContextSize;
178

  
179
		if (corpus != null) {
180
			setCQLSeparator(corpus.getCQLLimitQuery());
181
		}
182

  
183
		computeConcordance();
184
	}
185

  
186
	/**
187
	 * Creates a new concordance and compute it.
188
	 *
189
	 * @param corpus The corpus on which apply the query
190
	 * @param query The query defining the keywords
191
	 * @param analysisProperty The property used to sort the lines
192
	 * @param leftCViewProperties The property used to print the lines of Left context
193
	 * @param rightCViewProperties The property used to print the lines of right context
194
	 * @param keywordViewProperties The property used to print the lines of keyword
195
	 * @param referencePattern the reference pattern
196
	 * @param leftContextSize The size in words of the left context
197
	 * @param rightContextSize The size in words of the right context
198
	 * @throws CqiClientException the cqi client exception
199
	 */
200
	public Concordance(Corpus corpus, Query query, Property analysisProperty,
201
			List<Property> leftCViewProperties,
202
			List<Property> rightCViewProperties,
203
			List<Property> keywordViewProperties,
204
			ReferencePattern referencePattern, 
205
			ReferencePattern refAnalysePattern,int leftContextSize,
206
			int rightContextSize) throws CqiClientException {
207
		super(corpus);
208
		// set concordance parameters
209
		this.corpus = corpus;
210
		this.query = query;
211
		this.leftAnalysisProperties = Arrays.asList(analysisProperty);
212
		this.rightAnalysisProperties = Arrays.asList(analysisProperty);
213
		this.keywordAnalysisProperties = Arrays.asList(analysisProperty);
214
		this.leftCViewProperties = leftCViewProperties;
215
		this.rightCViewProperties = rightCViewProperties;
216
		this.keywordViewProperties = keywordViewProperties;
217
		this.updateViewPropertiesList();
218
		this.refViewPattern = referencePattern;
219
		this.refAnalysePattern = refAnalysePattern;
220
		this.leftContextSize = leftContextSize;
221
		this.rightContextSize = rightContextSize;
222

  
223
		if (corpus != null) {
224
			setCQLSeparator(corpus.getCQLLimitQuery());
225
		}
226

  
227
		computeConcordance();
228
	}
229

  
230
	/**
231
	 * Creates a new concordance and compute it.
232
	 *
233
	 * @param corpus The corpus on which apply the query
234
	 * @param query The query defining the keywords
235
	 * @param leftCAnalysisProperty the left c analysis property
236
	 * @param rightCAnalysisProperty the right c analysis property
237
	 * @param keywordAnalysisProperty the keyword analysis property
238
	 * @param leftCViewProperties The property used to print the lines of Left context
239
	 * @param rightCViewProperties The property used to print the lines of right context
240
	 * @param keywordViewProperties The property used to print the lines of keyword
241
	 * @param referencePattern the reference pattern
242
	 * @param leftContextSize The size in words of the left context
243
	 * @param rightContextSize The size in words of the right context
244
	 * @throws CqiClientException the cqi client exception
245
	 */
246
	public Concordance(Corpus corpus, Query query,
247
			Property leftCAnalysisProperty, Property rightCAnalysisProperty,
248
			Property keywordAnalysisProperty,
249
			List<Property> leftCViewProperties,
250
			List<Property> rightCViewProperties,
251
			List<Property> keywordViewProperties,
252
			ReferencePattern referencePattern, 
253
			ReferencePattern refAnalysePattern,
254
			int leftContextSize,
255
			int rightContextSize) throws CqiClientException {
256
		
257
		super(corpus);
258
		// set concordance parameters
259
		this.corpus = corpus;
260
		this.query = query;
261
		this.leftAnalysisProperties = Arrays.asList(leftCAnalysisProperty);
262
		this.rightAnalysisProperties = Arrays.asList(rightCAnalysisProperty);
263
		this.keywordAnalysisProperties = Arrays.asList(keywordAnalysisProperty);
264
		this.leftCViewProperties = leftCViewProperties;
265
		this.rightCViewProperties = rightCViewProperties;
266
		this.keywordViewProperties = keywordViewProperties;
267
		this.updateViewPropertiesList();
268
		this.refViewPattern = referencePattern;
269
		this.refAnalysePattern = refAnalysePattern;
270
		this.leftContextSize = leftContextSize;
271
		this.rightContextSize = rightContextSize;
272

  
273
		computeConcordance();
274
	}
275

  
276
	public Concordance(Corpus corpus, Query query,
277
			List<Property> selectedLeftCSortProperty,
278
			List<Property> selectedRightCSortProperty,
279
			List<Property> selectedKeywordSortProperty,
280
			List<Property> selectedLeftCViewProperties,
281
			List<Property> selectedRightCViewProperties,
282
			List<Property> selectedKeywordViewProperties,
283
			ReferencePattern referencePattern, 
284
			ReferencePattern refAnalysePattern, int leftContextSize,
285
			int rightContextSize) throws CqiClientException {
286
		
287
		super(corpus);
288
		// set concordance parameters
289
		this.corpus = corpus;
290
		this.query = query;
291
		this.leftAnalysisProperties = selectedLeftCSortProperty;
292
		this.rightAnalysisProperties = selectedRightCSortProperty;
293
		this.keywordAnalysisProperties = selectedKeywordSortProperty;
294
		this.leftCViewProperties = selectedLeftCViewProperties;
295
		this.rightCViewProperties = selectedRightCViewProperties;
296
		this.keywordViewProperties = selectedKeywordViewProperties;
297
		this.updateViewPropertiesList();
298
		this.refViewPattern = referencePattern;
299
		this.refAnalysePattern = refAnalysePattern;
300
		this.leftContextSize = leftContextSize;
301
		this.rightContextSize = rightContextSize;
302

  
303
		computeConcordance();
304
	}
305

  
306
	/**
307
	 * Update view properties list.
308
	 */
309
	private void updateViewPropertiesList() {
310
		// reset view properties
311
		this.viewProperties = new ArrayList<Property>();
312
		// fill it with the properties of the others
313
		viewProperties.addAll(keywordViewProperties);
314

  
315
		for (Property p : leftCViewProperties)// add the view properties of left context
316
		{
317
			if (!viewProperties.contains(p)) {
318
				viewProperties.add(p);
319
			}
320
		}
321

  
322
		for (Property p : rightCViewProperties)// add the view properties of right context
323
		{
324
			if (!viewProperties.contains(p)) {
325
				viewProperties.add(p);
326
			}
327
		}
328
	}
329

  
330
	/**
331
	 * Compute concordance.
332
	 *
333
	 * @return true, if successful
334
	 * @throws CqiClientException 
335
	 */
336
	private boolean computeConcordance() throws CqiClientException {
337
		this.queryResult = corpus.query(query, query.getQueryString()
338
				.replace(" ", "_") + "_concordance", true); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
339

  
340
		this.nLines = queryResult.getNMatch();
341
		this.lines = new ArrayList<Line>(Collections.nCopies(nLines,
342
				(Line) null));// lines are lazily fetched; we force an
343
		// ArrayList so we can use the 'set' method
344

  
345
		return true;
346
	}
347

  
348
	/**
349
	 * drop the concordance QueryResult
350
	 */
351
	public void cleanMemory() {
352
		try {
353
			if (queryResult != null) queryResult.drop();
354
		} catch (CqiClientException e) {
355
			System.out.println(ConcordanceMessages.Concordance_4+e);
356
		}
357
	}
358

  
359
	/**
360
	 * Returns the query used to build the concordance.
361
	 * 
362
	 * @return the query
363
	 */
364
	public Query getQuery() {
365
		return query;
366
	}
367

  
368
	//int[] textStarts = null;
369
	int[] CQLLimitStarts = null;
370
	String cql_limit;
371

  
372
	public List<Line> reloadLines(int topLine, int bottomLine) throws CqiClientException, IOException, CqiServerError {
373
		for (int i = topLine; i < bottomLine; i++) {
374
			lines.set(i, null);
375
		}
376

  
377
		return getLines(topLine, bottomLine);
378
	}
379

  
380
	/**
381
	 * Returns the line between from and to.
382
	 * 
383
	 * @param from
384
	 *            the from
385
	 * @param to
386
	 *            the to
387
	 * 
388
	 * @return the lines
389
	 * 
390
	 * @throws CqiClientException
391
	 *             the cqi client exception
392
	 * @throws CqiServerError 
393
	 * @throws IOException 
394
	 */
395
	public List<Line> getLines(int from, int to) throws CqiClientException, IOException, CqiServerError {
396

  
397
		Log.info(ConcordanceMessages.Concordance_6 + (to - from + 1) + ConcordanceMessages.Concordance_7);
398

  
399
		AnnotationManager am = corpus.getAnnotationManager();
400

  
401
		AbstractCqiClient cqiClient = CorpusManager.getCorpusManager().getCqiClient();
402
		
403
		long start = System.currentTimeMillis();
404

  
405
		// check asked lines numbers
406
		if (from < 0) from = 0;
407
		if (from > to) from = to;
408
		if (to >= nLines) to = nLines - 1;
409
		if (from < 0 || from > to || to >= nLines) {
410
			throw new IndexOutOfBoundsException();
411
		}
412

  
413
		List<Match> matches = queryResult.getMatches(from, to);
414

  
415
		//		System.out.println("cqllimit="+cql_limit);
416
		//		System.out.println("CQLLimitStarts="+CQLLimitStarts);
417
		if (cql_limit != null && CQLLimitStarts == null) { // initialize text limits
418
			try {
419
				Log.warning("Get CQL limit for query="+cql_limit);
420
				CQLLimitStarts = this.getCorpus().getStartLimits(cql_limit);
421
				if (CQLLimitStarts.length > 0 && CQLLimitStarts[0] != 0) {
422
					int[] tmp  = new int[CQLLimitStarts.length + 1];
423
					System.arraycopy(CQLLimitStarts, 0, tmp, 1, CQLLimitStarts.length);
424
					CQLLimitStarts = tmp;
425
				}
426
			} catch (Exception e) {
427
				org.txm.utils.logger.Log.printStackTrace(e);
428
				Log.severe(ConcordanceMessages.Concordance_8+e);
429
			}
430
		}
431

  
432
		int currentCQLLimit = 0;
433
		// System.out.println("texts: "+Arrays.toString(textStarts));
434
		// we create the blocks of lines not created yet that may occur between
435
		// from and to
436
		//int step = Math.max(100/(to - from), 1);
437
		for (int i = from; i <= to; i++) {
438
			int j;
439
			for (j = i; j <= to && lines.get(j) == null; j++); // THIS IS MANDATORY
440
			// j is the index of the first next existing line
441
			if (i != j) { // i does point at the beginning of a block of non
442
				// existing lines. We have to create the lines between i and j
443

  
444
				if (isCanceled()) return new ArrayList<Line>(); // check if user canceled the Job
445

  
446
				// First we get all the data we need : values for the view
447
				// properties, the analysis property and the reference
448
				List<Integer> beginingOfKeywordsPositions = new ArrayList<Integer>(j - i);
449
				List<Integer> targetPositions = new ArrayList<Integer>(j - i);
450
				List<Integer> lengthOfKeywords = new ArrayList<Integer>(j - i);
451
				List<Integer> beginingOfRightCtxPositions = new ArrayList<Integer>(	j - i);
452
				List<Integer> lengthOfRightCtx = new ArrayList<Integer>(j - i);
453
				List<Integer> beginingOfLeftCtxPositions = new ArrayList<Integer>(j - i);
454
				List<Integer> lengthOfLeftCtx = new ArrayList<Integer>(j - i);
455

  
456
				// get all first token and last token of all lines
457
				int currentKeywordPos;// = matches.get(0).getStart();
458
				//currentText = previousPivotText;
459

  
460
				List<Match> subsetMatch = new ArrayList<Match>(); 
461

  
462
				for (int k = 0; k < j - i; k++) {
463
					Match match = matches.get(i - from + k);
464
					subsetMatch.add(match);
465
					//System.out.println("match: "+match);
466
					//1) find current text using keyword position
467
					currentKeywordPos = match.getStart();
468

  
469
					if (CQLLimitStarts != null && currentCQLLimit < CQLLimitStarts.length) {
470
						while (currentCQLLimit < CQLLimitStarts.length && CQLLimitStarts[currentCQLLimit] <= currentKeywordPos) { // find the match's text
471
							currentCQLLimit++; // matches are ordered
472
						}
473
						if (currentCQLLimit > 0) {
474
							currentCQLLimit--; // get the previous text
475
						}
476
					}
477

  
478
					//System.out.println("text no: "+currentText+" text position: "+textStarts[currentText]);
479
					// LEFT CONTEXT LIMITS
480
					int ctxPosition = currentKeywordPos - leftContextSize; // left context start position
481
					if (CQLLimitStarts != null && currentCQLLimit < CQLLimitStarts.length) {
482
						if (CQLLimitStarts[currentCQLLimit] > ctxPosition) { // test if the end of left context is in the same text
483
							ctxPosition = CQLLimitStarts[currentCQLLimit]; // the context start is the start of the text
484
							//System.out.println("fix right "+currentText+" pos: "+ctxPosition);
485
						}
486
					}
487
					beginingOfLeftCtxPositions.add(ctxPosition);
488
					lengthOfLeftCtx.add(match.getStart() - ctxPosition); // distance between let context start position and keyword position
489
					//System.out.println("left: "+ctxPosition+ "len: "+(match.getStart() - ctxPosition));
490

  
491
					// KEYWORD LIMITS
492
					beginingOfKeywordsPositions.add(match.getStart());
493
					lengthOfKeywords.add(match.getEnd() - match.getStart() + 1);
494

  
495
					//TARGET POSITION
496
					targetPositions.add(match.getTarget());
497

  
498
					// check if the end of keyword pass a text limit
499
					// TODO: Can a keyword be over 2 texts ??
500
					currentKeywordPos = match.getEnd();
501

  
502
					if (CQLLimitStarts != null)
503
						if (currentCQLLimit < CQLLimitStarts.length) {
504
							while (currentCQLLimit < CQLLimitStarts.length && CQLLimitStarts[currentCQLLimit] <= currentKeywordPos) { // find the match's text
505
								currentCQLLimit++; // matches are ordered
506
							}
507
							if (currentCQLLimit > 0)
508
								currentCQLLimit--; // get the previous text
509
						}
510
					// find the right limit
511
					ctxPosition = match.getEnd() + rightContextSize;
512

  
513
					if (CQLLimitStarts != null)
514
						if (currentCQLLimit + 1 < CQLLimitStarts.length) {
515
							if (CQLLimitStarts[currentCQLLimit+1] < ctxPosition) { // test if the right context last position is in the same text as the pivot
516
								ctxPosition = CQLLimitStarts[currentCQLLimit+1] -1 ; // the context end is the next text start position
517
							}
518
						}
519

  
520
					//if (ctxPosition > corpus.getSize()) ctxPosition = corpus.getSize();
521

  
522
					beginingOfRightCtxPositions.add(match.getEnd() + 1);
523
					lengthOfRightCtx.add(ctxPosition - match.getEnd());
524
					//System.out.println("right: "+ctxPosition+" len: "+(ctxPosition - match.getEnd() + 1)+"\n");
525
				}
526

  
527
				//List<Annotation> allAnnotations = null;
528
				List<Annotation> annotationsPerMatch = null;;
529
				if (viewAnnotation != null && am != null) {
530
					try {
531
						annotationsPerMatch = am.getAnnotationsForMatches(viewAnnotation, subsetMatch, overlapAnnotation);
532
						//System.out.println("annotationsPerMatch: "+annotationsPerMatch);
533
					} catch (Exception e) {
534
						System.out.println("Error while reading annotation "+viewAnnotation+" and with "+subsetMatch.size()+" matches");
535
						Log.printStackTrace(e);
536
					}
537
				}
538

  
539
				//System.out.println("RIGHT ctx lengths: "+lengthOfRightCtx);
540
				// get all view property values of all lines
541
				Map<Property, List<List<String>>> keywordsViewPropValues = new HashMap<Property, List<List<String>>>();
542
				Map<Property, List<List<String>>> leftCtxViewPropValues = new HashMap<Property, List<List<String>>>();
543
				Map<Property, List<List<String>>> rightCtxViewPropValues = new HashMap<Property, List<List<String>>>();
544
				for (Property property : leftCViewProperties) {
545
					leftCtxViewPropValues.put(property, cqiClient.getData(property, beginingOfLeftCtxPositions,
546
							lengthOfLeftCtx));
547
				}
548
				for (Property property : rightCViewProperties) {
549
					rightCtxViewPropValues.put(property, cqiClient.getData(property, beginingOfRightCtxPositions,
550
							lengthOfRightCtx));
551
				}
552
				for (Property property : keywordViewProperties) {
553
					keywordsViewPropValues.put(property, cqiClient.getData(property, beginingOfKeywordsPositions,
554
							lengthOfKeywords));
555
				}
556

  
557
				// get all analysis property values of all lines
558
				HashMap<Property, List<List<String>>> leftCtxAnaPropValues = new HashMap<Property, List<List<String>>>();
559
				for(Property p : leftAnalysisProperties) {
560
					leftCtxAnaPropValues.put(p, cqiClient.getData(p, beginingOfLeftCtxPositions, lengthOfLeftCtx));
561
				}
562
				HashMap<Property, List<List<String>>> keywordsAnaPropValues = new HashMap<Property, List<List<String>>>();
563
				for(Property p : keywordAnalysisProperties) {
564
					keywordsAnaPropValues.put(p, cqiClient.getData(p, beginingOfKeywordsPositions, lengthOfKeywords));
565
				}
566
				HashMap<Property, List<List<String>>> rightCtxAnaPropValues = new HashMap<Property, List<List<String>>>();
567
				for(Property p : rightAnalysisProperties) {
568
					rightCtxAnaPropValues.put(p, cqiClient.getData(p, beginingOfRightCtxPositions, lengthOfRightCtx));
569
				}
570
				// get all view reference values of all lines
571
				Map<Property, List<List<String>>> refValues = new HashMap<Property, List<List<String>>>();
572
				for (Property property : refViewPattern) {
573
					refValues.put(property, cqiClient.getData(property, 
574
							beginingOfKeywordsPositions,
575
							Collections.nCopies(beginingOfKeywordsPositions.size(), 1)));
576
				}
577

  
578
				// get all sort reference values of all lines
579
				Map<Property, List<List<String>>> refSortValues = new HashMap<Property, List<List<String>>>();
580
				for (Property property : refAnalysePattern) {
581
					refSortValues.put(property, cqiClient.getData(property, beginingOfKeywordsPositions,
582
							Collections.nCopies(beginingOfKeywordsPositions.size(), 1)));
583
				}
584

  
585
				// get all lines' tokens ids
586
				Property id = corpus.getProperty("id"); //$NON-NLS-1$
587
				StructuralUnit text = corpus.getStructuralUnit("text"); //$NON-NLS-1$
588
				Property text_id = text.getProperty("id"); //$NON-NLS-1$
589

  
590
				List<List<String>> keywordsIdValues;
591
				List<List<String>> keywordsTextValues;
592
				if (id != null && text_id != null) {
593
					/** The occurrences Ids&Text => BackToText */
594
					keywordsIdValues = cqiClient.getData(id, beginingOfKeywordsPositions, lengthOfKeywords);
595
					keywordsTextValues = cqiClient.getData(text_id, beginingOfKeywordsPositions,
596
							Collections.nCopies(beginingOfKeywordsPositions
597
									.size(), 1));
598
				} else {
599
					keywordsTextValues = null;
600
					keywordsIdValues = null;
601
					Log.warning(ConcordanceMessages.Concordance_1);
602
				}
603

  
604
				// Since we get the value only for the first word of the
605
				// keyword, we know that refValues maps each property to a list
606
				// of list of size==1 : refValue.get(p).get(i).size()==1
607

  
608
				// Second, we build the lines
609
				for (int k = 0; k < j - i; k++) {
610
					//worked(1);
611
					// get the kth line's analysis property values
612
					HashMap<Property, List<String>> lineLeftCtxAnaPropValue = new HashMap<Property, List<String>>();
613
					for(Property p : leftAnalysisProperties) {
614
						lineLeftCtxAnaPropValue.put(p, leftCtxAnaPropValues.get(p).get(k));
615
					}
616
					HashMap<Property, List<String>> lineKeywordsAnaPropValue = new HashMap<Property, List<String>>();
617
					for(Property p : keywordAnalysisProperties) {
618
						lineKeywordsAnaPropValue.put(p, keywordsAnaPropValues.get(p).get(k));
619
					}
620
					HashMap<Property, List<String>> lineRightCtxAnaPropValue = new HashMap<Property, List<String>>();
621
					for(Property p : rightAnalysisProperties) {
622
						lineRightCtxAnaPropValue.put(p, rightCtxAnaPropValues.get(p).get(k));
623
					}
624
					// get the kth line's view property values
625
					Map<Property, List<String>> lineLeftCtxViewPropValue = new HashMap<Property, List<String>>();
626
					Map<Property, List<String>> lineKeywordsViewPropValue = new HashMap<Property, List<String>>();
627
					Map<Property, List<String>> lineRightCtxViewPropValue = new HashMap<Property, List<String>>();
628
					for (Property property : leftCViewProperties) {
629
						lineLeftCtxViewPropValue.put(property,
630
								leftCtxViewPropValues.get(property).get(k));
631
					}
632
					for (Property property : rightCViewProperties) {
633
						lineRightCtxViewPropValue.put(property,
634
								rightCtxViewPropValues.get(property).get(k));
635
					}
636
					for (Property property : keywordViewProperties) {
637
						lineKeywordsViewPropValue.put(property,
638
								keywordsViewPropValues.get(property).get(k));
639
					}
640

  
641
					// get the kth line reference values
642
					Map<Property, String> ref = new HashMap<Property, String>();
643
					for (Property property : refViewPattern) {
644
						ref.put(property, refValues.get(property).get(k).get(0));
645
					}
646

  
647
					// get the kth line reference values
648
					Map<Property, String> refAna = new HashMap<Property, String>();
649
					for (Property property : refAnalysePattern) {
650
						refAna.put(property, refSortValues.get(property).get(k).get(0));
651
					}
652

  
653
					// get Text id of the line
654
					String TextId;
655
					List<String> wordids;
656
					if (keywordsIdValues != null && keywordsTextValues != null) {
657
						TextId = keywordsTextValues.get(k).get(0);
658
						wordids = keywordsIdValues.get(k);
659
					} else {
660
						TextId = ConcordanceMessages.Concordance_2;
661
						wordids = new ArrayList<String>();
662
					}
663

  
664
					int targetpos = targetPositions.get(k);
665

  
666

  
667
					Annotation annotation = null;
668
					Match match = matches.get(i- from + k);
669
					if (annotationsPerMatch != null) {
670
						annotation = annotationsPerMatch.get(k);
671
					}
672
					TypedValue annotationValue = null;
673
					if (annotation!=null) {
674
						annotationValue = viewAnnotation.getTypedValue(annotation.getValue());
675
						if (annotationValue == null) { // the annotation is not stored in the KR type -> the annotation is surely built with the CQPAnnotationManager
676
							//System.out.println("WARNING: no annotation value found for value id="+annotation.getValue()+" - will be created.");
677
							annotationValue = new TypedValue(annotation.getValue(), annotation.getValue(), annotation.getType());
678
						}
679
					}
680

  
681
					Line line = new Line(this, wordids, TextId,
682
							lineLeftCtxViewPropValue,
683
							lineKeywordsViewPropValue,
684
							lineRightCtxViewPropValue, lineLeftCtxAnaPropValue,
685
							lineKeywordsAnaPropValue, lineRightCtxAnaPropValue,
686
							new Reference(ref, refViewPattern), 
687
							new Reference(refAna, refAnalysePattern), 
688
							match, 
689
							annotation,
690
							annotationValue,
691
							targetpos);
692
					lines.set(i + k, line);
693
				}
694
			}
695
			i = j;
696
		}
697
		List<Line> res = lines.subList(from, to + 1);// our to is inclusive,
698
		// sublist's is exlusive
699
		Log.info((to - from + 1) + ConcordanceMessages.Concordance_3
700
				+ (System.currentTimeMillis() - start) + "ms"); //$NON-NLS-1$ 
701
		return res;
702
	}
703

  
704

  
705
	private List<Annotation> prepareAnnotationsList(List<Match> matches, List<Annotation> annotations, boolean overlap){
706
		List<Annotation> annotsList = new ArrayList<Annotation>();
707

  
708
		int iMatch = 0;
709
		int iAnnotation = 0;
710
		int nMatch = matches.size();
711
		int nAnnotations = annotations.size();
712

  
713
		while (iMatch < nMatch && iAnnotation < nAnnotations) {
714
			if (overlap) {
715
				if (matches.get(iMatch).getEnd() < annotations.get(iAnnotation).getStart()) {
716
					iMatch++;
717
					annotsList.add(null); // nothing for this match
718
				} else if (annotations.get(iAnnotation).getEnd() < matches.get(iMatch).getStart()) {
719
					iAnnotation++;
720
				} else {
721
					annotsList.add(annotations.get(iAnnotation));
722
					iMatch++;
723
				}
724
			} else {
725
				if (matches.get(iMatch).getEnd() < annotations.get(iAnnotation).getStart()) {
726
					iMatch++;
727
					annotsList.add(null); // nothing for this match
728
				} else if (annotations.get(iAnnotation).getEnd() < matches.get(iMatch).getStart()) {
729
					iAnnotation++;
730
				} else if (annotations.get(iAnnotation).getStart() == matches.get(iMatch).getStart() && 
731
						annotations.get(iAnnotation).getEnd() == matches.get(iMatch).getEnd()) {
732
					annotsList.add(annotations.get(iAnnotation));
733
					iMatch++;
734
					iAnnotation++;
735
				} else {
736
					iAnnotation++;
737
				}
738
			}
739
		}
740

  
741
		while (annotsList.size() < matches.size() ) annotsList.add(null); // fill matches that were not process due to no more annotations
742

  
743
		return annotsList;
744
	}
745

  
746
	private HashMap<Match, Annotation> prepareAnnotationsMap(List<Match> matches, List<Annotation> annots, boolean overlap){
747
		HashMap<Match, Annotation> annotsList = new HashMap<Match, Annotation>();
748
		for(Match m : matches){
749
			boolean hasAnnotations = false;
750
			if(annots!=null){
751
				if(!annots.isEmpty()){
752
					for(Annotation annot : annots) {
753
						if(overlap){
754
							if ((annot.getStart() <= m.getStart() && m.getStart() <= annot.getEnd() && m.getEnd() >= annot.getEnd()) || 
755
									(annot.getStart() <= m.getEnd() && m.getEnd() <= annot.getEnd() && m.getStart() <= annot.getStart()) 
756
									|| !(annot.getEnd() < m.getStart() || annot.getStart() > m.getEnd())){
757
								annotsList.put(m, annot);
758
								hasAnnotations = true;
759
							}
760
						}else {
761
							if(annot.getStart()==m.getStart() && annot.getEnd()==m.getEnd()){
762
								annotsList.put(m, annot); 
763
								hasAnnotations = true;
764
							}
765
						}
766
					}
767
				}
768
			}
769
			if(!hasAnnotations){
770
				annotsList.put(m, null);
771
			}
772
		}
773
		return annotsList;
774
	}
775

  
776
	private String findAnnotationForLine(Match match, List<Annotation> annots, boolean overlap){
777
		String annotationValue = "";
778
		if(annots!=null){
779
			if(!annots.isEmpty()){
780
				for(Annotation annot : annots){
781
					if(overlap){
782
						if((annot.getStart()<=match.getStart() && annot.getEnd()>=match.getEnd()) || (annot.getStart()>match.getStart() && annot.getEnd()<match.getEnd())
783
								){
784
							annotationValue = annot.getValue(); 
785
							// use the first Annotation found, the one stored in the temporary HSQL database
786
							//should be modified to display a list of annotation values corresponding to the match positions (or wrapped if overlap is admitted)
787
						}
788
					}else {
789
						if(annot.getStart()==match.getStart() && annot.getEnd()==match.getEnd()){
790
							annotationValue = annot.getValue(); 
791
							// use the first Annotation found, the one stored in the temporary HSQL database
792
						}
793
					}
794
				}
795
			}
796
		}
797
		return annotationValue;
798
	}
799

  
800
	/**
801
	 * Gets the number of lines.
802
	 * 
803
	 * @return the n lines
804
	 */
805
	public int getNLines() {
806
		return nLines;
807
	}
808

  
809
	/**
810
	 * Sort the lines of the concordance according a comparator.
811
	 * 
812
	 * @param comparator
813
	 *            the comparator used to compare the lines
814
	 * 
815
	 * @throws CqiClientException
816
	 *             the cqi client exception
817
	 * @throws CqiServerError 
818
	 * @throws IOException 
819
	 */
820
	public void sort(LineComparator comparator) throws CqiClientException, IOException, CqiServerError {
821
		System.currentTimeMillis();
822
		this.acquireSemaphore();
823
		comparator.initialize(corpus);
824
		this.releaseSemaphore();
825
		if (getNLines() == 0) return;
826
		getLines(0, nLines - 1);
827
		if (lines.size() > 0) {
828
			Collections.sort(lines, comparator);
829
		}
830
		System.currentTimeMillis();
831
	}
832

  
833
	/**
834
	 * Write all the lines on a writer.
835
	 *
836
	 * @param outfile the outfile
837
	 * @param encoding the encoding
838
	 * @param colseparator the colseparator
839
	 * @param txtseparator the txtseparator
840
	 * @return true, if successful
841
	 * @throws IOException 
842
	 */
843
	public boolean toTxt(File outfile, String encoding, String colseparator, String txtseparator) throws IOException {
844

  
845
		// NK: writer declared as class attribute to perform a clean if the operation is interrupted
846
		try {
847
			this.writer = new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(outfile)), encoding);
848
			// if ("UTF-8".equals(encoding)) writer.write('\ufeff'); // UTF-8 BOM
849
			toTxt(writer, 0, nLines - 1, colseparator, txtseparator);
850
		} catch (UnsupportedEncodingException e) {
851
			// TODO Auto-generated catch block
852
			org.txm.utils.logger.Log.printStackTrace(e);
853
		} catch (Exception e) {
854
			System.err.println(ConcordanceMessages.Concordance_12 + e);
855
			Log.printStackTrace(e);
856
			return false;
857
		} 
858

  
859
		return true;
860
	}
861

  
862
	/**
863
	 * To txt.
864
	 *
865
	 * @param outfile the outfile
866
	 * @param format the format
867
	 * @return true, if successful
868
	 */
869
	public boolean toTxt(File outfile, Format format) {
870
		try {
871
			this.writer = new BufferedWriter(new OutputStreamWriter(
872
					new FileOutputStream(outfile), "UTF-8")); //$NON-NLS-1$
873
			toTxt(writer, 0, nLines - 1, format, "\t",""); //$NON-NLS-1$ //$NON-NLS-2$
874
		} catch (Exception e) {
875
			System.err.println(ConcordanceMessages.Concordance_12 + e);
876
			Log.printStackTrace(e);
877
			return false;
878
		}
879
		return true;
880
	}
881

  
882
	/**
883
	 * Write the lines between from and to on a writer.
884
	 * 
885
	 * @param writer
886
	 *            Where to write the lines
887
	 * @param from
888
	 *            The first line to be written
889
	 * @param to
890
	 *            The last line to be writen
891
	 * 
892
	 * @throws CqiClientException
893
	 *             the cqi client exception
894
	 * @throws IOException
895
	 *             Signals that an I/O exception has occurred.
896
	 * @throws CqiServerError 
897
	 */
898
	public void toTxt(Writer writer, int from, int to)
899
			throws CqiClientException, IOException, CqiServerError {
900

  
901
		toTxt(writer, from, to, Format.CONCORDANCE, "\t", ""); //$NON-NLS-1$ //$NON-NLS-2$
902
	}
903

  
904
	/**
905
	 * Write the lines between from and to on a writer with custom col and txt separators.
906
	 * 
907
	 * @param writer
908
	 *            Where to write the lines
909
	 * @param from
910
	 *            The first line to be written
911
	 * @param to
912
	 *            The last line to be writen
913
	 * @param colseparator
914
	 * 			  The column separator
915
	 * @param txtseparator
916
	 * 			  Thx text separator, e.g txtseparator=' : "I'm" >> "I''m"
917
	 * 
918
	 * @throws CqiClientException
919
	 *             the cqi client exception
920
	 * @throws IOException
921
	 *             Signals that an I/O exception has occurred.
922
	 * @throws CqiServerError 
923
	 */
924
	public void toTxt(Writer writer, int from, int to, String colseparator, String txtseparator)
925
			throws CqiClientException, IOException, CqiServerError {
926

  
927
		toTxt(writer, from, to, Format.CONCORDANCE, colseparator, txtseparator);
928
	}
929

  
930
	/**
931
	 * Adds the txt sep.
932
	 *
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff