Reputation: 15
new_dict = [{'confidence': 0.7181452631261411, 'sentence': 'In general working from home is not permitted due to the complexity of the responsibilities as well as infrastructural and other issues that arise if the leader functions from anywhere outside the office premises ', 'extraction': {'arg1': {'text': 'the other issues', 'offsets': [[53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68]]}, 'rel': {'text': 'arise', 'offsets': [[75, 76, 77, 78, 79]]}, 'arg2s': [], 'context': None, 'negated': False, 'passive': False}}, {'confidence': 0.7181452631261411, 'sentence': 'In general working from home is not permitted due to the complexity of the responsibilities as well as infrastructural and other issues that arise if the leader functions from anywhere outside the office premises ', 'extraction': {'arg1': {'text': 'the infrastructural issues', 'offsets': [[53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78]]}, 'rel': {'text': 'arise', 'offsets': [[85, 86, 87, 88, 89]]}, 'arg2s': [], 'context': None, 'negated': False, 'passive': False}}]
if len(new_dict) == 0:
yield sent
else:
for dict_value in new_dict:
for second_list in dict_value['extraction']['arg2s']:
test = "".join(str(x) for x in dict_value['extraction']['arg1']['text'] + " " + dict_value['extraction']['rel']['text'])
arg2 = "".join(second_list['text'])
new_result = "".join(filter(None,test + " " + arg2))
yield new_result
I want to concatenate the all strings which is present in the text field. Can someone help me. I am expecting output as ["the other issues arise", "the infrastructural issues arise"]
Upvotes: 0
Views: 34
Reputation: 26
I hope this will work.
conc=[]
for i in new_dict:
text=i['extraction']['arg1']['text']+" "+i['extraction'] ['rel']['text']
for j in i['extraction']['arg2s']:
text=text+" "+j['text']
conc.append(text)
Upvotes: 1