コード例 #1
0
def add_chunk(author_id, text_id, text_chunk_number, chunk_text):
    print "Creating chunk: %s" % (str(text_chunk_number))
    chunk = Chunk(author_id=author_id, text_id=text_id, text_chunk_number=text_chunk_number)
    print "Fingerprinting chunk"
    fingerprint = classifier.compute_fingerprint.fingerprint_text(chunk_text)
    for key in fingerprint.keys():
        setattr(chunk, key, fingerprint[key])
    chunk.save()
    print "Processed chunk with id %s" % (str(chunk.id))
    return True
コード例 #2
0
def create_text_average_chunk(text_id):
    text = Text.objects.get(pk=text_id)
    if (text.average_chunk is not None):
        text.average_chunk.delete()

    chunks = Chunk.get_chunks().filter(text=text)
    print "averaging %i chunks" % (len(chunks))
    average_fingerprint = Chunk.get_average_fingerprint_of_chunks(chunks)
    chunk = Chunk.objects.create()
    for key in average_fingerprint.keys():
        setattr(chunk, key, average_fingerprint[key])

    chunk.text = text
    chunk.save()
    text.average_chunk = chunk
    text.save()
    return True
コード例 #3
0
def create_author_average_chunk(author_id):
    author = Author.objects.get(pk=author_id)
    if (author.average_chunk is not None):
        author.average_chunk.delete()

    chunks = []
    texts = Text.objects.filter(author=author)
    for text in texts:
        chunks.append(text.average_chunk)

    print "averaging %i chunks" % (len(chunks))
    average_fingerprint = Chunk.get_average_fingerprint_of_chunks(chunks)
    chunk = Chunk.objects.create()
    for key in average_fingerprint.keys():
        setattr(chunk, key, average_fingerprint[key])

    chunk.author = author
    chunk.save()
    author.average_chunk = chunk
    author.status = "updated"
    author.save()
    return True