root / tmp / org.txm.groovy.core / src / groovy / org / txm / macro / prototypes / commands / CoocRecMacro.groovy @ 2156
History | View | Annotate | Download (3.3 kB)
1 |
// STANDARD DECLARATIONS
|
---|---|
2 |
package org.txm.macro
|
3 |
|
4 |
import org.kohsuke.args4j.* |
5 |
import groovy.transform.Field |
6 |
import org.txm.rcp.swt.widget.parameters.* |
7 |
import org.txm.searchengine.cqp.corpus.* |
8 |
import org.txm.searchengine.cqp.corpus.query.* |
9 |
import org.txm.cooccurrence.core.functions.* |
10 |
|
11 |
// BEGINNING OF PARAMETERS
|
12 |
|
13 |
println "corpora selection: "+corpusViewSelection
|
14 |
|
15 |
if (!(corpusViewSelection instanceof CQPCorpus)) { |
16 |
println "Selection is not a corpus: $corpusViewSelection"
|
17 |
return false; |
18 |
} |
19 |
|
20 |
@Field @Option(name="word", usage="an example query", widget="String", required=true, def='Life') |
21 |
def word
|
22 |
@Field @Option(name="ensure_transitive", usage="an example query", widget="Boolean", required=true, def='true') |
23 |
def ensure_transitive
|
24 |
@Field @Option(name="property", usage="an example query", widget="String", required=true, def='lemma') |
25 |
def property
|
26 |
@Field @Option(name="distance_max", usage="an example query", widget="Integer", required=true, def='9') |
27 |
def distance_max
|
28 |
@Field @Option(name="score_minimum", usage="an example query", widget="Float", required=true, def='2.5') |
29 |
def score_minimum
|
30 |
@Field @Option(name="profondeur_max", usage="an example query", widget="Integer", required=true, def='3') |
31 |
def profondeur_max
|
32 |
@Field @Option(name="debug", usage="an example query", widget="Boolean", required=true, def='false') |
33 |
def debug
|
34 |
|
35 |
// Open the parameters input dialog box
|
36 |
if (!ParametersDialog.open(this)) return; |
37 |
|
38 |
lmax = ""
|
39 |
for (int i = 0 ; i < profondeur_max; i++) lmax += "\t" |
40 |
|
41 |
def corpus = corpusViewSelection
|
42 |
wordProperty = corpus.getProperty(property) |
43 |
if (wordProperty == null) { |
44 |
println "CQP property not found: $property"
|
45 |
return false |
46 |
} |
47 |
|
48 |
|
49 |
|
50 |
def rightCooc = new Cooccurrence(corpus) |
51 |
r = new HashSet() |
52 |
def printCoocs(def pivots, def level, def cooc, def right_dir) { |
53 |
if (level.length() > lmax.length()) return; |
54 |
if (debug) println "#"+level+pivots |
55 |
|
56 |
def bouts = [] |
57 |
|
58 |
for (def s : pivots) { |
59 |
bouts << "[$property=\"$s\"%cd]"
|
60 |
} |
61 |
String qs = bouts.join(" []{0, ${distance_max}} ") |
62 |
|
63 |
def q = new CQLQuery(qs) |
64 |
if (debug) println level+q
|
65 |
|
66 |
r.addAll(pivots) |
67 |
|
68 |
if (right_dir)
|
69 |
cooc.setParameters(q, [wordProperty], null, 0, 0, 1, distance_max+1, 1, score_minimum, 1, false, false); |
70 |
else
|
71 |
cooc.setParameters(q, [wordProperty], null, distance_max+1, 1, 0, 0, 1, score_minimum, 1, false, false); |
72 |
|
73 |
cooc.setDirty(true)
|
74 |
|
75 |
cooc.compute() |
76 |
def lines = cooc.getLines()
|
77 |
def words = [:]
|
78 |
for (def line : lines) { |
79 |
if (!r.contains(line.props[0])) { |
80 |
words[line.props[0]] = line
|
81 |
} |
82 |
} |
83 |
if (debug) println level+lines.size()
|
84 |
|
85 |
for (def word : words.keySet()) { |
86 |
int size = 10+words[word].score |
87 |
if (size > 30) size = 30 |
88 |
|
89 |
def new_pivots = [] |
90 |
|
91 |
|
92 |
if (right_dir) {
|
93 |
def pivot = pivots[0] |
94 |
println "$level\"$pivot\" -> \"$word\" [label=\"${words[word].score}\",fontsize=$size,weight=${words[word].score}];"
|
95 |
if (ensure_transitive) new_pivots.addAll(pivots)
|
96 |
new_pivots << word |
97 |
} else {
|
98 |
def pivot = pivots[-1] |
99 |
println "$level\"$word\" -> \"$pivot\" [label=\"${words[word].score}\",fontsize=$size,weight=${words[word].score}];"
|
100 |
|
101 |
new_pivots << word |
102 |
if (ensure_transitive) new_pivots.addAll(pivots)
|
103 |
} |
104 |
|
105 |
printCoocs(new_pivots, level+" ", cooc, right_dir)
|
106 |
} |
107 |
} |
108 |
|
109 |
println "digraph {"
|
110 |
println "rankdir=LR;"
|
111 |
println "\"$word\" [shape=box];"
|
112 |
printCoocs([word], "", rightCooc, false) |
113 |
r = new HashSet() |
114 |
printCoocs([word], "", rightCooc, true) |
115 |
println "}"
|