Révision 2656
| tmp/org.txm.groovy.core/src/groovy/org/txm/macro/annotation/WordProperty2WordMacro.groovy (revision 2656) | ||
|---|---|---|
| 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 |
} |
|
| tmp/org.txm.groovy.core/src/groovy/org/txm/macro/annotation/CQL2AnnotationsMacro.groovy (revision 2656) | ||
|---|---|---|
| 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.searchengine.cqp.corpus.query.* |
|
| 8 |
import org.txm.rcp.views.corpora.CorporaView |
|
| 9 |
import org.txm.annotation.kr.core.KRAnnotationEngine |
|
| 10 |
import org.txm.annotation.kr.core.repository.* |
|
| 11 |
|
|
| 12 |
def scriptName = this.class.getSimpleName() |
|
| 13 |
|
|
| 14 |
if (!(corpusViewSelection instanceof CQPCorpus)) {
|
|
| 15 |
println "** $scriptName: please select a Corpus in the Corpus view." |
|
| 16 |
return 0 |
|
| 17 |
} |
|
| 18 |
|
|
| 19 |
CQPCorpus corpus = corpusViewSelection |
|
| 20 |
|
|
| 21 |
MainCorpus mcorpus = corpus.getMainCorpus(); |
|
| 22 |
KnowledgeRepository kr = KnowledgeRepositoryManager.createSimpleKnowledgeRepository(mcorpus.getName()); |
|
| 23 |
|
|
| 24 |
@Field @Option(name="query", usage="The CQL query to select tokens", widget="String", required=true, def="") |
|
| 25 |
String query |
|
| 26 |
|
|
| 27 |
@Field @Option(name="property", usage="The property to annotate", widget="String", required=true, def="property") |
|
| 28 |
String property |
|
| 29 |
|
|
| 30 |
@Field @Option(name="value", usage="the annotation value", widget="String", required=true, def="value") |
|
| 31 |
String value |
|
| 32 |
|
|
| 33 |
// Open the parameters input dialog box |
|
| 34 |
if (!ParametersDialog.open(this)) return |
|
| 35 |
|
|
| 36 |
if (query == null || query.trim().length() == 0) {
|
|
| 37 |
println "Error: no query set." |
|
| 38 |
return 0 |
|
| 39 |
} |
|
| 40 |
|
|
| 41 |
annotManager = KRAnnotationEngine.getAnnotationManager(corpus); |
|
| 42 |
|
|
| 43 |
AnnotationType type = kr.getType(property); |
|
| 44 |
if (type == null) {
|
|
| 45 |
AnnotationType t = kr.addType(property, property); |
|
| 46 |
t.setEffect(AnnotationEffect.TOKEN); |
|
| 47 |
type = t |
|
| 48 |
} else {
|
|
| 49 |
type.setEffect(AnnotationEffect.TOKEN); |
|
| 50 |
} |
|
| 51 |
|
|
| 52 |
value_to_add = kr.getValue(type, value); |
|
| 53 |
if (value_to_add == null) { // create or not the annotation is simple mode
|
|
| 54 |
value_to_add = kr.addValue(value, value, type.getId()); |
|
| 55 |
} |
|
| 56 |
|
|
| 57 |
qr = corpus.query(new CQLQuery(query), "TMP", false) |
|
| 58 |
if (qr.getNMatch() == 0) {
|
|
| 59 |
println "No match to annotate" |
|
| 60 |
return 0 |
|
| 61 |
} |
|
| 62 |
|
|
| 63 |
annotManager.createAnnotations(type, value_to_add, qr.getMatches(), null); |
|
| 64 |
|
|
| 65 |
println query+" created "+qr.getNMatch()+" annotations." |
|
| 66 |
|
|
| 67 |
return qr.getNMatch() |
|
| tmp/org.txm.groovy.core/src/groovy/org/txm/macro/annotation/CQLList2PropertiesMacro.groovy (revision 2656) | ||
|---|---|---|
| 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.rcp.utils.JobHandler |
|
| 8 |
import org.txm.rcp.views.corpora.CorporaView |
|
| 9 |
import org.eclipse.core.runtime.Status |
|
| 10 |
import org.txm.annotation.kr.core.KRAnnotationEngine |
|
| 11 |
import org.txm.annotation.kr.core.repository.* |
|
| 12 |
import org.txm.annotation.kr.rcp.commands.SaveAnnotations |
|
| 13 |
import org.txm.annotation.kr.rcp.concordance.WordAnnotationToolbar |
|
| 14 |
|
|
| 15 |
def scriptName = this.class.getSimpleName() |
|
| 16 |
|
|
| 17 |
if (!(corpusViewSelection instanceof CQPCorpus)) {
|
|
| 18 |
println "** $scriptName: please select a Corpus in the Corpus view." |
|
| 19 |
return 0 |
|
| 20 |
} |
|
| 21 |
|
|
| 22 |
CQPCorpus corpus = corpusViewSelection |
|
| 23 |
MainCorpus mcorpus = corpus.getMainCorpus(); |
|
| 24 |
|
|
| 25 |
@Field @Option(name="queries_file", usage="The CQL query to select tokens", widget="File", required=true, def="queries.tsv") |
|
| 26 |
File queries_file |
|
| 27 |
|
|
| 28 |
@Field @Option(name="annotation_type", usage="The annotation type", widget="String", required=true, def="type") |
|
| 29 |
String annotation_type |
|
| 30 |
|
|
| 31 |
// Open the parameters input dialog box |
|
| 32 |
if (!ParametersDialog.open(this)) return |
|
| 33 |
|
|
| 34 |
int total = 0; |
|
| 35 |
|
|
| 36 |
|
|
| 37 |
def hash = ["args": ["queries_file":queries_file, "annotation_type":annotation_type], |
|
| 38 |
"corpusViewSelection":corpusViewSelection, "gse":gse |
|
| 39 |
] |
|
| 40 |
int n = gse.run(CQLList2AnnotationsMacro, hash) |
|
| 41 |
|
|
| 42 |
if (n > 0) {
|
|
| 43 |
println "Saving annotations..." |
|
| 44 |
monitor.syncExec(new Runnable() {
|
|
| 45 |
public void run() {
|
|
| 46 |
def saveJob = SaveAnnotations.save(mcorpus); |
|
| 47 |
if (saveJob == null || saveJob.getResult() == Status.CANCEL_STATUS) {
|
|
| 48 |
// update editor corpus |
|
| 49 |
System.out.println("Fail to save annotations of the corpus."); //$NON-NLS-1$
|
|
| 50 |
return; |
|
| 51 |
} else {
|
|
| 52 |
return; // something was saved |
|
| 53 |
} |
|
| 54 |
} |
|
| 55 |
}); |
|
| 56 |
} else {
|
|
| 57 |
println "No annotation to save." |
|
| 58 |
return false |
|
| 59 |
} |
|
| tmp/org.txm.groovy.core/src/groovy/org/txm/macro/annotation/CQLList2AnnotationsMacro.groovy (revision 2656) | ||
|---|---|---|
| 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.rcp.views.corpora.CorporaView |
|
| 8 |
import org.txm.annotation.kr.core.KRAnnotationEngine |
|
| 9 |
import org.txm.annotation.kr.core.repository.* |
|
| 10 |
|
|
| 11 |
def scriptName = this.class.getSimpleName() |
|
| 12 |
|
|
| 13 |
if (!(corpusViewSelection instanceof CQPCorpus)) {
|
|
| 14 |
println "** $scriptName: please select a Corpus in the Corpus view." |
|
| 15 |
return 0 |
|
| 16 |
} |
|
| 17 |
|
|
| 18 |
@Field @Option(name="queries_file", usage="The CQL query to select tokens", widget="File", required=true, def="queries.tsv") |
|
| 19 |
File queries_file |
|
| 20 |
|
|
| 21 |
@Field @Option(name="property", usage="The annotation type", widget="String", required=true, def="type") |
|
| 22 |
String property |
|
| 23 |
|
|
| 24 |
// Open the parameters input dialog box |
|
| 25 |
if (!ParametersDialog.open(this)) return |
|
| 26 |
|
|
| 27 |
int total = 0; |
|
| 28 |
|
|
| 29 |
queries_file.eachLine("UTF-8") { line ->
|
|
| 30 |
String[] split = line.split("\t", 2)
|
|
| 31 |
if (!line.startsWith("#") && split.length == 2 && split[0].length() > 0 && split[1].length() >= 0) {
|
|
| 32 |
|
|
| 33 |
def hash = ["args": |
|
| 34 |
["query":split[1], "property":property, "annotation_value":split[0]], |
|
| 35 |
"corpusViewSelection":corpusViewSelection |
|
| 36 |
] |
|
| 37 |
int n = gse.run(CQL2AnnotationsMacro, hash) |
|
| 38 |
total += n |
|
| 39 |
} else {
|
|
| 40 |
println "## ignoring "+line |
|
| 41 |
} |
|
| 42 |
} |
|
| 43 |
|
|
| 44 |
println "$queries_file created $total annotations" |
|
| 45 |
|
|
| 46 |
return total |
|
| 47 |
package org.txm.macro.annotation |
|
| 48 |
|
|
| 49 |
// STANDARD DECLARATIONS |
|
| 50 |
import org.txm.rcpapplication.swt.widget.parameters.* |
|
| 51 |
import org.txm.searchengine.cqp.corpus.* |
|
| 52 |
import org.txm.rcp.views.corpora.CorporaView |
|
| 53 |
import org.txm.annotation.kr.core.KRAnnotationEngine |
|
| 54 |
import org.txm.annotation.kr.core.repository.* |
|
| 55 |
|
|
| 56 |
def scriptName = this.class.getSimpleName() |
|
| 57 |
|
|
| 58 |
if (!(corpusViewSelection instanceof CQPCorpus)) {
|
|
| 59 |
println "** $scriptName: please select a Corpus in the Corpus view." |
|
| 60 |
return 0 |
|
| 61 |
} |
|
| 62 |
|
|
| 63 |
@Field @Option(name="queries_file", usage="The CQL query to select tokens", widget="File", required=true, def="queries.tsv") |
|
| 64 |
File queries_file |
|
| 65 |
|
|
| 66 |
@Field @Option(name="property", usage="The property to annotate", widget="String", required=true, def="type") |
|
| 67 |
String property |
|
| 68 |
|
|
| 69 |
// Open the parameters input dialog box |
|
| 70 |
if (!ParametersDialog.open(this)) return |
|
| 71 |
|
|
| 72 |
int total = 0; |
|
| 73 |
|
|
| 74 |
queries_file.eachLine("UTF-8") { line ->
|
|
| 75 |
String[] split = line.split("\t", 2)
|
|
| 76 |
if (!line.startsWith("#") && split.length == 2 && split[0].length() > 0 && split[1].length() >= 0) {
|
|
| 77 |
|
|
| 78 |
def params = [ |
|
| 79 |
"query":split[1], "property":property, "value":split[0] |
|
| 80 |
] |
|
| 81 |
|
|
| 82 |
int n = gse.runMacro(CQL2AnnotationsMacro, params) |
|
| 83 |
total += n |
|
| 84 |
} else {
|
|
| 85 |
println "## ignoring "+line |
|
| 86 |
} |
|
| 87 |
} |
|
| 88 |
|
|
| 89 |
println "$queries_file created $total annotations" |
|
| 90 |
|
|
| 91 |
return total |
|
Formats disponibles : Unified diff