Statistics
| Revision:

root / tmp / org.txm.analec.rcp / src / org / txm / macro / urs / DemoMacro.groovy @ 2151

History | View | Annotate | Download (4 kB)

1
package org.txm.macro.urs
2

    
3
import org.txm.annotation.urs.URSCorpora
4
import org.txm.searchengine.cqp.corpus.CQPCorpus
5
import visuAnalec.elements.*
6

    
7
// get the CQP corpus
8
if (!(corpusViewSelection instanceof CQPCorpus)) {
9
        println "Corpus view selection is no a corpus: $corpusViewSelection"
10
        return false;
11
}
12
def corpus = corpusViewSelection
13

    
14
// get the Analec corpus : stores the annotations and annotation structure
15

    
16
def analecCorpus = URSCorpora.getCorpus(corpus)
17

    
18
// get the annotations structure : stores the available annotation types, properties and values
19

    
20
def structure = analecCorpus.getStructure()
21

    
22
// get the annotations view : stores annotations and annotation structure display rules
23

    
24
def view = URSCorpora.getVue(corpus)
25

    
26
// display annotations per Element type (Unite, Relation, Schema) and per type
27

    
28
// Create annotation type
29

    
30
structure.ajouterType(Unite.class, "EXEMPLE");
31
//structure.ajouterType(Relation.class, "EXEMPLE");
32
//structure.ajouterType(Schema.class, "EXEMPLE");
33
println structure.getTypes(Unite.class)
34

    
35
// Create annotation property
36

    
37
structure.ajouterProp(Unite.class, "EXEMPLE", "PEXEMPLE")
38
println structure.getNomsProps(Unite.class, "EXEMPLE")
39

    
40
// Create annotation value
41

    
42
structure.ajouterVal(Unite.class, "EXEMPLE", "PEXEMPLE", "oui")
43
structure.ajouterVal(Unite.class, "EXEMPLE", "PEXEMPLE", "non")
44

    
45
// Create annotations
46

    
47
// Unite
48
def u = analecCorpus.addUniteSaisie("EXEMPLE", 0, 10, ["PEXEMPLE":"oui"])
49
def u2 = analecCorpus.addUniteSaisie("EXEMPLE", 12, 12, ["PEXEMPLE":"oui"])
50
println u
51

    
52
// Edit annotations
53

    
54
u.getProps()["PEXEMPLE"] = "non"
55

    
56
// Unit getters
57

    
58
println u.getDeb() // start of unit
59
println u.getFin() // end of unit
60

    
61
println u.getProp("EXEMPLE")
62
println u.getType()
63

    
64
// Relation
65
Relation relation = new Relation("REXEMPLE", u, u2)
66
relation.getProps().put("PEXEMPLE", "oui")
67
analecCorpus.addRelationLue(relation)  // add the new relation
68

    
69
// Schema
70
Schema schema = new Schema()
71
schema.type = "SEXEMPLE"
72
schema.props.put("PEXEMPLE", "oui")
73
schema.ajouter(u) // insert one unit
74

    
75
analecCorpus.addSchemaLu(schema)  // add the new schema
76

    
77
// Browse Units
78

    
79
println "Units:"
80
for (String type : structure.getUnites()) {
81
        def units = analecCorpus.getUnites(type)
82
        if (units.size() > 0) {
83
                println "        ${units.size()} $type"
84
        }
85
}
86

    
87
// Browse Relations
88

    
89
println "Relations:"
90
for (String type : structure.getRelations()) {
91
        def relations = analecCorpus.getRelations(type)
92
        if (relations.size() > 0) {
93
                println "        ${relations.size()} $type"
94
        }
95
}
96

    
97
// Browse Schemas
98

    
99
println "Schemas:"
100
for (String type : structure.getSchemas()) {
101
        def schemas = analecCorpus.getSchemas(type)
102
        if (schemas.size() > 0) {
103
                println "        ${schemas.size()} $type"
104
        }
105
}
106

    
107
// URS selections
108

    
109
// select Schemas
110
def debug = 0 // 1 2 for more logs
111
def strict_inclusion = true
112
def position = 0
113
def minimum_schema_size = 1;
114
def maximum_schema_size = 10;
115
def schema_ursql = "SEXEMPLE"
116
def unit_ursql = "EXEMPLE@PEXEMPLE=oui"
117
println AnalecUtils.selectSchemasInCorpus(debug, analecCorpus, corpus, schema_ursql, minimum_schema_size, maximum_schema_size, strict_inclusion)
118

    
119

    
120
// with URSQL
121
println AnalecUtils.filterElements(debug, analecCorpus.getUnites("EXEMPLE"), unit_ursql)
122

    
123
// with intersection with CQP corpus matches
124
AnalecUtils.filterUniteByInclusion(debug, analecCorpus.getUnites("EXEMPLE"), corpus.getMatches(), strict_inclusion, position)
125

    
126
// by size
127
AnalecUtils.filterBySize(analecCorpus.getSchemas("SEXEMPLE"), minimum_schema_size, maximum_schema_size)
128

    
129
// Delete annotations
130

    
131
analecCorpus.supUnite(u)
132
//analecCorpus.supRelation(rel)
133
//analecCorpus.supSchema(sch)
134

    
135
// Delete annotation value
136

    
137
structure.supprimerVal(Unite.class, "EXEMPLE", "PEXEMPLE", "oui")
138
structure.supprimerVal(Unite.class, "EXEMPLE", "PEXEMPLE", "non")
139

    
140
// Delete annotation property
141

    
142
structure.supprimerProp(Unite.class, "EXEMPLE", "PEXEMPLE")
143

    
144
// Delete annotation type
145

    
146
structure.supprimerType(Unite.class, "EXEMPLE");
147
//structure.supprimerType(Relation.class, "EXEMPLE");
148
//structure.supprimerType(Schema.class, "EXEMPLE");
149

    
150
// Revert changes
151

    
152
//URSCorpora.revert(corpus);
153

    
154
// Save changes
155

    
156
//URSCorpora.saveCorpus(corpus)
157