Outils pour utilisateurs

Outils du site


public:specs_commande_list

Fonctionnalité PropertyList (nom à trouver)

Objectif

Pouvoir lister simplement toutes les valeurs qu'une propriété de mot ou de structure d'un corpus prend.

Méthode

Commencer par implémenter une macro réalisant la fonctionnalité

Solution

Macro PropertyList

La macro “décompile” les index CQP en s'appuyant sur les méthodes disponibles dans CQI.

Les propriétés de mot ne posent pas de problème, par contre les indexes de propriété de structure sont incomplets. Il manque des index sur les valeurs des propriétés d'une structure. On a que 2 index : la positions des structures et la valeur d'une propriété pour un numéro d'ordre de structure.

// STANDARD DECLARATIONS
package org.txm.macro

import org.kohsuke.args4j.*
import groovy.transform.Field
import org.txm.rcpapplication.swt.widget.parameters.*
import org.txm.*
import org.txm.searchengine.corpus.*
import org.txm.searchengine.cqp.corpus.*

// BEGINNING OF PARAMETERS


// Parameter declaration - Déclaration du paramètre
@Field @Option(name="propertyName", usage="word property or structure property name", widget="String", required=true, def="text_id")
String propertyName;

// Parameters settings UI
if (!ParametersDialog.open(this)) {
	println("** ExecCQLMacro error: Impossible to open Parameters settings UI dialog box.")
	return
}

if (!(corpusViewSelection instanceof Corpus)) {
	println "Corpora view selection must be a Corpus. Aborting"
	return;
}

def list_wordproperty(def corpus, def property) {
	println "Listing property values of '$property' property of '$corpus' corpus"
	def CQI = Toolbox.getCqiClient()
	int n = CQI.lexiconSize(property.getQualifiedName())
	println "$n values :"
	int[] ids = 0..(n-1);
	def rez = CQI.id2Str(property.getQualifiedName(), ids) // or call CQI.fdist1(subcorpus, cutoff, field, attribute)
	for (String s : rez) {
		println s
	} 
}

def list_structureproperty(def corpus, def property) {
	println "Listing structural unit property values of '"+property.getFullName()+"' of '$corpus' corpus"
	def CQI = Toolbox.getCqiClient()
	int n = CQI.attributeSize(property.getQualifiedName())
	println "$n values :"
	int[] strucs = 0..(n-1);
	def rez = CQI.struc2Str(property.getQualifiedName(), strucs)
	LinkedHashSet<String> set = new LinkedHashSet<String>();
	for (String s : rez) {
		set << s
	}
	
	for (String s : set) {
		println s
	}
}

Corpus corpus = corpusViewSelection
if (propertyName.contains("_")) {
	def split = propertyName.split("_", 2);
	def structName = split[0]
	propertyName = split[1]
	if (propertyName.contains("_") || structName.contains("_")) {
		println "malformed structure property name : struct_property is needed. We got '$structName' and '$propertyName'"
		return;
	}
	
	StructuralUnit su = corpus.getStructuralUnit(structName)
	if (su == null) {
		println "Structural unit not found: $structName"
		return;
	}
	
	Property prop = su.getProperty(propertyName)
	if (prop == null) {
		println "Structural unit property not found: ${structName}_$propertyName"
		return;
	}
	
	list_structureproperty(corpus, prop)
} else {
	Property prop = corpus.getProperty(propertyName)
	if (prop == null) {
		println "Word property not found: $propertyName"
		return;
	}
	
	list_wordproperty(corpus, prop)
}
public/specs_commande_list.txt · Dernière modification : 15/09/2016 17:37 de matthieu.decorde@ens-lyon.fr