Révision 2717
| tmp/org.txm.groovy.core/src/groovy/org/txm/macro/annotation/CQLList2WordPropertiesMacro.groovy (revision 2717) | ||
|---|---|---|
| 25 | 25 |
@Field @Option(name="queries_file", usage="The CQL query to select tokens", widget="File", required=true, def="queries.tsv") |
| 26 | 26 |
File queries_file |
| 27 | 27 |
|
| 28 |
@Field @Option(name="annotation_type", usage="The annotation type", widget="String", required=true, def="type")
|
|
| 29 |
String annotation_type
|
|
| 28 |
@Field @Option(name="property", usage="The annotation type", widget="String", required=true, def="type")
|
|
| 29 |
String property
|
|
| 30 | 30 |
|
| 31 | 31 |
// Open the parameters input dialog box |
| 32 | 32 |
if (!ParametersDialog.open(this)) return |
| ... | ... | |
| 34 | 34 |
int total = 0; |
| 35 | 35 |
|
| 36 | 36 |
|
| 37 |
def hash = ["args": ["queries_file":queries_file, "annotation_type":annotation_type],
|
|
| 37 |
def hash = ["args": ["queries_file":queries_file, "property":property],
|
|
| 38 | 38 |
"corpusViewSelection":corpusViewSelection, "gse":gse |
| 39 | 39 |
] |
| 40 |
int n = gse.run(CQLList2AnnotationsMacro, hash) |
|
| 40 |
int n = gse.run(CQLList2WordAnnotationsMacro, hash)
|
|
| 41 | 41 |
|
| 42 | 42 |
if (n > 0) {
|
| 43 | 43 |
println "Saving annotations..." |
| tmp/org.txm.groovy.core/src/groovy/org/txm/macro/annotation/CQLList2WordAnnotationsMacro.groovy (revision 2717) | ||
|---|---|---|
| 34 | 34 |
["query":split[1], "property":property, "annotation_value":split[0]], |
| 35 | 35 |
"corpusViewSelection":corpusViewSelection |
| 36 | 36 |
] |
| 37 |
int n = gse.run(CQL2AnnotationsMacro, hash) |
|
| 37 |
int n = gse.run(CQL2WordAnnotationsMacro, hash)
|
|
| 38 | 38 |
total += n |
| 39 | 39 |
} else {
|
| 40 | 40 |
println "## ignoring "+line |
| ... | ... | |
| 43 | 43 |
|
| 44 | 44 |
println "$queries_file created $total annotations" |
| 45 | 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 | 46 |
return total |
| tmp/org.txm.groovy.core/src/groovy/org/txm/macro/annotation/WordProperty2WordMacro.groovy (revision 2717) | ||
|---|---|---|
| 31 | 31 |
@Field @Option(name="outputDirectory", usage="The CQL query to select tokens", widget="Folder", required=true, def="result_directory") |
| 32 | 32 |
File outputDirectory |
| 33 | 33 |
|
| 34 |
@Field @Option(name="property", usage="The annotation type", widget="String", required=true, def="type")
|
|
| 34 |
@Field @Option(name="property", usage="The property to move", widget="String", required=true, def="type")
|
|
| 35 | 35 |
String property |
| 36 | 36 |
|
| 37 | 37 |
//@Field @Option(name="property_value_to_ignore", usage="The annotation type", widget="String", required=true, def="__undef__") |
| ... | ... | |
| 84 | 84 |
} |
| 85 | 85 |
} |
| 86 | 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 | 87 |
} |
Formats disponibles : Unified diff