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

Method __init__

pattern/text/tree.py:534–565  ·  view source on GitHub ↗

A nested tree of sentence words, chunks and prepositions. The input is a tagged string from parse(). The order in which token tags appear can be specified.

(self, string="", token=[WORD, POS, CHUNK, PNP, REL, ANCHOR, LEMMA], language="en")

Source from the content-addressed store, hash-verified

532class Sentence(object):
533
534 def __init__(self, string="", token=[WORD, POS, CHUNK, PNP, REL, ANCHOR, LEMMA], language="en"):
535 """ A nested tree of sentence words, chunks and prepositions.
536 The input is a tagged string from parse().
537 The order in which token tags appear can be specified.
538 """
539 # Extract token format from TokenString or TaggedString if possible.
540 if _is_tokenstring(string):
541 token, language = string.tags, getattr(string, "language", language)
542 # Convert to Unicode.
543 if isinstance(string, str):
544 for encoding in (("utf-8",), ("windows-1252",), ("utf-8", "ignore")):
545 try: string = string.decode(*encoding)
546 except:
547 pass
548 self.parent = None # A Slice refers to the Sentence it is part of.
549 self.text = None # A Sentence refers to the Text it is part of.
550 self.language = language
551 self.id = _uid()
552 self.token = list(token)
553 self.words = []
554 self.chunks = [] # Words grouped into chunks.
555 self.pnp = [] # Words grouped into PNP chunks.
556 self._anchors = {} # Anchor tags related to anchor chunks or attached PNP's.
557 self._relation = None # Helper variable: the last chunk's relation and role.
558 self._attachment = None # Helper variable: the last attachment tag (e.g., "P1") parsed in _do_pnp().
559 self._previous = None # Helper variable: the last token parsed in parse_token().
560 self.relations = { "SBJ":{}, "OBJ":{}, "VP":{} }
561 # Split the slash-formatted token into the separate tags in the given order.
562 # Append Word and Chunk objects according to the token's tags.
563 for chars in string.split(" "):
564 if len(chars) > 0:
565 self.append(*self.parse_token(chars, token))
566
567 @property
568 def word(self):

Callers

nothing calls this directly

Calls 7

appendMethod · 0.95
parse_tokenMethod · 0.95
_is_tokenstringFunction · 0.85
lenFunction · 0.85
_uidFunction · 0.70
decodeMethod · 0.45
splitMethod · 0.45

Tested by

no test coverage detected