arfficionado v0.1.0 Arfficionado View Source
Reader for ARFF (Attribute Relation File Format) data. Adaptable to application-specific needs through custom handler behaviour implementations.
{:ok, instances} =
File.stream!("data.arff")
|> Arfficionado.read(Arfficionado.ListHandler)
Current limitations:
- ISO-8601 is the only supported
dateformat, but you can pass a custom date parsing function to read other formats - no support for attributes of type
relational(not widely used) - no support for sparse format
Link to this section Summary
Functions
Parses an enumerable/stream of ARFF lines, invokes Arfficionado.Handler callbacks and returns final handler state.
Link to this section Functions
read(arff, handler, arg \\ nil, parse_date \\ &custom_date_parse/2)
View SourceParses an enumerable/stream of ARFF lines, invokes Arfficionado.Handler callbacks and returns final handler state.
Initializes handler state by invoking init(arg) and then modifies the state through invocations of the other handler callbacks.
Returns {:ok, final_handler_state} or {:error, reason, final_handler_state}.
A custom date parsing function can be given via parse_date. This function is expected to take two strings: a date and a date_format and to return either a DateTime or {:error, reason}. The default parse_date function will return {:error, "Please pass in a function for parsing non-iso_8601 dates."}.
Examples
Using Arfficionado.ListHandler to collect the instances (with weights) from the following ARFF input:
@relation example
@attribute a1 numeric
@attribute a2 string
@attribute a3 {red, blue}
@data
1, Hello, red
2, "Hi there!", blue
?, ?, ? % missing values
3.1415, 'What\'s up?', red % escaped '
4, abc, blue, {7} % instance weight 7
iex> [
...> ~s[@relation example],
...> ~s[@attribute a1 numeric],
...> ~s[@attribute a2 string],
...> ~s[@attribute a3 {red, blue}],
...> ~s[@data],
...> ~s[1, Hello, red],
...> ~s[2, "Hi there!", blue],
...> ~s[?, ?, ? % missing values],
...> ~s[3.1415, 'What\\'s up?', red % escaped '],
...> ~s[4, abc, blue, {7} % instance weight 7]
...> ] |>
...> Arfficionado.read(Arfficionado.ListHandler)
{:ok, [
{[1, "Hello", :red], 1},
{[2, "Hi there!", :blue], 1},
{[:missing, :missing, :missing], 1},
{[3.1415, "What's up?", :red], 1},
{[4, "abc", :blue], 7}
]}