def updateLex( G, f, sD, w, id ): if VERBOSE: G.dump( ) print( 'f', f, sD, w, id ) if f==0: ## rename 'S' and 'r' nodes... if (G.result('S',G.b),'r') in G: G.rename( id+'r', G.result('r',G.result('S',G.b)) ) G.rename( id+'s', G.result('S',G.b) ) G.rename( id, G.b ) G.b = id G[G.b,'0'] = sD G.equate( w, 'X', G.b ) G.a = G.result( 'A', G.b ) while (G.a,'A') in G: G.a = G[G.a,'A'] ## traverse all non-local dependencies on A if f==1: G.a = id G.equate( sD, '0', G.a ) G.equate( w, 'X', G.a ) ## add all nonlocal dependencies with no nolo on store... b = G.a for sN in reversed( gcgtree.deps(sD) ): if sN[1] in 'ghirv' and not G.findNolo( sN, G.b ): b = G.result( 'B', b ) G.equate( sN, '0', b ) G.equate( G.b, 'B', b ) ## rename 'r' nodes... if (G.result('S',G.a),'r') in G: G.equate( id+'r', 'r', G.result('S',G.a) ) ## attach rel pro / interrog pro antecedent... for i,psi in enumerate( gcgtree.deps(sD) ): if psi[1] in 'ir': G.equate( G.result('S',G.findNolo(psi,id)), str(G.getArity(sD)+1)+'\'',G.result('S',id) ) '''
def updateLex( G, f, sD, w, id ): if VERBOSE: G.dump( ) print( 'f', f, sD, w, id ) if f==0: ## rename 's' and 'r' nodes... G.rename( id+'r', G.result('r',G.result('s',G.b)) ) G.rename( id+'s', G.result('s',G.b) ) G.rename( id, G.b ) G.b = id G[G.b,'0'] = sD G.equate( w, 'w', G.b ) G.a = G.result( 'A', G.b ) while (G.a,'A') in G: G.a = G[G.a,'A'] ## traverse all non-local dependencies on A if f==1: G.a = id G.equate( sD, '0', G.a ) G.equate( w, 'w', G.a ) ## add all nonlocal dependencies with no nolo on store... b = G.a for sN in reversed( gcgtree.deps(sD) ): if sN[1] in 'ghirv' and not G.findNolo( sN, G.b ): b = G.result( 'B', b ) G.equate( sN, '0', b ) G.equate( G.b, 'B', b ) ## rename 'r' nodes... G.equate( id+'r', 'r', G.result('s',G.a) ) ## attach rel pro / interrog pro antecedent... for i,psi in enumerate( gcgtree.deps(sD) ): if psi[1] in 'ir' and sD[0] in 'AR': G.equate( G.result('s',G.findNolo(psi,id)), 'e', G.result('2',G.result('r',G.result('s',id))) ) ## adverbial relpro elif psi[1] in 'ir': G.equate( G.result('s',G.findNolo(psi,id)), 'e', G.result('r',G.result('s',id)) ) ## restrictive nominal relpro
def updateUna( G, s, sC, sD, id ): if VERBOSE: G.dump( ) print( 's', s, sC, sD, id ) n = '' l,d = ('B',G.a) if s==0 else ('A',G.b) dUpper,dLower = (G.a+'u',G.a) if s==0 else (G.b,G.b+'u') ## bottom-up on left child, top-down on right child if '-lV' in sD: ## V sN = re.findall('-v(?:[^-{}]|{[^{}]*})',sD)[-1] n = G.findNolo( sN, d ) if n=='': n = G.result( l, d+'u' ) G.equate( sN, '0', n ) G.equate( G.result(l,d), l, n ) else: G.equate( G.result(l,d), l, d+'u' ) G.equate( G.result('s',n), '1\'', G.result('s',dUpper) ) G.equate( G.result('s',dUpper), 'e', G.result('r',G.result('s',dLower)) ) elif '-lQ' in sD: ## Q G.equate( G.result(l,d), l, d+'u' ) G.equate( G.result('1\'',G.result('s',d)), '2\'', G.result('s',d+'u') ) ## switch 1' & 2' arguments (same process top-down as bottom-up) G.equate( G.result('2\'',G.result('s',d)), '1\'', G.result('s',d+'u') ) G.equate( G.result('s',dUpper), 'e', G.result('r',G.result('s',dLower)) ) elif '-lZ' in sD and sC.startswith('A-aN-x'): ## Zc G.equate( G.result(l,d), l, d+'u' ) G.equate( G.result('s',dLower), '2', G.result('r',G.result('s',dUpper)) ) G.equate( G.result('1\'',G.result('s',dUpper)), '1', G.result('r',G.result('s',dUpper)) ) G.equate( 'A-aN-bN:~', '0', G.result('r',G.result('s',dUpper)) ) elif '-lZ' in sD and sC.startswith('A-a'): ## Za G.equate( G.result(l,d), l, d+'u' ) G.equate( G.result('r',G.result('r',G.result('s',dLower))), '1\'', G.result('s',dUpper) ) G.equate( G.result('s',dUpper), 'h', G.result('s',dLower) ) ## hypothetical world inheritance -- should be implemented throughout elif '-lZ' in sD and sC.startswith('R-a'): ## Zb G.equate( G.result(l,d), l, d+'u' ) G.equate( G.result('s',dLower), '2', G.result('r',G.result('s',dUpper)) ) G.equate( G.result('1\'',G.result('s',dUpper)), '1', G.result('r',G.result('s',dUpper)) ) G.equate( 'A-aN-bN:during', '0', G.result('r',G.result('s',dUpper)) ) elif '-lE' in sD: nolos = gcgtree.deps( sC, 'ghirv' ) sN = nolos[0] n = G.findNolos( nolos, G[d,l] ) if n=='': n = G.result( l, d+'u' ) G.equate( sN, '0', n ) G.equate( G.result(l,d), l, n ) else: G.equate( G.result(l,d), l, d+'u' ) if len( gcgtree.deps(sC) ) > len( gcgtree.deps(sD) ) and sN.endswith('-rN}'): ## Ee G.equate( G.result('s',n), 'e', G.result('r',G.result('s',dLower)) ) elif len( gcgtree.deps(sC) ) > len( gcgtree.deps(sD) ): ## Eb,Ed # if sN.endswith('-aN}') or sN.endswith('-iN}') or sN.endswith('-rN}'): ## Eb,Ed G.equate( G.result('r',G.result('s',dLower)), '1\'', id+'y' ) G.equate( G.result('s',n), 'e', id+'y' ) else: ## Ea,Ec G.equate( G.result('s',n), 'e', G.result( str(G.getArity(sD))+'\'', G.result('s',dLower) ) ) G.equate( G.result('s',d), 's', d+'u' ) elif '-l' not in sD: ## T ## update category of every nonlocal sign on store that changes with type change... hideps = gcgtree.deps( sC ) lodeps = gcgtree.deps( sD ) a = d+'u' for i in range( len(hideps) ): if i<len(lodeps) and hideps[i][1]!=lodeps[i][1] and hideps[i][1] in 'ghirv' and lodeps[i][1] in 'ghirv': a = G.result( l, a ) G.equate( lodeps[i], '0', a ) ## note below only for s==1 G.equate( G.result('s',G.findNolo(hideps[i],d)), 's', a ) # if s==0: G[ G.findNolo(lodeps[i],d), '0' ] = hideps[i] ## bottom up on left child # else: G[ G.findNolo(hideps[i],d), '0' ] = lodeps[i] ## top down on right child if a == d+'u': return ## don't add 'u' node G.equate( G[d,l], l, a ) else: return ## don't add 'u' node ## add 'u' node if s==0: G.a = d+'u' G.equate( sC, '0', d+'u' ) if s==1: G.b = d+'u' G.equate( sD, '0', d+'u' ) if n!='' and not G.isNoloNeeded(n,d+'u'): G[n,'0']+='-closed'
def updateBin( G, j, sC, sD, sE, id ): if VERBOSE: G.dump( ) print( 'j', j, sC, sD, sE, id ) G.b = id + 'b' G.equate( sE, '0', G.b ) if j==0: c = id + 'a' G.equate( c, 'A', G.result('A',G.b) if '-lG' in sD or '-lI' in sE or '-lR' in sE or re.match('.*-[ri]N-lH$',sE)!=None else G.b ) G.equate( sC, '0', c ) ## add all nonlocal dependencies with no nolo on store... b = c for sN in reversed( gcgtree.deps(sC) ): if sN[1] in 'ghirv' and G.findNolo( sN, G[G.a,'B'] )=='': b = G.result( 'B', b ) G.equate( sN, '0', b ) G.equate( G.result('B',G.a), 'B', b ) if j==1: c = G.result( 'B', G.a ) while (c,'B') in G: c = G[c,'B'] ## if there are non-local dependencies on B G.equate( G.result('A',c), 'A', G.result('A',G.b) if '-lG' in sD or '-lI' in sE or '-lR' in sE or re.match('.*-[ri]N-lH$',sE)!=None else G.b ) d,e = G.a,G.b if '-lA' in sD: ## Aa G.equate( G.result('s',c), 's', e ) G.equate( G.result('s',d), str(G.getArity(sE))+'\'', G.result('s',e) ) elif '-lA' in sE: ## Ab G.equate( G.result('s',d), 's', c ) # G.equate( G.result('r',G.result('s',d)), 'r', G.result('s',c) ) ## rename 'r' node as well as 's' G.equate( G.result('s',e), str(G.getArity(sD))+'\'', G.result('s',d) ) elif '-lU' in sD: ## Ua G.equate( G.result('s',d), 's', c ) G.equate( G.result('s',d), str(G.getArity(sE))+'\'', G.result('s',e) ) elif '-lU' in sE: ## Ub G.equate( G.result('s',c), 's', e ) G.equate( G.result('s',e), str(G.getArity(sD))+'\'', G.result('s',d) ) elif '-lM' in sD: ## Ma G.equate( G.result('s',c), 's', e ) G.equate( G.result('r',G.result('s',e)), '1\'', G.result('s',d) ) elif '-lM' in sE: ## Mb G.equate( G.result('s',d), 's', c ) G.equate( G.result('r',G.result('s',d)), '1\'', G.result('s',e) ) elif '-lC' in sD: ## Ca,Cb G.equate( G.result('s',c), 's', e ) G.equate( G.result('r',G.result('s',e)), 'c', G.result('r',G.result('s',d)) ) G.equate( G.result('s',e), 'c', G.result('s',d) ) for i in range( 1, len(gcgtree.deps(sC,'ab'))+1 ): #G.getArity(sC)+1 ): G.equate( G.result(str(i)+'\'',G.result('s',c)), str(i)+'\'', G.result('s',d) ) elif '-lC' in sE: ## Cc G.equate( G.result('s',d), 's', c ) G.equate( G.result('r',G.result('s',d)), 'c', G.result('r',G.result('s',e)) ) G.equate( G.result('s',d), 'c', G.result('s',e) ) for i in range( 1, len(gcgtree.deps(sC,'ab'))+1 ): #G.getArity(sC)+1 ): G.equate( G.result(str(i)+'\'',G.result('s',c)), str(i)+'\'', G.result('s',e) ) elif '-lG' in sD: ## G G.equate( G.result('s',c), 's', e ) G.equate( G.result('s',d), 's', G.result('A',e) ) G.equate( gcgtree.lastdep(sE), '0', G.result('A',e) ) elif '-lH' in sE: ## H G.equate( G.result('s',d), 's', c ) n = G.findNolo( gcgtree.lastdep(sD), d ) if n!='': if re.match('.*-[ri]N-lH$',sE)!=None: ## Hb G.equate( G.result('r',G.result('s',n)), 's', G.result('A',e) ) G.equate( gcgtree.lastdep(sE), '0', G.result('A',e) ) else: ## Ha G.equate( G.result('s',e), 's', n ) G[n,'0']+='-closed' ## close off nolo elif '-lI' in sE: ## I G.equate( G.result('s',d), 's', c ) if sD.startswith('N-b{V-g') or sD.startswith('N-b{I-aN-g'): ## nominal clause G.equate( G.result('s',d), 's', G.result('A',e) ) elif '-b{I-aN-gN}' in sD: ## tough construction G.equate( G.result('1\'',G.result('s',d)), 's', G.result('A',e) ) G.equate( G.result('s',e), str(G.getArity(sD))+'\'', G.result('s',d) ) else: G.equate( G.result('s',G.result('A',e)), str(G.getArity(sD))+'\'', G.result('s',d) ) ## embedded question G.equate( gcgtree.lastdep(sE), '0', G.result('A',e) ) elif '-lR' in sD: ## Ra (off-spec) G.equate( G.result('s',c), 's', e ) G.equate( G.result('s',e), 's', G.result('B',d) ) G.equate( gcgtree.lastdep(sD), '0', G.result('B',d) ) elif 'I-aN-g{R-aN}-lR' == sE: ## Rc (off-spec) G.equate( G.result('s',d), 's', c ) G.equate( 'A-aN-bN:support', '0', G.result('r',G.result('s',G.result('A',e))) ) G.equate( G.result('s',d), '2', G.result('r',G.result('s',G.result('A',e))) ) G.equate( gcgtree.lastdep(sE), '0', G.result('A',e) ) elif '-lR' in sE: ## R G.equate( G.result('s',d), 's', c ) G.equate( G.result('s',d), 's', G.result('A',e) ) G.equate( gcgtree.lastdep(sE), '0', G.result('A',e) ) else: if sC != sD != sE != 'FAIL': sys.stderr.write( 'WARNING: No analysis for annotated binary expansion ' + sC + ' -> ' + sD + ' ' + sE + '.\n' )
def updateUna(G, s, sC, sD, id): if VERBOSE: G.dump() print('s', s, sC, sD, id) n = '' l, d = ('B', G.a) if s == 0 else ('A', G.b) dUpper, dLower = (G.a + 'u', G.a) if s == 0 else ( G.b, G.b + 'u') ## bottom-up on left child, top-down on right child if '-lV' in sD: ## V sN = re.findall('-v(?:[^-{}]|{[^{}]*})', sD)[-1] n = G.findNolo(sN, d) if n == '': n = G.result(l, d + 'u') G.equate(sN, '0', n) G.equate(G.result(l, d), l, n) else: G.equate(G.result(l, d), l, d + 'u') G.equate(G.result('s', n), '1\'', G.result('s', dUpper)) G.equate(G.result('s', dUpper), 'e', G.result('r', G.result('s', dLower))) elif '-lQ' in sD: ## Q G.equate(G.result(l, d), l, d + 'u') G.equate( G.result('1\'', G.result('s', d)), '2\'', G.result('s', d + 'u') ) ## switch 1' & 2' arguments (same process top-down as bottom-up) G.equate(G.result('2\'', G.result('s', d)), '1\'', G.result('s', d + 'u')) G.equate(G.result('s', dUpper), 'e', G.result('r', G.result('s', dLower))) elif '-lZ' in sD and sC.startswith('A-aN-x'): ## Zc G.equate(G.result(l, d), l, d + 'u') G.equate(G.result('s', dLower), '2', G.result('r', G.result('s', dUpper))) G.equate(G.result('1\'', G.result('s', dUpper)), '1', G.result('r', G.result('s', dUpper))) G.equate('A-aN-bN:~', '0', G.result('r', G.result('s', dUpper))) elif '-lZ' in sD and sC.startswith('A-a'): ## Za G.equate(G.result(l, d), l, d + 'u') G.equate(G.result('r', G.result('r', G.result('s', dLower))), '1\'', G.result('s', dUpper)) G.equate( G.result('s', dUpper), 'h', G.result('s', dLower) ) ## hypothetical world inheritance -- should be implemented throughout elif '-lZ' in sD and sC.startswith('R-a'): ## Zb G.equate(G.result(l, d), l, d + 'u') G.equate(G.result('s', dLower), '2', G.result('r', G.result('s', dUpper))) G.equate(G.result('1\'', G.result('s', dUpper)), '1', G.result('r', G.result('s', dUpper))) G.equate('A-aN-bN:during', '0', G.result('r', G.result('s', dUpper))) elif '-lE' in sD: nolos = gcgtree.deps(sC, 'ghirv') sN = nolos[0] n = G.findNolos(nolos, G[d, l]) if n == '': n = G.result(l, d + 'u') G.equate(sN, '0', n) G.equate(G.result(l, d), l, n) else: G.equate(G.result(l, d), l, d + 'u') if len(gcgtree.deps(sC)) > len( gcgtree.deps(sD)) and sN.endswith('-rN}'): ## Ee G.equate(G.result('s', n), 'e', G.result('r', G.result('s', dLower))) elif len(gcgtree.deps(sC)) > len(gcgtree.deps(sD)): ## Eb,Ed # if sN.endswith('-aN}') or sN.endswith('-iN}') or sN.endswith('-rN}'): ## Eb,Ed G.equate(G.result('r', G.result('s', dLower)), '1\'', id + 'y') G.equate(G.result('s', n), 'e', id + 'y') else: ## Ea,Ec G.equate( G.result('s', n), 'e', G.result( str(G.getArity(sD)) + '\'', G.result('s', dLower))) G.equate(G.result('s', d), 's', d + 'u') elif '-l' not in sD: ## T ## update category of every nonlocal sign on store that changes with type change... hideps = gcgtree.deps(sC) lodeps = gcgtree.deps(sD) a = d + 'u' for i in range(len(hideps)): if i < len(lodeps) and hideps[i][1] != lodeps[i][1] and hideps[ i][1] in 'ghirv' and lodeps[i][1] in 'ghirv': a = G.result(l, a) G.equate(lodeps[i], '0', a) ## note below only for s==1 G.equate(G.result('s', G.findNolo(hideps[i], d)), 's', a) # if s==0: G[ G.findNolo(lodeps[i],d), '0' ] = hideps[i] ## bottom up on left child # else: G[ G.findNolo(hideps[i],d), '0' ] = lodeps[i] ## top down on right child if a == d + 'u': return ## don't add 'u' node G.equate(G[d, l], l, a) else: return ## don't add 'u' node ## add 'u' node if s == 0: G.a = d + 'u' G.equate(sC, '0', d + 'u') if s == 1: G.b = d + 'u' G.equate(sD, '0', d + 'u') if n != '' and not G.isNoloNeeded(n, d + 'u'): G[n, '0'] += '-closed'
def updateBin(G, j, sC, sD, sE, id): if VERBOSE: G.dump() print('j', j, sC, sD, sE, id) G.b = id + 'b' G.equate(sE, '0', G.b) if j == 0: c = id + 'a' G.equate( c, 'A', G.result('A', G.b) if '-lG' in sD or '-lI' in sE or '-lR' in sE or re.match('.*-[ri]N-lH$', sE) != None else G.b) G.equate(sC, '0', c) ## add all nonlocal dependencies with no nolo on store... b = c for sN in reversed(gcgtree.deps(sC)): if sN[1] in 'ghirv' and G.findNolo(sN, G[G.a, 'B']) == '': b = G.result('B', b) G.equate(sN, '0', b) G.equate(G.result('B', G.a), 'B', b) if j == 1: c = G.result('B', G.a) while (c, 'B') in G: c = G[c, 'B'] ## if there are non-local dependencies on B G.equate( G.result('A', c), 'A', G.result('A', G.b) if '-lG' in sD or '-lI' in sE or '-lR' in sE or re.match('.*-[ri]N-lH$', sE) != None else G.b) d, e = G.a, G.b if '-lA' in sD: ## Aa G.equate(G.result('s', c), 's', e) G.equate(G.result('s', d), str(G.getArity(sE)) + '\'', G.result('s', e)) elif '-lA' in sE: ## Ab G.equate(G.result('s', d), 's', c) # G.equate( G.result('r',G.result('s',d)), 'r', G.result('s',c) ) ## rename 'r' node as well as 's' G.equate(G.result('s', e), str(G.getArity(sD)) + '\'', G.result('s', d)) elif '-lU' in sD: ## Ua G.equate(G.result('s', d), 's', c) G.equate(G.result('s', d), str(G.getArity(sE)) + '\'', G.result('s', e)) elif '-lU' in sE: ## Ub G.equate(G.result('s', c), 's', e) G.equate(G.result('s', e), str(G.getArity(sD)) + '\'', G.result('s', d)) elif '-lM' in sD: ## Ma G.equate(G.result('s', c), 's', e) G.equate(G.result('r', G.result('s', e)), '1\'', G.result('s', d)) elif '-lM' in sE: ## Mb G.equate(G.result('s', d), 's', c) G.equate(G.result('r', G.result('s', d)), '1\'', G.result('s', e)) elif '-lC' in sD: ## Ca,Cb G.equate(G.result('s', c), 's', e) G.equate(G.result('r', G.result('s', e)), 'c', G.result('r', G.result('s', d))) G.equate(G.result('s', e), 'c', G.result('s', d)) for i in range(1, len(gcgtree.deps(sC, 'ab')) + 1): #G.getArity(sC)+1 ): G.equate(G.result(str(i) + '\'', G.result('s', c)), str(i) + '\'', G.result('s', d)) elif '-lC' in sE: ## Cc G.equate(G.result('s', d), 's', c) G.equate(G.result('r', G.result('s', d)), 'c', G.result('r', G.result('s', e))) G.equate(G.result('s', d), 'c', G.result('s', e)) for i in range(1, len(gcgtree.deps(sC, 'ab')) + 1): #G.getArity(sC)+1 ): G.equate(G.result(str(i) + '\'', G.result('s', c)), str(i) + '\'', G.result('s', e)) elif '-lG' in sD: ## G G.equate(G.result('s', c), 's', e) G.equate(G.result('s', d), 's', G.result('A', e)) G.equate(gcgtree.lastdep(sE), '0', G.result('A', e)) elif '-lH' in sE: ## H G.equate(G.result('s', d), 's', c) n = G.findNolo(gcgtree.lastdep(sD), d) if n != '': if re.match('.*-[ri]N-lH$', sE) != None: ## Hb G.equate(G.result('r', G.result('s', n)), 's', G.result('A', e)) G.equate(gcgtree.lastdep(sE), '0', G.result('A', e)) else: ## Ha G.equate(G.result('s', e), 's', n) G[n, '0'] += '-closed' ## close off nolo elif '-lI' in sE: ## I G.equate(G.result('s', d), 's', c) if sD.startswith('N-b{V-g') or sD.startswith( 'N-b{I-aN-g'): ## nominal clause G.equate(G.result('s', d), 's', G.result('A', e)) elif '-b{I-aN-gN}' in sD: ## tough construction G.equate(G.result('1\'', G.result('s', d)), 's', G.result('A', e)) G.equate(G.result('s', e), str(G.getArity(sD)) + '\'', G.result('s', d)) else: G.equate(G.result('s', G.result('A', e)), str(G.getArity(sD)) + '\'', G.result('s', d)) ## embedded question G.equate(gcgtree.lastdep(sE), '0', G.result('A', e)) elif '-lR' in sD: ## Ra (off-spec) G.equate(G.result('s', c), 's', e) G.equate(G.result('s', e), 's', G.result('B', d)) G.equate(gcgtree.lastdep(sD), '0', G.result('B', d)) elif 'I-aN-g{R-aN}-lR' == sE: ## Rc (off-spec) G.equate(G.result('s', d), 's', c) G.equate('A-aN-bN:support', '0', G.result('r', G.result('s', G.result('A', e)))) G.equate(G.result('s', d), '2', G.result('r', G.result('s', G.result('A', e)))) G.equate(gcgtree.lastdep(sE), '0', G.result('A', e)) elif '-lR' in sE: ## R G.equate(G.result('s', d), 's', c) G.equate(G.result('s', d), 's', G.result('A', e)) G.equate(gcgtree.lastdep(sE), '0', G.result('A', e)) else: sys.stderr.write( 'WARNING: No analysis for annotated binary expansion ' + sC + ' -> ' + sD + ' ' + sE + '.\n')
def updateBin( G, j, sC, sD, sE, id ): if VERBOSE: G.dump( ) print( 'j', j, sC, sD, sE, id ) G.b = id + 'b' G.equate( sE, '0', G.b ) if j==0: c = id + 'a' # G.equate( c, 'A', G.result('A',G.b) if '-lG' in sD or '-lI' in sE or '-lR' in sE or re.match('.*-[ri]N-lH$',sE)!=None or re.match('.*-g{.-aN}-lH$',sE)!=None or sE.endswith('-g{V-gN}-lC') else G.b ) G.equate( c, 'A', G.result('A',G.b) if '-lG' in sD or '-lI' in sE or '-lR' in sE or ('-lH' in sE and re.match('.*-h\{[^\}]*-[ri]N\}$',sD)!=None) or re.match('.*-g\{.-aN\}-lH$',sE)!=None or sE.endswith('-g{V-gN}-lC') else G.b ) G.equate( sC, '0', c ) ## add all nonlocal dependencies with no nolo on store... b = c for sN in reversed( gcgtree.deps(sC) ): if sN[1] in 'ghirv' and G.findNolo( sN, G[G.a,'B'] )=='': b = G.result( 'B', b ) G.equate( sN, '0', b ) G.equate( G.result('B',G.a), 'B', b ) if j==1: c = G.result( 'B', G.a ) while (c,'B') in G: c = G[c,'B'] ## if there are non-local dependencies on B # G.equate( G.result('A',c), 'A', G.result('A',G.b) if '-lG' in sD or '-lI' in sE or '-lR' in sE or re.match('.*-[ri]N-lH$',sE)!=None or re.match('.*{.-aN}-lH$',sE)!=None or sE.endswith('-g{V-gN}-lC') else G.b ) G.equate( G.result('A',c), 'A', G.result('A',G.b) if '-lG' in sD or '-lI' in sE or '-lR' in sE or ('-lH' in sE and re.match('.*-h\{[^\}]*-[ri]N\}$',sD)!=None) or re.match('.*\{.-aN\}-lH$',sE)!=None or sE.endswith('-g{V-gN}-lC') else G.b ) d,e = G.a,G.b if '-lD' in sD: ## Da G.equate( G.result('S',c), 'S', e ) elif '-lD' in sE: ## Db G.equate( G.result('S',d), 'S', c ) elif '-lA' in sD: ## Aa G.equate( G.result('S',c), 'S', e ) G.equate( G.result('S',d), str(G.getArity(sE))+'\'', G.result('S',e) ) elif '-lA' in sE: ## Ab G.equate( G.result('S',d), 'S', c ) # G.equate( G.result('r',G.result('S',d)), 'r', G.result('S',c) ) ## rename 'r' node as well as 'S' G.equate( G.result('S',e), str(G.getArity(sD))+'\'', G.result('S',d) ) elif '-lU' in sD: ## Ua G.equate( G.result('S',d), 'S', c ) G.equate( G.result('S',d), str(G.getArity(sE))+'\'', G.result('S',e) ) elif '-lU' in sE: ## Ub G.equate( G.result('S',c), 'S', e ) G.equate( G.result('S',e), str(G.getArity(sD))+'\'', G.result('S',d) ) elif '-lM' in sD: ## Ma G.equate( G.result('S',c), 'S', e ) G.equate( G.result('r',G.result('S',e)), '1\'', G.result('S',d) ) elif '-lM' in sE: ## Mb G.equate( G.result('S',d), 'S', c ) G.equate( G.result('r',G.result('S',d)), '1\'', G.result('S',e) ) elif '-lC' in sD: ## Ca,Cb G.equate( G.result('S',c), 'S', e ) G.equate( G.result('r',G.result('S',e)), 'c', G.result('r',G.result('S',d)) ) G.equate( G.result('S',e), 'c', G.result('S',d) ) G.equate( G.result('H',G.result('S',d)), 'H', G.result('S',c) ) G.equate( G.result('H',G.result('S',c)), 'H', G.result('S',e) ) for i in range( 1, len(gcgtree.deps(sC,'ab'))+1 ): #G.getArity(sC)+1 ): G.equate( G.result(str(i)+'\'',G.result('S',c)), str(i)+'\'', G.result('S',d) ) elif '-lC' in sE: ## Cc G.equate( G.result('S',d), 'S', c ) G.equate( G.result('r',G.result('S',d)), 'c', G.result('r',G.result('S',e)) ) G.equate( G.result('S',d), 'c', G.result('S',e) ) G.equate( G.result('H',G.result('S',d)), 'H', G.result('S',c) ) G.equate( G.result('H',G.result('S',c)), 'H', G.result('S',e) ) for i in range( 1, len(gcgtree.deps(sC,'ab'))+1 ): #G.getArity(sC)+1 ): G.equate( G.result(str(i)+'\'',G.result('S',c)), str(i)+'\'', G.result('S',e) ) if sE.endswith('-g{V-gN}-lC'): ## Cd G.equate( gcgtree.lastdep(sE), '0', G.result('A',e) ) # G.equate( G.result('W',G.result('S',d)), 'w', G.result('S',G.result('A',e)) ) # G.equate( G.result('s',G.result('W',G.result('S',d))), 't', G.result('W',G.result('S',d)) ) G.equate( G.result('W',d), 'w', G.result('S',G.result('A',e)) ) G.equate( G.result('s',G.result('W',d)), 't', G.result('W',d) ) elif '-lG' in sD: ## G G.equate( G.result('S',c), 'S', e ) G.equate( G.result('S',d), 'S', G.result('A',e) ) # grab nusco # G.equate( G.result('r',G.result('S',d)), 'S', G.result('A',e) ) # grab restrictor G.equate( gcgtree.lastdep(sE), '0', G.result('A',e) ) elif '-lH' in sE: ## H G.equate( G.result('S',d), 'S', c ) n = G.findNolo( gcgtree.lastdep(sD), d ) if n!='': # if re.match('.*-[ri]N-lH$',sE)!=None: ## Hb if '-lH' in sE and re.match('.*-h\{[^\}]*-[ri]N\}$',sD)!=None: ## Hb G.equate( G.result('r',G.result('S',n)), 'S', G.result('A',e) ) G.equate( gcgtree.lastdep(sE), '0', G.result('A',e) ) elif re.match('.*-g\{.-aN\}-lH$',sE)!=None: ## Hc G.equate( G.result('S',n), 'S', G.result('A',e) ) G.equate( gcgtree.lastdep(sE), '0', G.result('A',e) ) else: ## Ha G.equate( G.result('S',e), 'S', n ) G[n,'0']+='-closed' ## close off nolo elif '-lI' in sE: ## I G.equate( G.result('S',d), 'S', c ) if sD.startswith('N-b{V-g') or sD.startswith('N-b{I-aN-g'): ## nominal clause G.equate( G.result('S',d), 'S', G.result('A',e) ) elif '-b{I-aN-gN}' in sD: ## tough construction G.equate( G.result('1\'',G.result('S',d)), 'S', G.result('A',e) ) G.equate( G.result('S',e), str(G.getArity(sD))+'\'', G.result('S',d) ) else: G.equate( G.result('S',G.result('A',e)), str(G.getArity(sD))+'\'', G.result('S',d) ) ## embedded question G.equate( gcgtree.lastdep(sE), '0', G.result('A',e) ) elif '-lR' in sD: ## Ra (off-spec) G.equate( G.result('S',c), 'S', e ) # G.equate( G.result('S',e), 'S', G.result('B',d) ) G.equate( G.result('r',G.result('S',e)), 'S', G.result('B',d) ) # grab restrictor, tho 'which' gets put on restrictor of nolo G.equate( gcgtree.lastdep(sD), '0', G.result('B',d) ) elif 'I-aN-g{R-aN}-lR' == sE: ## Rc (off-spec) G.equate( G.result('S',d), 'S', c ) G.equate( 'A-aN-bN:support', '0', G.result('r',G.result('S',G.result('A',e))) ) G.equate( G.result('1\'',G.result('S',G.result('A',e))), '1', G.result('r',G.result('S',G.result('A',e))) ) G.equate( G.result('r',G.result('S',d)), '2', G.result('r',G.result('S',G.result('A',e))) ) G.equate( gcgtree.lastdep(sE), '0', G.result('A',e) ) elif sE.endswith('-g{R-aN}-lR'): ## Rd (off-spec: "the only/furthest north I can go") G.equate( G.result('S',d), 'S', c ) G.equate( G.result('S',d), 'S', G.result('A',e) ) # grab nusco G.equate( gcgtree.lastdep(sE), '0', G.result('A',e) ) elif '-lR' in sE: ## R G.equate( G.result('S',d), 'S', c ) # G.equate( G.result('S',d), 'S', G.result('A',e) ) G.equate( G.result('r',G.result('S',d)), 'S', G.result('A',e) ) # grab restrictor, tho 'which' gets put on restrictor of nolo G.equate( gcgtree.lastdep(sE), '0', G.result('A',e) ) elif sD.startswith(',') and sE.endswith('-pPc') or sD.startswith(';') and sE.endswith('-pPs'): G.equate( G.result('S',c), 'S', e ) elif sD=='U' and sE=='U': G.equate( G.result('S',d), 'S', c ) G.equate( G.result('S',c), 'S', e ) else: if sC != 'FAIL': #sC != sD != sE != 'FAIL': sys.stderr.write( 'WARNING: No analysis for annotated binary expansion ' + sC + ' -> ' + sD + ' ' + sE + ' at ' + str(id) + '.\n' ) if ( '-lE' in sD or '-lE' in sE or '-lZ' in sD or '-lZ' in sE or '-lz' in sD or '-lz' in sE or '-lQ' in sD or '-lQ' in sE or '-lF' in sD or '-lF' in sE or '-lV' in sD or '-lV' in sE ): sys.stderr.write( 'WARNING: Illegal unary operator in binary expansion ' + sC + ' -> ' + sD + ' ' + sE + ' at ' + str(id) + '.\n' )
def updateUna( G, s, sC, sD, id ): if VERBOSE: G.dump( ) print( 'S', s, sC, sD, id ) n = '' l,d = ('B',G.a) if s==0 else ('A',G.b) dUpper,dLower = (G.a+'u',G.a) if s==0 else (G.b,G.b+'u') ## bottom-up on left child, top-down on right child if '-lV' in sD: ## V sN = re.findall('-v(?:[^-\{\}]|\{[^\{\}]*\})',sD)[-1] n = G.findNolo( sN, d ) if n=='': n = G.result( l, d+'u' ) G.equate( sN, '0', n ) G.equate( G.result(l,d), l, n ) else: G.equate( G.result(l,d), l, d+'u' ) G.equate( G.result('S',n), '1\'', G.result('S',dUpper) ) G.equate( G.result('S',dUpper), 'e', G.result('r',G.result('S',dLower)) ) elif '-lF' in sD: ## F (I?) sN = re.findall('-i(?:[^-\{\}]|\{[^\{\}]*\})',sD)[-1] n = G.findNolo( sN, d ) if n=='': n = G.result( l, d+'u' ) G.equate( sN, '0', n ) G.equate( G.result(l,d), l, n ) else: G.equate( G.result(l,d), l, d+'u' ) G.equate( G.result('r',G.result('S',dUpper)), 'S', n ) elif '-lQ' in sD: ## Q G.equate( G.result(l,d), l, d+'u' ) G.equate( G.result('1\'',G.result('S',d)), '2\'', G.result('S',d+'u') ) ## switch 1' & 2' arguments (same process top-down as bottom-up) G.equate( G.result('2\'',G.result('S',d)), '1\'', G.result('S',d+'u') ) G.equate( G.result('S',dUpper), 'e', G.result('r',G.result('S',dLower)) ) elif '-lZ' in sD and sC.startswith('N-aD-b{N-aD}'): ## Zd (cardinal quant) G.equate( G.result(l,d), l, d+'u' ) G.equate( G.result('S',dLower), '3', G.result('r',G.result('S',dUpper)) ) G.equate( G.result('2\'',G.result('S',dUpper)), '2', G.result('r',G.result('S',dUpper)) ) G.equate( G.result('r',G.result('2\'',G.result('S',dUpper))), '1', G.result('r',G.result('S',dUpper)) ) G.equate( 'D:eqQ', '0', G.result('r',G.result('S',dUpper)) ) elif '-lZ' in sD and sC.startswith('A-aN-x'): ## Zc G.equate( G.result(l,d), l, d+'u' ) G.equate( G.result('S',dLower), '2', G.result('r',G.result('S',dUpper)) ) G.equate( G.result('1\'',G.result('S',dUpper)), '1', G.result('r',G.result('S',dUpper)) ) G.equate( 'A-aN-bN:~', '0', G.result('r',G.result('S',dUpper)) ) elif '-lZ' in sD and sC.startswith('A-a'): ## Za if VERBOSE: print( 'applying Za' ) G.equate( G.result(l,d), l, d+'u' ) # G.equate( G.result('r',G.result('r',G.result('S',dLower))), '1\'', G.result('S',dUpper) ) G.equate( G.result('r',G.result('S',dLower)), '1\'', G.result('S',dUpper) ) # G.equate( G.result('S',dUpper), 'h', G.result('S',dLower) ) ## hypothetical world inheritance -- should be implemented throughout G.equate( G.result('S',dUpper), 'H', G.result('S',dLower) ) ## hypothetical world inheritance # after 'S' G.equate( G.result('S',dUpper), 'H', dLower ) ## hypothetical world inheritance # G.equate( G.result('S',dUpper), 'h', G.result('r',G.result('E',G.result('S',dLower))) ) ## hypothetical world inheritance elif '-lZ' in sD and sC.startswith('R-a'): ## Zb (during) G.equate( G.result(l,d), l, d+'u' ) G.equate( G.result('S',dLower), '2', G.result('r',G.result('S',dUpper)) ) G.equate( G.result('1\'',G.result('S',dUpper)), '1', G.result('r',G.result('S',dUpper)) ) G.equate( 'A-aN-bN:during', '0', G.result('r',G.result('S',dUpper)) ) elif '-lz' in sD: ## Zb (contain) G.equate( G.result(l,d), l, d+'u' ) G.equate( G.result('S',dLower), '2', G.result('r',G.result('S',dUpper)) ) G.equate( G.result('1\'',G.result('S',dUpper)), '1', G.result('r',G.result('S',dUpper)) ) G.equate( 'B-aN-bN:contain', '0', G.result('r',G.result('S',dUpper)) ) elif '-lE' in sD: nolos = gcgtree.deps( sC, 'ghirv' ) if len(nolos)<1: sys.stderr.write( 'ERROR: opearator E not supported in absence of non-local dependencies: ' + sC + ' -> ' + sD + '\n' ) print( 'ERROR: opearator E not supported in absence of non-local dependencies: ' + sC + ' -> ' + sD ) exit( 1 ) sN = nolos[0] n = G.findNolos( nolos, G[d,l] ) if n=='': n = G.result( l, d+'u' ) G.equate( sN, '0', n ) G.equate( G.result(l,d), l, n ) else: G.equate( G.result(l,d), l, d+'u' ) if len( gcgtree.deps(sC) ) > len( gcgtree.deps(sD) ) and sN.endswith('-rN}'): ## Ee if VERBOSE: print( 'using rule Ee' ) G.equate( G.result('S',n), 'e', G.result('r',G.result('S',dLower)) ) elif len( gcgtree.deps(sC) ) > len( gcgtree.deps(sD) ) and sN == '-g{V-aN}': ## Ef if VERBOSE: print( 'using rule Ef' ) # if sN.endswith('-aN}') or sN.endswith('-iN}') or sN.endswith('-rN}'): ## Eb,Ed G.equate( G.result('1\'',G.result('S',n)), 'e', G.result('S',dLower) ) # G.equate( G.result('s',G.result('S',dLower)), 's', G.result('1\'',G.result('S',n)) ) ## sent7 # G.equate( G.result('r',G.result('S',dLower)), '1\'', id+'y' ) # G.equate( G.result('S',n), 'e', id+'y' ) elif len( gcgtree.deps(sC) ) > len( gcgtree.deps(sD) ) and sN == '-g{V-gN}': ## Eg if VERBOSE: print( 'using rule Eg' ) G.equate( G.result('S',dLower), 's', G.result('S',n) ) G.equate( 'D:someQ', '0', G.result('Q',G.result('S',n)) ) G.equate( G.result('r',G.result('S',n)), '1', G.result('Q',G.result('S',n)) ) G.equate( G.result('S',n), '2', G.result('Q',G.result('S',n)) ) elif len( gcgtree.deps(sC) ) > len( gcgtree.deps(sD) ): ## Ec,Ed if VERBOSE: print( 'using rule Ec/Ed' ) # if sN.endswith('-aN}') or sN.endswith('-iN}') or sN.endswith('-rN}'): ## Eb,Ed G.equate( G.result('1\'',G.result('S',n)), 'e', G.result('r',G.result('S',dLower)) ) # G.equate( G.result('s',G.result('S',dLower)), 's', G.result('1\'',G.result('S',n)) ) ## sent7 # G.equate( G.result('r',G.result('S',dLower)), '1\'', id+'y' ) # G.equate( G.result('S',n), 'e', id+'y' ) else: ## Ea,Eb if VERBOSE: print( 'using rule Ea/Eb' ) ## should not add 'e' G.equate( G.result('S',n), 'e', G.result( str(G.getArity(sD))+'\'', G.result('S',dLower) ) ) G.equate( G.result('S',n), str(G.getArity(sD))+'\'', G.result('S',dLower) ) # if '-g' in sN: ## Ea,Eb # G.equate( G.result('r',G.result('S',n)), str(G.getArity(sD))+'\'', G.result('S',dLower) ) # else: ## Eh?,Ei? don't get restrictor for passive # G.equate( G.result('S',n), str(G.getArity(sD))+'\'', G.result('S',dLower) ) G.equate( G.result('S',d), 'S', d+'u' ) elif '-l' not in sD: ## T ## update category of every nonlocal sign on store that changes with type change... hideps = gcgtree.deps( sC ) lodeps = gcgtree.deps( sD ) a = d+'u' for i in range( len(hideps) ): if i<len(lodeps) and hideps[i][1]!=lodeps[i][1] and hideps[i][1] in 'ghirv' and lodeps[i][1] in 'ghirv': a = G.result( l, a ) G.equate( lodeps[i], '0', a ) ## note below only for s==1 G.equate( G.result('S',G.findNolo(hideps[i],d)), 'S', a ) # if s==0: G[ G.findNolo(lodeps[i],d), '0' ] = hideps[i] ## bottom up on left child # else: G[ G.findNolo(hideps[i],d), '0' ] = lodeps[i] ## top down on right child if a == d+'u': return ## don't add 'u' node G.equate( G[d,l], l, a ) else: sys.stderr.write( 'ERROR: No analysis for annotated unnary expansion ' + sC + ' -> ' + sD + ' at ' + str(id) + '.\n' ) print( 'ERROR: No analysis for annotated unnary expansion ' + sC + ' -> ' + sD + ' at ' + str(id) ) return ## don't add 'u' node ## add 'u' node if s==0: G.a = d+'u' G.equate( sC, '0', d+'u' ) if s==1: G.b = d+'u' G.equate( sD, '0', d+'u' ) if n!='' and not G.isNoloNeeded(n,d+'u'): G[n,'0']+='-closed'