CWB
Data Structures | Defines | Typedefs | Functions | Variables

attributes.c File Reference

#include <ctype.h>
#include <sys/types.h>
#include "globals.h"
#include "endian.h"
#include "corpus.h"
#include "macros.h"
#include "fileutils.h"
#include "cdaccess.h"
#include "makecomps.h"
#include "list.h"
#include "attributes.h"

Data Structures

Defines

Typedefs

Functions

Variables


Define Documentation

#define KEEP_SILENT

if KEEP_SILENT is defined, ensure_component won't complain about non-accessible data.

See also:
ensure_component

Typedef Documentation


Function Documentation

char* aid_name ( int  i)

Gets a string containing a description of the specified attribute type.

Non-exported function.

Parameters:
iThe attribute-type whose name is required. (Should be one of the values of the constants defined in cl.h.)
Returns:
String (pointer to internal constant string, do not change or free).

References ATT_ALIGN, ATT_DYN, ATT_NONE, ATT_POS, and ATT_STRUC.

Referenced by create_component(), describe_attribute(), load_component(), and setup_attribute().

char* argid_name ( int  i)

Gets a string containing a description of the specified dynamic attribute argument type.

Non-exported function.

Parameters:
iThe argument-type whose name is required. (Should be one of the values of the constants defined in cl.h.)
Returns:
String (pointer to internal constant string, do not change or free).

References ATTAT_FLOAT, ATTAT_INT, ATTAT_NONE, ATTAT_PAREF, ATTAT_POS, ATTAT_STRING, and ATTAT_VAR.

Referenced by describe_attribute().

char* cid_name ( ComponentID  id)

Gets a string containing the name of the attribute component with the specified ID-code.

References find_cid_id(), and component_field_spec::name.

Referenced by create_component(), declare_component(), describe_component(), ensure_component(), load_component(), makeall_do_attribute(), makeall_make_component(), and validate_revcorp().

int cl_delete_attribute ( Attribute attribute)

Deletes the specified Attribute object.

The function also appropriately amends the Corpus object of which this Attribute is a dependent. This means you can call it repreatedly on the first element of a Corpus's Attribute list (as the linked list is automatically adjusted).

Returns:
Boolean: true for all OK, false for a problem.

References _Attribute::any, Dynamic_Attribute::arglist, ATT_DYN, ATT_NONE, ATT_POS, TCorpus::attributes, Dynamic_Attribute::call, cl_free, comp_drop_component(), CompDirectory, CompLast, corpus, _Attribute::dyn, POS_Attribute::hc, _DynArg::next, _Attribute::pos, and _Attribute::type.

Referenced by cl_delete_corpus(), cqi_drop_attribute(), and drop_attribute().

char* cl_make_set ( char *  s,
int  split 
)

Generates a set attribute value.

Parameters:
sThe input string.
splitBoolean; if True, s is split on whitespace. If False, the function expects input in '|'-delimited format.
Returns:
The set attribute value in standard syntax ('|' delimited, sorted with cl_strcmp). If there is any syntax error, cl_make_set() returns NULL.

References CDA_EFSETINV, CDA_OK, cl_delete_string_list(), cl_errno, cl_free, cl_malloc(), cl_new_string_list(), cl_strdup(), cl_string_list_append(), cl_string_list_get(), cl_string_list_qsort(), and cl_string_list_size().

Referenced by encode_add_wattr_line(), range_open(), and sencode_check_set().

Attribute* cl_new_attribute_oldstyle ( Corpus corpus,
char *  attribute_name,
int  type,
char *  data 
)

Finds an attribute that matches the specified parameters, if one exists, for the given corpus.

Note that although this is a cl_new_* function, and it is the canonical way that we get an Attribute to call Attribute-functions on, it doesn't actually create any kind of object. The Attribute exists already as one of the dependents of the Corpus object; this function simply locates it and returns a pointer to it.

This function is DEPRACATED. Use cl_new_attribute() instead (which is actually a macro to this function, but the parameter list is different.)

See also:
cl_new_attribute
Parameters:
corpusThe corpus in which to search for the attribute.
attribute_nameThe name of the attribute (i.e. the handle it has in the registry file).
typeType of attribute to be searched for.
dataNOT USED.
Returns:
Pointer to Attribute object, or NULL if not found.

References _Attribute::any, TCorpus::attributes, STREQ, and _Attribute::type.

Referenced by drop_attribute(), get_matched_corpus_positions(), and main().

int cl_set_intersection ( char *  result,
const char *  s1,
const char *  s2 
)

Computes the intersection of two set attribute values.

Compute intersection of two set attribute values (in standard syntax, i.e. sorted and '|'-delimited); memory for the result string must be allocated by the caller.

Returns:
0 on error, 1 otherwise

References CDA_EBUFFER, CDA_EFSETINV, CDA_OK, CL_DYN_STRING_SIZE, cl_errno, cl_strcmp(), s1, and s2.

Referenced by call_predefined_function().

int cl_set_size ( char *  s)

Counts the number of elements in a set attribute value.

This function counts the number of elements in a set attribute value (using '|'-delimited standard syntax);

Returns:
-1 on error (in particular, if set is malformed)

References CDA_EFSETINV, CDA_OK, and cl_errno.

Referenced by call_predefined_function().

ComponentState comp_component_state ( Component component)
int comp_drop_component ( Component comp)

Delete a Component object.

The specified component object, and all memory associated with it, is freed.

Returns:
Always 1.

References _Attribute::any, TComponent::attribute, cl_free, CompHuffCodes, CompLast, TComponent::corpus, TComponent::data, POS_Attribute::hc, TComponent::id, mfree(), TComponent::path, and _Attribute::pos.

Referenced by cl_delete_attribute(), and drop_component().

char* component_full_name ( Attribute attribute,
ComponentID  cid,
char *  path 
)

Initializes the path of an attribute Component.

This function starts with the path it is passed, and then evaluates variables in the form $UPPERCASE. The resulting path is assigned to the specified entry in the component array for the given Attribute.

Note that if it is called for a Component that does not yet exist, this function creates the component by calling declare_component().

See also:
declare_component
Component_Field_Specs
Parameters:
attributeThe Attribute object to work with.
cidThe identifier of the Component to which the path is to be added.
pathThe path to assign to the component. Can be NULL, in which case, the default path from Component_Field_Specs is used.
Returns:
Pointer to this function's static buffer for creating the path (NB: NOT to the path in the actual component! which is a copy). If a path already exists, a pointer to that path. NULL in case of error in Component_Field_Specs.

References _Attribute::any, buf, cl_strdup(), component_full_name(), declare_component(), component_field_spec::default_path, find_cid_id(), find_cid_name(), component_field_spec::id, MAX_LINE_LENGTH, TComponent::path, and STREQ.

Referenced by component_full_name(), compress_reversed_index(), compute_code_lengths(), creat_freqs(), declare_component(), decode_check_huff(), decompress_check_reversed_index(), and main().

ComponentID component_id ( char *  name)

Gets the identifier of the attribute component with the specified name.

References CompLast, find_cid_name(), and component_field_spec::id.

Referenced by main().

ComponentState component_state ( Attribute attribute,
ComponentID  cid 
)

Gets the state of a specified component on the given attribute.

Parameters:
attributeThe attribute to look at.
cidThe component whose state to get.
Returns:
The return value in case the component is not found is ComponentUndefined. Otherwise, some other value of ComponentState.

References _Attribute::any, comp_component_state(), CompLast, and ComponentUndefined.

Referenced by cl_has_extended_alignment(), cl_index_compressed(), cl_sequence_compressed(), cl_struc_values(), component_ok(), create_component(), and makeall_make_component().

Component* create_component ( Attribute attribute,
ComponentID  cid 
)

Creates the specified component for the given Attribute.

This function only works for the following components: CompRevCorpus, CompRevCorpusIdx, CompLexiconSrt, CompCorpusFreqs. Also, it only works if the state of the component is ComponentDefined.

"Create" here means create the CWB data files. This is accomplished by calling one of the "creat_*" functions, of which there is one for each of the four available component types. These are defined in makecomps.c.

Each of these functions reads in the data it needs, processes it, and then writes a new file.

Parameters:
attributeThe Attribute object to work with.
cidThe identifier of the Component to create.
Returns:
Pointer to the component created, or NULL in case of error (e.g. if an invalid component was requested).

References aid_name(), _Attribute::any, cid_name(), cl_debug, CompAlignData, CompCompRF, CompCompRFX, CompCorpus, CompCorpusFreqs, CompDirectory, CompHuffCodes, CompHuffSeq, CompHuffSync, CompLast, CompLexicon, CompLexiconIdx, CompLexiconSrt, component_state(), ComponentDefined, CompRevCorpus, CompRevCorpusIdx, CompStrucAVS, CompStrucAVX, CompStrucData, CompXAlignData, creat_freqs(), creat_rev_corpus(), creat_rev_corpus_idx(), creat_sort_lexicon(), TMblob::data, TComponent::data, TComponent::path, and _Attribute::type.

Referenced by ensure_component(), and makeall_make_component().

Component* declare_component ( Attribute attribute,
ComponentID  cid,
char *  path 
)

Sets up a component for the given attribute.

If the component of the specified ComponentID does not already exist, a new Component object is created, set up, and assigned to the attribute's component array. Finally, the component path is initialised using the path argument.

See also:
component_full_name
Parameters:
attributeThe Attribute for which to create this component.
cidThe ID of the component to create.
pathPath to be passed to component_full_name. Can be NULL.
Returns:
The new component if all is OK. If a component with the specified ID already exists, it is returned and no new component is created (and a warning message is printed to STDERR). If the attribute is NULL, return is NULL (and a warning is printed).

References _Attribute::any, TComponent::attribute, cid_name(), component_full_name(), TComponent::corpus, TComponent::data, TComponent::id, init_mblob(), and TComponent::path.

Referenced by component_full_name(), and declare_default_components().

void declare_default_components ( Attribute attribute)

Sets up a default set of components on the given attribute.

Note that in each case, a call is made to declare_component with the path as NULL.

See also:
declare_component

References _Attribute::any, CompDirectory, CompLast, declare_component(), _Attribute::type, and component_field_spec::using_atts.

void describe_attribute ( Attribute attribute)
void describe_component ( Component component)
int drop_attribute ( Corpus corpus,
char *  attribute_name,
int  type,
char *  data 
)

Drops an attribute for the given corpus.

The attribute to be dropped is specified by its attribute name and its type (i.e. no pointer needed: compare cl_delete_attribute).

After calling this, the corpus does not have the attribute any longer -- it is the same as it was never defined.

This is an internal function; the function exposed in the API for this purpose is cl_delete_attribute().

tODO: this function can probably actually be deleted. It doesn't todo: seem to be used anywhere, and is much more complex than todo: cl_delete_attribute

See also:
cl_delete_attribute
Returns:
Boolean: true for all OK, false for a problem

References cl_delete_attribute(), and cl_new_attribute_oldstyle().

int drop_component ( Attribute attribute,
ComponentID  cid 
)

Drops the specified component for the given Attribute.

See also:
comp_drop_component
Parameters:
attributeThe Attribute object to work with.
cidThe identifier of the Component to drop.
Returns:
Always 1.

References _Attribute::any, and comp_drop_component().

Referenced by main().

Component* ensure_component ( Attribute attribute,
ComponentID  cid,
int  try_creation 
)

Ensures that a component is loaded and ready.

The state of the component specified should be ComponentLoaded once this function has run (assuming all is well). If the component is unloaded, the function will try to load it. If the component is defined, the function MAY try to create it. If the component is undefined, nothing will be done.

There are flags in attributes.c that control the behaviour of this function (e.g. if failure to ensure causes the program to abort).

See also:
KEEP_SILENT
ENSURE_COMPONENT_EXITS
ALLOW_COMPONENT_CREATION
Parameters:
attributeThe Attribute object to work with.
cidThe identifier of the Component to "ensure".
try_creationBoolean. True = attempt to create a component that does not exist. False = don't. This behaviour only applies when ALLOW_COMPONENT CREATION is defined; otherwise component creation will never be attempted.
Returns:
A pointer to the specified component (or NULL if the component cannot be "ensured").

References _Attribute::any, cid_name(), comp_component_state(), ComponentDefined, ComponentLoaded, ComponentUndefined, ComponentUnloaded, create_component(), and load_component().

Referenced by cl_alg2cpos(), cl_cpos2alg(), cl_cpos2alg2cpos_oldstyle(), cl_cpos2id(), cl_cpos2struc2cpos(), cl_cpos2struc_oldstyle(), cl_id2cpos_oldstyle(), cl_id2freq(), cl_id2sort(), cl_id2str(), cl_id2strlen(), cl_idlist2cpos_oldstyle(), cl_max_alg(), cl_max_cpos(), cl_max_id(), cl_new_stream(), cl_regex2id(), cl_sort2id(), cl_str2id(), cl_struc2cpos(), cl_struc2str(), compress_reversed_index(), compute_code_lengths(), creat_freqs(), creat_rev_corpus(), creat_rev_corpus_idx(), creat_sort_lexicon(), get_nr_of_strucs(), and validate_revcorp().

struct component_field_spec* find_cid_id ( ComponentID  id) [read]

Gets the specification for the identified component field.

This function returns a pointer to an element of the global, static Component_Field_Specs array.

Parameters:
idThe ComponentID for the component field to be looked up.
Returns:
Pointer to the desired specification, or NULL if not found.
See also:
Component_Field_Specs

References CompLast, and component_field_spec::id.

Referenced by cid_name(), component_full_name(), and MayHaveComponent().

struct component_field_spec* find_cid_name ( char *  name) [read]

Gets the specification for the named component field.

This function returns a pointer to an element of the global, static Component_Field_Specs array.

Parameters:
nameA string that identifies the component field to be looked up.
Returns:
Pointer to the desired specification, or NULL if not found.
See also:
Component_Field_Specs

References CompLast.

Referenced by component_full_name(), and component_id().

Component* find_component ( Attribute attribute,
ComponentID  cid 
)

Gets a pointer to the specified component for the given Attribute.

References _Attribute::any.

Referenced by creat_freqs().

Attribute* first_corpus_attribute ( Corpus corpus)

Get a pointer to the head entry in the specified corpus's list of attributes.

Returns:
NULL if the corpus parameter is NULL; otherwise a pointer to Attribute.

References TCorpus::attributes, and loop_ptr.

Referenced by send_cqi_corpus_attributes().

Component* load_component ( Attribute attribute,
ComponentID  cid 
)

Loads the specified component for this attribute.

"Loading" means that the file specified by the component's "path" member is read into the "data" member.

If the component is CompHuffCodes, the data is also copied to the attribute's pos.hc member.

Note that the action of this function is dependent on the component's state. If the component's state is ComponentUnloaded, the component is loaded. If the component's state is ComponentDefined, the size is set to 0 and nothing else is done.

Parameters:
attributeThe Attribute object to work with.
cidThe identifier of the Component to load.
Returns:
Pointer to the component. This will be NULL if the component has not been declared (i.e. created).

References aid_name(), _Attribute::any, cid_name(), comp_component_state(), CompDirectory, CompHuffCodes, CompLast, ComponentDefined, ComponentLoaded, ComponentUnloaded, TMblob::data, TComponent::data, POS_Attribute::hc, item_sequence_is_compressed, _huffman_code_descriptor::lcount, _huffman_code_descriptor::length, _huffman_code_descriptor::max_codelen, MAXCODELEN, _huffman_code_descriptor::min_code, _huffman_code_descriptor::min_codelen, MMAPPED, TMblob::nr_items, TComponent::path, _Attribute::pos, read_file_into_blob(), TComponent::size, _huffman_code_descriptor::size, _huffman_code_descriptor::symbols, _huffman_code_descriptor::symindex, and _Attribute::type.

Referenced by ensure_component().

DynArg* makearg ( char *  type_id)

Creates a DynArg object.

The object created is a dynamic argument of the type specified by the argument type_id, with its "next" pointer set to NULL.

See also:
DynArg
Parameters:
type_idString specifying the type of argument required; choose from: STRING, POS, INT, VARARG, FLOAT
Returns:
Pointer to the new DynArg object, or NULL in case of an invalid type_id.

References ATTAT_FLOAT, ATTAT_INT, ATTAT_POS, ATTAT_STRING, ATTAT_VAR, _DynArg::next, and _DynArg::type.

int MayHaveComponent ( int  attr_type,
ComponentID  cid 
)

Checks whether a particular Attribute type can possess the specified component field.

Returns:
True or false.

References CompLast, find_cid_id(), component_field_spec::id, and component_field_spec::using_atts.

Attribute* next_corpus_attribute ( )

Get a pointer to the next attribute on the list currently being processed.

References _Attribute::any, and loop_ptr.

Referenced by send_cqi_corpus_attributes().

Attribute* setup_attribute ( Corpus corpus,
char *  attribute_name,
int  type,
char *  data 
)

Sets up a corpus attribute.

NEVER CALL THIS!! ONLY USED WHILE PARSING A REGISTRY ENTRY!!!!

Parameters:
corpusThe corpus this attribute belongs to.
attribute_nameThe name of the attribute (i.e. the handle it has in the registry file).
typeType of attribute to be created.
dataUnused. It can just be NULL.

References aid_name(), _Attribute::any, ATT_POS, ATT_STRUC, ATTAT_POS, TCorpus::attributes, cl_new_attribute, CompDirectory, CompLast, corpus, DEFAULT_ATT_NAME, Struc_Attribute::has_attribute_values, POS_Attribute::hc, TCorpus::id, _Attribute::pos, _Attribute::struc, POS_Attribute::this_block_nr, and _Attribute::type.


Variable Documentation

Initial value:
{ 
  { CompDirectory,    "DIR",     ATT_ALL,    "$APATH"},

  { CompCorpus,       "CORPUS",  ATT_POS,    "$DIR" SUBDIR_SEP_STRING "$ANAME.corpus"},
  { CompRevCorpus,    "REVCORP", ATT_POS,    "$CORPUS.rev"},
  { CompRevCorpusIdx, "REVCIDX", ATT_POS,    "$CORPUS.rdx"},
  { CompCorpusFreqs,  "FREQS",   ATT_POS,    "$CORPUS.cnt"},
  { CompLexicon,      "LEXICON", ATT_POS,    "$DIR" SUBDIR_SEP_STRING "$ANAME.lexicon"},
  { CompLexiconIdx,   "LEXIDX",  ATT_POS,    "$LEXICON.idx"},
  { CompLexiconSrt,   "LEXSRT",  ATT_POS,    "$LEXICON.srt"},


  { CompAlignData,    "ALIGN",   ATT_ALIGN,  "$DIR" SUBDIR_SEP_STRING "$ANAME.alg"},
  { CompXAlignData,   "XALIGN",  ATT_ALIGN,  "$DIR" SUBDIR_SEP_STRING "$ANAME.alx"},

  { CompStrucData,    "STRUC",   ATT_STRUC,  "$DIR" SUBDIR_SEP_STRING "$ANAME.rng"},
  { CompStrucAVS,     "STRAVS",  ATT_STRUC,  "$DIR" SUBDIR_SEP_STRING "$ANAME.avs"},
  { CompStrucAVX,     "STRAVX",  ATT_STRUC,  "$DIR" SUBDIR_SEP_STRING "$ANAME.avx"},

  { CompHuffSeq,      "CIS",     ATT_POS,    "$DIR" SUBDIR_SEP_STRING "$ANAME.huf"},
  { CompHuffCodes,    "CISCODE", ATT_POS,    "$DIR" SUBDIR_SEP_STRING "$ANAME.hcd"},
  { CompHuffSync,     "CISSYNC", ATT_POS,    "$CIS.syn"},

  { CompCompRF,       "CRC",     ATT_POS,    "$DIR" SUBDIR_SEP_STRING "$ANAME.crc"},
  { CompCompRFX,      "CRCIDX",  ATT_POS,    "$DIR" SUBDIR_SEP_STRING "$ANAME.crx"},

  { CompLast,         "INVALID", 0,          "INVALID"}
}

Global object in the "attributes" module, giving specifications for each component in the array of components that each Attribute object contains.

Non-exported variable: accessed via the attribute-looping functions.

See also:
first_corpus_attribute
next_corpus_attribute

Referenced by first_corpus_attribute(), and next_corpus_attribute().