Révision 2150
tmp/org.txm.analec.rcp/src/org/txm/macro/urs/edit/ConcordanceToUnitsMacro.groovy (revision 2150) | ||
---|---|---|
18 | 18 |
@Field @Option(name="unit_type", usage="The unit type to create", widget="String", required=true, def="MENTION") |
19 | 19 |
def unit_type |
20 | 20 |
|
21 |
@Field @Option(name="move_start", usage="move the start position", widget="Integer", required=true, def="0") |
|
22 |
def move_start |
|
23 |
|
|
24 |
@Field @Option(name="move_end", usage="move the end position", widget="Integer", required=true, def="0") |
|
25 |
def move_end |
|
26 |
|
|
21 | 27 |
@Field @Option(name="create_only_if_new", usage="Create the unit if not already annotated", widget="Boolean", required=true, def="true") |
22 | 28 |
def create_only_if_new |
23 | 29 |
|
24 |
@Field @Option(name="prop", usage="prop", widget="String", required=true, def="REF") |
|
30 |
@Field @Option(name="property_name", usage="prop", widget="String", required=true, def="REF")
|
|
25 | 31 |
def property_name |
26 | 32 |
|
27 |
@Field @Option(name="value", usage="default value", widget="String", required=true, def="NAME") |
|
33 |
@Field @Option(name="property_value", usage="default value", widget="String", required=true, def="NAME")
|
|
28 | 34 |
def property_value |
29 | 35 |
|
30 | 36 |
// END OF PARAMETERS |
... | ... | |
54 | 60 |
} |
55 | 61 |
|
56 | 62 |
// Open the parameters input dialog box |
57 |
if (!ParametersDialog.open(this)) return; |
|
63 |
if (!ParametersDialog.open(this)) { |
|
64 |
println "User canceled parameters" |
|
65 |
return; |
|
66 |
} |
|
58 | 67 |
|
59 | 68 |
// check the corpus structure has the unit_type provided |
60 | 69 |
def analecCorpus = URSCorpora.getCorpus(corpus) |
... | ... | |
73 | 82 |
if (!analecCorpus.getStructure().getValeursProp(Unite.class, unit_type, property_name).contains(property_value)) { |
74 | 83 |
//println "The corpus structure does not contains unit with type=$unit_type" |
75 | 84 |
//return; |
76 |
analecCorpus.getStructure().ajouterVal(Unite.class, unit_type, property_name, value) |
|
85 |
analecCorpus.getStructure().ajouterVal(Unite.class, unit_type, property_name, property_value)
|
|
77 | 86 |
} |
78 | 87 |
|
79 | 88 |
// browse lines and check |
80 | 89 |
def units = analecCorpus.getUnites(unit_type) |
81 | 90 |
def lines = concordance.getLines() |
82 | 91 |
|
92 |
println "Annotating ${lines.size()} lines." |
|
83 | 93 |
int n = 0 |
84 | 94 |
for (int iLine = 0 ; iLine < lines.size() ; iLine++) { |
85 | 95 |
int iUnit = 0 |
86 | 96 |
def line = lines[iLine] |
87 | 97 |
def m = line.getMatch() |
98 |
def start = m.getStart()+move_start |
|
99 |
def end = m.getEnd()+move_end |
|
100 |
|
|
88 | 101 |
def do_create = true |
89 | 102 |
if (create_only_if_new && iUnit < units.size()) { // test only if create_only_if_new == true |
90 | 103 |
def unit = null |
91 | 104 |
//TODO don't iterates over all units |
92 |
while (iUnit < units.size() ) { //&& units[iUnit].getDeb() < m.getStart()) {
|
|
105 |
while (iUnit < units.size() ) { //&& units[iUnit].getDeb() < start) {
|
|
93 | 106 |
if (iUnit < units.size()) { |
94 | 107 |
unit = units[iUnit++] |
95 |
if (unit.getDeb() == m.getStart() && unit.getFin() == m.getEnd()) { // skip and print the line
|
|
108 |
if (unit.getDeb() == start && unit.getFin() == end) { // skip and print the line
|
|
96 | 109 |
println("skiping concordance line '"+line.keywordToString()+"' at "+line.getViewRef().toString()+" ("+unit.getDeb()+ ", "+unit.getFin()+")") |
97 | 110 |
do_create = false |
98 | 111 |
continue |
... | ... | |
104 | 117 |
n++ |
105 | 118 |
def props = [:] |
106 | 119 |
props[property_name] = property_value |
107 |
Unite u = analecCorpus.addUniteSaisie(unit_type, m.getStart(), m.getEnd(), props)
|
|
120 |
Unite u = analecCorpus.addUniteSaisie(unit_type, start, end, props)
|
|
108 | 121 |
// println "$props -> "+u.getProps() |
109 | 122 |
} |
110 | 123 |
} |
Formats disponibles : Unified diff