Révision 3528
TXM/trunk/org.txm.core/src/java/org/txm/core/results/TXMResult.java (revision 3528) | ||
---|---|---|
1 | 1 |
package org.txm.core.results; |
2 | 2 |
|
3 |
import java.io.BufferedReader; |
|
3 | 4 |
import java.io.File; |
4 | 5 |
import java.io.IOException; |
5 | 6 |
import java.lang.reflect.Constructor; |
... | ... | |
1185 | 1186 |
} |
1186 | 1187 |
|
1187 | 1188 |
/** |
1188 |
* |
|
1189 |
* load or reload parameters from the preference store node
|
|
1189 | 1190 |
* @return |
1190 | 1191 |
* @throws Exception |
1191 | 1192 |
*/ |
1192 |
protected boolean autoLoadParametersFromAnnotations() throws Exception {
|
|
1193 |
public boolean autoLoadParametersFromAnnotations() throws Exception {
|
|
1193 | 1194 |
return this.autoLoadParametersFromAnnotations(Parameter.COMPUTING) && this.autoLoadParametersFromAnnotations(Parameter.INTERNAL); |
1194 | 1195 |
} |
1195 | 1196 |
|
... | ... | |
2076 | 2077 |
} |
2077 | 2078 |
clone = this.getClass().getDeclaredConstructor(String.class).newInstance(newNodePath); |
2078 | 2079 |
|
2079 |
System.out.println("CLONE HAS BEEN COMPUTED? " + clone.hasBeenComputedOnce()); |
|
2080 |
System.out.println("CLONE IS DIRTY? " + clone.isDirty()); |
|
2080 |
//System.out.println("CLONE HAS BEEN COMPUTED? " + clone.hasBeenComputedOnce());
|
|
2081 |
//System.out.println("CLONE IS DIRTY? " + clone.isDirty());
|
|
2081 | 2082 |
|
2082 | 2083 |
if (all) { |
2083 | 2084 |
for (TXMResult child : this.children) { |
... | ... | |
2095 | 2096 |
public boolean importParameters(File parameters) { |
2096 | 2097 |
try { |
2097 | 2098 |
Properties props = new Properties(); |
2098 |
props.load(IOUtils.getReader(parameters)); |
|
2099 |
BufferedReader r = IOUtils.getReader(parameters); |
|
2100 |
props.load(r); |
|
2101 |
r.close(); |
|
2099 | 2102 |
|
2100 | 2103 |
// some tests before... |
2101 | 2104 |
String className = props.getProperty(TXMPreferences.CLASS); |
TXM/trunk/org.txm.libs.deptreeviz/src/org/txm/libs/deptreeviz/UDPrintTree.java (revision 3528) | ||
---|---|---|
8 | 8 |
import java.util.Arrays; |
9 | 9 |
import java.util.List; |
10 | 10 |
|
11 |
|
|
12 | 11 |
import io.gitlab.nats.deptreeviz.DepTree; |
13 | 12 |
import io.gitlab.nats.deptreeviz.SimpleParse; |
14 | 13 |
import io.gitlab.nats.deptreeviz.SimpleWord; |
... | ... | |
16 | 15 |
public class UDPrintTree { |
17 | 16 |
|
18 | 17 |
public static File print(File file, List<String> conll, String[] Tvalues, String[] NTvalues) { |
18 |
|
|
19 | 19 |
try { |
20 | 20 |
PrintWriter pw = new PrintWriter(file); |
21 | 21 |
|
... | ... | |
24 | 24 |
List<String> labels = p.getVerticesLabels().get("SYN"); |
25 | 25 |
if (Tvalues != null && Tvalues.length == words.size()) { |
26 | 26 |
|
27 |
for (int i = 0 ; i < words.size() ; i++) {
|
|
27 |
for (int i = 0; i < words.size(); i++) {
|
|
28 | 28 |
SimpleWord w = words.get(i); |
29 | 29 |
|
30 | 30 |
Field fword = SimpleWord.class.getDeclaredField("word"); |
31 | 31 |
fword.setAccessible(true); |
32 |
fword.set(w, w.getWord()+"/"+Tvalues[i]);
|
|
32 |
fword.set(w, w.getWord() + "/" + Tvalues[i]);
|
|
33 | 33 |
} |
34 | 34 |
} |
35 | 35 |
|
36 | 36 |
if (NTvalues != null && NTvalues.length == words.size()) { |
37 |
ArrayList<String> tmp = (ArrayList)labels; |
|
37 |
ArrayList<String> tmp = (ArrayList) labels;
|
|
38 | 38 |
tmp.clear(); |
39 |
for (int i = 0 ; i < words.size() ; i++) {
|
|
39 |
for (int i = 0; i < words.size(); i++) {
|
|
40 | 40 |
tmp.add(NTvalues[i]); |
41 | 41 |
} |
42 | 42 |
} |
43 | 43 |
DepTree<SimpleParse, SimpleWord> dt = new DepTree<SimpleParse, SimpleWord>(p); |
44 |
//dt.setShowingReferent(true); |
|
45 |
//dt.setShowingCat(true); |
|
44 |
// dt.setShowingReferent(true);
|
|
45 |
// dt.setShowingCat(true);
|
|
46 | 46 |
dt.writeTree(pw); |
47 |
//w.close(); |
|
47 |
// w.close();
|
|
48 | 48 |
return file; |
49 | 49 |
} |
50 | 50 |
catch (Throwable e) { |
... | ... | |
55 | 55 |
} |
56 | 56 |
|
57 | 57 |
public static void main(String[] args) throws IOException { |
58 |
File file = File.createTempFile("txm", ".svg", new File("/home/mdecorde")); |
|
59 |
|
|
60 |
List<String> conll = Arrays.asList( |
|
61 |
"1 Ce ce PRON _ Number=Sing|Person=3|PronType=Dem 2 nsubj _ _", |
|
62 |
"2 doit devoir VERB _ Mood=Ind|Number=Sing|Person=3|Tense=Pres|VerbForm=Fin 0 root _ _", |
|
63 |
"3 être être AUX _ VerbForm=Inf 5 cop _ _", |
|
64 |
"4 un un DET _ Definite=Ind|Gender=Masc|Number=Sing|PronType=Art 5 det _ _", |
|
65 |
"5 général général NOUN _ Gender=Masc|Number=Sing 2 xcomp _ _", |
|
66 |
"6 étranger étranger ADJ _ Gender=Masc|Number=Sing 5 amod _ _", |
|
67 |
"7 . . PUNCT _ _ 2 punct _ _" |
|
68 |
); |
|
69 | 58 |
|
70 |
|
|
71 |
System.out.println("FILE: "+print(file, conll, null, null)); |
|
59 |
File file = File.createTempFile("txm", ".svg", new File("/home/mdecorde")); |
|
60 |
|
|
61 |
List<String> conll = Arrays.asList( |
|
62 |
"1 Ce ce PRON _ Number=Sing|Person=3|PronType=Dem 2 nsubj _ _", |
|
63 |
"2 doit devoir VERB _ Mood=Ind|Number=Sing|Person=3|Tense=Pres|VerbForm=Fin 0 root _ _", |
|
64 |
"3 être être AUX _ VerbForm=Inf 5 cop _ _", |
|
65 |
"4 un un DET _ Definite=Ind|Gender=Masc|Number=Sing|PronType=Art 5 det _ _", |
|
66 |
"5 général général NOUN _ Gender=Masc|Number=Sing 2 xcomp _ _", |
|
67 |
"6 étranger étranger ADJ _ Gender=Masc|Number=Sing 5 amod _ _", |
|
68 |
"7 . . PUNCT _ _ 2 punct _ _"); |
|
69 |
|
|
70 |
|
|
71 |
System.out.println("FILE: " + print(file, conll, null, null)); |
|
72 | 72 |
} |
73 | 73 |
|
74 | 74 |
} |
TXM/trunk/org.txm.groovy.core/src/groovy/org/txm/macro/pdf/PDF2TXTMacro.groovy (revision 3528) | ||
---|---|---|
1 |
package org.txm.macro.pdf |
|
2 |
// STANDARD DECLARATIONS |
|
3 |
|
|
4 |
import org.kohsuke.args4j.* |
|
5 |
import groovy.transform.Field |
|
6 |
import org.txm.rcp.swt.widget.parameters.* |
|
7 |
import org.apache.pdfbox.Loader |
|
8 |
import org.apache.pdfbox.text.PDFTextStripper |
|
9 |
|
|
10 |
// WARNING THIS MACRO NEEDS THE INSTALLATION OF THE PDFBOX (https://pdfbox.apache.org) Java library: https://dlcdn.apache.org/pdfbox/3.0.0-alpha3/pdfbox-app-3.0.0-alpha3.jar (standalone library) |
|
11 |
|
|
12 |
// BEGINNING OF PARAMETERS |
|
13 |
|
|
14 |
@Field @Option(name="input_file", usage=".pdf input file", widget="File", required=true, def="") |
|
15 |
def input_file |
|
16 |
|
|
17 |
@Field @Option(name="input_dir", usage="The directory containing the .pdf files to read", widget="Folder", required=false, def="") |
|
18 |
def input_dir |
|
19 |
|
|
20 |
// Open the parameters input dialog box |
|
21 |
if (!ParametersDialog.open(this)) return |
|
22 |
|
|
23 |
// END OF PARAMETERS |
|
24 |
|
|
25 |
if (input_dir != null && input_dir.exists() && input_dir.isDirectory()) { |
|
26 |
|
|
27 |
nFiles = 0 |
|
28 |
input_dir.eachFileMatch(~/.*.pdf/) { f -> |
|
29 |
name = f.getName() |
|
30 |
println "Processing $name..." |
|
31 |
idx = name.lastIndexOf(".") |
|
32 |
if (idx > 0) name = name.substring(0, idx) |
|
33 |
outputFile = new File(f.getParentFile(), name + ".txt") |
|
34 |
|
|
35 |
pdfFile = f.getAbsolutePath() |
|
36 |
if (pdfFile.toUpperCase().endsWith(".PDF")) { |
|
37 |
textFile = pdfFile.substring(0, pdfFile.length() - 3) + "txt" |
|
38 |
try { |
|
39 |
outputFile.withWriter("UTF-8") { writer -> |
|
40 |
doc = Loader.loadPDF(f) |
|
41 |
strip = new PDFTextStripper() |
|
42 |
writer.print strip.getText(doc) |
|
43 |
doc.close() |
|
44 |
writer.close() |
|
45 |
nFiles++ |
|
46 |
} |
|
47 |
} catch (Exception e) { |
|
48 |
e.printStackTrace() |
|
49 |
} |
|
50 |
} |
|
51 |
} |
|
52 |
println "Done processed $nFiles files." |
|
53 |
} else if (input_file != null && input_file.exists() && input_file.isFile()) { |
|
54 |
|
|
55 |
name = input_file.getName() |
|
56 |
idx = name.lastIndexOf(".") |
|
57 |
if (idx > 0) name = name.substring(0, idx) |
|
58 |
outputFile = new File(input_file.getParentFile(), name + ".txt") |
|
59 |
|
|
60 |
pdfFile = input_file.getAbsolutePath() |
|
61 |
if (pdfFile.toUpperCase().endsWith(".PDF")) { |
|
62 |
textFile = pdfFile.substring(0, pdfFile.length() - 3) + "txt" |
|
63 |
try { |
|
64 |
outputFile.withWriter("UTF-8") { writer -> |
|
65 |
doc = Loader.loadPDF(input_file) |
|
66 |
strip = new PDFTextStripper() |
|
67 |
writer.print strip.getText(doc) |
|
68 |
doc.close() |
|
69 |
writer.close() |
|
70 |
} |
|
71 |
} catch (Exception e) { |
|
72 |
e.printStackTrace() |
|
73 |
} |
|
74 |
} |
|
75 |
} |
Formats disponibles : Unified diff