EduNLP.utils

EduNLP.utils.abs_current_dir(filepath)[source]

获取文件所在目录的绝对路径

Example

abs_current_dir(__file__)
EduNLP.utils.dict2str4sif(obj: dict, key_as_tag=True, tag_mode='delimiter', add_list_no_tag=True, keys=None) str[source]

The function aims to transfer dictionary format item to string format item.

Parameters
  • obj

  • key_as_tag

  • tag_mode – delimiter: add $SIFTag{key_begin}$ in the head and add $SIFTag{key_end}$ at the end head: add $SIFTag{key}$ in the head tail: add $SIFTag{key}$ at the end

  • add_list_no_tag

  • keys

Examples

>>> item = {
...     "stem": r"若复数$z=1+2 i+i^{3}$,则$|z|=$",
...     "options": ['0', '1', r'$\sqrt{2}$', '2'],
... }
>>> item
{'stem': '若复数$z=1+2 i+i^{3}$,则$|z|=$', 'options': ['0', '1', '$\\sqrt{2}$', '2']}
>>> dict2str4sif(item) 
'$\\SIFTag{stem_begin}$...$\\SIFTag{stem_end}$$\\SIFTag{options_begin}$...$\\SIFTag{options_end}$'
>>> dict2str4sif(item, add_list_no_tag=True) 
'...$\\SIFTag{options_begin}$$\\SIFTag{list_0}$0$\\SIFTag{list_1}$1...$\\SIFTag{options_end}$'
>>> dict2str4sif(item, tag_mode="head") 
'$\\SIFTag{stem}$...$\\SIFTag{options}$...'
>>> dict2str4sif(item, tag_mode="tail") 
'若复数$z=1+2 i+i^{3}$,则$|z|=$$\\SIFTag{stem}$...2$\\SIFTag{options}$'
>>> dict2str4sif(item, add_list_no_tag=False) 
'...$\\SIFTag{options_begin}$0$\\SIFSep$1$\\SIFSep$...$\\SIFTag{options_end}$'
>>> dict2str4sif(item, key_as_tag=False)
'若复数$z=1+2 i+i^{3}$,则$|z|=$0$\\SIFSep$1$\\SIFSep$$\\sqrt{2}$$\\SIFSep$2'
EduNLP.utils.path_append(path, *addition, to_str=False)[source]

路径合并函数

Examples

path_append("../", "../data", "../dataset1/", "train", to_str=True)
'../../data/../dataset1/train'
Parameters
  • path (str or PurePath) –

  • addition (list(str or PurePath)) –

  • to_str (bool) – Convert the new path to str