CWB
Macros | Functions
class-mapping.c File Reference
#include "globals.h"
#include "macros.h"
#include "cdaccess.h"
#include "class-mapping.h"

Macros

#define NAME_TOKEN   "#name "
 The token that identifies a "name" line in a mapping file. More...
 
#define CLASS_REALLOC_THRESHOLD   16
 increment for memory reallocation of classes in a SingleMapping More...
 
#define TOKEN_REALLOC_THRESHOLD   16
 increment for memory reallocation of tokens in a SingleMapping More...
 

Functions

int drop_single_mapping (SingleMapping *smap)
 Deletes a SingleMapping object. More...
 
static int intcompare (const void *i, const void *j)
 
Mapping read_mapping (Corpus *corpus, char *attr_name, char *file_name, char **error_string)
 Creates a Mapping from a file. More...
 
int drop_mapping (Mapping *map)
 Deletes a Mapping object. More...
 
void print_mapping (Mapping map)
 Writes a description of a Mapping object to STDERR. More...
 
SingleMapping map_token_to_class (Mapping map, char *token)
 Gets the SingleMapping that contains a particular token in the given Mapping. More...
 
int map_token_to_class_number (Mapping map, char *token)
 Gets the number of the class that contains a particular token in the given Mapping. More...
 
int map_id_to_class_number (Mapping map, int id)
 Gets the number of the class that contains a particular token in the given Mapping. More...
 
int * map_class_to_tokens (SingleMapping map, int *nr_tokens)
 Gets the location of the token IDs in this class. More...
 
int number_of_classes (Mapping map)
 Gets the number of classes possessed by this Mapping. More...
 
SingleMapping find_mapping (Mapping map, char *name)
 Find a class within this mapping. More...
 
int number_of_tokens (SingleMapping map)
 Gets the number of tokens possessed by this Mapping. More...
 
int member_of_class_s (Mapping map, SingleMapping class, char *token)
 Checks whether a token is a member of a class in a Mapping. More...
 
int member_of_class_i (Mapping map, SingleMapping class, int id)
 Checks whether a token is a member of a class in a Mapping. More...
 

Macro Definition Documentation

#define CLASS_REALLOC_THRESHOLD   16

increment for memory reallocation of classes in a SingleMapping

Referenced by read_mapping().

#define NAME_TOKEN   "#name "

The token that identifies a "name" line in a mapping file.

Referenced by read_mapping().

#define TOKEN_REALLOC_THRESHOLD   16

increment for memory reallocation of tokens in a SingleMapping

Referenced by read_mapping().

Function Documentation

int drop_mapping ( Mapping map)

Deletes a Mapping object.

Parameters
mapAddress of the object to delete.
Returns
Always 1.

References cl_free.

Referenced by read_mapping().

int drop_single_mapping ( SingleMapping smap)

Deletes a SingleMapping object.

Parameters
smapAddress of the object to delete.
Returns
Always 1.

References cl_free.

SingleMapping find_mapping ( Mapping  map,
char *  name 
)

Find a class within this mapping.

Parameters
mapThe Mapping to look in.
nameThe class to look for.
Returns
The SingleMapping containing the class which has the name "name".

References _single_mapping::class_name, _mapping::classes, and _mapping::nr_classes.

Referenced by read_mapping().

static int intcompare ( const void *  i,
const void *  j 
)
static

Referenced by member_of_class_i(), and read_mapping().

int* map_class_to_tokens ( SingleMapping  map,
int *  nr_tokens 
)

Gets the location of the token IDs in this class.

Parameters
mapThe SingleMapping representing the class in question.
nr_tokensAddress of an integer, which will be set to the number of tokens in this class.
Returns
A pointer to the token IDs of this class (don't free this!!)

References _single_mapping::nr_tokens, and _single_mapping::tokens.

int map_id_to_class_number ( Mapping  map,
int  id 
)

Gets the number of the class that contains a particular token in the given Mapping.

Parameters
mapThe Mapping to look in.
idThe token to look for, identified by its integer ID.
Returns
The "class number" of the class containing the token (i.e. an index in the Mapping's "array" of SingleMappings) or -1 if the token was not found.

References _mapping::classes, member_of_class_i(), and _mapping::nr_classes.

Referenced by get_position_values(), and map_token_to_class_number().

SingleMapping map_token_to_class ( Mapping  map,
char *  token 
)

Gets the SingleMapping that contains a particular token in the given Mapping.

Parameters
mapThe Mapping to look in.
tokenThe token to look for, identified by string.
Returns
The SingleMapping representing the class that contains that token (or NULL if the token was not found).

References _mapping::classes, and map_token_to_class_number().

Referenced by read_mapping().

int map_token_to_class_number ( Mapping  map,
char *  token 
)

Gets the number of the class that contains a particular token in the given Mapping.

Parameters
mapThe Mapping to look in.
tokenThe token to look for, identified by string.
Returns
The "class number" of the class containing the token (i.e. an index in the Mapping's "array" of SingleMappings) or -1 if the token was not found.

References _mapping::attribute, CDA_OK, cderrno, get_id_of_string, and map_id_to_class_number().

Referenced by map_token_to_class().

int member_of_class_i ( Mapping  map,
SingleMapping  class,
int  id 
)

Checks whether a token is a member of a class in a Mapping.

See also
member_of_class_s
Parameters
mapThe mapping to look in.
classThe class to check.
idThe token to look for (identified by its integer ID).
Returns
Boolean.

References intcompare().

Referenced by map_id_to_class_number(), and member_of_class_s().

int member_of_class_s ( Mapping  map,
SingleMapping  class,
char *  token 
)

Checks whether a token is a member of a class in a Mapping.

The token is identified by its

See also
member_of_class_i
Parameters
mapThe mapping to look in.
classThe class to check.
tokenThe token to look for (identified by its actual string).
Returns
Boolean.

References _mapping::attribute, CDA_OK, cderrno, get_id_of_string, and member_of_class_i().

int number_of_classes ( Mapping  map)

Gets the number of classes possessed by this Mapping.

References _mapping::nr_classes.

int number_of_tokens ( SingleMapping  map)

Gets the number of tokens possessed by this Mapping.

References _single_mapping::nr_tokens.

void print_mapping ( Mapping  map)
Mapping read_mapping ( Corpus corpus,
char *  attr_name,
char *  file_name,
char **  error_string 
)

Creates a Mapping from a file.

Each line in the file results in a SingleMapping (unless it begins in #, in which case it either indicates the name of the mapping or is a comment).

Within a single line, the first white-space delimited token represents the name of the class, and the other tokens are attribute values.

Any parse failure in the file will stop the entire Mapping-creation process and result in NULL being returned.

Parameters
corpusThe corpus for which the Mapping is valid (pointer).
attr_nameString naming the attribute for which the mapping is valid.
file_nameThe filename of the map spec.
error_stringA char * (not char[]), which is set to an error string, or to NULL if all is OK.
Returns
The resulting Mapping object, or NULL in case of error.

References ATT_POS, _mapping::attribute, CDA_OK, cderrno, cl_malloc(), CL_MAX_LINE_LENGTH, cl_realloc(), cl_strdup(), _single_mapping::class_name, CLASS_REALLOC_THRESHOLD, _mapping::classes, corpus, _mapping::corpus, drop_mapping(), find_attribute, find_mapping(), get_id_of_string, intcompare(), map_token_to_class(), _mapping::mapping_name, NAME_TOKEN, _mapping::nr_classes, _single_mapping::nr_tokens, token, TOKEN_REALLOC_THRESHOLD, and _single_mapping::tokens.