Révision 449
tmp/org.txm.searchengine.cqp.core/plugin.xml (revision 449) | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<?eclipse version="3.4"?> |
|
3 |
<plugin> |
|
4 |
<extension |
|
5 |
point="org.txm.searchengine.core.SearchEngine"> |
|
6 |
<SearchEngine |
|
7 |
class="org.txm.searchengine.cqp.CQPEngine"> |
|
8 |
</SearchEngine> |
|
9 |
</extension> |
|
10 |
|
|
11 |
|
|
12 |
</plugin> |
|
0 | 13 |
tmp/org.txm.searchengine.cqp.core/.settings/org.eclipse.jdt.core.prefs (revision 449) | ||
---|---|---|
1 |
eclipse.preferences.version=1 |
|
2 |
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled |
|
3 |
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 |
|
4 |
org.eclipse.jdt.core.compiler.compliance=1.7 |
|
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.7 |
|
0 | 8 |
tmp/org.txm.searchengine.cqp.core/.classpath (revision 449) | ||
---|---|---|
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.7"/> |
|
4 |
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"> |
|
5 |
<accessrules> |
|
6 |
<accessrule kind="accessible" pattern="**"/> |
|
7 |
</accessrules> |
|
8 |
</classpathentry> |
|
9 |
<classpathentry kind="src" path="src"/> |
|
10 |
<classpathentry kind="output" path="bin"/> |
|
11 |
</classpath> |
|
0 | 12 |
tmp/org.txm.searchengine.cqp.core/META-INF/MANIFEST.MF (revision 449) | ||
---|---|---|
1 |
Manifest-Version: 1.0 |
|
2 |
Bundle-ManifestVersion: 2 |
|
3 |
Bundle-Name: CQP |
|
4 |
Bundle-SymbolicName: org.txm.searchengine.cqp.core;singleton:=true |
|
5 |
Bundle-Version: 1.1.0.qualifier |
|
6 |
Require-Bundle: org.eclipse.ui, |
|
7 |
org.eclipse.core.runtime, |
|
8 |
org.txm.core;bundle-version="0.7.0", |
|
9 |
org.txm.searchengine.core;bundle-version="1.0.0", |
|
10 |
org.txm.libs.cqp;bundle-version="1.0.0" |
|
11 |
Bundle-RequiredExecutionEnvironment: JavaSE-1.6 |
|
12 |
Bundle-ClassPath: res/, |
|
13 |
. |
|
14 |
Bundle-Vendor: Textometrie.org |
|
15 |
Export-Package: org.txm.functions.diagnostic, |
|
16 |
org.txm.functions.internal, |
|
17 |
org.txm.functions.preview, |
|
18 |
org.txm.functions.selection, |
|
19 |
org.txm.functions.summary, |
|
20 |
org.txm.importer.cwb, |
|
21 |
org.txm.searchengine.cqp, |
|
22 |
org.txm.searchengine.cqp.clientExceptions, |
|
23 |
org.txm.searchengine.cqp.corpus, |
|
24 |
org.txm.searchengine.cqp.corpus.query, |
|
25 |
org.txm.searchengine.cqp.serverException, |
|
26 |
org.txm.test |
|
0 | 27 |
tmp/org.txm.searchengine.cqp.core/.project (revision 449) | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<projectDescription> |
|
3 |
<name>org.txm.searchengine.cqp.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 |
tmp/org.txm.searchengine.cqp.core/src/cwbinstaller/Activator.java (revision 449) | ||
---|---|---|
1 |
package cwbinstaller; |
|
2 |
|
|
3 |
import org.eclipse.jface.resource.ImageDescriptor; |
|
4 |
import org.eclipse.ui.plugin.AbstractUIPlugin; |
|
5 |
import org.osgi.framework.BundleContext; |
|
6 |
|
|
7 |
/** |
|
8 |
* The activator class controls the plug-in life cycle |
|
9 |
*/ |
|
10 |
public class Activator extends AbstractUIPlugin { |
|
11 |
|
|
12 |
// The plug-in ID |
|
13 |
public static final String PLUGIN_ID = "CQP"; //$NON-NLS-1$ |
|
14 |
|
|
15 |
// The shared instance |
|
16 |
private static Activator plugin; |
|
17 |
|
|
18 |
/** |
|
19 |
* The constructor |
|
20 |
*/ |
|
21 |
public Activator() { |
|
22 |
} |
|
23 |
|
|
24 |
/* |
|
25 |
* (non-Javadoc) |
|
26 |
* @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) |
|
27 |
*/ |
|
28 |
public void start(BundleContext context) throws Exception { |
|
29 |
super.start(context); |
|
30 |
plugin = this; |
|
31 |
} |
|
32 |
|
|
33 |
/* |
|
34 |
* (non-Javadoc) |
|
35 |
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) |
|
36 |
*/ |
|
37 |
public void stop(BundleContext context) throws Exception { |
|
38 |
plugin = null; |
|
39 |
super.stop(context); |
|
40 |
} |
|
41 |
|
|
42 |
/** |
|
43 |
* Returns the shared instance |
|
44 |
* |
|
45 |
* @return the shared instance |
|
46 |
*/ |
|
47 |
public static Activator getDefault() { |
|
48 |
return plugin; |
|
49 |
} |
|
50 |
|
|
51 |
/** |
|
52 |
* Returns an image descriptor for the image file at the given |
|
53 |
* plug-in relative path |
|
54 |
* |
|
55 |
* @param path the path |
|
56 |
* @return the image descriptor |
|
57 |
*/ |
|
58 |
public static ImageDescriptor getImageDescriptor(String path) { |
|
59 |
return imageDescriptorFromPlugin(PLUGIN_ID, path); |
|
60 |
} |
|
61 |
} |
|
0 | 62 |
tmp/org.txm.searchengine.cqp.core/src/cwbinstaller/commands/DoInstallStep.java (revision 449) | ||
---|---|---|
1 |
package cwbinstaller.commands; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
|
|
5 |
import org.eclipse.core.commands.ExecutionEvent; |
|
6 |
import org.eclipse.core.commands.ExecutionException; |
|
7 |
import org.eclipse.jface.util.Util; |
|
8 |
import org.osgi.framework.Version; |
|
9 |
import org.txm.core.preferences.TBXPreferences; |
|
10 |
import org.txm.core.preferences.TXMPreferences; |
|
11 |
import org.txm.utils.BundleUtils; |
|
12 |
import org.txm.utils.logger.Log; |
|
13 |
|
|
14 |
import cwbinstaller.CQPPreferences; |
|
15 |
|
|
16 |
public class DoInstallStep extends org.txm.rcp.commands.TxmCommand { |
|
17 |
protected String name = "cwbbinaries.commands.DoInstallStep"; //$NON-NLS-1$ |
|
18 |
|
|
19 |
@Override |
|
20 |
public Object execute(ExecutionEvent event) throws ExecutionException { |
|
21 |
// TODO Auto-generated method stub |
|
22 |
return null; |
|
23 |
} |
|
24 |
|
|
25 |
@Override |
|
26 |
public void install() { |
|
27 |
|
|
28 |
} |
|
29 |
|
|
30 |
@Override |
|
31 |
public void preInstall() { |
|
32 |
String CQPFRAGMENT = "CQP."+System.getProperty("osgi.os"); |
|
33 |
|
|
34 |
Log.info("CQP.DoInstallStep.install()"); |
|
35 |
String saved = TXMPreferences.getString(CQPPreferences.VERSION, CQPPreferences.PREFERENCES_NODE); |
|
36 |
Version currentVersion = BundleUtils.getBundleVersion(CQPFRAGMENT); // the CQPFRAGMENT plugin contains the right version |
|
37 |
|
|
38 |
if (saved != null && saved.length() > 0) { |
|
39 |
Version savedVersion = new Version(saved); |
|
40 |
if (currentVersion.compareTo(savedVersion) <= 0) { |
|
41 |
Log.info("No post-installation of CQP to do"); |
|
42 |
return; // nothing to do |
|
43 |
} |
|
44 |
} |
|
45 |
System.out.println("Updating CWB preferences for CQP version="+currentVersion); |
|
46 |
|
|
47 |
String os = "win"; |
|
48 |
String ext = ""; |
|
49 |
if (Util.isWindows()) { //$NON-NLS-1$ |
|
50 |
if (System.getProperty("os.arch").contains("64")) { os = "win64"; } |
|
51 |
else { os = "win32"; } |
|
52 |
ext = ".exe"; |
|
53 |
} else if (Util.isMac()) { //$NON-NLS-1$ |
|
54 |
os = "macosx"; |
|
55 |
} else { |
|
56 |
os = "linux32"; |
|
57 |
if (System.getProperty("os.arch").contains("64")) |
|
58 |
os = "linux64"; |
|
59 |
} |
|
60 |
|
|
61 |
File bundleDir = BundleUtils.getBundleFile(CQPFRAGMENT); |
|
62 |
if (bundleDir == null) { |
|
63 |
System.out.println("Error while retrieving TreeTaggerInstaller bundle directory."); |
|
64 |
return; |
|
65 |
} |
|
66 |
File cwbDir = new File(bundleDir, "res"); |
|
67 |
File initFile = new File(cwbDir, "cqpserver.init"); |
|
68 |
File OSDir = new File(cwbDir, os); |
|
69 |
File execFile = new File(OSDir, "cqpserver"+ext); |
|
70 |
|
|
71 |
TXMPreferences.putString(TBXPreferences.PREFERENCES_NODE, TBXPreferences.CQI_SERVER_PATH_TO_CQPLIB, OSDir.getAbsolutePath()); |
|
72 |
TXMPreferences.putString(TBXPreferences.PREFERENCES_NODE, TBXPreferences.CQI_SERVER_PATH_TO_INIT_FILE, initFile.getAbsolutePath()); |
|
73 |
TXMPreferences.putString(TBXPreferences.PREFERENCES_NODE, TBXPreferences.CQI_SERVER_PATH_TO_EXECUTABLE, execFile.getAbsolutePath()); |
|
74 |
if (!Util.isWindows()) { |
|
75 |
try { |
|
76 |
Log.info("Setting execution file rights to: "+OSDir.getAbsolutePath()); |
|
77 |
Runtime.getRuntime().exec("chmod -R +x "+OSDir.getAbsolutePath()).waitFor(); |
|
78 |
} catch (Exception e) { |
|
79 |
System.out.println("Error while setting execution file rights to: "+OSDir.getAbsolutePath()); |
|
80 |
e.printStackTrace(); |
|
81 |
} |
|
82 |
} |
|
83 |
|
|
84 |
if (!execFile.canExecute()) { |
|
85 |
System.out.println("File right setting error, cannot execute: "+execFile); |
|
86 |
} |
|
87 |
Log.warning("SearchEngine preferences set with: "+OSDir.getAbsolutePath()+ ", "+initFile.getAbsolutePath()+ " and "+execFile.getAbsolutePath()); |
|
88 |
TXMPreferences.putString(CQPPreferences.PREFERENCES_NODE, CQPPreferences.VERSION, currentVersion.toString()); |
|
89 |
} |
|
90 |
} |
|
0 | 91 |
tmp/org.txm.searchengine.cqp.core/src/cwbinstaller/CQPPreferences.java (revision 449) | ||
---|---|---|
1 |
package cwbinstaller; |
|
2 |
|
|
3 |
import org.eclipse.core.runtime.preferences.DefaultScope; |
|
4 |
import org.osgi.service.prefs.Preferences; |
|
5 |
import org.txm.core.preferences.TXMPreferences; |
|
6 |
|
|
7 |
public class CQPPreferences extends TXMPreferences { |
|
8 |
|
|
9 |
public static final String PREFERENCES_NODE = "cwbinstaller"; |
|
10 |
|
|
11 |
public static final String VERSION = "cwbinstaller.commands.version"; |
|
12 |
|
|
13 |
@Override |
|
14 |
public void initializeDefaultPreferences() { |
|
15 |
Preferences preferences = DefaultScope.INSTANCE.getNode(PREFERENCES_NODE); |
|
16 |
preferences.put(VERSION, "0.0"); |
|
17 |
} |
|
18 |
} |
|
0 | 19 |
tmp/org.txm.searchengine.cqp.core/src/org/txm/functions/internal/InternalView.java (revision 449) | ||
---|---|---|
1 |
package org.txm.functions.internal; |
|
2 |
|
|
3 |
import java.util.ArrayList; |
|
4 |
import java.util.Collection; |
|
5 |
import java.util.HashMap; |
|
6 |
import java.util.List; |
|
7 |
|
|
8 |
import org.txm.Toolbox; |
|
9 |
import org.txm.core.messages.TXMCoreMessages; |
|
10 |
import org.txm.core.results.TXMResult; |
|
11 |
import org.txm.searchengine.cqp.CQPEngine; |
|
12 |
import org.txm.searchengine.cqp.clientExceptions.CqiClientException; |
|
13 |
import org.txm.searchengine.cqp.corpus.Corpus; |
|
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.query.Match; |
|
18 |
import org.txm.searchengine.cqp.corpus.query.Query; |
|
19 |
|
|
20 |
public class InternalView extends TXMResult { |
|
21 |
Corpus corpus; |
|
22 |
List<Property> properties; |
|
23 |
StructuralUnit struct; |
|
24 |
List<Property> structProperties; |
|
25 |
|
|
26 |
int currentStruct = -1; |
|
27 |
int nmatches = 0; |
|
28 |
List<Match> matches = new ArrayList<Match>(); |
|
29 |
|
|
30 |
|
|
31 |
public InternalView(Corpus corpus, List<Property> properties, StructuralUnit struct, List<Property> structProperties) throws CqiClientException { |
|
32 |
this.corpus = corpus; |
|
33 |
this.properties = properties; |
|
34 |
this.struct = struct; |
|
35 |
this.structProperties = structProperties; |
|
36 |
|
|
37 |
//find struct start-end |
|
38 |
Query query = new Query("<"+struct.getName()+"> [] expand to "+struct); //$NON-NLS-1$ //$NON-NLS-2$ |
|
39 |
//System.out.println(query); |
|
40 |
QueryResult result = corpus.query(query, "test", false); //$NON-NLS-1$ |
|
41 |
nmatches = result.getNMatch(); |
|
42 |
if (nmatches > 0) { |
|
43 |
matches = result.getMatches(); |
|
44 |
} |
|
45 |
result.drop(); |
|
46 |
//System.out.println(matches); |
|
47 |
} |
|
48 |
|
|
49 |
public String getStructInfos() { |
|
50 |
|
|
51 |
try { |
|
52 |
if (structProperties.size() > 0) { |
|
53 |
String str = TXMCoreMessages.InternalView_3; |
|
54 |
for (Property sup : structProperties) { |
|
55 |
int[] array = {getCurrentSegmentNo()}; |
|
56 |
str += " "+sup.getName()+"="+CQPEngine.getCqiClient().struc2Str(sup.getQualifiedName(), array)[0]; //$NON-NLS-1$ //$NON-NLS-2$ |
|
57 |
} |
|
58 |
return str; |
|
59 |
} |
|
60 |
} catch (Exception e) { |
|
61 |
System.out.println(TXMCoreMessages.InternalView_6+e.getMessage()); |
|
62 |
org.txm.utils.logger.Log.printStackTrace(e); |
|
63 |
} |
|
64 |
return TXMCoreMessages.InternalView_7; |
|
65 |
} |
|
66 |
|
|
67 |
public HashMap<Property, List<String>> getNext() throws CqiClientException { |
|
68 |
int next = currentStruct + 1; |
|
69 |
if (next < nmatches) { |
|
70 |
return getSegment(next); |
|
71 |
} |
|
72 |
return new HashMap<Property, List<String>>(); |
|
73 |
} |
|
74 |
|
|
75 |
public HashMap<Property, List<String>> getPrevious() throws CqiClientException { |
|
76 |
int previous = currentStruct - 1; |
|
77 |
if (previous >= 0 && previous < nmatches) { |
|
78 |
return getSegment(previous); |
|
79 |
} |
|
80 |
return new HashMap<Property, List<String>>(); |
|
81 |
} |
|
82 |
|
|
83 |
public HashMap<Property, List<String>> getFirst() throws CqiClientException { |
|
84 |
if (0 < nmatches) { |
|
85 |
return getSegment(0); |
|
86 |
} |
|
87 |
return new HashMap<Property, List<String>>(); |
|
88 |
} |
|
89 |
|
|
90 |
public HashMap<Property, List<String>> getLast() throws CqiClientException { |
|
91 |
if (nmatches - 1 >= 0) { |
|
92 |
return getSegment(nmatches - 1); |
|
93 |
} |
|
94 |
return new HashMap<Property, List<String>>(); |
|
95 |
} |
|
96 |
|
|
97 |
public HashMap<Property, List<String>> getSegment(int i) throws CqiClientException { |
|
98 |
HashMap<Property, List<String>> rez = new HashMap<Property, List<String>>(); |
|
99 |
|
|
100 |
if (i >= 0 && i < nmatches) { |
|
101 |
Match m = matches.get(i); |
|
102 |
Collection<? extends Integer> positions = m.getRange(); |
|
103 |
int[] p = new int[positions.size()]; |
|
104 |
int c = 0; |
|
105 |
for(int v : positions) p[c++] = v; |
|
106 |
for (Property prop : properties) { |
|
107 |
rez.put(prop, Match.getValuesForProperty(prop, p)); |
|
108 |
} |
|
109 |
currentStruct = i; |
|
110 |
} |
|
111 |
return rez; |
|
112 |
} |
|
113 |
|
|
114 |
public void printNext() throws CqiClientException { |
|
115 |
HashMap<Property, List<String>> seg = getNext(); |
|
116 |
if (seg.size() > 0) |
|
117 |
System.out.println(seg); |
|
118 |
} |
|
119 |
|
|
120 |
public void printPrevious() throws CqiClientException { |
|
121 |
HashMap<Property, List<String>> seg = getPrevious(); |
|
122 |
if (seg.size() > 0) |
|
123 |
System.out.println(seg); |
|
124 |
} |
|
125 |
|
|
126 |
public void printSeg(HashMap<Property, List<String>> seg) { |
|
127 |
Collection<List<String>> values = seg.values(); |
|
128 |
if(values.size() == 0) return; |
|
129 |
|
|
130 |
for(List<String> list : values) { |
|
131 |
for(String value : list) |
|
132 |
System.out.print("\t"+value); //$NON-NLS-1$ |
|
133 |
System.out.println(); |
|
134 |
} |
|
135 |
System.out.println(); |
|
136 |
} |
|
137 |
|
|
138 |
public Corpus getCorpus() { |
|
139 |
return corpus; |
|
140 |
} |
|
141 |
|
|
142 |
public StructuralUnit getStructuralUnit() { |
|
143 |
return struct; |
|
144 |
} |
|
145 |
|
|
146 |
public List<Property> getProperties() { |
|
147 |
return properties; |
|
148 |
} |
|
149 |
|
|
150 |
public int getCurrentSegmentNo() { |
|
151 |
return currentStruct; |
|
152 |
} |
|
153 |
|
|
154 |
public int getNSegment() { |
|
155 |
return nmatches; |
|
156 |
} |
|
157 |
|
|
158 |
public int getSegmentLength() { |
|
159 |
if (matches.size() == 0) return 0; |
|
160 |
Match m = matches.get(currentStruct); |
|
161 |
return m.size(); |
|
162 |
} |
|
163 |
|
|
164 |
public boolean isFirst() { |
|
165 |
return currentStruct == 0; |
|
166 |
} |
|
167 |
|
|
168 |
public boolean isLast() { |
|
169 |
return currentStruct == nmatches - 1; |
|
170 |
} |
|
171 |
|
|
172 |
public String getLocationTail() { |
|
173 |
return " / "+nmatches; //$NON-NLS-1$ |
|
174 |
} |
|
175 |
|
|
176 |
public String getCurrentLocation() { |
|
177 |
return ""+(currentStruct+1); //$NON-NLS-1$ |
|
178 |
} |
|
179 |
|
|
180 |
public String getDetails() { |
|
181 |
// TODO Auto-generated method stub |
|
182 |
return corpus.getName()+" "+struct.getName()+" "+(currentStruct+1); //$NON-NLS-1$ //$NON-NLS-2$ |
|
183 |
} |
|
184 |
|
|
185 |
public void setProperties(List<Property> properties2) { |
|
186 |
this.properties = properties2; |
|
187 |
} |
|
188 |
|
|
189 |
public void setStructProperties(List<Property> properties2) { |
|
190 |
this.structProperties = properties2; |
|
191 |
} |
|
192 |
|
|
193 |
@Override |
|
194 |
public String getName() { |
|
195 |
// TODO Auto-generated method stub |
|
196 |
return null; |
|
197 |
} |
|
198 |
|
|
199 |
@Override |
|
200 |
public String getSimpleName() { |
|
201 |
// TODO Auto-generated method stub |
|
202 |
return null; |
|
203 |
} |
|
204 |
|
|
205 |
@Override |
|
206 |
public void clean() { |
|
207 |
// TODO Auto-generated method stub |
|
208 |
|
|
209 |
} |
|
210 |
} |
|
0 | 211 |
tmp/org.txm.searchengine.cqp.core/src/org/txm/functions/internal/package.html (revision 449) | ||
---|---|---|
1 |
<html> |
|
2 |
<body> |
|
3 |
<p>Internal view</p> |
|
4 |
</body> |
|
5 |
</html> |
|
0 | 6 |
tmp/org.txm.searchengine.cqp.core/src/org/txm/functions/summary/Summary.java (revision 449) | ||
---|---|---|
1 |
package org.txm.functions.summary; |
|
2 |
|
|
3 |
import java.io.IOException; |
|
4 |
import java.util.ArrayList; |
|
5 |
import java.util.Arrays; |
|
6 |
|
|
7 |
import org.txm.Toolbox; |
|
8 |
import org.txm.core.messages.TXMCoreMessages; |
|
9 |
import org.txm.core.results.TXMResult; |
|
10 |
import org.txm.objects.Edition; |
|
11 |
import org.txm.objects.Page; |
|
12 |
import org.txm.objects.Text; |
|
13 |
import org.txm.searchengine.cqp.CQPEngine; |
|
14 |
import org.txm.searchengine.cqp.clientExceptions.CqiClientException; |
|
15 |
import org.txm.searchengine.cqp.corpus.MainCorpus; |
|
16 |
import org.txm.searchengine.cqp.corpus.Property; |
|
17 |
import org.txm.searchengine.cqp.corpus.QueryResult; |
|
18 |
import org.txm.searchengine.cqp.corpus.StructuralUnitProperty; |
|
19 |
import org.txm.searchengine.cqp.corpus.query.Query; |
|
20 |
import org.txm.searchengine.cqp.serverException.CqiServerError; |
|
21 |
|
|
22 |
public class Summary extends TXMResult { |
|
23 |
MainCorpus corpus; |
|
24 |
TreeNode treenodes = new TreeNode("root"); //$NON-NLS-1$ |
|
25 |
private ArrayList<StructuralUnitProperty> properties; |
|
26 |
|
|
27 |
public Summary(MainCorpus corpus) |
|
28 |
{ |
|
29 |
this.corpus = corpus; |
|
30 |
} |
|
31 |
|
|
32 |
public TreeNode getRoot() |
|
33 |
{ |
|
34 |
return treenodes; |
|
35 |
} |
|
36 |
|
|
37 |
public boolean init(ArrayList<StructuralUnitProperty> properties) throws CqiClientException, IOException, CqiServerError |
|
38 |
{ |
|
39 |
this.properties = properties; |
|
40 |
treenodes.end = corpus.getSize(); |
|
41 |
treenodes.id = corpus.getName(); |
|
42 |
treenodes.start = 0; |
|
43 |
treenodes.parent = null; |
|
44 |
// get all type of structures |
|
45 |
for (int j = 0 ; j < properties.size() ; j++) { |
|
46 |
String suname = properties.get(j).getStructuralUnit().getName(); |
|
47 |
//System.out.println("getting : "+properties.get(j).getFullName()); |
|
48 |
|
|
49 |
QueryResult result = corpus.query(new Query("<"+properties.get(j).getFullName()+">[]"), "summary", false); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
|
50 |
int[] starts = result.getStarts(); |
|
51 |
result.drop(); |
|
52 |
result = corpus.query(new Query("[]</"+properties.get(j).getFullName()+">"), "summary", false); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
|
53 |
int[] ends = result.getStarts(); |
|
54 |
result.drop(); |
|
55 |
//System.out.println("starts: "+Arrays.toString(starts)); |
|
56 |
//System.out.println("ends: "+Arrays.toString(ends)); |
|
57 |
int[] strcutpos = CQPEngine.getCqiClient().cpos2Struc(properties.get(j).getQualifiedName(), starts); |
|
58 |
String[] infos = CQPEngine.getCqiClient().struc2Str(properties.get(j).getQualifiedName(), strcutpos); |
|
59 |
//allMatches.put(suname, list); |
|
60 |
if (starts.length != ends.length) { |
|
61 |
System.out.println(suname+": starts.length "+starts.length+" != ends.length "+ends.length); //$NON-NLS-1$ //$NON-NLS-2$ |
|
62 |
return false; |
|
63 |
} |
|
64 |
for (int i = 0 ; i < starts.length ; i++) { |
|
65 |
//System.out.println("suname: "+suname+" start: "+m.getStart()); |
|
66 |
TreeNode node = new TreeNode(); |
|
67 |
node.start = starts[i]; |
|
68 |
node.end = ends[i]; |
|
69 |
node.struct = suname; |
|
70 |
node.id = infos[i]; |
|
71 |
treenodes.add(node); |
|
72 |
} |
|
73 |
} |
|
74 |
//this.print(); |
|
75 |
|
|
76 |
//System.out.println("sorting... "+treenodes.size()+" nodes"); |
|
77 |
processNodeList(treenodes); |
|
78 |
|
|
79 |
//System.out.println("checking result..."+treenodes.size()+" nodes"); |
|
80 |
if (treenodes.check()) |
|
81 |
return true; |
|
82 |
else |
|
83 |
return false; |
|
84 |
} |
|
85 |
|
|
86 |
private void processNodeList(TreeNode nodes) |
|
87 |
{ |
|
88 |
//System.out.println("+processing node list: "+nodes.size()); |
|
89 |
if (nodes.size() == 0) |
|
90 |
return; |
|
91 |
|
|
92 |
// 1st loop |
|
93 |
//System.out.println("1st loop: "+nodes.size()); |
|
94 |
for (int i = 0 ; i < nodes.size() ; i++) { |
|
95 |
TreeNode node = nodes.get(i); |
|
96 |
if (node.end == -1) |
|
97 |
System.out.println("ERROR: node.end = -1"); //$NON-NLS-1$ |
|
98 |
for (int j = 0 ; j < nodes.size() ; j++) { |
|
99 |
if (j != i) { |
|
100 |
TreeNode n2 = nodes.get(j); |
|
101 |
if (n2.start >= node.start && n2.end <= node.end) { |
|
102 |
n2.parent = node; |
|
103 |
node.add(n2); |
|
104 |
nodes.remove(j); |
|
105 |
j--; |
|
106 |
if (j < i) |
|
107 |
i--; |
|
108 |
} |
|
109 |
} |
|
110 |
} |
|
111 |
} |
|
112 |
|
|
113 |
//process sublists |
|
114 |
//System.out.println("processing sublists: "+nodes.size()); |
|
115 |
for (int i = 0 ; i < nodes.size() ; i++) { |
|
116 |
TreeNode node = nodes.get(i); |
|
117 |
processNodeList(node); |
|
118 |
} |
|
119 |
} |
|
120 |
|
|
121 |
public ArrayList<StructuralUnitProperty> getProperties() |
|
122 |
{ |
|
123 |
return properties; |
|
124 |
} |
|
125 |
|
|
126 |
public void print() |
|
127 |
{ |
|
128 |
for (TreeNode node : treenodes) |
|
129 |
System.out.println("\n"+node); //$NON-NLS-1$ |
|
130 |
} |
|
131 |
|
|
132 |
|
|
133 |
public Page getDefaultEditionPage(TreeNode node) throws Exception |
|
134 |
{ |
|
135 |
StructuralUnitProperty text_id = corpus.getStructuralUnit("text").getProperty("id"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
136 |
Property w_id = corpus.getProperty("id"); //$NON-NLS-1$ |
|
137 |
int[] positions = {node.getStart()}; |
|
138 |
final String[] wordids = CQPEngine.getCqiClient().cpos2Str(w_id.getQualifiedName(), positions); |
|
139 |
int[] textidstruct = CQPEngine.getCqiClient().cpos2Struc(text_id.getQualifiedName(), positions); |
|
140 |
String[] textids = CQPEngine.getCqiClient().struc2Str(text_id.getQualifiedName(), textidstruct); |
|
141 |
|
|
142 |
if (wordids.length == 1 && textids.length == 1) { |
|
143 |
Text text = corpus.getText(textids[0]); |
|
144 |
if (text == null) { |
|
145 |
System.out.println(TXMCoreMessages.Summary_13+textids[0]+TXMCoreMessages.Summary_14); |
|
146 |
return null; |
|
147 |
} |
|
148 |
|
|
149 |
Edition edition = text.getEdition("default"); //$NON-NLS-1$ |
|
150 |
if (edition == null) { |
|
151 |
if (text.getEditions().size() == 0) { |
|
152 |
System.out.println("No edition for text: "+text); |
|
153 |
} else { |
|
154 |
for (Edition ed : text.getEditions()) { |
|
155 |
edition = ed; |
|
156 |
break; |
|
157 |
} |
|
158 |
} |
|
159 |
} |
|
160 |
if (edition == null) { |
|
161 |
System.out.println(TXMCoreMessages.Summary_15); |
|
162 |
return null; |
|
163 |
} |
|
164 |
|
|
165 |
node.wordid = wordids[0]; |
|
166 |
return edition.getPageForWordId(wordids[0]); |
|
167 |
} else { |
|
168 |
System.out.println(TXMCoreMessages.Summary_16+Arrays.toString(textids)+TXMCoreMessages.Summary_17+Arrays.toString(wordids)); |
|
169 |
return null; |
|
170 |
} |
|
171 |
} |
|
172 |
|
|
173 |
public class TreeNode extends ArrayList<TreeNode> |
|
174 |
{ |
|
175 |
/** |
|
176 |
* |
|
177 |
*/ |
|
178 |
private static final long serialVersionUID = 1L; |
|
179 |
|
|
180 |
public TreeNode parent; |
|
181 |
boolean leaf = false; |
|
182 |
String struct; |
|
183 |
String id; |
|
184 |
int start = -1; |
|
185 |
int end = -1; |
|
186 |
public String wordid; |
|
187 |
|
|
188 |
public TreeNode() |
|
189 |
{ |
|
190 |
|
|
191 |
} |
|
192 |
|
|
193 |
public boolean check() { |
|
194 |
for (TreeNode node : this) { |
|
195 |
if(node.start >= this.start && node.end <= this.end && (node.end-node.start) < (this.end-this.start)) |
|
196 |
return node.check(); |
|
197 |
else |
|
198 |
return false; |
|
199 |
} |
|
200 |
return true; |
|
201 |
} |
|
202 |
|
|
203 |
|
|
204 |
public TreeNode(String struct) { |
|
205 |
this(); |
|
206 |
this.struct = struct; |
|
207 |
} |
|
208 |
|
|
209 |
@Override |
|
210 |
public String toString() |
|
211 |
{ |
|
212 |
String str = struct+"("+start+", "+end+")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
|
213 |
if(size() > 0) |
|
214 |
str +="\n\t"+super.toString(); //$NON-NLS-1$ |
|
215 |
return str; |
|
216 |
} |
|
217 |
|
|
218 |
public TreeNode getParent() |
|
219 |
{ |
|
220 |
return parent; |
|
221 |
} |
|
222 |
|
|
223 |
public String getInfo() { |
|
224 |
return id; |
|
225 |
} |
|
226 |
|
|
227 |
public int getStart() { |
|
228 |
return start; |
|
229 |
} |
|
230 |
|
|
231 |
public String getWordId() { |
|
232 |
return wordid; |
|
233 |
} |
|
234 |
} |
|
235 |
|
|
236 |
@Override |
|
237 |
public String getName() { |
|
238 |
// TODO Auto-generated method stub |
|
239 |
return null; |
|
240 |
} |
|
241 |
|
|
242 |
@Override |
|
243 |
public String getSimpleName() { |
|
244 |
// TODO Auto-generated method stub |
|
245 |
return null; |
|
246 |
} |
|
247 |
|
|
248 |
@Override |
|
249 |
public String getDetails() { |
|
250 |
// TODO Auto-generated method stub |
|
251 |
return null; |
|
252 |
} |
|
253 |
|
|
254 |
@Override |
|
255 |
public void clean() { |
|
256 |
// TODO Auto-generated method stub |
|
257 |
|
|
258 |
} |
|
259 |
} |
|
0 | 260 |
tmp/org.txm.searchengine.cqp.core/src/org/txm/functions/preview/package.html (revision 449) | ||
---|---|---|
1 |
<html> |
|
2 |
<body> |
|
3 |
<p>Prototype of Preview functionnaly: shows the begining of a corpus or a partition.</p> |
|
4 |
</body> |
|
5 |
</html> |
|
0 | 6 |
tmp/org.txm.searchengine.cqp.core/src/org/txm/functions/preview/Preview.java (revision 449) | ||
---|---|---|
1 |
package org.txm.functions.preview; |
|
2 |
|
|
3 |
import java.util.Collection; |
|
4 |
import java.util.List; |
|
5 |
|
|
6 |
import org.txm.core.results.TXMResult; |
|
7 |
import org.txm.searchengine.cqp.corpus.Corpus; |
|
8 |
import org.txm.searchengine.cqp.corpus.Partition; |
|
9 |
import org.txm.searchengine.cqp.corpus.Property; |
|
10 |
import org.txm.searchengine.cqp.corpus.query.Match; |
|
11 |
|
|
12 |
public class Preview extends TXMResult { |
|
13 |
private Corpus corpus; |
|
14 |
private Partition partition; |
|
15 |
private Property prop; |
|
16 |
|
|
17 |
private int n; |
|
18 |
|
|
19 |
public Preview(Corpus corpus, Property prop, int n) { |
|
20 |
this.corpus = corpus; |
|
21 |
this.prop = prop; |
|
22 |
this.n = n; |
|
23 |
} |
|
24 |
|
|
25 |
public Preview(Partition partition, Property prop, int n) { |
|
26 |
this.partition = partition; |
|
27 |
this.prop = prop; |
|
28 |
this.n = n; |
|
29 |
} |
|
30 |
|
|
31 |
public boolean compute() { |
|
32 |
if (partition != null) { |
|
33 |
return computePartition(); |
|
34 |
} else { |
|
35 |
return computeCorpus(); |
|
36 |
} |
|
37 |
} |
|
38 |
|
|
39 |
protected boolean computeCorpus() { |
|
40 |
boolean ok = false; |
|
41 |
|
|
42 |
return ok; |
|
43 |
} |
|
44 |
|
|
45 |
protected boolean computePartition() { |
|
46 |
boolean ok = false; |
|
47 |
List<Match> matches = corpus.getMatches(); |
|
48 |
for (Match m : matches) { |
|
49 |
if (m.getLength() >= n) { |
|
50 |
ok = true; |
|
51 |
} |
|
52 |
} |
|
53 |
return ok; |
|
54 |
} |
|
55 |
|
|
56 |
private String getLine(Corpus corpus) { |
|
57 |
List<Match> matches = corpus.getMatches(); |
|
58 |
if (matches.size() == 0) return ""; //$NON-NLS-1$ |
|
59 |
|
|
60 |
Match firstOkMatch = matches.get(0); |
|
61 |
for (Match m : matches) { |
|
62 |
if (m.getLength() >= n) { |
|
63 |
Collection<? extends Integer> positions = m.getRange(); |
|
64 |
|
|
65 |
} |
|
66 |
} |
|
67 |
return "";//getString(firstOkMatch); //$NON-NLS-1$ |
|
68 |
} |
|
69 |
|
|
70 |
@Override |
|
71 |
public String getName() { |
|
72 |
// TODO Auto-generated method stub |
|
73 |
return null; |
|
74 |
} |
|
75 |
|
|
76 |
@Override |
|
77 |
public String getSimpleName() { |
|
78 |
// TODO Auto-generated method stub |
|
79 |
return null; |
|
80 |
} |
|
81 |
|
|
82 |
@Override |
|
83 |
public String getDetails() { |
|
84 |
// TODO Auto-generated method stub |
|
85 |
return null; |
|
86 |
} |
|
87 |
|
|
88 |
@Override |
|
89 |
public void clean() { |
|
90 |
// TODO Auto-generated method stub |
|
91 |
|
|
92 |
} |
|
93 |
} |
|
0 | 94 |
tmp/org.txm.searchengine.cqp.core/src/org/txm/functions/diagnostic/Diagnostic.java (revision 449) | ||
---|---|---|
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-09-19 10:31:00 +0200 (Mon, 19 Sep 2016) $ |
|
25 |
// $LastChangedRevision: 3298 $ |
|
26 |
// $LastChangedBy: mdecorde $ |
|
27 |
// |
|
28 |
package org.txm.functions.diagnostic; |
|
29 |
|
|
30 |
import java.io.BufferedWriter; |
|
31 |
import java.io.File; |
|
32 |
import java.io.FileNotFoundException; |
|
33 |
import java.io.FileOutputStream; |
|
34 |
import java.io.IOException; |
|
35 |
import java.io.OutputStreamWriter; |
|
36 |
import java.io.UnsupportedEncodingException; |
|
37 |
import java.util.ArrayList; |
|
38 |
import java.util.Collections; |
|
39 |
import java.util.HashMap; |
|
40 |
import java.util.LinkedHashSet; |
|
41 |
import java.util.List; |
|
42 |
import java.util.Locale; |
|
43 |
|
|
44 |
import org.eclipse.osgi.util.NLS; |
|
45 |
import org.txm.core.messages.TXMCoreMessages; |
|
46 |
import org.txm.functions.Function; |
|
47 |
import org.txm.objects.Base; |
|
48 |
import org.txm.searchengine.cqp.AbstractCqiClient; |
|
49 |
import org.txm.searchengine.cqp.clientExceptions.CqiClientException; |
|
50 |
import org.txm.searchengine.cqp.corpus.Corpus; |
|
51 |
import org.txm.searchengine.cqp.corpus.CorpusManager; |
|
52 |
import org.txm.searchengine.cqp.corpus.Part; |
|
53 |
import org.txm.searchengine.cqp.corpus.Partition; |
|
54 |
import org.txm.searchengine.cqp.corpus.Property; |
|
55 |
import org.txm.searchengine.cqp.corpus.StructuralUnit; |
|
56 |
import org.txm.searchengine.cqp.corpus.StructuralUnitProperty; |
|
57 |
import org.txm.utils.logger.Log; |
|
58 |
|
|
59 |
// TODO: Auto-generated Javadoc |
|
60 |
/** |
|
61 |
* compute a diagnostic of Corpus, sub corpus and partition @ author mdecorde. |
|
62 |
*/ |
|
63 |
public class Diagnostic extends Function { |
|
64 |
// Base base; |
|
65 |
/** The corpus. */ |
|
66 |
Corpus corpus; |
|
67 |
|
|
68 |
/** The partition. */ |
|
69 |
Partition partition; |
|
70 |
|
|
71 |
/** The maxvalue. */ |
|
72 |
int maxvalue = 20; |
|
73 |
|
|
74 |
// Numbers |
|
75 |
/** The T. */ |
|
76 |
int T = 0; // number of word |
|
77 |
|
|
78 |
/** The N properties. */ |
|
79 |
int NProperties = 0; // number of word properties |
|
80 |
//HashMap<String, Integer> propertiesCounts = new HashMap<String, Integer>(); // properties counts |
|
81 |
/** The properties values. */ |
|
82 |
HashMap<String, List<String>> propertiesValues = new HashMap<String, List<String>>(); // properties values |
|
83 |
|
|
84 |
/** The N structures. */ |
|
85 |
int NStructures = 0; // number of structures |
|
86 |
|
|
87 |
/** The structures counts. */ |
|
88 |
HashMap<String, Integer> structuresCounts = new HashMap<String, Integer>(); // structures counts |
|
89 |
|
|
90 |
/** The internal architecture. */ |
|
91 |
List<String> internalArchitecture = new ArrayList<String>(); // wtc structures = propertiesCounts keys but ordered |
|
92 |
|
|
93 |
/** The hierarchie counts. */ |
|
94 |
HashMap<String, Integer> hierarchieCounts = new HashMap<String, Integer>(); // hierarchic structures counts |
|
95 |
|
|
96 |
/** The internal architecture properties. */ |
|
97 |
HashMap<String, HashMap<String, List<String>>> internalArchitectureProperties = new HashMap<String, HashMap<String, List<String>>>(); // hierarchic structures counts |
|
98 |
|
|
99 |
/** The internal architecture properties counts. */ |
|
100 |
HashMap<String, HashMap<String, Integer>> internalArchitecturePropertiesCounts = new HashMap<String, HashMap<String, Integer>>(); // hierarchic structures counts |
|
101 |
|
|
102 |
// Annotations description |
|
103 |
/** The annotations types. */ |
|
104 |
HashMap<String, Integer> annotationsTypes = new HashMap<String, Integer>(); // for each annotation its description |
|
105 |
|
|
106 |
/** The annotations origins. */ |
|
107 |
HashMap<String, Integer> annotationsOrigins = new HashMap<String, Integer>(); // for each annoation its origin description |
|
108 |
|
|
109 |
// Import description |
|
110 |
/** The import description. */ |
|
111 |
String importDescription = ""; //$NON-NLS-1$ |
|
112 |
|
|
113 |
/** The properties. */ |
|
114 |
List<Property> properties; |
|
115 |
|
|
116 |
/** The structures. */ |
|
117 |
List<StructuralUnit> structures; |
|
118 |
|
|
119 |
/** |
|
120 |
* Instantiates a new diagnostic. |
|
121 |
* |
|
122 |
* @param corpus a MainCorpus or a SubCorpus |
|
123 |
* @param maxvalue the number of values of properties shown |
|
124 |
*/ |
|
125 |
public Diagnostic(Corpus corpus, int maxvalue) { |
|
126 |
// long start = System.currentTimeMillis(); |
|
127 |
// base = b; |
|
128 |
super(corpus); |
|
129 |
this.corpus = corpus; |
|
130 |
if (maxvalue <= 0) |
|
131 |
maxvalue = 10; |
|
132 |
this.maxvalue = maxvalue; |
|
133 |
} |
|
134 |
|
|
135 |
/** |
|
136 |
* Process. |
|
137 |
*/ |
|
138 |
public void process() { |
|
139 |
stepGeneralInfos(); |
|
140 |
stepLexicalProperties(); |
|
141 |
stepStructuralUnits(); |
|
142 |
} |
|
143 |
|
|
144 |
/** |
|
145 |
* Step general infos. |
|
146 |
*/ |
|
147 |
public void stepGeneralInfos() |
|
148 |
{ |
|
149 |
try { |
|
150 |
properties = corpus.getProperties(); |
|
151 |
NProperties = properties.size(); |
|
152 |
} catch (CqiClientException e1) { |
|
153 |
Log.severe(TXMCoreMessages.Diagnostic_1 + corpus.getName() |
|
154 |
+ TXMCoreMessages.Diagnostic_4); |
|
155 |
return; |
|
156 |
} |
|
157 |
try { |
|
158 |
T = corpus.getSize();// corpus.getLexicon(corpus.getProperty("id")).nbrOfToken(); |
|
159 |
} catch (CqiClientException e1) { |
|
160 |
Log.severe(TXMCoreMessages.Diagnostic_6 + corpus.getName() |
|
161 |
+ TXMCoreMessages.Diagnostic_8); |
|
162 |
return; |
|
163 |
} |
|
164 |
} |
|
165 |
|
|
166 |
/** |
|
167 |
* step2. |
|
168 |
* randomly position are choose |
|
169 |
*/ |
|
170 |
public void stepLexicalProperties() |
|
171 |
{ |
|
172 |
AbstractCqiClient cqiClient = CorpusManager.getCorpusManager().getCqiClient(); |
|
173 |
for (Property p : properties) { |
|
174 |
//int size; |
|
175 |
try { |
|
176 |
//size = CorpusManager.getCorpusManager().getCqiClient().lexiconSize(p.getQualifiedName()); |
|
177 |
//propertiesCounts.put(p.getName(), size); |
|
178 |
//List<String> list = Arrays.asList(corpus.getLexicon(p).getForms(this.maxvalue)); |
|
179 |
|
|
180 |
int[] positions = new int[Math.min(maxvalue, T)]; |
|
181 |
for(int i = 0 ; i < Math.min(maxvalue, T) ; i++) |
|
182 |
positions[i] = i; |
|
183 |
|
|
184 |
//ArrayList<String> values = new ArrayList<String>(); |
|
185 |
LinkedHashSet<String> values = new LinkedHashSet<String>(cqiClient.getSingleData(p, positions)); |
|
186 |
propertiesValues.put(p.getName(), new ArrayList<String>(values)); |
|
187 |
} catch (Exception e) { |
|
188 |
org.txm.utils.logger.Log.printStackTrace(e); |
|
189 |
} |
|
190 |
|
|
191 |
// System.out.println("Lexi size "+p+" : "+(System.currentTimeMillis()- |
|
192 |
// start)); |
|
193 |
// start = System.currentTimeMillis(); |
|
194 |
} |
|
195 |
} |
|
196 |
|
|
197 |
/** |
|
198 |
* Step structural units. |
|
199 |
*/ |
|
200 |
public void stepStructuralUnits() |
|
201 |
{ |
|
202 |
try { |
|
203 |
structures = corpus.getOrderedStructuralUnits(); |
|
204 |
} catch (CqiClientException e1) { |
|
205 |
Log.severe(TXMCoreMessages.Diagnostic_1 + corpus.getName() |
|
206 |
+ TXMCoreMessages.Diagnostic_11); |
|
207 |
return; |
|
208 |
} |
|
209 |
NStructures = structures.size(); |
|
210 |
for (StructuralUnit su : structures) { // for each structural unit |
|
211 |
internalArchitecture.add(su.getName()); |
|
212 |
hierarchieCounts.put(su.getName(), -1); |
|
213 |
internalArchitectureProperties.put(su.getName(), |
|
214 |
new HashMap<String, List<String>>()); |
|
215 |
internalArchitecturePropertiesCounts.put(su.getName(), |
|
216 |
new HashMap<String, Integer>()); |
|
217 |
if (su.getProperties().size() > 0) { |
|
218 |
for (StructuralUnitProperty sup : su.getProperties()) {// for each of its property |
|
219 |
try { |
|
220 |
List<String> allvalues = sup.getValues(corpus); |
|
221 |
internalArchitectureProperties.get(su.getName()).put( |
|
222 |
sup.getName(), |
|
223 |
allvalues.subList(0, Math.min(allvalues.size(), |
|
224 |
maxvalue))); |
|
225 |
internalArchitecturePropertiesCounts.get(su.getName()) |
|
226 |
.put(sup.getName(), allvalues.size()); |
|
227 |
} catch (Exception e) { |
|
228 |
ArrayList<String> list = new ArrayList<String>(1); |
|
229 |
list.add(TXMCoreMessages.Diagnostic_2); |
|
230 |
internalArchitectureProperties.get(su.getName()).put( |
|
231 |
sup.getName(), list); |
|
232 |
internalArchitecturePropertiesCounts.get(su.getName()) |
|
233 |
.put(sup.getName(), -1); |
|
234 |
} |
|
235 |
} |
|
236 |
} |
|
237 |
} |
|
238 |
} |
|
239 |
|
|
240 |
/** |
|
241 |
* Instantiates a new diagnostic. |
|
242 |
* |
|
243 |
* @param partition the partition |
|
244 |
* @throws CqiClientException the cqi client exception |
|
245 |
*/ |
|
246 |
public Diagnostic(Partition partition) throws CqiClientException { |
|
247 |
corpus = partition.getCorpus(); |
|
248 |
this.partition = partition; |
|
249 |
int T = corpus.getSize(); |
|
250 |
System.out.println(TXMCoreMessages.Diagnostic_12); |
|
251 |
int nbParts = partition.getNPart(); |
|
252 |
List<String> partNames = partition.getPartNames(); |
|
253 |
List<Integer> partSizes = new ArrayList<Integer>(); |
|
254 |
List<List<Property>> partProperties = new ArrayList<List<Property>>(); |
|
255 |
List<String> partQueries = new ArrayList<String>(); |
|
256 |
for (Part part : partition.getParts()) { |
|
257 |
partSizes.add(part.getSize()); |
|
258 |
partProperties.add(part.getProperties()); |
|
259 |
partQueries.add(part.getQuery().getQueryString()); |
|
260 |
} |
|
261 |
} |
|
262 |
|
|
263 |
/** |
|
264 |
* dump the results of the diagnostic in a String containing HTML code. |
|
265 |
* |
|
266 |
* @return the string |
|
267 |
*/ |
|
268 |
public String htmldump() { |
|
269 |
StringBuffer buff = new StringBuffer(); |
|
270 |
|
|
271 |
buff.append("<? version=\"1.0\" encoding=\"UTF-8\"?>\n" + //$NON-NLS-1$ |
|
272 |
"<html>" + //$NON-NLS-1$ |
|
273 |
"<head>" + //$NON-NLS-1$ |
|
274 |
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/>" + //$NON-NLS-1$ |
|
275 |
"</head>" + //$NON-NLS-1$ |
|
276 |
"<body>\n"); //$NON-NLS-1$ |
|
277 |
buff.append("<h2 style'font-family:\"Arial\";'>"+TXMCoreMessages.Diagnostic_3 + this.corpus.getName() + "</h2>\n"); //$NON-NLS-2$ //$NON-NLS-1$ |
|
278 |
|
|
279 |
if (corpus.getDescription() != null && corpus.getDescription().length() > 0) { |
|
280 |
buff.append("<p>"+corpus.getDescription()+"</p>"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
281 |
} |
|
282 |
|
|
283 |
buff.append("<h3 style'font-family:\"Arial\";'>"+TXMCoreMessages.Diagnostic_5+ "</h3>\n"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
284 |
|
|
285 |
|
|
286 |
|
|
287 |
// counts |
|
288 |
buff.append("<ul>\n"); //$NON-NLS-1$ |
|
289 |
buff.append("<li>" + TXMCoreMessages.Diagnostic_7 + T + "</li>\n"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
290 |
buff |
|
291 |
.append("<li>" + TXMCoreMessages.Diagnostic_9 + (NProperties - 1) + "</li>\n"); //$NON-NLS-2$ //$NON-NLS-1$ |
|
292 |
buff.append("<li>" + TXMCoreMessages.Diagnostic_16 + NStructures + "</li>\n"); //$NON-NLS-2$ //$NON-NLS-1$ |
|
293 |
buff.append("</ul>\n"); //$NON-NLS-1$ |
|
294 |
|
|
295 |
// Propriétés d'occurrences |
|
296 |
buff.append("<h3 style'font-family:\"Arial\";'>"+NLS.bind(TXMCoreMessages.Diagnostic_14, maxvalue) + "</h3>\n"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
297 |
ArrayList<String> properties = new ArrayList<String>(propertiesValues.keySet()); |
|
298 |
Collections.sort(properties); |
|
299 |
buff.append("<ul>\n"); //$NON-NLS-1$ |
|
300 |
for (String s : properties) { |
|
301 |
if (!s.equals("id")) //$NON-NLS-1$ |
|
302 |
{ |
|
303 |
//buff.append("<li> " + s + " (" + propertiesCounts.get(s) + ") : "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
|
304 |
buff.append("<li> " + s + " : "); //$NON-NLS-1$ //$NON-NLS-2$ |
|
305 |
for (String v : propertiesValues.get(s)) |
|
306 |
buff.append(v + ", "); //$NON-NLS-1$ |
|
307 |
buff.append("..."); //$NON-NLS-1$ |
|
308 |
buff.append("</li>\n"); //$NON-NLS-1$ |
|
309 |
} |
|
310 |
} |
|
311 |
buff.append("</ul>\n"); //$NON-NLS-1$ |
|
312 |
|
|
313 |
// Propriété de structures |
|
314 |
buff.append("<h3 style'font-family:\"Arial\";'>"+NLS.bind(TXMCoreMessages.Diagnostic_22, maxvalue)+"</h3>\n"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
315 |
buff.append("<ul>\n"); //$NON-NLS-1$ |
|
316 |
for (String s : internalArchitecture) { |
|
317 |
StringBuffer subbuffer = new StringBuffer(); |
|
318 |
if (s.equals("txmcorpus")) //$NON-NLS-1$ |
|
319 |
continue;//ignore the txmcorpus structure |
|
320 |
|
|
321 |
properties = new ArrayList<String>(internalArchitectureProperties.get(s).keySet()); |
|
322 |
|
|
323 |
subbuffer.append("<li> " + s + "\n<ul>\n"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
324 |
if (internalArchitectureProperties.get(s).keySet().size() == 0) |
|
325 |
subbuffer.append("<li>"+TXMCoreMessages.Diagnostic_26+"</li>\n"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
326 |
|
|
327 |
|
|
328 |
//System.out.println("struct: "+s+" >> "+properties); |
|
329 |
Collections.sort(properties); |
|
330 |
//System.out.println("struct: "+s+" >sort> "+properties); |
|
331 |
int nbOfValues = 0; |
|
332 |
for (String ps : properties) { |
|
333 |
if (!ps.equals("project") && !ps.equals("base") ) //$NON-NLS-1$ //$NON-NLS-2$ |
|
334 |
{ |
|
335 |
//System.out.println("struct: "+s+" >> "+ps); |
|
336 |
int valuecount = internalArchitecturePropertiesCounts.get(s).get(ps); |
|
337 |
ArrayList<String> values = new ArrayList<String>( |
|
338 |
internalArchitectureProperties.get(s).get(ps)); |
|
339 |
subbuffer.append("<li> " + ps + " (" + valuecount + ") = "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
|
340 |
//System.out.println("VALUES: "+values); |
|
341 |
Collections.sort(values); |
|
342 |
for (int i = 0 ; i < values.size() ; i++) { |
|
343 |
nbOfValues++; |
|
344 |
String psv = values.get(i); |
|
345 |
if (psv != null && psv.length() > 0) |
|
346 |
subbuffer.append(psv.replace("<", "<")); //$NON-NLS-1$ //$NON-NLS-2$ |
|
347 |
else |
|
348 |
subbuffer.append("\"\""); //$NON-NLS-1$ |
|
349 |
|
|
350 |
if (i == values.size() -1) |
|
351 |
subbuffer.append("."); //$NON-NLS-1$ |
|
352 |
else |
|
353 |
subbuffer.append(", "); //$NON-NLS-1$ |
|
354 |
|
|
355 |
if (i >= maxvalue) { |
|
356 |
subbuffer.append("..."); //$NON-NLS-1$ |
|
357 |
break; |
|
358 |
} |
|
359 |
} |
|
360 |
subbuffer.append("</li>\n"); //$NON-NLS-1$ |
|
361 |
} |
|
362 |
} |
|
363 |
subbuffer.append("</ul>\n</li>\n"); //$NON-NLS-1$ |
|
364 |
if (nbOfValues > 0) { |
|
365 |
buff.append(subbuffer); |
|
366 |
} |
|
367 |
} |
|
368 |
buff.append("</ul>\n"); //$NON-NLS-1$ |
|
369 |
buff.append("</body>\n"); //$NON-NLS-1$ |
|
370 |
buff.append("</html>\n"); //$NON-NLS-1$ |
|
371 |
|
|
372 |
return buff.toString(); |
|
373 |
} |
|
374 |
|
|
375 |
|
|
376 |
|
|
377 |
/** |
|
378 |
* dump the result in the console. |
|
379 |
* |
|
380 |
* @param maxvalue the maxvalue |
|
381 |
* @return the string |
|
382 |
*/ |
|
383 |
public String dump(int maxvalue) { |
|
384 |
StringBuffer buff = new StringBuffer(); |
|
385 |
|
|
386 |
buff.append(TXMCoreMessages.Diagnostic_40); |
|
387 |
buff.append(TXMCoreMessages.Diagnostic_41 + String.format(Locale.FRANCE,"%,d", T) + "\n"); //$NON-NLS-1$ |
|
388 |
buff.append(TXMCoreMessages.Diagnostic_43 + String.format("%,d", NProperties) + "\n"); //$NON-NLS-1$ |
|
389 |
/*for (String s : propertiesCounts.keySet()) |
|
390 |
if (!s.equals("id")) //$NON-NLS-1$ |
|
391 |
buff.append(" - " + s + " " + propertiesCounts.get(s) + "\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
|
392 |
*/ |
|
393 |
buff.append(TXMCoreMessages.Diagnostic_49 + String.format("%,d", NStructures) + "\n"); //$NON-NLS-1$ |
|
394 |
for (String s : structuresCounts.keySet()) |
|
395 |
buff.append(" - " + s + "\n");//+structuresCounts.get(s)+"\n"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
396 |
|
|
397 |
/* |
|
398 |
* buff.append("* Structural Units counts\n"); for(String s : |
|
399 |
* internalArchitecture) |
|
400 |
* buff.append(" - "+s+" "+hierarchieCounts.get(s)+"\n"); |
|
401 |
*/ |
|
402 |
buff.append(TXMCoreMessages.Diagnostic_0); |
|
403 |
for (String s : internalArchitecture) { |
|
404 |
buff.append(" - " + s + "\n"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
405 |
for (String ps : internalArchitectureProperties.get(s).keySet()) { |
|
406 |
if (!(s.equals("text") && (ps.equals("project") || ps.equals("base") || ps.equals("id")))) //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ |
|
407 |
{ |
|
408 |
buff |
|
409 |
.append(" - " + ps + "(" + internalArchitectureProperties.get(s).get(ps).size() + ") = "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
|
410 |
|
|
411 |
int valuecount = 0; |
|
412 |
for (String psv : internalArchitectureProperties.get(s) |
|
413 |
.get(ps)) { |
|
414 |
buff.append(psv); |
|
415 |
if (valuecount++ >= maxvalue) { |
|
416 |
buff.append("..."); //$NON-NLS-1$ |
|
417 |
break; |
|
418 |
} |
|
419 |
if (valuecount < internalArchitectureProperties.get(s) |
|
420 |
.get(ps).size()) |
|
421 |
buff.append(", "); //$NON-NLS-1$ |
|
422 |
} |
|
423 |
|
|
424 |
buff.append("\n"); //$NON-NLS-1$ |
|
425 |
} |
|
426 |
} |
|
427 |
} |
|
428 |
|
|
429 |
return buff.toString(); |
|
430 |
} |
|
431 |
|
|
432 |
/** |
|
433 |
* dump the result in the console with maxvalue=30. |
|
434 |
* |
|
435 |
* @return the string |
|
436 |
*/ |
|
437 |
public String dump() { |
|
438 |
return dump(30); |
|
439 |
} |
|
440 |
|
|
441 |
/** |
|
442 |
* Gets the name. |
|
443 |
* |
|
444 |
* @return the name |
|
445 |
*/ |
|
446 |
public String getName() { |
|
447 |
return corpus.getName(); |
|
448 |
} |
|
449 |
|
|
450 |
/** |
|
451 |
* Gets the base. |
|
452 |
* |
|
453 |
* @return the base |
|
454 |
*/ |
|
455 |
public Base getBase() { |
|
456 |
return corpus.getBase(); |
|
457 |
} |
|
458 |
|
|
459 |
/** |
|
460 |
* Gets the t. |
|
461 |
* |
|
462 |
* @return the t |
|
463 |
*/ |
|
464 |
public int getT() { |
|
465 |
return T; |
|
466 |
} |
|
467 |
|
|
468 |
/** |
|
469 |
* Gets the n properties. |
|
470 |
* |
|
471 |
* @return the n properties |
|
472 |
*/ |
|
473 |
public int getNProperties() { |
|
474 |
return NProperties; |
|
475 |
} |
|
476 |
|
|
477 |
/** |
|
478 |
* Gets the internal architecture. |
|
479 |
* |
|
480 |
* @return the internal architecture |
|
481 |
*/ |
|
482 |
public List<String> getInternalArchitecture() { |
|
483 |
return internalArchitecture; |
|
484 |
} |
|
485 |
|
|
486 |
/*public HashMap<String, Integer> getPropertiesCounts() { |
|
487 |
return propertiesCounts; |
|
488 |
}*/ |
|
489 |
|
|
490 |
/** |
|
491 |
* Gets the n structures. |
|
492 |
* |
|
493 |
* @return the n structures |
|
494 |
*/ |
|
495 |
public int getNStructures() { |
|
496 |
return NStructures; |
|
497 |
} |
|
498 |
|
|
499 |
/** |
|
500 |
* Gets the structures counts. |
|
501 |
* |
|
502 |
* @return the structures counts |
|
503 |
*/ |
|
504 |
public HashMap<String, Integer> getStructuresCounts() { |
|
505 |
return structuresCounts; |
|
506 |
} |
|
507 |
|
|
508 |
/** |
|
509 |
* Gets the annotations types. |
|
510 |
* |
|
511 |
* @return the annotations types |
|
512 |
*/ |
|
513 |
public HashMap<String, Integer> getAnnotationsTypes() { |
|
514 |
return annotationsTypes; |
|
515 |
} |
|
516 |
|
|
517 |
/** |
|
518 |
* Gets the annotations origins. |
|
519 |
* |
|
520 |
* @return the annotations origins |
|
521 |
*/ |
|
522 |
public HashMap<String, Integer> getAnnotationsOrigins() { |
|
523 |
return annotationsOrigins; |
|
524 |
} |
|
525 |
|
|
526 |
/** |
Formats disponibles : Unified diff