"""matchzoo/models/README.md generater."""

from pathlib import Path

import markdown_generator

import matchzoo


def _get_table_skeleton():
    table = markdown_generator.Table()
    table.add_column('name', markdown_generator.Alignment.RIGHT)
    table.add_column('description')
    table.add_column('default value')
    table.add_column('default hyper space')
    return table


def _make_table(params):
    table = _get_table_skeleton()
    for param in params:
        name = param.name
        desc = param.desc or ''
        val = param.value or ''
        if param.hyper_space is None:
            hyper = ''
        else:
            hyper = str(param.hyper_space)
        table.append(name, desc, val, hyper)
    return str(table)


if __name__ == '__main__':
    full = '# MatchZoo Model Hyper-parameters Reference \n\n'
    full += '## Shared Parameters \n\n'
    shared = matchzoo.engine.BaseModel.get_default_params()
    full += _make_table(shared)

    for m in matchzoo.models.list_available():
        m = m()
        full += '## ' + str(m.__class__.__name__) + '\n\n'
        full += _make_table([p for p in m.get_default_params()
                             if p.name not in shared.keys()])

    file_path = Path(__file__).parent.joinpath('README.md')
    with open(file_path, 'w', encoding='utf-8') as out_file:
        out_file.write(full)

@@ -70,34 +70,59 @@
 %0Aimport 
-markdown_generator
+tabulate%0Aimport inspect%0Aimport pandas as pd
 %0A%0Aimport
@@ -141,683 +141,914 @@
 def 
-_
 ge
-t_table_skeleton():%0A    table = markdown_generator.Table()%0A    table.add_column('name', markdown_generator.Alignment.RIGHT)%0A    table.add_column('description')%0A    table.add_column('default value')%0A    table.add_column('default hyper space')%0A    return table%0A%0A%0Adef _make_table(param
+nerate():%0A    full = make_title()%0A    for model_class in matchzoo.models.list_available():%0A        full += make_model_class_subtitle(model_class)%0A        full += make_doc_section_subsubtitle()%0A        full += make_model_doc(model_clas
 s)
-:
 %0A    
-table = _get_table_skeleton()%0A    for param in params:%0A        name = param.name%0A        desc = param.desc or ''%0A        val = param.value or ''%0A        if param.hyper_space is None:%0A            hyper = ''%0A        else:%0A            hyper = str(param.hyper_space)%0A        table.append(name, desc, val, hyper)%0A    return str(table)%0A%0A%0Aif __name__ == '__main__':%0A    full = '# MatchZoo 
+    model = model_class()%0A        full += make_params_section_subsubtitle()%0A        full += make_model_params_table(model)%0A    write_to_files(full)%0A%0A%0Adef make_title():%0A    title = 'MatchZoo Model Reference'%0A    line = '*' * len(title)%0A    return line + '%5Cn' + title + '%5Cn' + line + '%5Cn%5Cn'%0A%0A%0Adef make_model_class_subtitle(model_class):%0A    subtitle = model_class.__name__%0A    line = '#' * len(subtitle)%0A    return subtitle + '%5Cn' + line + '%5Cn%5Cn'%0A%0A%0Adef make_doc_section_subsubtitle():%0A    subsubtitle = 'Model Documentation'%0A    line = '*' * len(subsubtitle)%0A    return subsubtitle + '%5Cn' + line + '%5Cn%5Cn'%0A%0A%0Adef make_params_section_subsubtitle():%0A    subsubtitle = '
 Mode
@@ -1058,10 +1058,10 @@
 yper
--p
+ P
 aram
@@ -1069,342 +1069,422 @@
 ters
- Reference %5Cn%5Cn'%0A    full += '## Shared Parameters %5Cn%5Cn'%0A    shared = matchzoo.engine.BaseModel.get_default_params()%0A    full += _make_table(shared)%0A%0A    for m in matchzoo.models.list_available():%0A        m = m()%0A        full += '## ' + str(m.__class__.__name__) + '%5Cn%5Cn'%0A        full += _make_table(%5Bp for p in m.get_default_
+'%0A    line = '*' * len(subsubtitle)%0A    return subsubtitle + '%5Cn' + line + '%5Cn%5Cn'%0A%0A%0Adef make_model_doc(model_class):%0A    return inspect.getdoc(model_class) + '%5Cn%5Cn'%0A%0A%0Adef make_model_params_table(model):%0A    params = model.get_default_params()%0A    df = pd.DataFrame(data=%7B%0A        'Name': %5Bp.name for p in params%5D,%0A        'Description': %5Bp.desc for p in params%5D,%0A        'Default Value': %5Bp.value for p in 
 params
-()
+%5D,
 %0A   
@@ -1492,123 +1492,506 @@
     
-                     if p.name not in shared.keys()%5D)%0A%0A    file_path = Path(__file__).parent.joinpath('README.md')%0A
+'Default Hyper-Space': %5Bp.hyper_space for p in params%5D%0A    %7D, columns=%5B'Name', 'Description', 'Default Value', 'Default Hyper-Space'%5D)%0A    return tabulate.tabulate(df, tablefmt='rst', headers='keys') + '%5Cn%5Cn'%0A%0A%0Adef write_to_files(full):%0A    readme_file_path = Path(__file__).parent.joinpath('README.rst')%0A    doc_file_path = Path(__file__).parent.parent.parent. %5C%0A        joinpath('docs').joinpath('source').joinpath('model_reference.rst')%0A    for file_path in readme_file_path, doc_file_path:%0A    
     
@@ -2055,16 +2055,20 @@
         
+    
 out_file
@@ -2076,12 +2076,56 @@
 write(full)%0A
+%0A%0Aif __name__ == '__main__':%0A    generate()%0A

Update readme generator.