rem stringlengths 0 322k | add stringlengths 0 2.05M | context stringlengths 8 228k |
|---|---|---|
_, _, data = self.resource.get_json() self._name = data['db_name'] | if ddoc is not None: _, _, data = self.resource('_design', ddoc, '_info').get_json() else: _, _, data = self.resource.get_json() self._name = data['db_name'] | def info(self): """Return information about the database as a dictionary. |
if not streamed and method in ('GET', 'HEAD') and 'etag' in resp.msg: | if not streamed and method == 'GET' and 'etag' in resp.msg: | def _retry(): conn.close() conn.connect() return _try_request(retries - 1) |
for ln in data._iterchunks(): | chunks = data._iterchunks() for ln in chunks: | def _changes(self, **opts): _, _, data = self.resource.get('_changes', **opts) for ln in data._iterchunks(): # Skip non-JSON lines (heartbeats). if ln[0] != '{': continue # Yield the update up to and inluding the last_seq line. doc = json.decode(ln) yield doc if 'last_seq' in doc: break |
if 'last_seq' in doc: break | def _changes(self, **opts): _, _, data = self.resource.get('_changes', **opts) for ln in data._iterchunks(): # Skip non-JSON lines (heartbeats). if ln[0] != '{': continue # Yield the update up to and inluding the last_seq line. doc = json.decode(ln) yield doc if 'last_seq' in doc: break | |
return reduce(*cmd, rereduce=True) | return reduce(*cmd, **{'rereduce': True}) | def rereduce(*cmd): return reduce(*cmd, rereduce=True) |
if headers.get('content-type') == 'application/json': | if 'application/json' in headers.get('content-type'): | def delete_json(self, *a, **k): status, headers, data = self.delete(*a, **k) if headers.get('content-type') == 'application/json': data = json.decode(data.read()) return status, headers, data |
if headers.get('content-type') == 'application/json': | if 'application/json' in headers.get('content-type'): | def get_json(self, *a, **k): status, headers, data = self.get(*a, **k) if headers.get('content-type') == 'application/json': data = json.decode(data.read()) return status, headers, data |
if headers.get('content-type') == 'application/json': | if 'application/json' in headers.get('content-type'): | def post_json(self, *a, **k): status, headers, data = self.post(*a, **k) if headers.get('content-type') == 'application/json': data = json.decode(data.read()) return status, headers, data |
if headers.get('content-type') == 'application/json': | if 'application/json' in headers.get('content-type'): | def put_json(self, *a, **k): status, headers, data = self.put(*a, **k) if headers.get('content-type') == 'application/json': data = json.decode(data.read()) return status, headers, data |
Takes since, feed, heartbeat and timeout options. The continuous feed mode isn't supported yet, but normal and longpoll should work. """ if 'feed' in opts and opts['feed'] == 'continuous': | Takes since, feed, heartbeat and timeout options. """ if opts.get('feed') == 'continuous': | def changes(self, **opts): """Retrieve a changes feed from the database. |
for docid in db: | def dump_db(dburl, username=None, password=None, boundary=None, output=sys.stdout): db = Database(dburl) if username is not None and password is not None: db.resource.http.add_credentials(username, password) envelope = write_multipart(output, boundary=boundary) for docid in db: doc = db.get(docid, attachments=True) p... | |
}, ) | }) | def dump_db(dburl, username=None, password=None, boundary=None, output=sys.stdout): db = Database(dburl) if username is not None and password is not None: db.resource.http.add_credentials(username, password) envelope = write_multipart(output, boundary=boundary) for docid in db: doc = db.get(docid, attachments=True) p... |
if not options.compact: return for dbname in dbnames: target_server[dbname].compact() | if options.compact: for (sdb, tdb) in databases: print 'compact', tdb target[tdb].compact() | def main(): usage = '%prog [options] <source> <target>' parser = optparse.OptionParser(usage=usage) parser.add_option('--continuous', action='store_true', dest='continuous', help='trigger continuous replication in cochdb') parser.add_option('--compact', action='store_true', dest='compact', help='compact target databas... |
resp, data = self.resource.post('_compact', ddoc) | resp, data = self.resource('_compact').post(ddoc) | def compact(self, ddoc=None): """Compact the database or a design document's index. |
elif self.scheme == 'https': | elif scheme == 'https': | def _get_connection(self, url): scheme, host = urlsplit(url, 'http', False)[:2] self.lock.acquire() try: conns = self.conns.setdefault((scheme, host), []) if conns: conn = conns.pop(-1) else: if scheme == 'http': cls = HTTPConnection elif self.scheme == 'https': cls = HTTPSConnection else: raise ValueError('%s is not a... |
emit(doc.foo, null); | if(doc.foo !== undefined) { emit(doc.foo, null); } | def test_collation(self): values = [ None, False, True, 1, 2, 3.0, 4, 'a', 'A', 'aa', 'b', 'B', 'ba', 'bb', ['a'], ['b'], ['b', 'c'], ['b', 'c', 'a'], ['b', 'd'], ['b', 'd', 'e'], {'a': 1}, {'a': 2}, {'b': 1}, {'b': 2}, {'b': 2, 'c': 2}, ] self.db['0'] = {'bar': 0} for idx, value in enumerate(values): self.db[str(idx +... |
top, context = get_first(node, r'/([ICV]P|V[VA]|VRD|VSB|VCD)/=TOP $ *=SS', with_context=True) | top, context = get_first(node, r'/([ICV]P|V[VA]|VRD|VSB|VCD)/=TOP $ *=SS', with_context=True, left_to_right=True) | def fix_subject_extraction(self, _, n, pred, w=None, reduced=False): debug("%s", reduced) node = n debug("Fixing subject extraction: %s", lrp_repr(node)) if not reduced: self.remove_null_element(node) |
yield Derivation.from_header_and_derivation(header, deriv_string) | deriv = Derivation.from_header_and_derivation(header, deriv_string) yield deriv | def __iter__(self): '''Yields an iterator over this document.''' while True: try: header, deriv_string = self.derivs.next(), self.derivs.next() except StopIteration: self.file.close() raise yield Derivation.from_header_and_derivation(header, deriv_string) |
elif is_apposition(node): tag(last_kid, 'r') for kid in node: if not kid.tag.startswith('PU'): if kid.tag.endswith('-APP') and not kid.tag.startswith('CP'): tag(kid, 'A') else: tag(kid, 'a') | def label(root): root = preprocess(root) for node in nodes(root): if node.is_leaf(): continue first_kid, first_kid_index = get_nonpunct_kid(node, get_last=False) last_kid, last_kid_index = get_nonpunct_kid(node, get_last=True) for kid in node: if has_modification_tag(kid): tag(kid, 'm') elif kid.tag == 'MSP': tag... | |
elif is_apposition(node): tag(last_kid, 'r') for kid in node: if not kid.tag.startswith('PU'): if kid.tag.endswith('-APP') and not kid.tag.startswith('CP'): tag(kid, 'A') else: tag(kid, 'a') | def label(root): root = preprocess(root) for node in nodes(root): if node.is_leaf(): continue first_kid, first_kid_index = get_nonpunct_kid(node, get_last=False) last_kid, last_kid_index = get_nonpunct_kid(node, get_last=True) for kid in node: if has_modification_tag(kid): tag(kid, 'm') elif kid.tag == 'MSP': tag... | |
debug('final_punctuation_stk: %s', final_punctuation_stk) debug('now going to label: %s', pprint(node)) | def label_root(node): debug('originally: %s', pprint(node)) final_punctuation_stk = [] # These derivations consist of a leaf PU root: 24:73(4), 25:81(4), 28:52(21) if node.is_leaf(): return node # inconsistent top-level taggings (0:21(4)) lead to a CCG-like absorption analysis elif is_right_punct_absorption(node): ret... | |
debug('result: %s', pprint(result)) | def label_root(node): debug('originally: %s', pprint(node)) final_punctuation_stk = [] # These derivations consist of a leaf PU root: 24:73(4), 25:81(4), 28:52(21) if node.is_leaf(): return node # inconsistent top-level taggings (0:21(4)) lead to a CCG-like absorption analysis elif is_right_punct_absorption(node): ret... | |
(C(r'(S[dcl]\S[dcl])/S[dcl]'), C(r'((S[dcl]{_}\S[dcl]{Z}{_})/S[dcl]{Y}){_}')) | (C(r'(S[dcl]\S[dcl])/S[dcl]'), C(r'((S[dcl]{_}\S[dcl]{Z}){_}/S[dcl]{Y}){_}')) | def is_np_n(cat): '''Returns whether _cat_ is the category NP/N.''' return cat.left == NP and cat.right == N |
or node.kids[0].tag.startswith(cand) for cand in ('PP-PRD', 'QP-PRD', 'LCP-PRD'))) or | or any(node.kids[0].tag.startswith(cand) for cand in ('PP-PRD', 'QP-PRD', 'LCP-PRD')) ) ) or | def label_node(node, inside_np_internal_structure=False, do_shrink=True): if node.is_leaf(): return node elif node.count() == 1: # shrinkage rules (NP < NN shrinks to NN) if (do_shrink and ((inside_np_internal_structure and node.tag.startswith("NP") and has_noun_tag(node.kids[0]) or node.kids[0].tag == "AD") or # (node... |
@echo | def fcomp(l, r): if (l.is_leaf() or r.is_leaf() or l.right != r.left or l.direction != FORWARD or l.direction != r.direction): return None return fake_unify(l, r, l.left / r.right) | |
def label_adjunction(node, inherit_tag=False, without_labelling=False, inside_np_internal_structure=False): kid_tag = strip_tag_if(not inherit_tag, node.tag) | def label_adjunction(node, without_labelling=False, inside_np_internal_structure=False): kid_tag = node.tag | def label_adjunction(node, inherit_tag=False, without_labelling=False, inside_np_internal_structure=False): kid_tag = strip_tag_if(not inherit_tag, node.tag) if not without_labelling: kids = map(lambda node: label_node(node, inside_np_internal_structure=inside_np_internal_structure), node.kids) else: kids = node.kids ... |
def label_apposition(node, inherit_tag=False, inside_np_internal_structure=False): kid_tag = strip_tag_if(not inherit_tag, node.tag) | def label_apposition(node, inside_np_internal_structure=False): kid_tag = node.tag | def label_apposition(node, inherit_tag=False, inside_np_internal_structure=False): kid_tag = strip_tag_if(not inherit_tag, node.tag) if node.count() > 2: # Label the first kid before removing it from the node: if we did this the # other way around, then shrinking (which relies on replace_kid) would not # find _node[0]... |
label_node(node[0], inside_np_internal_structure=inside_np_internal_structure) first = node.kids.pop(0) return Node(kid_tag, [first, label_node(node)]) return label_adjunction(node, inherit_tag=inherit_tag) def label_np_internal_structure(node, inherit_tag=False): | first = label_node(node[0], inside_np_internal_structure=inside_np_internal_structure) node.kids.pop(0) return Node(kid_tag, [first, label_node(node, inside_np_internal_structure=inside_np_internal_structure)]) return label_adjunction(node) def label_np_internal_structure(node): | def label_apposition(node, inherit_tag=False, inside_np_internal_structure=False): kid_tag = strip_tag_if(not inherit_tag, node.tag) if node.count() > 2: # Label the first kid before removing it from the node: if we did this the # other way around, then shrinking (which relies on replace_kid) would not # find _node[0]... |
kid_tag = strip_tag_if(not inherit_tag, node.tag) | kid_tag = node.tag | def label_np_internal_structure(node, inherit_tag=False): if (node.kids[-1].tag.endswith(':&') # prevent movement when we have an NP with only two children NN ETC and node.count() > 2): etc = node.kids.pop() kid_tag = strip_tag_if(not inherit_tag, node.tag) old_tag = node.tag node.tag = kid_tag return Node(old_tag, ... |
return Node(old_tag, [ label_coordination(node, inside_np_internal_structure), etc ]) | return Node(old_tag, [ label_coordination(node, inside_np_internal_structure=inside_np_internal_structure), etc ]) | def _label_coordination(node, inside_np_internal_structure=False): if (node.kids[-1].tag.endswith(':&') # prevent movement when we have an NP with only two children NN ETC and node.count() > 2): etc = node.kids.pop() kid_tag = base_tag(node.tag, strip_cptb_tag=False) old_tag = node.tag node.tag = kid_tag return Node... |
def label_head_initial(node, inherit_tag=False): kid_tag = strip_tag_if(not inherit_tag, node.tag) | def label_head_initial(node): kid_tag = node.tag | def label_head_initial(node, inherit_tag=False): kid_tag = strip_tag_if(not inherit_tag, node.tag) kids = map(label_node, node.kids)[::-1] first_kid, second_kid = kids.pop(), kids.pop() cur = Node(kid_tag, [first_kid, second_kid]) while kids: kid = kids.pop() cur = Node(node.tag, [cur, kid]) cur.tag = node.tag retu... |
def label_predication(node, inherit_tag=False): | def label_predication(node): | def label_predication(node, inherit_tag=False): kids = map(label_node, node.kids) |
kid_tag = strip_tag_if(not inherit_tag, node.tag) | kid_tag = node.tag | def label_predication(node, inherit_tag=False): kids = map(label_node, node.kids) |
trees = parse_tree(sys.stdin.read()) | trees = parse_tree(sys.stdin.read(), AugmentedPennParser) | def base_pprint(node, level=0, sep=' ', newline='\n', reduced_leaves=False): out = [] if level == 0: out.append('(') else: out.append( sep * level ) if node.is_leaf(): if reduced_leaves: out.append(node_repr(node)) else: out.append("(%s)" % node_repr(node)) else: # special case for nodes with all-leaf children if no... |
elif is_right_adjunction(node): return label_right_adjunction(node) | def label(node, inside_np=False): ''' Labels the descendants of _node_ and returns _node_. ''' if node.category is None: node.category = ptb_to_cat(node) # if this matches the IP root with a *PRO* trace under it, then # we shouldn't map IP -> S, but rather IP -> S\NP if node.tag.startswith('NT'): # map NT -> NP, not N... | |
else: | if not new_parent_category: | def fix_categories_starting_from(self, node, until): |
if cur == SfS and l == N or l == NP: return "nongap_topicalisation" | if cur == SfS and (l == N or l == NP): return "nongap_topicalisation" | def try_unary_rules(l, r, cur): '''Determines if [l r -> cur] matches any unary rules.''' if l == SbNP: for cand_cat, rule in { SfS: "lex_typechange", NP: "lex_typechange", SbNPfSbNP: "lex_typechange", SbS: "lex_typechange", SfSfNP: "np_topicalisation", }.iteritems(): if cur == cand_cat: return rule if config.cn_rule... |
if rooted_in_Sdcl(l) and l == r and r == cur: return "vcd_compound" | if rooted_in_Sdcl(l) and l.equal_respecting_features(r) and r == cur: return "vcd_compound" | def try_binary_rules(l, r, cur): if not config.cn_rules: return False # rhs NP needs to be feature-less, otherwise NP NP[conj] gets interpreted # as apposition if r.equal_respecting_features(NP): if cur == NP: if l == NP: return 'np_np_apposition' # NP NP -> NP elif l == S: return 's_np_apposition' # S NP... |
return label_adjunction(Node(node.tag, kids), inside_np_internal_structure=inside_np_internal_structure, without_labelling=True) | return reshape_for_coordination(Node(node.tag, kids), inside_np_internal_structure=inside_np_internal_structure) def get_kid(kids, node_tag, seen_cc): print "1: %s" % kids pu = kids.pop() print "2: %s" % kids if seen_cc and len(kids) > 0: xp = kids.pop() print "3: %s" % kids xp_ = Node(xp.tag, [xp, pu]) return... | def label_nonconjunctions(kid): if kid.tag not in ('CC', 'PU'): return label_node(kid, inside_np_internal_structure=inside_np_internal_structure) else: return kid |
result = get_first(node, r'*=S $ /DE[CG]/=REL', with_context=True, left_to_right=True) | result = get_first(node, r'/DEC/=REL $ *=S', with_context=True, left_to_right=True) if result is None: result = get_first(node, r'/DEG/=REL $ *=S', with_context=True, left_to_right=True) | def relabel_relativiser(self, node): # Relabel the relativiser category (NP/NP)\S to (NP/NP)\(S|NP) # There's a mis-annotated DEG for DEC in 21:2(1) inter alia result = get_first(node, r'*=S $ /DE[CG]/=REL', with_context=True, left_to_right=True) if result is not None: _, context = result s, relativiser = context['S']... |
elif any(kid.lex in ("β", "γ") for kid in leaf_kids(node)) and any(kid.lex in ("β", "γ") for kid in leaf_kids(node)): lqu = first_index_such_that(lambda kid: kid.is_leaf() and kid.lex in ("β", "γ"), node) rqu = first_index_such_that(lambda kid: kid.is_leaf() and kid.lex in ("β", "γ"), node) if rqu != node.count()-1: qu... | def preprocess(root): # IP < PP PU -> PP < PP PU (20:58(1)) if root.count() == 2 and root[1].tag == 'PU' and root[0].tag.startswith('PP'): root.tag = root[0].tag for node in nodes(root): if node.is_leaf(): continue first_kid, first_kid_index = get_nonpunct_kid(node, get_last=False) last_kid, last_kid_index = get_no... | |
elif is_etc(node): return label_head_final(node) | def label(node, inside_np=False): ''' Labels the descendants of _node_ and returns _node_. ''' if node.category is None: node.category = ptb_to_cat(node) # if this matches the IP root with a *PRO* trace under it, then # we shouldn't map IP -> S, but rather IP -> S\NP if has_noun_tag(node): node.category = N else: node... | |
elif is_etc(node): return label_head_final(node) | def label(node, inside_np=False): ''' Labels the descendants of _node_ and returns _node_. ''' if node.category is None: node.category = ptb_to_cat(node) # if this matches the IP root with a *PRO* trace under it, then # we shouldn't map IP -> S, but rather IP -> S\NP if has_noun_tag(node): node.category = N else: node... | |
elif is_PRO_trace(node): new_node = shrink_left(node, node.parent) ret = label(new_node) return ret | def label(node, inside_np=False): ''' Labels the descendants of _node_ and returns _node_. ''' if node.category is None: node.category = ptb_to_cat(node) # if this matches the IP root with a *PRO* trace under it, then # we shouldn't map IP -> S, but rather IP -> S\NP if has_noun_tag(node): node.category = N else: node... | |
def label_root(node): node.category = ptb_to_cat(node, is_root=True) return label(node) | def label_root(root): root.category = ptb_to_cat(root, is_root=True) for node in nodes(root): if is_PRO_trace(node): new_node = shrink_left(node, node.parent) new_node.tag = base_tag(new_node.tag, strip_cptb_tag=False) inherit_tag(new_node, node) return label(root) | def label_root(node): node.category = ptb_to_cat(node, is_root=True) return label(node) |
@echo | def rename_category_while_labelling_with(label_function, node, substitute, when=None): if when and (not when(node.category)): return label_function(node) old_category = node.category node.category = substitute ret = label_function(node) node.category = old_category return ret | |
@echo | def label_predication(node): node.kids[0] = label(node[0]) node[1].category = node.category | node[0].category node.kids[1] = label(node[1]) return node | |
@echo | def label_left_absorption(node): node[0].category = ptb_to_cat(node[0]) node[1].category = node.category node.kids[1] = label(node[1]) return node | |
@echo | def label_right_absorption(node): node[1].category = ptb_to_cat(node[1]) node[0].category = node.category node.kids[0] = label(node[0]) return node | |
@echo | def label_adjunction(node): node[1].category = ptb_to_cat(node[1], return_none_when_unmatched=True) or node.category node.kids[1] = label(node[1]) node[0].category = featureless(node.category) / featureless(node[1].category) node.kids[0] = label(node[0]) return node | |
@echo | def label_np_structure(node): node[0].category = node.category / node.category node.kids[0] = label(node[0]) if node.count() > 1: node[1].category = node.category node.kids[1] = label(node[1]) return node | |
@echo | def label_right_adjunction(node): node[0].category = node.category node.kids[0] = label(node[0]) no_features = featureless(node.category) node[1].category = no_features | no_features node.kids[1] = label(node[1]) return node | |
@echo | def label_head_final(node): node.kids[0] = label(node[0]) node[1].category = node.category | node[0].category node.kids[1] = label(node[1]) return node | |
@echo | def label_head_initial(node): node.kids[1] = label(node[1]) node[0].category = node.category / node[1].category node.kids[0] = label(node[0]) return node | |
@echo | def label_coordination(node, inside_np=False, ucp=False): node[0].category = node.category node.kids[0] = label(node[0], inside_np) node[1].category = ptb_to_cat(node[1]) if ucp else node.category # Label then apply [conj], so that kid categories don't inherit the feature node.kids[1] = label(node[1]) node[1].category... | |
@echo | def make_atomic_category(atom): return AtomicCategory(atom) | |
@echo | def np_modifier_tag_to_cat(ptb_tag): ptb_tag = base_tag(ptb_tag) return copy(NPModifierMap.get(ptb_tag, None)) | |
@echo | def is_PRO_trace(node): return (node.count() >= 2 and node[0].count() == 1 and node[0][0].tag == "-NONE-" and node[0][0].lex == "*PRO*") | |
if node.is_leaf(): return "%s %s" % (node.tag, node.lex) | if hasattr(node, 'category') and node.category is not None: if node.is_leaf(): return "%s {%s} %s" % (node.tag, node.category, node.lex) else: return "%s {%s}" % (node.tag, node.category) | def default_node_repr(node): if node.is_leaf(): return "%s %s" % (node.tag, node.lex) else: return "%s" % node.tag |
return "%s" % node.tag def aug_node_repr(node): if node.is_leaf(): return "%s {%s} %s" % (node.tag, node.category, node.lex) else: return "%s {%s}" % (node.tag, node.category) | if node.is_leaf(): return "%s %s" % (node.tag, node.lex) else: return "%s" % node.tag | def default_node_repr(node): if node.is_leaf(): return "%s %s" % (node.tag, node.lex) else: return "%s" % node.tag |
if config.aug_pprint: pprint = pprint_with(aug_node_repr) else: pprint = pprint_with(default_node_repr) | pprint = pprint_with(default_node_repr) | def base_pprint(node, level=0, sep=' ', newline='\n', reduced_leaves=False): out = [] if level == 0: out.append('(') else: out.append( sep * level ) if node.is_leaf(): if reduced_leaves: out.append(node_repr(node)) else: out.append("(%s)" % node_repr(node)) else: # special case for nodes with all-leaf children if no... |
node[0].category = node.category | node[0].category = ptb_to_cat(node[0]) if ucp else node.category | def label_coordination(node, inside_np=False, ucp=False): node[0].category = node.category node.kids[0] = label(node[0], inside_np) node[1].category = ptb_to_cat(node[1]) if ucp else node.category # Label then apply [conj], so that kid categories don't inherit the feature node.kids[1] = label(node[1]) node[1].category... |
(node.tag.startswith('ADVP') and node[0].tag == 'CC') or | (node.tag.startswith('ADVP') and node[0].tag in ('CC', 'PN')) or | def _label_node(node, inside_np_internal_structure=False, do_shrink=True): if node.is_leaf(): return node elif node.count() == 1: # shrinkage rules (NP < NN shrinks to NN) if (do_shrink and ((inside_np_internal_structure and ((node.tag.startswith("NP") and (not node.tag.endswith(':A')) and has_noun_tag(node[0])) or no... |
(node.tag.startswith('NP') and node[0].tag.startswith('NT')) or | (node.tag.startswith('NP') and (node[0].tag.startswith('NT') or node[0].tag.startswith('DT'))) or | def _label_node(node, inside_np_internal_structure=False, do_shrink=True): if node.is_leaf(): return node elif node.count() == 1: # shrinkage rules (NP < NN shrinks to NN) if (do_shrink and ((inside_np_internal_structure and ((node.tag.startswith("NP") and (not node.tag.endswith(':A')) and has_noun_tag(node[0])) or no... |
(node.tag.startswith('DP') and node[0].tag.startswith('NN')) or | (node.tag.startswith('DP') and (node[0].tag.startswith('NN') or node[0].tag.startswith('PN'))) or | def _label_node(node, inside_np_internal_structure=False, do_shrink=True): if node.is_leaf(): return node elif node.count() == 1: # shrinkage rules (NP < NN shrinks to NN) if (do_shrink and ((inside_np_internal_structure and ((node.tag.startswith("NP") and (not node.tag.endswith(':A')) and has_noun_tag(node[0])) or no... |
def label_coordination(node): def _label_coordination(node, inside_np_internal_structure=False): if (node.kids[-1].tag.endswith(':&') and node.count() > 2): etc = node.kids.pop() kid_tag = base_tag(tag, strip_cptb_tag=False) old_tag = node.tag node.tag = kid_tag return Node(old_tag, [ label_coordination(node, insid... | def _label_coordination(node, inside_np_internal_structure=False): if (node.kids[-1].tag.endswith(':&') and node.count() > 2): etc = node.kids.pop() kid_tag = base_tag(tag, strip_cptb_tag=False) old_tag = node.tag node.tag = kid_tag return Node(old_tag, [ label_coordination(node, inside_np_internal_structure), etc ... | def label_coordination(node): def _label_coordination(node, inside_np_internal_structure=False): if (node.kids[-1].tag.endswith(':&') # prevent movement when we have an NP with only two children NN ETC and node.count() > 2): etc = node.kids.pop() kid_tag = base_tag(tag, strip_cptb_tag=False) old_tag = node.tag node.t... |
top, context = get_first(node, r'/([ICV]P|V[VA]|VRD|VSB|VCD)/=TOP $ *=SS', with_context=True, left_to_right=True) ss = context.ss | result = get_first(node, r'{ /([ICV]P|V[VA]|VRD|VSB|VCD)/=TOP $ *=SS } ! > /([ICV]P|V[VA]|VRD|VSB|VCD)/', with_context=True, left_to_right=True) if not result: debug('Could not find verbal category; did not create null relativiser.') return | def fix_subject_extraction(self, _, n, pred, w=None, reduced=False): debug("%s", reduced) node = n debug("Fixing subject extraction: %s", lrp_repr(node)) if not reduced: self.remove_null_element(node) |
debug("Creating null relativiser unary category: %s", ss.category/ss.category) replace_kid(top.parent, top, Node(ss.category/ss.category, "NN", [top])) | top, context = result SS = context.ss.category debug("Creating null relativiser unary category: %s", SS/SS) replace_kid(top.parent, top, Node(SS/SS, "NN", [top])) | def fix_subject_extraction(self, _, n, pred, w=None, reduced=False): debug("%s", reduced) node = n debug("Fixing subject extraction: %s", lrp_repr(node)) if not reduced: self.remove_null_element(node) |
node[0].category = node.category / node.category | node[0].category = featureless(node.category) / featureless(node.category) | def label_np_structure(node): node[0].category = node.category / node.category node.kids[0] = label(node[0]) if node.count() > 1: node[1].category = node.category node.kids[1] = label(node[1]) return node |
(r'/(IP|CP-CND|VP)/=P < {/-TPC-\d+:t$/a=T $ /(IP|CP-CND)/=S }', self.fix_topicalisation_with_gap), | (r'/(IP|CP-CND)/=P < {/-TPC-\d+:t$/a=T $ /(IP|CP-CND)/=S }', self.fix_topicalisation_with_gap), | def pattern(self): return list(( # must come before object extraction (r'*=TOP $ /-SBJ-d+/a=N < { * < /LB/=BEI } << { /NP-(?:TPC|OBJ)/ < ^/\*/ $ /V[PV]|VRD|VSB|VCD/=PRED }', self.fix_reduced_long_bei_gap), (r'*=TOP < { * < /LB/=BEI } << { /NP-(?:TPC|OBJ)/ < ^/\*/ $ /V[PV]|VRD|VSB|VCD/=PRED }', self.fix_r... |
for node, ctx in find_all(top, r'/VP/=VP < /NP/=NP < /(QP|V[PV])/=QP', with_context=True): | for node, ctx in find_all(top, r'/VP/=VP <1 /NP/=NP <2 /(QP|V[PV])/=QP', with_context=True): | def clusterfix(self, top, pp, p, s, t): debug("Fixing argument cluster coordination: %s", pprint(top)) debug('T: %s', t) # 1. Shrink the verb (node T) self.fix_object_gap(pp, p, t, s) # 2. Reattach the verb above the TOP node new_node = Node(top.category, 'TAG', top.kids) top.kids = [t, new_node] # (Reattaching parent ... |
node.kids[0] = node[0][0] | node.kids = node[0].kids | def label(root): for node in nodes(root): if node.is_leaf(): continue first_kid, first_kid_index = get_nonpunct_kid(node, get_last=False) last_kid, last_kid_index = get_nonpunct_kid(node, get_last=True) # CPTB/Chinese-specific fixes # --------------------------- # PP(P CP NP) in derivations like 5:11(3) should be P... |
ModifierTags = frozenset(("TPC", "LOC", "EXT", "ADV", "DIR", "IO", "LGS", "MNR", "PN", "PRP", "TMP", "TTL")) ModifierTagsRegex = "(?:" + "|".join(ModifierTags) + ")" | def is_rooted_in(subcat, cat, respecting_features=False): cur = cat while not cur.is_leaf() and cur.left: cur = cur.left return cur.equal_respecting_features(subcat) if respecting_features else cur == subcat | |
(r'^/\*T\*/ > { /[NPQ]P(?:-(?:TPC|LOC|EXT|ADV|DIR|IO|LGS|MNR|PN|PRP|TMP|TTL))?(?!-\d+)/=K >> { /[ICV]P/ $ {/WH[NP]P(-\d+)?/ > { /CP/=PRED > *=N } } } }', self.fix_nongap_extraction), | (r'''^/\*T\*/ > { /[NPQ]P(?:-%(tags)s)?(?!-\d+)/=K >> { /[ICV]P/ $ {/WH[NP]P(-\d+)?/ > { /CP/=PRED > *=N } } } }''' % { 'tags': ModifierTagsRegex }, self.fix_nongap_extraction), | def pattern(self): return list(( # /VP/ < { /VP:c/ < /V[PVEC]|VRD|VSB|VCD/ < /NP/=NP < /QP/=QP } < { /VP:c/ < /NP/ < /QP/ ! < /V[PVEC]|VRD|VSB|VCD/ } # must come before object extraction (r'*=TOP $ /-SBJ-d+/a=N < { * < /LB/=BEI } << { /NP-(?:TPC|OBJ)/ < ^/\*/ $ /V[PV]|VRD|VSB|VCD/=PRED }', self.fix_reduced_long_bei_gap... |
inherit_tag(ctx['S'], ctx['P']) self.fix_object_gap(ctx['PP'], ctx['P'], ctx['T'], ctx['S']) self.fix_categories_starting_from(ctx['S'], g) | inherit_tag(ctx.s, ctx.p) self.fix_object_gap(ctx.pp, ctx.p, ctx.t, ctx.s) self.fix_categories_starting_from(ctx.s, g) | def fix_rnr(self, rnr, g): debug("Fixing RNR: %s", pprint(g)) index = get_trace_index_from_tag(rnr.lex) # -i debug("index: %s", index) expr = r'*=PP < { *=P < { *=T < ^/\*RNR\*%s/ $ *=S } }' % index for node, ctx in find_all(g, expr, with_context=True): inherit_tag(ctx['S'], ctx['P']) self.fix_object_gap(ctx['PP'], ctx... |
argument = ctx['T'] self.fix_object_gap(ctx['PP'], ctx['P'], ctx['T'], ctx['S']) | argument = ctx.t self.fix_object_gap(ctx.pp, ctx.p, ctx.t, ctx.s) | def fix_rnr(self, rnr, g): debug("Fixing RNR: %s", pprint(g)) index = get_trace_index_from_tag(rnr.lex) # -i debug("index: %s", index) expr = r'*=PP < { *=P < { *=T < ^/\*RNR\*%s/ $ *=S } }' % index for node, ctx in find_all(g, expr, with_context=True): inherit_tag(ctx['S'], ctx['P']) self.fix_object_gap(ctx['PP'], ctx... |
debug('PP: %s, P: %s, T: %s, S: %s', *map(lrp_repr, (ctx['PP'],ctx['P'],ctx['T'],ctx['S']))) | debug('PP: %s, P: %s, T: %s, S: %s', *map(lrp_repr, (ctx.pp, ctx.p, ctx.t, ctx.s))) | def fix_rnr(self, rnr, g): debug("Fixing RNR: %s", pprint(g)) index = get_trace_index_from_tag(rnr.lex) # -i debug("index: %s", index) expr = r'*=PP < { *=P < { *=T < ^/\*RNR\*%s/ $ *=S } }' % index for node, ctx in find_all(g, expr, with_context=True): inherit_tag(ctx['S'], ctx['P']) self.fix_object_gap(ctx['PP'], ctx... |
new_g.category = ctx['S'].category.left | new_g.category = ctx.s.category.left | def fix_rnr(self, rnr, g): debug("Fixing RNR: %s", pprint(g)) index = get_trace_index_from_tag(rnr.lex) # -i debug("index: %s", index) expr = r'*=PP < { *=P < { *=T < ^/\*RNR\*%s/ $ *=S } }' % index for node, ctx in find_all(g, expr, with_context=True): inherit_tag(ctx['S'], ctx['P']) self.fix_object_gap(ctx['PP'], ctx... |
pp, context = get_first(node, r'*=PP < { *=P < { /WH[NP]P/=T $ *=S } }', with_context=True) p, t, s = context['P'], context['T'], context['S'] | pp, ctx = get_first(node, r'*=PP < { *=P < { /WH[NP]P/=T $ *=S } }', with_context=True) p, t, s = ctx.p, ctx.t, ctx.s | def remove_null_element(self, node): # Remove the null element WHNP and its trace -NONE- '*OP*' and shrink tree pp, context = get_first(node, r'*=PP < { *=P < { /WH[NP]P/=T $ *=S } }', with_context=True) p, t, s = context['P'], context['T'], context['S'] |
s, relativiser = context['S'], context['REL'] | s, relativiser = context.s, context.rel | def relabel_relativiser(self, node): # Relabel the relativiser category (NP/NP)\S to (NP/NP)\(S|NP) result = get_first(node, r'*=S $ /(DEC|SP)/=REL', with_context=True, left_to_right=True) |
for trace_NP, context in find_all(node, expr, with_context=True): pp, p, t, s = (context[n] for n in "PP P T S".split()) | for trace_NP, ctx in find_all(node, expr, with_context=True): pp, p, t, s = ctx.pp, ctx.p, ctx.t, ctx.s | def fix_subject_extraction(self, _, n, pred, w=None, reduced=False): debug("%s", reduced) node = n debug("Fixing subject extraction: %s", lrp_repr(node)) if not reduced: self.remove_null_element(node) |
ss = context["SS"] | ss = context.ss | def fix_subject_extraction(self, _, n, pred, w=None, reduced=False): debug("%s", reduced) node = n debug("Fixing subject extraction: %s", lrp_repr(node)) if not reduced: self.remove_null_element(node) |
expr = r'*=PP < { *=P < { /[NPQ]P(?:-(?:TPC|LOC|EXT|ADV|DIR|IO|LGS|MNR|PN|PRP|TMP|TTL))?%s/=T << ^/\*T\*/ $ *=S } }' % index | expr = (r'*=PP < { *=P < { /[NPQ]P(?:-%(tags)s)?%(index)s/=T << ^/\*T\*/ $ *=S } }' % { 'tags': ModifierTagsRegex, 'index': index }) | def fix_nongap_extraction(self, _, n, pred, k): node = n debug("Fixing nongap extraction: %s", pprint(node)) debug("k %s", pprint(k)) self.remove_null_element(node) |
for trace_NP, context in find_all(node, expr, with_context=True): pp, p, t, s = (context[n] for n in "PP P T S".split()) | for trace_NP, ctx in find_all(node, expr, with_context=True): pp, p, t, s = ctx.pp, ctx.p, ctx.t, ctx.s | def fix_nongap_extraction(self, _, n, pred, k): node = n debug("Fixing nongap extraction: %s", pprint(node)) debug("k %s", pprint(k)) self.remove_null_element(node) |
ss = context["SS"] | ss = context.ss | def fix_nongap_extraction(self, _, n, pred, k): node = n debug("Fixing nongap extraction: %s", pprint(node)) debug("k %s", pprint(k)) self.remove_null_element(node) |
for trace_NP, context in find_all(node, expr, with_context=True): top, pp, p, t, s = (context[n] for n in "TOP PP P T S".split()) | for trace_NP, ctx in find_all(node, expr, with_context=True): top, pp, p, t, s = ctx.top, ctx.pp, ctx.p, ctx.t, ctx.s | def fix_object_extraction(self, _, n, pred, w=None, reduced=False): node = n debug("Fixing object extraction: %s", lrp_repr(node)) if not reduced: self.remove_null_element(node) if w: index = get_trace_index_from_tag(w.tag) else: index = '' expr = r'/IP/=TOP << { *=PP < { *=P < { /NP-OBJ/=T << ^/\*T\*%s/ $ *=S } } }'... |
_, ctx = result; ss = ctx['SS'] | _, ctx = result; ss = ctx.ss | def fix_object_extraction(self, _, n, pred, w=None, reduced=False): node = n debug("Fixing object extraction: %s", lrp_repr(node)) if not reduced: self.remove_null_element(node) if w: index = get_trace_index_from_tag(w.tag) else: index = '' expr = r'/IP/=TOP << { *=PP < { *=P < { /NP-OBJ/=T << ^/\*T\*%s/ $ *=S } } }'... |
bei, context = get_first(top, r'*=S [ $ /LB/=BEI | $ ^"η±"=BEI ]', with_context=True) s = context['S'] bei = context['BEI'] | bei, ctx = get_first(top, r'*=S [ $ /LB/=BEI | $ ^"η±"=BEI ]', with_context=True) s, bei = ctx.s, ctx.bei | def relabel_bei_category(self, top, pred): bei, context = get_first(top, r'*=S [ $ /LB/=BEI | $ ^"η±"=BEI ]', with_context=True) s = context['S'] bei = context['BEI'] |
ba, context = get_first(top, r'*=S [ $ /BA/=BA ]', with_context=True) s, ba = context['S'], context['BA'] | _, ctx = get_first(top, r'*=S [ $ /BA/=BA ]', with_context=True) s, ba = ctx.s, ctx.ba | def relabel_ba_category(self, top, ba): ba, context = get_first(top, r'*=S [ $ /BA/=BA ]', with_context=True) s, ba = context['S'], context['BA'] |
trace_NP, context = get_first(top, expr, with_context=True) pp, p, t, s = (context[n] for n in "PP P T S".split()) | trace_NP, ctx = get_first(top, expr, with_context=True) pp, p, t, s = ctx.pp, ctx.p, ctx.t, ctx.s | def fix_long_bei_gap(self, node, bei, pred, top, n=None, reduced=False): debug("Fixing long bei gap: %s", lrp_repr(node)) |
for trace_NP, context in find_all(top, r'*=PP < {*=P < { /NP-OBJ/=T < ^/\*-/ $ *=S } }', with_context=True): | for trace_NP, ctx in find_all(top, r'*=PP < {*=P < { /NP-OBJ/=T < ^/\*-/ $ *=S } }', with_context=True): | def fix_ba_object_gap(self, node, top, c, ba): debug("Fixing ba-construction object gap: %s" % lrp_repr(node)) |
pp, p, t, s = (context[n] for n in "PP P T S".split()) | pp, p, t, s = ctx.pp, ctx.p, ctx.t, ctx.s | def fix_ba_object_gap(self, node, top, c, ba): debug("Fixing ba-construction object gap: %s" % lrp_repr(node)) |
self.fix_categories_starting_from(ctx['S'], until=top) | self.fix_categories_starting_from(ctx.s, until=top) | def fix_topicalisation_with_gap(self, node, p, s, t): debug("Fixing topicalisation with gap:\nnode=%s\ns=%s\nt=%s", lrp_repr(node), pprint(s), pprint(t)) |
(C(r'(S\S)\(S\S)'), C(r'((S{Y}\S{Z}){Y}\(S{Y}\S{Z}){Y}){_}')) | (C(r'(S\S)\(S\S)'), C(r'((S{Y}\S{Z}){Y}\(S{Y}\S{Z}){Y}){_}')), | def is_np_n(cat): '''Returns whether _cat_ is the category NP/N.''' return cat.left == NP and cat.right == N |
if cur == NfN and (l == SbNP or l == SfNP or l == S): return "null_relativiser_typechange" | if cur in (NfN, C('(N/N)/(N/N)')) and (l == SbNP or l == SfNP or l == S): return "null_relativiser_typechange" | def try_unary_rules(l, r, cur): '''Determines if [l r -> cur] matches any unary rules.''' if l == SbNP: for cand_cat, rule in { SfS: "lex_typechange", NP: "lex_typechange", SbNPfSbNP: "lex_typechange", SbS: "lex_typechange", SfSfNP: "np_topicalisation", }.iteritems(): if cur == cand_cat: return rule if config.cn_rule... |
if cur.direction == BACKWARD and cur.direction != r.direction: | if cur.direction == BACKWARD and cur.direction == r.direction: | def try_composition(l, r, cur, examine_modes=False): '''Determines if [l r -> cur] matches any composition rules. If _examine_modes_ is true, then the modes of the arguments are checked to see if they permit composition.''' if is_composition(l, r, cur, examine_modes): if l.direction == FORWARD: # Forward harmonic or cr... |
if cur.direction == FORWARD and cur.direction != r.direction: | if cur.direction == FORWARD and cur.direction == l.direction: | def try_composition(l, r, cur, examine_modes=False): '''Determines if [l r -> cur] matches any composition rules. If _examine_modes_ is true, then the modes of the arguments are checked to see if they permit composition.''' if is_composition(l, r, cur, examine_modes): if l.direction == FORWARD: # Forward harmonic or cr... |
if cur.direction == BACKWARD and cur.direction == r.direction: | if cur.direction == BACKWARD and cur.direction == l.direction: | def try_composition(l, r, cur, examine_modes=False): '''Determines if [l r -> cur] matches any composition rules. If _examine_modes_ is true, then the modes of the arguments are checked to see if they permit composition.''' if is_composition(l, r, cur, examine_modes): if l.direction == FORWARD: # Forward harmonic or cr... |
if not reduced: self.remove_null_element(node) | if pred.tag.startswith('NP'): n[0].kids.pop(0) else: if not reduced: self.remove_null_element(node) | def fix_subject_extraction(self, _, n, pred, w=None, reduced=False): debug("%s", reduced) node = n debug("Fixing subject extraction: %s", lrp_repr(node)) if not reduced: self.remove_null_element(node) |
if not reduced: self.remove_null_element(node) | if pred.tag.startswith('NP'): n[0].kids.pop(0) else: if not reduced: self.remove_null_element(node) | def fix_object_extraction(self, _, n, pred, w=None, reduced=False): node = n debug("Fixing object extraction: %s", lrp_repr(node)) if not reduced: self.remove_null_element(node) if w: index = get_trace_index_from_tag(w.tag) else: index = '' expr = r'/IP/=TOP << { *=PP < { *=P < { /NP-(OBJ|EXT)/=T << ^/\*T\*%s/ $ *=S ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.