at = computed.setdefault(key, {}).setdefault(sensitive, {})
                for book in books:
                    print book, name, canonical, position
                    at.setdefault(book, set()).add(position)

for (canonical, name), sensitivity in computed.items():
    sensitive = sensitivity.get(True, {})
    insensitive = sensitivity.get(False, {})
    for book, positions in insensitive.items():
        positions.difference_update(sensitive.get(book, set()))

def citations():
    for name in NAMES:
        key = (name["Canonical"], name["Name"].lower())
        at = computed.get(key, {})
        sensitive, insensitive = (
            ", ".join(
                "%s#%d" % (book, len(positions))
                for book, positions in sorted(
                    at.get(sensitivity, {}).items(),
                    key = lambda (book, positions): BOOKS.book_index(book)
                )
                if len(positions)
            )
            for sensitivity in (True, False)
        )
        yield name["Canonical"], name["Name"], sensitive, insensitive

codecs.open("names-citations.tsv", "w", "utf-8").write(tsv.format(citations()))

Beispiel #2
0
def cross_reference_txt():
    from tsv import format
    open('tolkiengateway.tsv', 'w').write(format(cross_reference()))
Beispiel #3
0
def dump():
    import tsv
    import codecs
    data = tsv.format(sorted(analyze()))
    codecs.open("tuckborough.tsv", "w", "utf-8").write(data)