Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@preprocessor()
def returns_none(x: DataPoint) -> DataPoint:
return None
@preprocessor()
def square(x: Row) -> Row:
return Row(num=x.num, num_squared=x.num ** 2)
@preprocessor()
def copy_features(x: DataPoint) -> DataPoint:
"""Compute x2 + 0.25 for direct comparison to x1."""
x.x3 = x.x2 + 0.25
return x
@preprocessor()
def combine_text(x: DataPoint) -> DataPoint:
x.text = f"{x.title} {x.article}"
return x
@preprocessor(memoize=True)
def square_memoize(x: DataPoint) -> DataPoint:
return Row(num=x.num, num_squared=x.num ** 2)
@preprocessor()
def combine_text(x):
return Row(title=x.title, body=x.body, article=f"{x.title} {x.body}")
@preprocessor()
def combine_text(x):
x.article = f"{x.title} {x.body}"
return x
@preprocessor(memoize=True)
def textblob_polarity(x):
if isinstance(x.review_text, str):
x.blob = TextBlob(x.review_text)
else:
x.blob = None
return x
@preprocessor()
def get_text_between(cand):
"""
Returns the text between the two person mentions in the sentence for a candidate
"""
start = cand.person1_word_idx[1] + 1
end = cand.person2_word_idx[0]
cand.text_between = " ".join(cand.tokens[start:end])
return cand
@preprocessor(memoize=True)
def textblob_sentiment(x):
scores = TextBlob(x.text)
x.polarity = scores.sentiment.polarity
x.subjectivity = scores.sentiment.subjectivity
return x