arfficionado v0.1.0 Arfficionado.Handler behaviour View Source
Handler behaviour.
Arfficionado.read/4 will:
- call
init(arg)to obtain the initial handler state (argdefaults tonil) parse the ARFF header and
- call
relationwith the relation name and optional comment - call
attributeswith the list of attributes found in the header - call
line_commentfor lines that consists of commentary only - call
begin_datawith optional comment to indicate that the header is finished and instance data will follow
- call
parse the ARFF data section
- call
instancefor each line of data, reporting instance values, weight and optional comment - call
line_commentfor lines that consists of commentary only
- call
- call
close
Arfficionado.read/4 will pass in the current handler state on each callback invocation. Callback functions return an updated handler state and generally indicate whether to continue reading the ARFF file or to stop early.
Once the ARFF file is exhausted, an error is encountered in the ARFF file, or the handler has indicated that it wishes to stop the processing, the close callback will be invoked, allowing the handler to create the final result state (and clean up resources).
Implement this behaviour as per your application's requirements (for example, including side effects such as creating and writing to an ETS table). The sources for Arfficionado.ListHandler and Arfficionado.MapHandler may provide some general guidance.
Link to this section Summary
Types
An attribute definition with name, type and optional comment.
Attribute type.
List of attribute definitions (ARFF header).
A comment.
Date format.
Name for an attribute/relation.
A comment or nil.
Your handler's state.
Success/failure indicator.
Arfficionado.Handler type.
Return value for most handler callbacks.
An attribute-value.
An instance's attribute-values.
Instance weight.
Callbacks
Invoked once all @attributes have been parsed.
Invoked when @data has been encountered, reporting the optional comment following @data.
Invoked when the processing has finished. The first argument indicates whether processing was successful (:ok) or an error was encountered (:error).
Creates initial state from given argument.
Invoked for each data instance, reporting the list of attribute-values (in the order given in the ARFF header), the instance weight (defaulting to 1) and an optional comment.
Invoked when a line is encountered that contains nothing but a comment.
Invoked when @relation is encountered, reporting the relation name and an optional comment.
Link to this section Types
attribute()
View Sourceattribute() :: {:attribute, name(), attribute_type(), optional_comment()}
An attribute definition with name, type and optional comment.
attribute_type()
View Sourceattribute_type() ::
:numeric | {:nominal, [atom()]} | :string | {:date, date_format()}
Attribute type.
List of attribute definitions (ARFF header).
A comment.
Date format.
Name for an attribute/relation.
A comment or nil.
Your handler's state.
Success/failure indicator.
Arfficionado.Handler type.
Return value for most handler callbacks.
An attribute-value.
An instance's attribute-values.
Instance weight.
Link to this section Callbacks
attributes(attributes, state)
View Sourceattributes(attributes(), state()) :: updated_state()
Invoked once all @attributes have been parsed.
begin_data(optional_comment, state)
View Source (optional)begin_data(optional_comment(), state()) :: updated_state()
Invoked when @data has been encountered, reporting the optional comment following @data.
Invoked when the processing has finished. The first argument indicates whether processing was successful (:ok) or an error was encountered (:error).
Creates initial state from given argument.
instance(values, weight, optional_comment, state)
View Sourceinstance(values(), weight(), optional_comment(), state()) :: updated_state()
Invoked for each data instance, reporting the list of attribute-values (in the order given in the ARFF header), the instance weight (defaulting to 1) and an optional comment.
Return {:cont, updated_state} to continue parsing, or {:halt, updated_state} to stop early.
line_comment(comment, state)
View Source (optional)line_comment(comment(), state()) :: updated_state()
Invoked when a line is encountered that contains nothing but a comment.
relation(name, optional_comment, state)
View Source (optional)relation(name(), optional_comment(), state()) :: updated_state()
Invoked when @relation is encountered, reporting the relation name and an optional comment.