MCPcopy Index your code
hub / github.com/clips/pattern / _parse_relation

Function _parse_relation

pattern/text/tree.py:1442–1453  ·  view source on GitHub ↗

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")

Source from the content-addressed store, hash-verified

1440 return tokens
1441
1442def _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
1455def _parse_token(word, chunk="O", pnp="O", relation="O", anchor="O",
1456 format=[WORD, POS, CHUNK, PNP, REL, ANCHOR, LEMMA]):

Callers 1

_parse_tokensFunction · 0.85

Calls 4

lenFunction · 0.85
zipFunction · 0.85
getMethod · 0.45
splitMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…