示例#1
0
文件: test.py 项目: sandersn/dialect
def testTinify(self):
    regions = {'The Moon!':map(path.paths, concat(acltree.values())),
               "Bikini Gulch":map(path.paths, concat(tree.values()))}
    test([2,3], map(len, regions.values()))
    test([['root-[-A-1',
           'root-A-2',
           'root-]-A-3',
           'root-B-[-i',
           'root-B-ii-[-x',
           'root-]-B-ii-y',
           'root-C-[-1',
           'root-C-2-[-in',
           ']-root-C-2-out'],
          ['root-[-A-arf',
           'root-A-quad',
           'root-A-quam',
           'root-]-A-quim',
           ']-root-B-neighbourhood'],
          ['A-[-1-i',
           'A-]-1-ii',
           'A-2-[-x',
           ']-A-2-y']],
         regions["Bikini Gulch"])
    neoregions = extract.tinify(regions)
    test(2, len(neoregions))
    test({'The Moon!': [['7', '5', "'", '6'], ['7', '0', '.', '6']],
          'Bikini Gulch': [['"', ',', '+', '!', '*', '4', '-', '3', ')'],
                           ['1', '%', '(', '&', '$'],
                           ['/', ' ', '#', '2']]},
         neoregions)
示例#2
0
文件: align.py 项目: sandersn/dialect
def run_collapse_differences(fs, get=getdst):
    base = fs[0]
    del fs[0]
    subs = [
        [get(rule) for rule in concat(compare(base, f)) if rule.type == lev.SUB and rule.dst != rule.src] for f in fs
    ]
    return dct.zip(dct.count(concat(subs)), default=0, *map(dct.count, subs))
示例#3
0
文件: ice.py 项目: sandersn/dialect
def compare(a,b):
    r_total = debug(r(normalise(concat(a),concat(b)).itervalues()))
    # Original code: (1 line to 10)
    # return countif(cur(le,r_total), map(r,unzip(normaliseall(a,b).values())))
    count = 0
    totals = [0] * 1000
    normeds = normaliseall(a,b)
    for ab in normeds.itervalues():
        for i in xrange(1000):
            a,b = ab[i]
            avg_ab = (a + b) / 2
            totals[i] += abs(a - avg_ab) + abs(b - avg_ab)
    return countif(cur(le,r_total), totals)
示例#4
0
文件: path.py 项目: sandersn/dialect
def bracketpaths(paths):
    "add brackets to disambiguate paths (and remove Eq wrapper)"
    spans = dct.count(concat(paths))
    hapax = set(node for (node,n) in spans.items() if n==1)
    firsts = dict((node,findif(elem(node),paths)[-1]) for node in spans)
    lasts = dict((node,findif(elem(node),reversed(paths))[-1]) for node in spans)
    @typecheck([Eq], [str])
    def bracket(path):
        first = edge(path, firsts, hapax)
        last = edge(path, lasts, hapax)
        if first != -1:
            return map(Eq.get,path[:first+1])+["["]+map(Eq.get,path[first+1:])
        elif last != -1:
            return map(Eq.get,path[:last])+["]"]+map(Eq.get,path[last:])
        else:
            return map(Eq.get, path)
    return map(bracket, paths)
示例#5
0
文件: sed.py 项目: sandersn/dialect
def sed_avg(ws1, ws2):
    "[{str:[float]}]*[{str:[float]}] -> float"
    segs1,segs2 = (concat(transpose_word(ws1)), concat(transpose_word(ws1)))
    return lst.avg(map(fnc.uncurry(feature_sub), lst.cross(segs1, segs2)))
示例#6
0
文件: hielo.py 项目: sandersn/dialect
def directed(graph):
    return dct.collapse_pairs(concat([[(k, v), (v, k)] for k in graph for v in graph[k]]))
示例#7
0
文件: align.py 项目: sandersn/dialect
def classify(row):
    "[[lev.Rule]] -> {utf-8-char:set<lev.Rule>}"
    return dct.map(
        set, dct.collapse(filter(negate(self_sub), concat(row)), keymap=lambda rule: rule.src)  # collapse_envs,
    )
示例#8
0
文件: ice.py 项目: sandersn/dialect
def permutation(dialect):
    return concat([random.choice(dialect) for _ in xrange(1000)])
示例#9
0
def extractTnt(path, sites):
    for region,files in groupedSites(path, sites).items():
        t = '\n'.join(filter(isne('\x15'),
                             concat(concat(map(read(path), files)))))
        open(region + '.t', 'w', encoding='utf-8').write(t)