Skip to content

Instantly share code, notes, and snippets.

@sharvaridhote
Last active February 2, 2021 04:44
Show Gist options
  • Select an option

  • Save sharvaridhote/82d21852de730495633a1f5211ced117 to your computer and use it in GitHub Desktop.

Select an option

Save sharvaridhote/82d21852de730495633a1f5211ced117 to your computer and use it in GitHub Desktop.
Data Label Creator
def label_creator(x):
"""
Find and remove citation from the text and creates labels
parameters:
x : str - charecters in the string
returns :
cleanx : str - cleaned text without citation
label : int - sentence with citation: 1 else 0
"""
infix = re.compile('\[(.+?)\]')
clean_x = re.findall(infix, x)
if len(clean_x):
label = 1
else:
label = 0
cleanx = re.sub(infix, '', x)
return cleanx, label
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment