Skip to content

Commit ef82c1f

Browse files
authored
Merge pull request #121 from FengZiYjun/doc-fixing
[Doc] Improve Documentation (2)
2 parents 27ae52c + 43982d2 commit ef82c1f

24 files changed

+360
-334
lines changed

.travis.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ python:
44
# command to install dependencies
55
install:
66
- pip install --quiet -r requirements.txt
7-
- pip install pytest pytest-cov
7+
- pip install pytest>=3.6
8+
- pip install pytest-cov
89
# command to run tests
910
script:
1011
- pytest --cov=./

fastNLP/core/batch.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ class Batch(object):
1010
for batch_x, batch_y in Batch(data_set, batch_size=16, sampler=SequentialSampler()):
1111
# ...
1212
13-
:param dataset: a DataSet object
14-
:param batch_size: int, the size of the batch
15-
:param sampler: a Sampler object
16-
:param as_numpy: bool. If True, return Numpy array. Otherwise, return torch tensors.
13+
:param DataSet dataset: a DataSet object
14+
:param int batch_size: the size of the batch
15+
:param Sampler sampler: a Sampler object
16+
:param bool as_numpy: If True, return Numpy array. Otherwise, return torch tensors.
1717
1818
"""
1919

fastNLP/io/base_loader.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33

44

55
class BaseLoader(object):
6+
"""Base loader for all loaders.
67
8+
"""
79
def __init__(self):
810
super(BaseLoader, self).__init__()
911

@@ -32,7 +34,9 @@ def load_with_cache(cls, data_path, cache_path):
3234

3335

3436
class DataLoaderRegister:
35-
""""register for data sets"""
37+
"""Register for all data sets.
38+
39+
"""
3640
_readers = {}
3741

3842
@classmethod

fastNLP/io/config_io.py

+22-27
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66

77

88
class ConfigLoader(BaseLoader):
9-
"""loader for configuration files"""
9+
"""Loader for configuration.
10+
11+
:param str data_path: path to the config
12+
13+
"""
1014

1115
def __init__(self, data_path=None):
1216
super(ConfigLoader, self).__init__()
@@ -19,13 +23,15 @@ def parse(string):
1923

2024
@staticmethod
2125
def load_config(file_path, sections):
22-
"""
23-
:param file_path: the path of config file
24-
:param sections: the dict of {section_name(string): Section instance}
25-
Example:
26+
"""Load section(s) of configuration into the ``sections`` provided. No returns.
27+
28+
:param str file_path: the path of config file
29+
:param dict sections: the dict of ``{section_name(string): ConfigSection object}``
30+
Example::
31+
2632
test_args = ConfigSection()
2733
ConfigLoader("config.cfg", "").load_config("./data_for_tests/config", {"POS_test": test_args})
28-
:return: return nothing, but the value of attributes are saved in sessions
34+
2935
"""
3036
assert isinstance(sections, dict)
3137
cfg = configparser.ConfigParser()
@@ -60,9 +66,12 @@ def load_config(file_path, sections):
6066

6167

6268
class ConfigSection(object):
69+
"""ConfigSection is the data structure storing all key-value pairs in one section in a config file.
70+
71+
"""
6372

6473
def __init__(self):
65-
pass
74+
super(ConfigSection, self).__init__()
6675

6776
def __getitem__(self, key):
6877
"""
@@ -132,25 +141,12 @@ def data(self):
132141
return self.__dict__
133142

134143

135-
if __name__ == "__main__":
136-
config = ConfigLoader('there is no data')
137-
138-
section = {'General': ConfigSection(), 'My': ConfigSection(), 'A': ConfigSection()}
139-
"""
140-
General and My can be found in config file, so the attr and
141-
value will be updated
142-
A cannot be found in config file, so nothing will be done
143-
"""
144-
145-
config.load_config("../../test/data_for_tests/config", section)
146-
for s in section:
147-
print(s)
148-
for attr in section[s].__dict__.keys():
149-
print(s, attr, getattr(section[s], attr), type(getattr(section[s], attr)))
150-
151-
152144
class ConfigSaver(object):
145+
"""ConfigSaver is used to save config file and solve related conflicts.
146+
147+
:param str file_path: path to the config file
153148
149+
"""
154150
def __init__(self, file_path):
155151
self.file_path = file_path
156152
if not os.path.exists(self.file_path):
@@ -244,9 +240,8 @@ def _write_section(self, sect_list, sect_key_list):
244240
def save_config_file(self, section_name, section):
245241
"""This is the function to be called to change the config file with a single section and its name.
246242
247-
:param section_name: The name of section what needs to be changed and saved.
248-
:param section: The section with key and value what needs to be changed and saved.
249-
:return:
243+
:param str section_name: The name of section what needs to be changed and saved.
244+
:param ConfigSection section: The section with key and value what needs to be changed and saved.
250245
"""
251246
section_file = self._get_section(section_name)
252247
if len(section_file.__dict__.keys()) == 0: # the section not in the file before

0 commit comments

Comments
 (0)