Revision 2105 tmp/org.txm.analec.rcp/src/org/txm/macro/urs/exploit/SchemasListMacro.groovy

SchemasListMacro.groovy (revision 2105)
18 18
import org.apache.commons.lang.StringUtils
19 19
import org.txm.searchengine.cqp.CQPSearchEngine
20 20

  
21
if (!(corpusViewSelection instanceof CQPCorpus)) {
22
	println "Corpus view selection is not a Corpus"
23
	return;
21
def selection = []
22
for (def s : corpusViewSelections) {
23
	if (s instanceof CQPCorpus) selection << s
24
	else if (s instanceof Partition) selection.addAll(s.getParts())
24 25
}
25 26

  
27
if (selection.size() == 0) {
28
	println "** $scriptName: please select a Corpus or a Partition in the Corpus view: "+corpusViewSelections
29
	return false
30
} else {
31
	for (def c : selection) c.compute(false)
32
}
33

  
26 34
// BEGINNING OF PARAMETERS
27 35
@Field @Option(name="schema_ursql", usage="TYPE@PROP=VALUE", widget="String", required=true, def="CHAINE")
28 36
String schema_ursql
......
50 58
if (debug == "OFF") debug = 0; else if (debug == "ON") debug = 1; else if (debug == "ALL") debug = 2 else if (debug == "REALLY ALL") debug = 3
51 59

  
52 60

  
53
CQPCorpus corpus = corpusViewSelection
54
def analecCorpus = URSCorpora.getCorpus(corpus)
55

  
56
def errors = AnalecUtils.isPropertyDefined(Schema.class, analecCorpus, schema_ursql)
57
if (errors.size() > 0) {
58
	println "** The $schema_ursql schema URSQL cannot be computed in the corpus with types: $errors."
59
	return;
60
}
61

  
62
errors=AnalecUtils.isPropertyDefined(Unite.class, analecCorpus, unit_ursql)
63
if (errors.size() > 0) {
64
	println "** $unit_ursql unit URSQL cannot be computed in the corpus with types: $errors."
65
	return;
66
}
67

  
68
def CQI = CQPSearchEngine.getCqiClient()
69

  
70
if (buildCQL) {
71
	word_prop = corpus.getProperty("id")
72
} else {
73
	word_prop = corpus.getProperty(word_property)
74
}
75

  
76
def schemas = AnalecUtils.selectSchemasInCorpus(debug, analecCorpus, corpus, schema_ursql, minimum_schema_size, maximum_schema_size);
77
schemas.sort() {it.getProps()}
78
def nSchemas = 0
79

  
80
def lens = [:]
81
for (def schema : schemas) {
82

  
83
	def allUnites = schema.getUnitesSousjacentesNonTriees()
84
	def units = AnalecUtils.filterElements(debug, allUnites, unit_ursql)
61
for (def corpus : selection) {
62
	def analecCorpus = URSCorpora.getCorpus(corpus)
85 63
	
86
	print schema.getProps().toString()+ ": "
87
	def first = true
88
	for (def unit : units) {
89

  
90
		String forme =  null;
91

  
92
		if (buildCQL) {
93
			int[] pos = null
94
			if (unit.getDeb() == unit.getFin()) pos = [unit.getDeb()]
95
			else pos = (unit.getDeb()..unit.getFin())
96
			def first2= true
97
			q = ""
98
			pos.each {
99
				if (first2) { first2 = false } else { q = q+" " }
100
				int[] pos2 = [it]
101
				q = q+"["+word_prop+"=\""+CQI.cpos2Str(word_prop.getQualifiedName(), pos2)[0]+"\"]"
102
			}
103
			if (first) { first = false } else { print "|" }
104
			print "("+q+")"
105
		} else {
106
			if (word_prop == null) { // word_property is the analec unit property to use
107
				forme = unit.getProp(word_property)
108
			} else {
64
	def errors = AnalecUtils.isPropertyDefined(Schema.class, analecCorpus, schema_ursql)
65
	if (errors.size() > 0) {
66
		println "** The $schema_ursql schema URSQL cannot be computed in the corpus with types: $errors."
67
		return;
68
	}
69
	
70
	errors=AnalecUtils.isPropertyDefined(Unite.class, analecCorpus, unit_ursql)
71
	if (errors.size() > 0) {
72
		println "** $unit_ursql unit URSQL cannot be computed in the corpus with types: $errors."
73
		return;
74
	}
75
	
76
	def CQI = CQPSearchEngine.getCqiClient()
77
	
78
	if (buildCQL) {
79
		word_prop = corpus.getProperty("id")
80
	} else {
81
		word_prop = corpus.getProperty(word_property)
82
	}
83
	
84
	def schemas = AnalecUtils.selectSchemasInCorpus(debug, analecCorpus, corpus, schema_ursql, minimum_schema_size, maximum_schema_size);
85
	schemas.sort() {it.getProps()}
86
	def nSchemas = 0
87
	
88
	def lens = [:]
89
	
90
	println "$corpus schemas (${schemas.size()}):"
91
	for (def schema : schemas) {
92
	
93
		def allUnites = schema.getUnitesSousjacentesNonTriees()
94
		def units = AnalecUtils.filterElements(debug, allUnites, unit_ursql)
95
		
96
		print schema.getProps().toString()+ ": "
97
		def first = true
98
		for (def unit : units) {
99
	
100
			String forme =  null;
101
	
102
			if (buildCQL) {
109 103
				int[] pos = null
110 104
				if (unit.getDeb() == unit.getFin()) pos = [unit.getDeb()]
111 105
				else pos = (unit.getDeb()..unit.getFin())
112
				
113
					forme = StringUtils.join(CQI.cpos2Str(word_prop.getQualifiedName(), pos), " ") // ids is enough
106
				def first2= true
107
				q = ""
108
				pos.each {
109
					if (first2) { first2 = false } else { q = q+" " }
110
					int[] pos2 = [it]
111
					q = q+"["+word_prop+"=\""+CQI.cpos2Str(word_prop.getQualifiedName(), pos2)[0]+"\"]"
112
				}
113
				if (first) { first = false } else { print "|" }
114
				print "("+q+")"
115
			} else {
116
				if (word_prop == null) { // word_property is the analec unit property to use
117
					forme = unit.getProp(word_property)
118
				} else {
119
					int[] pos = null
120
					if (unit.getDeb() == unit.getFin()) pos = [unit.getDeb()]
121
					else pos = (unit.getDeb()..unit.getFin())
122
					
123
						forme = StringUtils.join(CQI.cpos2Str(word_prop.getQualifiedName(), pos), " ") // ids is enough
124
				}
125
	
126
				if (first) { first = false } else { print separator }
127
				print forme
114 128
			}
115

  
116
			if (first) { first = false } else { print separator }
117
			print forme
118 129
		}
130
		println ""
131
	
132
		nSchemas++
119 133
	}
120
	println ""
134
}
121 135

  
122
	nSchemas++
123
}

Also available in: Unified diff