{"version":2,"relationshipURLBase":"https://codingai-lec03.pages.dev/course/notebook-blocks/3be3345fe62d47d99d64a1e4491c6f03.html","relationshipResolution":"Resolve relative relationship URLs against relationshipURLBase; complete records and absolute URLs are in blocks.","title":"3. 正确分解目标、参照物和关系 · 实现代码","url":"https://codingai-lec03.pages.dev/course/notebook-blocks/3be3345fe62d47d99d64a1e4491c6f03.html","markdown":"https://codingai-lec03.pages.dev/course/notebook-blocks/3be3345fe62d47d99d64a1e4491c6f03.md","pages":[{"id":"reading-opening","title":"3. 正确分解目标、参照物和关系 · 实现代码","unit":"3. 正确分解目标、参照物和关系 · 实现代码","unitId":"notebook-blocks/3be3345fe62d47d99d64a1e4491c6f03","chapter":"course","number":1}],"aliases":[{"oldId":"b-f5991103266d7df5358d5c0d","targetId":"b-f5991103266d7df5358d5c0d","page":"reading-opening","operation":"move","beforeSHA256":"ee0f99ad7c7d0d958d3e0d80348bfe5a62a81423953405ed50add20d633934dd","afterSHA256":"ee0f99ad7c7d0d958d3e0d80348bfe5a62a81423953405ed50add20d633934dd","reason":"Same source body in authored semantic page"},{"oldId":"b-a9a91411be25393447208231","targetId":"b-a9a91411be25393447208231","page":"reading-opening","operation":"move","beforeSHA256":"1dc9945dec8910cba23a64d92425c902ee29cd741505dc6c05b4abcdca2ba39b","afterSHA256":"1dc9945dec8910cba23a64d92425c902ee29cd741505dc6c05b4abcdca2ba39b","reason":"Same source body in authored semantic page"},{"oldId":"b-b80843bdadaae52dbd7585ec","targetId":"b-b80843bdadaae52dbd7585ec","page":"reading-opening","operation":"move","beforeSHA256":"e91f24e4e4ca40e2099a0d81d30db6568f4bf2074b499eeee6e3959617bd97ac","afterSHA256":"e91f24e4e4ca40e2099a0d81d30db6568f4bf2074b499eeee6e3959617bd97ac","reason":"Same source body in authored semantic page"},{"oldId":"b-0df3da7f1f9380da4f9322bb","targetId":"b-0df3da7f1f9380da4f9322bb","page":"reading-opening","operation":"move","beforeSHA256":"3f002b87ee5d2038f92b49a8b54826e9b65444b765dddaea38342c0fba3e3d3b","afterSHA256":"3f002b87ee5d2038f92b49a8b54826e9b65444b765dddaea38342c0fba3e3d3b","reason":"Same source body in authored semantic page"},{"oldId":"b-4eaec97212e4845979038c5c","targetId":"b-4eaec97212e4845979038c5c","page":"reading-opening","operation":"move","beforeSHA256":"da4d4a83d781cb386c45ead04ad69f033fd35c902386687cd848b0291345c0f9","afterSHA256":"da4d4a83d781cb386c45ead04ad69f033fd35c902386687cd848b0291345c0f9","reason":"Same source body in authored semantic page"}],"blocks":[{"id":"b-f5991103266d7df5358d5c0d","type":"p","scope":"document","url":"https://codingai-lec03.pages.dev/course/notebook-blocks/3be3345fe62d47d99d64a1e4491c6f03.html#b-f5991103266d7df5358d5c0d","content":"[LAB 15 · 语言指代小练习：目标、参照与关系](/course/notebooks/7dc83786d067465aa76264475db2c62d.html)","sha256":"ee0f99ad7c7d0d958d3e0d80348bfe5a62a81423953405ed50add20d633934dd","chapter":{"id":"course","title":"3. 正确分解目标、参照物和关系 · 实现代码"},"unit":{"id":"notebook-blocks/3be3345fe62d47d99d64a1e4491c6f03","title":"3. 正确分解目标、参照物和关系 · 实现代码"},"page":{"id":"reading-opening","title":"3. 正确分解目标、参照物和关系 · 实现代码","number":1},"sectionTitle":"3. 正确分解目标、参照物和关系 · 实现代码","currentQuestion":"3. 正确分解目标、参照物和关系 · 实现代码","sourceSlides":[],"knowledgeBlock":null,"formulas":[],"previousBlock":null,"nextBlock":"b-a9a91411be25393447208231","prerequisites":[],"relatedBlocks":[]},{"id":"b-a9a91411be25393447208231","type":"h1","scope":"document","url":"https://codingai-lec03.pages.dev/course/notebook-blocks/3be3345fe62d47d99d64a1e4491c6f03.html#b-a9a91411be25393447208231","content":"# 3. 正确分解目标、参照物和关系 · 实现代码","sha256":"1dc9945dec8910cba23a64d92425c902ee29cd741505dc6c05b4abcdca2ba39b","chapter":{"id":"course","title":"3. 正确分解目标、参照物和关系 · 实现代码"},"unit":{"id":"notebook-blocks/3be3345fe62d47d99d64a1e4491c6f03","title":"3. 正确分解目标、参照物和关系 · 实现代码"},"page":{"id":"reading-opening","title":"3. 正确分解目标、参照物和关系 · 实现代码","number":1},"sectionTitle":"3. 正确分解目标、参照物和关系 · 实现代码","currentQuestion":"3. 正确分解目标、参照物和关系 · 实现代码","sourceSlides":[],"knowledgeBlock":null,"formulas":[],"previousBlock":"b-f5991103266d7df5358d5c0d","nextBlock":"b-b80843bdadaae52dbd7585ec","prerequisites":[{"id":"b-f5991103266d7df5358d5c0d","url":"#b-f5991103266d7df5358d5c0d","role":"problem-context"}],"relatedBlocks":[]},{"id":"b-b80843bdadaae52dbd7585ec","type":"p","scope":"document","url":"https://codingai-lec03.pages.dev/course/notebook-blocks/3be3345fe62d47d99d64a1e4491c6f03.html#b-b80843bdadaae52dbd7585ec","content":"按问题继续","sha256":"e91f24e4e4ca40e2099a0d81d30db6568f4bf2074b499eeee6e3959617bd97ac","chapter":{"id":"course","title":"3. 正确分解目标、参照物和关系 · 实现代码"},"unit":{"id":"notebook-blocks/3be3345fe62d47d99d64a1e4491c6f03","title":"3. 正确分解目标、参照物和关系 · 实现代码"},"page":{"id":"reading-opening","title":"3. 正确分解目标、参照物和关系 · 实现代码","number":1},"sectionTitle":"3. 正确分解目标、参照物和关系 · 实现代码","currentQuestion":"3. 正确分解目标、参照物和关系 · 实现代码","sourceSlides":[],"knowledgeBlock":null,"formulas":[],"previousBlock":"b-a9a91411be25393447208231","nextBlock":"b-0df3da7f1f9380da4f9322bb","prerequisites":[{"id":"b-a9a91411be25393447208231","url":"#b-a9a91411be25393447208231","role":"section-title"},{"id":"b-f5991103266d7df5358d5c0d","url":"#b-f5991103266d7df5358d5c0d","role":"problem-context"}],"relatedBlocks":[]},{"id":"b-0df3da7f1f9380da4f9322bb","type":"p","scope":"document","url":"https://codingai-lec03.pages.dev/course/notebook-blocks/3be3345fe62d47d99d64a1e4491c6f03.html#b-0df3da7f1f9380da4f9322bb","content":"RGB规则提框、错误关键词基线、目标/参照/关系与干预","sha256":"3f002b87ee5d2038f92b49a8b54826e9b65444b765dddaea38342c0fba3e3d3b","chapter":{"id":"course","title":"3. 正确分解目标、参照物和关系 · 实现代码"},"unit":{"id":"notebook-blocks/3be3345fe62d47d99d64a1e4491c6f03","title":"3. 正确分解目标、参照物和关系 · 实现代码"},"page":{"id":"reading-opening","title":"3. 正确分解目标、参照物和关系 · 实现代码","number":1},"sectionTitle":"3. 正确分解目标、参照物和关系 · 实现代码","currentQuestion":"3. 正确分解目标、参照物和关系 · 实现代码","sourceSlides":[],"knowledgeBlock":null,"formulas":[],"previousBlock":"b-b80843bdadaae52dbd7585ec","nextBlock":"b-4eaec97212e4845979038c5c","prerequisites":[{"id":"b-a9a91411be25393447208231","url":"#b-a9a91411be25393447208231","role":"section-title"},{"id":"b-f5991103266d7df5358d5c0d","url":"#b-f5991103266d7df5358d5c0d","role":"problem-context"}],"relatedBlocks":[]},{"id":"b-4eaec97212e4845979038c5c","type":"pre","scope":"document","url":"https://codingai-lec03.pages.dev/course/notebook-blocks/3be3345fe62d47d99d64a1e4491c6f03.html#b-4eaec97212e4845979038c5c","content":"```\ndef connected_components(mask):\n    seen=np.zeros(mask.shape,bool);components=[]\n    for y,x in zip(*np.where(mask)):\n        if seen[y,x]:continue\n        stack=[(int(y),int(x))];seen[y,x]=True;points=[]\n        while stack:\n            yy,xx=stack.pop();points.append((yy,xx))\n            for dy,dx in [(1,0),(-1,0),(0,1),(0,-1)]:\n                ny,nx=yy+dy,xx+dx\n                if 0<=ny<mask.shape[0] and 0<=nx<mask.shape[1] and mask[ny,nx] and not seen[ny,nx]:\n                    seen[ny,nx]=True;stack.append((ny,nx))\n        if len(points)>=30:\n            yy,xx=np.array(points).T\n            components.append([int(xx.min()),int(yy.min()),int(xx.max()+1),int(yy.max()+1)])\n    return components\n\ndef pixel_candidates(rgb):\n    candidates=[]\n    for color,value in PALETTE.items():\n        distance=np.linalg.norm(rgb.astype(float)-np.array(value),axis=-1)\n        for box in connected_components(distance<20):\n            candidates.append({'color':color,'category':'book' if color=='brown' else 'cup','box':box,'center_x':(box[0]+box[2])/2})\n    return candidates\n\ndef ground(rgb,phrase):\n    objects=pixel_candidates(rgb)\n    if ' left of ' in phrase or ' right of ' in phrase:\n        relation='left' if ' left of ' in phrase else 'right'\n        target_noun,reference_phrase=phrase.split(' '+relation+' of ')\n        ref_color=reference_phrase.split()[0]\n        refs=[o for o in objects if o['category']=='cup' and o['color']==ref_color]\n        if len(refs)!=1:return {'status':'reference missing/ambiguous','target':None,'reference':None,'candidates':objects}\n        ref=refs[0]\n        possible=[o for o in objects if o['category']==target_noun and o is not ref and ((o['center_x']<ref['center_x']) if relation=='left' else (o['center_x']>ref['center_x']))]\n        return {'status':'unique target' if len(possible)==1 else 'no unique visible target','target':possible[0] if len(possible)==1 else None,'reference':ref,'relation':relation,'candidates':objects}\n    color,noun=phrase.split();found=[o for o in objects if o['color']==color and o['category']==noun]\n    return {'status':'unique target' if len(found)==1 else 'no unique visible target','target':found[0] if len(found)==1 else None,'reference':None,'candidates':objects}\n\ncases=[('base',base,'cup left of blue cup'),('target occluded',occluded,'cup left of blue cup'),('colors exchanged',swapped,'cup left of blue cup'),('relation changed',swapped,'cup right of blue cup')]\nresults=[]\nfor condition,pixels,phrase in cases:\n    row={'condition':condition,'phrase':phrase,**ground(pixels,phrase)};results.append(row)\n    print(condition,phrase,'->',row['status'],'target',row['target'],'reference',row['reference'])\nassert results[0]['target']['color']=='red'\nassert results[0]['reference']['color']=='blue'\nassert results[0]['target']['box']==[15,19,50,58]\nassert results[1]['target'] is None\nassert results[2]['target'] is None\nassert results[3]['target']['color']=='red' and results[3]['target']['box'][0]==109\n```","sha256":"da4d4a83d781cb386c45ead04ad69f033fd35c902386687cd848b0291345c0f9","chapter":{"id":"course","title":"3. 正确分解目标、参照物和关系 · 实现代码"},"unit":{"id":"notebook-blocks/3be3345fe62d47d99d64a1e4491c6f03","title":"3. 正确分解目标、参照物和关系 · 实现代码"},"page":{"id":"reading-opening","title":"3. 正确分解目标、参照物和关系 · 实现代码","number":1},"sectionTitle":"3. 正确分解目标、参照物和关系 · 实现代码","currentQuestion":"3. 正确分解目标、参照物和关系 · 实现代码","sourceSlides":[],"knowledgeBlock":null,"formulas":[],"previousBlock":"b-0df3da7f1f9380da4f9322bb","nextBlock":null,"prerequisites":[{"id":"b-a9a91411be25393447208231","url":"#b-a9a91411be25393447208231","role":"section-title"},{"id":"b-f5991103266d7df5358d5c0d","url":"#b-f5991103266d7df5358d5c0d","role":"problem-context"}],"relatedBlocks":[]}]}
