Statistics
| Revision:

root / tmp / org.txm.core / src / groovy / org / txm / tal / melt / MEltAnnotate.groovy @ 148

History | View | Annotate | Download (4.5 kB)

1
// Copyright © 2010-2013 ENS de Lyon.
2
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of
3
// Lyon 2, University of Franche-Comté, University of Nice
4
// Sophia Antipolis, University of Paris 3.
5
//
6
// The TXM platform is free software: you can redistribute it
7
// and/or modify it under the terms of the GNU General Public
8
// License as published by the Free Software Foundation,
9
// either version 2 of the License, or (at your option) any
10
// later version.
11
//
12
// The TXM platform is distributed in the hope that it will be
13
// useful, but WITHOUT ANY WARRANTY; without even the implied
14
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15
// PURPOSE. See the GNU General Public License for more
16
// details.
17
//
18
// You should have received a copy of the GNU General
19
// Public License along with the TXM platform. If not, see
20
// http://www.gnu.org/licenses.
21
//
22
//
23
//
24
// $LastChangedDate: 2013-11-08 13:38:06 +0100 (Fri, 08 Nov 2013) $
25
// $LastChangedRevision: 2569 $
26
// $LastChangedBy: mdecorde $
27
//
28
package org.txm.tal.melt
29

    
30
import java.text.DateFormat
31

    
32
import org.txm.Toolbox
33
import org.txm.importer.*
34
import org.txm.importer.cwb.*
35
import org.txm.objects.*
36
import org.txm.scripts.teitxm.Annotate
37
import org.txm.tal.SlashFile2TTRez
38

    
39
// TODO: Auto-generated Javadoc
40
/**
41
 * Annotate and replace the TEI-TXM files of the folder $rootDirFile/txm with TreeTagger.
42
 * creates $rootDirFile/interp and $rootDirFile/treetagger
43
 *
44
 */
45
class MEltAnnotate extends Annotate {
46

    
47
        public void initTTOutfileInfos(File rootDirFile, File modelfile)
48
        {
49
                reportFile = new File(rootDirFile,"NLPToolsParameters.xml");
50

    
51
                respPerson = System.getProperty("user.name");
52
                respId = "txm";
53
                respDesc = "NLP annotation tool";
54
                respDate = DateFormat.getDateInstance(DateFormat.SHORT, Locale.UK).format(new Date());
55
                respWhen = DateFormat.getDateInstance(DateFormat.FULL, Locale.UK).format(new Date());
56

    
57
                appIdent = "MElt";
58
                appVersion = "2.0";
59

    
60
                distributor = "";
61
                publiStmt = """""";
62
                sourceStmt = """""";
63

    
64
                types = ["frpos"];
65
                typesTITLE = ["frpos"];
66

    
67
                typesDesc = ["pos tagset built from MElt"]
68
                typesTAGSET = ["",""]
69
                typesWEB = ["",""]
70

    
71
                idform ="w";
72
        }
73

    
74
        /**
75
         * Apply tt.
76
         *
77
         * @param ttsrcfile the ttsrcfile
78
         * @param ttoutfile the ttoutfile
79
         * @param modelfile the modelfile
80
         * @return true, if successful
81
         */
82
        public boolean applyTT(File ttsrcfile, File ttoutfile, File modelfile) {
83
                return applyMElt(ttsrcfile, ttoutfile)
84
        }
85

    
86
        public boolean applyMElt(File ttsrcfile, File ttoutfile) {
87
                // Call Melt
88
                def args = [];
89
                args << "MElt"
90
                args
91
                ProcessBuilder pb = new ProcessBuilder(args);
92
                Process process = null;
93
                try {
94
                        process = pb.start();
95
                } catch (IOException e) {
96
                        System.err.println(e);
97
                }
98
                InputStream is = process.getInputStream();
99
                OutputStream os = process.getOutputStream();
100
                InputStreamReader isr = new InputStreamReader(is);
101
                BufferedReader br = new BufferedReader(isr);
102
                ttsrcfile.eachLine ("UTF-8") { line ->
103
                        println "> $line"
104
                        os.println line
105
                }
106
                
107
                ttoutfile.withWriter("UTF-8") { writer ->
108
                        String line;
109
                        println "getting result"
110
                        while ((line = br.readLine()) != null) {
111
                                println "< $line"
112
                                writer.println(line);
113
                        }
114
                        println "end of result"
115
                        int e = 0;
116
                        try {
117
                                e = process.waitFor();
118
                        } catch (Exception err) {        }
119

    
120
                        if (e != 0) {
121
                                System.err .println("Process exited abnormally with code " + e + " at " + DateFormat.getDateInstance(DateFormat.FULL, Locale.UK).format(new Date())); //$NON-NLS-1$ //$NON-NLS-2$
122

    
123
                                for (int c = 0; c < args.size(); c++)
124
                                        System.out.print("" + args.get(c) + " "); //$NON-NLS-1$ //$NON-NLS-2$
125
                                System.out.println();
126
                        }
127
                }
128

    
129
                // Reformat MElt output
130
                File tmpFile = new File(ttoutfile.getParentFile(),ttoutfile.getName()+".tmp")
131
                new SlashFile2TTRez(ttoutfile, tmpFile, "UTF-8")
132
        }
133
        
134
        public boolean run(File binDir, File txmDir) {
135
                return run(binDir, txmDir, "fr.par")
136
        }
137

    
138
        public static void main(def args) {
139
                Toolbox.setParam(Toolbox.INSTALL_DIR,new File("C:/Program Files/TXM"));
140
                Toolbox.setParam(Toolbox.TREETAGGER_INSTALL_PATH, new File("/home/mdecorde/treetagger"));
141
                Toolbox.setParam(Toolbox.TREETAGGER_MODELS_PATH, new File("/home/mdecorde/treetagger/models"));
142
                Toolbox.setParam(Toolbox.METADATA_ENCODING, "UTF-8");
143
                Toolbox.setParam(Toolbox.METADATA_COLSEPARATOR, ",");
144
                Toolbox.setParam(Toolbox.METADATA_TXTSEPARATOR, "\"");
145
                Toolbox.setParam(Toolbox.USER_TXM_HOME, new File("/home/mdecorde/TXM"));
146
                
147
                println "-- ANNOTATE - Running MElt tool"
148

    
149
                File binDir = new File("/home/mdecorde/xml/melt-out")
150
                File txmDir = new File("/home/mdecorde/xml/melt-in")
151
                new MEltAnnotate().run(binDir, txmDir);
152
        }
153
}