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

Function _parse_token

pattern/text/tree.py:1455–1472  ·  view source on GitHub ↗

Returns a list of token tags parsed from the given element. Tags that are not attributes in a (e.g., relation) can be given as parameters.

(word, chunk="O", pnp="O", relation="O", anchor="O", 
                 format=[WORD, POS, CHUNK, PNP, REL, ANCHOR, LEMMA])

Source from the content-addressed store, hash-verified

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]):
1457 """ Returns a list of token tags parsed from the given <word> element.
1458 Tags that are not attributes in a <word> (e.g., relation) can be given as parameters.
1459 """
1460 tags = []
1461 for tag in format:
1462 if tag == WORD : tags.append(xml_decode(word.value))
1463 elif tag == POS : tags.append(xml_decode(word.get(XML_TYPE, "O")))
1464 elif tag == CHUNK : tags.append(chunk)
1465 elif tag == PNP : tags.append(pnp)
1466 elif tag == REL : tags.append(relation)
1467 elif tag == ANCHOR : tags.append(anchor)
1468 elif tag == LEMMA : tags.append(xml_decode(word.get(XML_LEMMA, "")))
1469 else:
1470 # Custom tags when the parser has been extended, see also Word.custom_tags{}.
1471 tags.append(xml_decode(word.get(tag, "O")))
1472 return tags
1473
1474### NLTK TREE ######################################################################################
1475

Callers 1

_parse_tokensFunction · 0.85

Calls 3

xml_decodeFunction · 0.85
appendMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…