Fix sense is incomplete when phrase has multiple senses in cambridge(Test word 'beg').
This commit is contained in:
parent
e7d422e1ed
commit
cc8b082e75
@ -88,22 +88,25 @@ class Cambridge(WebService):
|
|||||||
|
|
||||||
if sense_body:
|
if sense_body:
|
||||||
l = result['def_list']
|
l = result['def_list']
|
||||||
for block in sense_body:
|
|
||||||
if isinstance(block, Tag) is not True:
|
|
||||||
continue
|
|
||||||
|
|
||||||
phrase = None
|
def extract_sense(block, phrase=None):
|
||||||
|
if isinstance(block, Tag) is not True:
|
||||||
|
return
|
||||||
|
|
||||||
block_type = block['class'][0]
|
block_type = block['class'][0]
|
||||||
if block_type == 'def-block':
|
if block_type == 'def-block':
|
||||||
pass
|
pass
|
||||||
elif block_type == 'phrase-block':
|
elif block_type == 'phrase-block':
|
||||||
phrase_header = block.find('span', class_='phrase-head')
|
_phrase_header = block.find('span', class_='phrase-head')
|
||||||
phrase = phrase_header.get_text() if phrase_header else None
|
_phrase_body = block.find('div', class_='phrase-body pad-indent')
|
||||||
pass
|
if _phrase_body:
|
||||||
|
for p_b in _phrase_body:
|
||||||
|
extract_sense(p_b, _phrase_header.get_text() if _phrase_header else None)
|
||||||
|
return
|
||||||
elif block_type == 'runon-body':
|
elif block_type == 'runon-body':
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
continue
|
return
|
||||||
|
|
||||||
span_df = block.find('span', class_='def-info')
|
span_df = block.find('span', class_='def-info')
|
||||||
def_info = (span_df.get_text().replace('›', '') if span_df else '')
|
def_info = (span_df.get_text().replace('›', '') if span_df else '')
|
||||||
@ -125,6 +128,9 @@ class Cambridge(WebService):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
for b in sense_body:
|
||||||
|
extract_sense(b)
|
||||||
result['def'] = u'<ul>' + u''.join(s for s in l) + u'</ul>'
|
result['def'] = u'<ul>' + u''.join(s for s in l) + u'</ul>'
|
||||||
img = sense.find('img', class_='lightboxLink')
|
img = sense.find('img', class_='lightboxLink')
|
||||||
if img:
|
if img:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user