MCPcopy Create free account
hub / github.com/GitsSaikat/PyGen / tokenize

Function tokenize

pygen/CodeBLEU.py:21–26  ·  view source on GitHub ↗
(code)

Source from the content-addressed store, hash-verified

19def calculate_token_match(generated_code: str, reference_code: str) -> float:
20 import re
21 def tokenize(code):
22 # Remove comments and docstrings
23 code = re.sub(r'(\"\"\".*?\"\"\"|\'\'\'.*?\'\'\')', '', code, flags=re.DOTALL)
24 code = re.sub(r'#.*', '', code)
25 tokens = re.findall(r'\b\w+\b', code)
26 return set(tokens)
27
28 gen_tokens = tokenize(generated_code)
29 ref_tokens = tokenize(reference_code)

Callers 1

calculate_token_matchFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected