'Saves the document as a text file at the given path.
The file content has the following format:
# Cat document.
@name: cat
@type: animal
a 3
cat 2
catch 1
claw 1'

def save(self, path):

    s = []
    for x in self.description.split('\n'):
        s.append(('#    %s' % x))
    for (k, v) in (('@name:', self.name), ('@type:', self.type), ('@lang:', self.language)):
        if (v is not None):
            s.append(('%s    %s' % (k, v.replace('\n', '\\n'))))
    for (w, f) in sorted(self.terms.items()):
        if isinstance(f, int):
            s.append(('%s    %i' % (w, f)))
        if isinstance(f, float):
            s.append(('%s    %.3f' % (w, f)))
    s = '\n'.join(s)
    s = encode_utf8(s)
    f = open(path, 'wb')
    f.write(codecs.BOM_UTF8)
    f.write(s)
    f.close()
