Revision 2715

tmp/org.txm.groovy.core/src/groovy/org/txm/macro/annotation/CQLList2PropertiesMacro.groovy (revision 2715)
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 2715)
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
tmp/org.txm.groovy.core/src/groovy/org/txm/macro/annotation/CQL2AnnotationsMacro.groovy (revision 2715)
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/CQLList2WordPropertiesMacro.groovy (revision 2715)
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/CQLList2WordAnnotationsMacro.groovy (revision 2715)
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
tmp/org.txm.groovy.core/src/groovy/org/txm/macro/annotation/CQL2WordAnnotationsMacro.groovy (revision 2715)
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()

Also available in: Unified diff