Returns a string of the roles and relations parsed from the given element. The chunk type (which is part of the relation string) can be given as parameter.
(chunk, type="O")
| 1440 | return tokens |
| 1441 | |
| 1442 | def _parse_relation(chunk, type="O"): |
| 1443 | """ Returns a string of the roles and relations parsed from the given <chunk> element. |
| 1444 | The chunk type (which is part of the relation string) can be given as parameter. |
| 1445 | """ |
| 1446 | r1 = chunk.get(XML_RELATION) |
| 1447 | r2 = chunk.get(XML_ID, chunk.get(XML_OF)) |
| 1448 | r1 = [x != "-" and x or None for x in r1.split("|")] or [None] |
| 1449 | r2 = [x != "-" and x or None for x in r2.split("|")] or [None] |
| 1450 | r2 = [x is not None and x.split(_UID_SEPARATOR )[-1] or x for x in r2] |
| 1451 | if len(r1) < len(r2): r1 = r1 + r1 * (len(r2)-len(r1)) # [1] ["SBJ", "OBJ"] => "SBJ-1;OBJ-1" |
| 1452 | if len(r2) < len(r1): r2 = r2 + r2 * (len(r1)-len(r2)) # [2,4] ["OBJ"] => "OBJ-2;OBJ-4" |
| 1453 | return ";".join(["-".join([x for x in (type, r1, r2) if x]) for r1, r2 in zip(r1, r2)]) |
| 1454 | |
| 1455 | def _parse_token(word, chunk="O", pnp="O", relation="O", anchor="O", |
| 1456 | format=[WORD, POS, CHUNK, PNP, REL, ANCHOR, LEMMA]): |
no test coverage detected
searching dependent graphs…