MCPcopy Create free account
hub / github.com/FSoft-AI4Code/CodeText-parser / clean_docstring

Function clean_docstring

src/codetext/clean/noise_removal.py:841–887  ·  view source on GitHub ↗

Clean docstring by removing special tag/url, characters, unrelevant information

(docstring: str, loosen_filter: bool = False)

Source from the content-addressed store, hash-verified

839
840
841def clean_docstring(docstring: str, loosen_filter: bool = False):
842 """
843 Clean docstring by removing special tag/url, characters, unrelevant information
844 """
845 cleaned_docstring = []
846 if docstring == '' or docstring == None:
847 return None
848 _docstring = remove_comment_delimiters(docstring)
849 if check_docstring_literal(_docstring): # True is not pass
850 return None #, [f"<check_docstring_literal> {docstring}"]
851
852 # _docstring = '\n'.join(remove_comment_delimiters(docstring))
853 docstring_paragraph_list = _docstring.strip().split('\n\n')
854
855 for para in docstring_paragraph_list:
856 docs = remove_unrelevant(para)
857 docstring_list = re.split(r'(?<=.)[.!\?](?=\s+)', docs, flags=re.M)
858 clean_line = []
859 for line in docstring_list:
860 try:
861 line = remove_special_tag(line)
862 except:
863 print('Oops')
864 return None
865
866 # not_pass, res = check_docstring(line, loosen_filter)
867 not_pass = check_docstring(line, loosen_filter)
868 if not not_pass:
869 clean_line.append(line)
870 else:
871 break
872
873 if len(clean_line) < len(docstring_list):
874 clean_line.append('')
875 cleaned_docstring.append('.'.join(clean_line))
876
877
878 cleaned_docstring = '\n\n'.join(cleaned_docstring)
879
880
881 if check_docstring_length(cleaned_docstring):
882 # if not res:
883 # return None #, [f"<check_docstring_length> {docstring}"]
884 # else:
885 return None #, res
886
887 return cleaned_docstring #, res
888
889if __name__ == '__main__':
890 # test remove comment delimiters

Callers 1

noise_removal.pyFile · 0.85

Calls 6

check_docstring_literalFunction · 0.85
remove_unrelevantFunction · 0.85
remove_special_tagFunction · 0.85
check_docstringFunction · 0.85
check_docstring_lengthFunction · 0.85

Tested by

no test coverage detected