class-mapping.c File Reference

#include "globals.h"
#include "macros.h"
#include "cdaccess.h"
#include "class-mapping.h"

Defines

Functions


Define 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:
map Address 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:
smap Address 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:
map The Mapping to look in.
name The 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:
map The SingleMapping representing the class in question.
nr_tokens Address 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:
map The Mapping to look in.
id The 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:
map The Mapping to look in.
token The 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:
map The Mapping to look in.
token The 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:
map The mapping to look in.
class The class to check.
id The 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:
map The mapping to look in.
class The class to check.
token The 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:
corpus The corpus for which the Mapping is valid (pointer).
attr_name String naming the attribute for which the mapping is valid.
file_name The filename of the map spec.
error_string A 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_realloc(), cl_strdup(), _single_mapping::class_name, CLASS_REALLOC_THRESHOLD, _mapping::classes, _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_REALLOC_THRESHOLD, and _single_mapping::tokens.


Generated on Sun Feb 28 18:08:04 2010 for CWB by  doxygen 1.6.1