text=re.sub(r" X "," *"+x["span2_text"]+"* ",_wsc_inputs(x))
text=re.sub(r" X "," *"+x["span2_text"]+"* ",_wsc_inputs(x))
return"wsc: "+text
return"wsc: "+text
def_wsc_inputs(x):
def_wsc_inputs(x):
words=x['text'].split(" ")
words=x["text"].split(" ")
# We would need some special logic to handle the case where the pronoun is the
# We would need some special logic to handle the case where the pronoun is the
# first or last word in the text. None of the examples in WSC seem to have
# first or last word in the text. None of the examples in WSC seem to have
# this, so we are ignoring these cases.
# this, so we are ignoring these cases.
assertx['span2_index']>0
assertx["span2_index"]>0
assertx['span2_index']<len(words)
assertx["span2_index"]<len(words)
pronoun_index=x['span2_index']
pronoun_index=x["span2_index"]
defcreate_input():
defcreate_input():
assertwords[pronoun_index]==x['span2_text']
assertwords[pronoun_index]==x["span2_text"]
return" ".join([
return" ".join(
" ".join(
[
words[:pronoun_index]
" ".join(words[:pronoun_index]),
),
"X",
'X',
" ".join(words[pronoun_index+1:]),
" ".join(
]
words[pronoun_index+1:]
)
),
])
# Handle some special cases.
# Handle some special cases.
ifx['text']=='The boy continued to whip the pony , and eventually the pony threw him over. John laughed out quite loud. \"Good for him,\" he said. ':
if(
x["text"]
=='The boy continued to whip the pony , and eventually the pony threw him over. John laughed out quite loud. "Good for him," he said. '
):
return(
return(
'The boy continued to whip the pony , and eventually the pony threw '
"The boy continued to whip the pony , and eventually the pony threw "
'him over. John laughed out quite loud. "Good for X ," he said.'
'him over. John laughed out quite loud. "Good for X ," he said.'
)
)
# Using the span2_index, we get 'use' instead of 'it'.
# Using the span2_index, we get 'use' instead of 'it'.
ifx['text']=='When they had eventually calmed down a bit , and had gotten home, Mr. Farley put the magic pebble in an iron safe . Some day they might want to use it , but really for now, what more could they wish for?':
if(
x["text"]
=="When they had eventually calmed down a bit , and had gotten home, Mr. Farley put the magic pebble in an iron safe . Some day they might want to use it , but really for now, what more could they wish for?"
):
return(
return(
'When they had eventually calmed down a bit , and had gotten home, '
"When they had eventually calmed down a bit , and had gotten home, "
'Mr. Farley put the magic pebble in an iron safe . Some day they might '
"Mr. Farley put the magic pebble in an iron safe . Some day they might "
'want to use X , but really for now, what more could they wish for?'
"want to use X , but really for now, what more could they wish for?"