Statistics
| Revision:

root / tmp / org.txm.groovy.core / src / groovy / org / txm / scripts / swb / SearchReplaceFromList.groovy @ 1000

History | View | Annotate | Download (2.2 kB)

1
package org.txm.scripts.sw
2
// Copyright © - ENS de Lyon - http://textometrie.ens-lyon.fr
3
// @author mdecorde
4
//
5
// This file is part of the TXM platform.
6
//
7
// The TXM platform is free software: you can redistribute it and/or modify
8
// it under the terms of the GNU General Public License as published by
9
// the Free Software Foundation, either version 3 of the License, or
10
// (at your option) any later version.
11
//
12
// The TXM platform is distributed in the hope that it will be useful,
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
// GNU General Public License for more details.
16
//
17
// You should have received a copy of the GNU General Public License
18
// along with the TXM platform.  If not, see <http://www.gnu.org/licenses/>.
19
//
20
// $LastChangedDate: 2012-10-01 08:24:58 +0200 (lun., 01 oct. 2012) $
21
// $LastChangedRevision: 2269 $
22
// $LastChangedBy: sheiden $
23
//
24

    
25
// parameters
26

    
27
file = new File("/home/mdecorde/xml/apollinaire/apollinaire.xml")
28
out = new File("/home/mdecorde/xml/apollinaire/apo/apollinaire.xml")
29
def changesFind = [ "</recueil>",        "<paragraphe>", "</paragraphe>", "<racine>",        "</racine>", "<interp",        "</interp>", "<TEI xmlns=\"http://www.tei-c.org/ns/1.0\" xmlns:txm=\"http://textometrie.org/1.0\">"        ]
30
def changesReplace = [ "</recueil><pb/>", "<p>", "</p><lb/>", '<text id ="apollinaire">', '</text',        '<txm:ana',        '</txm:ana>', """<TEI xmlns="http://www.tei-c.org/ns/1.0" xmlns:txm="http://textometrie.org/1.0">
31
<teiHeader type="text">
32
<fileDesc>
33
<titleStmt>
34
<title>null</title>
35
<respStmt>
36
<resp id="cordial">initial tagging</resp></respStmt>
37
</titleStmt>
38
</fileDesc>
39
<encodingDesc>
40
<classDecl>
41
<taxonomy id="pos"><bibl type="tagset"/></taxonomy>
42
<taxonomy id="func"><bibl type="tagset"/></taxonomy>
43
<taxonomy id="lemma"><bibl type="tagset"/></taxonomy>
44
</classDecl>
45
</encodingDesc>
46
</teiHeader>""" ]
47

    
48
// main body
49
out.write('')                                // create empty file
50
out.withWriter { writer ->
51
        String text = file.getText("UTF-8");
52
        for (int i = 0 ; i < changesFind.size() ; i++) {
53
                println "loop $i: "+changesFind[i] +" >> "+ changesReplace[i]
54
                text = text.replaceAll(changesFind[i], changesReplace[i])
55
        }
56
        out.write(text)
57
}