Statistics
| Revision:

root / tmp / org.txm.groovy.core / src / groovy / org / txm / macro / annotation / WordProperty2WordMacro.groovy @ 2656

History | View | Annotate | Download (4.8 kB)

1

    
2
package org.txm.macro.annotation
3

    
4
// STANDARD DECLARATIONS
5
import org.txm.rcpapplication.swt.widget.parameters.*
6
import org.txm.searchengine.cqp.corpus.*
7
import org.txm.xml.DOMIdentityHook
8
import org.txm.xml.LocalNameHookActivator
9
import org.txm.xml.XMLProcessor
10
import org.txm.objects.*
11
import org.txm.rcp.utils.JobHandler
12
import org.txm.rcp.views.corpora.CorporaView
13
import org.eclipse.core.runtime.Status
14
import org.txm.annotation.kr.core.KRAnnotationEngine
15
import org.txm.annotation.kr.core.repository.*
16
import org.txm.annotation.kr.rcp.commands.SaveAnnotations
17
import org.txm.annotation.kr.rcp.concordance.WordAnnotationToolbar
18
import org.txm.importer.StaxIdentityParser
19

    
20
def scriptName = this.class.getSimpleName()
21

    
22
if (!(corpusViewSelection instanceof MainCorpus)) {
23
        println "** $scriptName: please select a Corpus in the Corpus view."
24
        return 0
25
}
26

    
27
MainCorpus mcorpus = corpusViewSelection
28
Project project = mcorpus.getProject()
29
File txmDir = new File(project.getProjectDirectory(), "txm/"+mcorpus.getName())
30

    
31
@Field @Option(name="outputDirectory", usage="The CQL query to select tokens", widget="Folder", required=true, def="result_directory")
32
File outputDirectory
33

    
34
@Field @Option(name="property", usage="The annotation type", widget="String", required=true, def="type")
35
String property
36

    
37
//@Field @Option(name="property_value_to_ignore", usage="The annotation type", widget="String", required=true, def="__undef__")
38
//String property_value_to_ignore
39

    
40
// Open the parameters input dialog box
41
if (!ParametersDialog.open(this)) return
42

    
43
if (!outputDirectory.exists()) {
44
        println "Error: output directory not found: "+outputDirectory
45
        return false
46
}
47

    
48
for (Text text : project.getChildren(Text.class)) {
49
        println "Text: "+text
50
        
51
        File orig = text.getXMLTXMFile()
52
        if (!orig.exists()) {
53
                println "Warning: no XML-TXM file found for "+text
54
                continue // next !
55
        }
56
        
57
        File result = new File(outputDirectory, orig.getName())
58
        
59
        if (false && result.lastModified() > orig.lastModified()) {
60
                println "Skipping $text: result file is more recent: $result"
61
                continue // next !
62
        }
63
        
64
        XMLProcessor xp = new XMLProcessor(orig);
65
        LocalNameHookActivator activator = new LocalNameHookActivator("w");
66
        new DOMIdentityHook("word", activator, xp) {
67
                @Override
68
                public void processDom() {
69
                        //println dom
70
                        use(groovy.xml.dom.DOMCategory) {
71
                                def form = dom.form[0]
72
                                def anatype = dom.ana.findAll(){ a -> a['@type'] == "#$property"}
73
                                println form.text()+" -> $anatype"
74
                                if (anatype.size() > 0) { // keep the word
75
                                        anatype = anatype[0]
76
                                        def s = form.text()
77
                                        form.setTextContent(anatype.text())
78
                                        anatype['@type'] = "#form"
79
                                        anatype.setTextContent(s)
80
                                } else {
81
                                        dom = null;
82
                                }
83
                        }
84
                }
85
        }
86
        xp.process(result)
87
}
88
package org.txm.macro.annotation
89

    
90
// STANDARD DECLARATIONS
91
import org.txm.rcpapplication.swt.widget.parameters.*
92
import org.txm.searchengine.cqp.corpus.*
93
import org.txm.xml.DOMIdentityHook
94
import org.txm.xml.LocalNameHookActivator
95
import org.txm.xml.XMLProcessor
96
import org.txm.objects.*
97
import org.txm.rcp.utils.JobHandler
98
import org.txm.rcp.views.corpora.CorporaView
99
import org.eclipse.core.runtime.Status
100
import org.txm.annotation.kr.core.KRAnnotationEngine
101
import org.txm.annotation.kr.core.repository.*
102
import org.txm.annotation.kr.rcp.commands.SaveAnnotations
103
import org.txm.annotation.kr.rcp.concordance.WordAnnotationToolbar
104
import org.txm.importer.StaxIdentityParser
105

    
106
def scriptName = this.class.getSimpleName()
107

    
108
if (!(corpusViewSelection instanceof MainCorpus)) {
109
        println "** $scriptName: please select a Corpus in the Corpus view."
110
        return 0
111
}
112

    
113
MainCorpus mcorpus = corpusViewSelection
114
Project project = mcorpus.getProject()
115
File txmDir = new File(project.getProjectDirectory(), "txm/"+mcorpus.getName())
116

    
117
@Field @Option(name="outputDirectory", usage="The CQL query to select tokens", widget="Folder", required=true, def="result_directory")
118
File outputDirectory
119

    
120
@Field @Option(name="property", usage="The property used to create words", widget="String", required=true, def="type")
121
String property
122

    
123
// Open the parameters input dialog box
124
if (!ParametersDialog.open(this)) return
125

    
126
if (!outputDirectory.exists()) {
127
        println "Error: output directory not found: "+outputDirectory
128
        return false
129
}
130

    
131
for (Text text : project.getChildren(Text.class)) {
132
        println "Text: "+text
133
        
134
        File orig = text.getXMLTXMFile()
135
        if (!orig.exists()) {
136
                println "Warning: no XML-TXM file found for "+text
137
                continue // next !
138
        }
139
        
140
        File result = new File(outputDirectory, orig.getName())
141
        
142
        if (result.lastModified() > orig.lastModified()) {
143
                println "Skipping $text: result file is more recent: $result"
144
                continue // next !
145
        }
146
        
147
        XMLProcessor xp = new XMLProcessor(orig);
148
        LocalNameHookActivator activator = new LocalNameHookActivator("w");
149
        new DOMIdentityHook("word", activator, xp) {
150
                @Override
151
                public void processDom() {
152
                        println dom.ana.size()
153
                }
154
        }
155
        xp.process(result)
156
}