How to use first_child method in Selene

Best Python code snippet using selene_python

POSTree.py

Source:POSTree.py Github

copy

Full Screen

...255 assert(srcnode != None and dstnode != None)256 srcnode.next_sibling = dstnode.next_sibling257 dstnode.next_sibling = srcnode258 return srcnode259 def __insert_as_first_child(self, srcnode, dstnode):260 assert(srcnode != None and dstnode != None)261 srcnode.next_sibling = dstnode.first_child262 dstnode.first_child = srcnode263 return srcnode264 def __insert_as_last_child(self, srcnode, dstnode):265 assert(srcnode != None and dstnode != None)266 lc = dstnode.first_child267 if lc == None:268 self.__insert_as_first_child(srcnode, dstnode)269 else:270 while lc.next_sibling != None:271 lc = lc.next_sibling272 self.__insert_after(srcnode, lc)273 return srcnode274 def __adjust_SQ_in_SBARQ(self, SQ, WH):275 prefirst, first = self.__check_ADVP(SQ, SQ.first_child)276 277 # SQ = VP278 if first.token == 'VP':279 return SQ280 # SQ = NP + VP281 if (first.token == 'NP' and first.next_sibling != None 282 and first.next_sibling.token == 'VP' and first.next_sibling.next_sibling == None):283 return SQ284 if not self.__check_VB(first):285 raise ValueError('First child of SQ in SBARQ is not VB*/MD')286 # process 's 're 've287 if first.first_child.token == "'s":288 first.first_child.token = 'is'289 elif first.first_child.token == "'re":290 first.first_child.token = 'are'291 elif first.first_child.token == "'ve":292 first.first_child.token = 'have'293 presecond, second = self.__check_ADVP(first, first.next_sibling)294 # SQ = VB* + [ADVP]295 if second == None:296 return SQ297 # process RB(not) and auxiliary do/does/did298 if second.token == 'RB' and second.first_child.token in ("n't", "not"):299 if first.first_child.token == 'ca':300 first.first_child.token = 'can not'301 else:302 first.first_child.token += ' not'303 self.__delete_tree(presecond, second)304 presecond, second = self.__check_ADVP(first, first.next_sibling)305 else:306 if first.first_child.token in ('do', 'does', 'did'):307 first.first_child.token = ''308 # SQ = VB*+PP/ADJP/VP309 if second.next_sibling == None and second.token in ('PP', 'ADJP', 'VP'):310 return SQ311 312 # SQ = VB* + NP313 # | |314 # first second315 if second.token == 'NP' and second.next_sibling == None:316 fc = second.first_child317 # second = NP + ?318 # | |319 # fc sc320 if (fc.token == 'NP' and fc.next_sibling != None321 and fc.next_sibling.next_sibling == None):322 sc = fc.next_sibling323 if ((sc.token == 'PP' and WH.token == 'WHADVP')324 or (sc.token == 'PP' and sc.first_child.token == 'IN' 325 and sc.first_child.next_sibling == None)326 or (sc.token == 'NP' and ' '.join(self.__gather_word(fc)) == 'there')327 or (sc.token == 'ADJP')328 or (sc.token == 'SBAR' and sc.first_child.token == 'WHADVP')):329 self.__delete_node(presecond, second)330 VB = self.__delete_tree(prefirst, first)331 self.__insert_after(VB, fc)332 return SQ333 VB = self.__delete_tree(prefirst, first)334 self.__insert_after(VB, second)335 return SQ336 # SQ = VB* + NP + ? 337 # | | |338 # first second third339 if second.token == 'NP' and second.next_sibling != None:340 prethird, third = self.__check_ADVP(second, second.next_sibling)341 # SQ = VB* + NP + ADVP342 if third == None:343 VB = self.__delete_tree(prefirst, first)344 self.__insert_after(VB, second)345 return SQ346 if third.next_sibling == None:347 if ((third.token in ('ADJP', 'PP', 'NP', 'VP'))348 or (third.token == 'S' 349 and self.__tree_to_text(third).startswith('(S(VP(TO to)(VP(VB'))):350 VB = self.__delete_tree(prefirst, first)351 self.__insert_after(VB, second)352 return SQ353 raise ValueError('Unknown SQ structure in SBARQ!')354 def __prefix_by_to_WH(self, WH):355 BY = self.Node('BY')356 BY.first_child = self.Node('by')357 self.__insert_as_first_child(BY, WH)358 return WH359 def __insert_WH_into_SQ(self, WH, SQ):360 if self.words[0] == 'why':361 self.__insert_as_last_child(WH, SQ)362 return SQ363 prefirst, first = self.__check_ADVP(SQ, SQ.first_child)364 if first.next_sibling == None:365 # SQ = VP366 if first.token == 'VP':367 self.__insert_as_first_child(WH, SQ)368 return SQ369 # SQ = NP370 if first.token == 'NP':371 self.__insert_after(WH, first)372 return SQ373 # SQ = VB*374 if self.__check_VB(first):375 self.__insert_as_first_child(WH, SQ)376 return SQ377 raise ValueError('Unknown SQ structure!')378 presecond, second = self.__check_ADVP(first, first.next_sibling)379 # SQ = VB* + ADVP380 if self.__check_VB(first) and second == None:381 self.__insert_as_first_child(WH, SQ)382 return SQ383 # SQ = VB* + VP/PP/ADJP384 # | |385 # first second386 if (self.__check_VB(first) and second.next_sibling == None 387 and second.token in ('VP', 'PP', 'ADJP')):388 self.__insert_as_first_child(WH, SQ)389 return SQ390 prethird, third = self.__check_ADVP(second, second.next_sibling)391 # SQ = NP + VB* + [ADVP]392 # | | 393 # first second 394 if (first.token == 'NP' and self.__check_VB(second) and 395 (second.next_sibling == None or third == None)):396 self.__insert_after(WH, second)397 return SQ398 # SQ = NP + VP399 # | |400 # first second401 if (first.token == 'NP' and second.token == 'VP' 402 and second.next_sibling == None):403 if WH.token in ('WHNP', 'WHADJP'):404 self.__insert_as_first_child(WH, SQ)405 return SQ406 if WH.token == 'WHPP':407 self.__insert_after(WH, second)408 return SQ409 if third == None:410 raise ValueError('Unknown SQ structure!')411 # SQ = NP + VB* + ?412 # | | |413 # first second third414 if first.token == 'NP' and self.__check_VB(second) and third.next_sibling == None:415 # SQ = NP + VB* + VP416 if third.token == 'VP':417 VB = second418 VP = third...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Selene automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful