numenta/nupic — pull request #1524 by DavidRagazzi (2014-11-17 21:05:22+00:00)
Title: String conversion to binary array

NuPIC Network API lacks of a mechanism to read binary arrays from a record and pass them to PassThroughEncoder. The problem is that FileRecordStream only accepts 'string', 'datetime', 'int', 'float', 'bool' for record data types in CSV files.

This PR brings a simple solution to this. We simply use `string` as data-type for the binary array:

```
Square
string
T
000000000000000000000000000000000110000000000000011000000000000000000000000000000000000000000000
000000000000000000000000000000000000110000000000000011000000000000000000000000000000000000000000
000000000000000000000000000000000000000110000000000000011000000000000000000000000000000000000000
000000000000000000000000000000000000000000110000000000000011000000000000000000000000000000000000
000000000000000000000000000000000000000000000110000000000000011000000000000000000000000000000000
```

And then we adjust PassThroughEncoder to check if the value passed to it is a list of 0's and 1's or a string containing only 0's and 1's to be splitted into a list of integers. Something like that:

```
def encodeIntoArray(self, input, output):
"""See method description in base.py"""

if isinstance(input, basestring):
strInput = input
input = []
for c in strInput:
if c == '0':
input.append(0)
else c == '1':
input.append(1)
else:
raise ValueError("Input should be string only with 0's and 1's.")
```