Révision 2170
tmp/org.txm.groovy.core/src/groovy/org/txm/macro/prototypes/commands/CoocRecMacro.groovy (revision 2170) | ||
---|---|---|
17 | 17 |
return false; |
18 | 18 |
} |
19 | 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 |
|
20 |
@Field @Option(name="starting_word", usage="The starting word", widget="String", required=true, def='Life') |
|
21 |
def starting_word |
|
24 | 22 |
@Field @Option(name="property", usage="an example query", widget="String", required=true, def='lemma') |
25 |
def property |
|
23 |
def property |
|
24 |
@Field @Option(name="mode", usage="an example query", widget="StringArray", metaVar="Poly Reccursive", required=true, def='Poly') |
|
25 |
def mode |
|
26 | 26 |
@Field @Option(name="distance_max", usage="an example query", widget="Integer", required=true, def='9') |
27 |
def distance_max |
|
27 |
def distance_max
|
|
28 | 28 |
@Field @Option(name="score_minimum", usage="an example query", widget="Float", required=true, def='2.5') |
29 |
def score_minimum |
|
29 |
def score_minimum
|
|
30 | 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
|
|
31 |
def profondeur_max
|
|
32 |
@Field @Option(name="debug", usage="Show internal variable content", widget="StringArray", metaVar="OFF ON ALL REALLY ALL", required=true, def="OFF")
|
|
33 |
debug
|
|
34 | 34 |
|
35 | 35 |
// Open the parameters input dialog box |
36 | 36 |
if (!ParametersDialog.open(this)) return; |
37 |
if (debug == "OFF") debug = 0; else if (debug == "ON") debug = 1; else if (debug == "ALL") debug = 2 else if (debug == "REALLY ALL") debug = 3 |
|
38 |
mode = mode == "Poly" |
|
37 | 39 |
|
38 | 40 |
lmax = "" |
39 | 41 |
for (int i = 0 ; i < profondeur_max; i++) lmax += "\t" |
... | ... | |
45 | 47 |
return false |
46 | 48 |
} |
47 | 49 |
|
48 |
|
|
49 |
|
|
50 | 50 |
def rightCooc = new Cooccurrence(corpus) |
51 | 51 |
r = new HashSet() |
52 | 52 |
def printCoocs(def pivots, def level, def cooc, def right_dir) { |
53 | 53 |
if (level.length() > lmax.length()) return; |
54 |
if (debug) println "#"+level+pivots |
|
55 |
|
|
54 |
if (debug > 1) println "#"+level+pivots
|
|
55 |
|
|
56 | 56 |
def bouts = [] |
57 |
|
|
57 |
|
|
58 | 58 |
for (def s : pivots) { |
59 | 59 |
bouts << "[$property=\"$s\"%cd]" |
60 | 60 |
} |
61 | 61 |
String qs = bouts.join(" []{0, ${distance_max}} ") |
62 |
|
|
62 |
|
|
63 | 63 |
def q = new CQLQuery(qs) |
64 |
if (debug) println level+q |
|
65 |
|
|
64 |
if (debug > 0) println level+q
|
|
65 |
|
|
66 | 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 |
|
|
67 |
|
|
68 |
if (mode) { |
|
69 |
if (right_dir) |
|
70 |
cooc.setParameters(q, [wordProperty], null, 0, 0, 1, distance_max+1, 1, score_minimum, 1, false, false); |
|
71 |
else |
|
72 |
cooc.setParameters(q, [wordProperty], null, distance_max+1, 1, 0, 0, 1, score_minimum, 1, false, false); |
|
73 |
} else { |
|
74 |
cooc.setParameters(q, [wordProperty], null, distance_max+1, 1, 1, distance_max+1, 1, score_minimum, 1, false, false); |
|
75 |
} |
|
73 | 76 |
cooc.setDirty(true) |
74 |
|
|
77 |
|
|
75 | 78 |
cooc.compute() |
79 |
if (debug > 0) println "cooc="+cooc.getLastParametersFromHistory() |
|
76 | 80 |
def lines = cooc.getLines() |
77 | 81 |
def words = [:] |
78 | 82 |
for (def line : lines) { |
79 | 83 |
if (!r.contains(line.props[0])) { |
80 | 84 |
words[line.props[0]] = line |
81 |
}
|
|
85 |
} |
|
82 | 86 |
} |
83 |
if (debug) println level+lines.size() |
|
84 |
|
|
87 |
if (debug > 1) println level+lines.size()
|
|
88 |
|
|
85 | 89 |
for (def word : words.keySet()) { |
86 | 90 |
int size = 10+words[word].score |
87 | 91 |
if (size > 30) size = 30 |
88 | 92 |
|
89 | 93 |
def new_pivots = [] |
90 | 94 |
|
91 |
|
|
92 |
if (right_dir) { |
|
93 |
def pivot = pivots[-1] |
|
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 { |
|
95 |
if (mode) { |
|
96 |
if (right_dir) { |
|
97 |
def pivot = pivots[-1] |
|
98 |
println "$level\"$pivot\" -> \"$word\" [label=\"${words[word].score}\",fontsize=$size,weight=${words[word].score}];" |
|
99 |
if (mode) new_pivots.addAll(pivots) |
|
100 |
new_pivots << word |
|
101 |
} else { |
|
102 |
def pivot = pivots[0] |
|
103 |
println "$level\"$word\" -> \"$pivot\" [label=\"${words[word].score}\",fontsize=$size,weight=${words[word].score}];" |
|
104 |
|
|
105 |
new_pivots << word |
|
106 |
|
|
107 |
if (mode) new_pivots.addAll(pivots) |
|
108 |
} |
|
109 |
printCoocs(new_pivots, level+" ", cooc, right_dir) |
|
110 |
} else { |
|
98 | 111 |
def pivot = pivots[0] |
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) |
|
112 |
println "$level\"$pivot\" -- \"$word\" [label=\"${words[word].score}\",fontsize=$size,weight=${words[word].score}];" |
|
113 |
printCoocs([word], level+" ", cooc, true) |
|
103 | 114 |
} |
104 |
|
|
105 |
printCoocs(new_pivots, level+" ", cooc, right_dir) |
|
106 | 115 |
} |
107 | 116 |
} |
108 | 117 |
|
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) |
|
118 |
|
|
119 |
if (mode) { |
|
120 |
println "digraph {" |
|
121 |
println "rankdir=LR;" |
|
122 |
} else { |
|
123 |
println "graph {" |
|
124 |
} |
|
125 |
|
|
126 |
println "\"$starting_word\" [shape=box];" |
|
127 |
if (mode) { |
|
128 |
printCoocs([starting_word], "", rightCooc, true) |
|
129 |
r = new HashSet() |
|
130 |
printCoocs([starting_word], "", rightCooc, false) |
|
131 |
} else { |
|
132 |
printCoocs([starting_word], "", rightCooc, true) |
|
133 |
} |
|
134 |
|
|
115 | 135 |
println "}" |
Formats disponibles : Unified diff