Exemple #1
0
def layout_punto5e6(nome_A, cat_A, nome_B, cat_B):
    table = Texttable()  # creo oggetto tabella
    table.__init__(0)  # imposto la max_width infinita
    raw_head = [
        "", nome_A, nome_B
    ]  # lista contenente le stringhe da inserire nel titolo della tabella non ancora formattati
    head_format = [
        "{:^12}", "{:^24}", "{:^24}"
    ]  # tipo di formattazione da applicare alle stringhe di raw_head
    head = []  # lista in cui inserire le stringhe di raw_head formattate
    for i, j in zip(raw_head, head_format):
        head.append(j.format(i))  # applico la formattazione
    table.header(
        head
    )  # definisco le stringhe titoli della tabella (passate tramite lista)

    raw_subHead = ["", "freq_rel %", "media", "freq_rel %",
                   "media"]  # stringhe sottotitolo non formattate
    subHead_format = ["{:^12}", "{:^12}", "{:^12}", "{:^12}",
                      "{:^12}"]  # formattazione sottotitolo
    subHead = []  # stringhe sottotitolo formattate
    for i, j in zip(raw_subHead, subHead_format):
        subHead.append(j.format(i))
    subHead[1] += subHead[
        2]  # unisco le stringhe [1] e [2] le quali comporranno le il sottotitolo (devo fare questo per via della limitazione di texttable di inserire non piu' elementi della prima riga nelle righe successive)
    subHead[3] += subHead[4]  # come sopra per stringhe [3] e [4]
    del (subHead[2])  # elimino [2] che ho gia' unito alla stringa [1]
    del (
        subHead[3]
    )  # elimino [3] che ho gia' unito alla stringa [2] ([3] e [2] sono rispettivamente [3] e [4] prima della eliminazione della stringa [2])
    table.add_row(subHead)  # aggiungo la riga sottotitolo alla tabella

    catGram = ["sostantivi", "aggettivi", "verbi", "pronomi"]
    j = 0
    for i in catGram:  # creo le righe in cui inserisco i dati
        # dati da inserire nella riga senza formattazione
        raw_row = [
            i,
            str(cat_A[j][0]),
            str(cat_A[j][1]),
            str(cat_B[j][0]),
            str(cat_B[j][1])
        ]
        row_format = ["{:^12}", "{:^12}", "{:^12}", "{:^12}",
                      "{:^12}"]  # formattazione riga
        row = []  # array che conterra riga di dati formattata
        for i, k in zip(raw_row, row_format):
            row.append(k.format(i))
        row[1] += row[2]  # stessi passaggi come riga subHead
        row[3] += row[4]  # //
        del (row[2])  # //
        del (row[3])  # //
        table.add_row(row)  # aggiunta riga dati alla tabella
        j += 1

    print table.draw()  # stampa tabella
Exemple #2
0
def layout_trig_e_big(nome_A, elem_A, nome_B, elem_B, dim, argomento):
    table = Texttable()  # creo oggetto tabella
    table.__init__(0)  # imposto la max_width infinita
    raw_head = [
        "", nome_A, nome_B
    ]  # lista contenente le stringhe da inserire nel titolo della tabella non ancora formattati
    head_format = [
        "{:^7}", "{:^22}", "{:^22}"
    ]  # tipo di formattazione da applicare alle stringhe di raw_head
    head = []  # lista in cui inserire le stringhe di raw_head formattate
    for i, j in zip(raw_head, head_format):
        head.append(j.format(i))  # applico la formattazione
    table.header(
        head
    )  # definisco le stringhe titoli della tabella (passate tramite lista)

    raw_subHead = ["rango", argomento, "freq", argomento,
                   "freq"]  # stringhe sottotitolo non formattate
    subHead_format = ["{:^7}", "{:^15}", "{:^15}", "{:^15}",
                      "{:^15}"]  # formattazione sottotitolo
    subHead = []  # stringhe sottotitolo formattate
    for i, j in zip(raw_subHead, subHead_format):
        subHead.append(j.format(i))
    subHead[1] += subHead[
        2]  # unisco le stringhe [1] e [2] le quali comporranno le il sottotitolo (devo fare questo per via della limitazione di texttable di inserire non piu' elementi della prima riga nelle righe successive)
    subHead[3] += subHead[4]  # come sopra per stringhe [3] e [4]
    del (subHead[2])  # elimino [2] che ho gia' unito alla stringa [1]
    del (
        subHead[3]
    )  # elimino [3] che ho gia' unito alla stringa [2] ([3] e [2] sono rispettivamente [3] e [4] prima della eliminazione della stringa [2])
    table.add_row(subHead)  # aggiungo la riga sottotitolo alla tabella

    j = 0
    for i in range(dim):  # creo le righe in cui inserisco i dati
        # dati da inserire nella riga senza formattazione
        tri_A = ""
        tri_B = ""
        for k in elem_A[j][0]:
            tri_A += k + " "  # stringa contenente i trigrammi del corpus A
        for k in elem_B[j][0]:
            tri_B += k + " "  # stringa contenente i trigrammi del corpus B

        raw_row = [i + 1, tri_A, str(elem_A[j][1]), tri_B, str(elem_B[j][1])]
        row_format = ["{:^7}", "{:^15}", "{:^15}", "{:^15}",
                      "{:^15}"]  # formattazione riga
        row = []  # array che conterra riga di dati formattata
        for i, k in zip(raw_row, row_format):
            row.append(k.format(i))
        row[1] += row[2]  # stessi passaggi come riga subHead
        row[3] += row[4]  # //
        del (row[2])  # //
        del (row[3])  # //
        table.add_row(row)  # aggiunta riga dati alla tabella
        j += 1

    print table.draw()  # stampa tabella
Exemple #3
0
    def __init__(self, title=None, header=None, descr=None, data=None, export='plain'):
        Texttable.__init__(self)
        self.set_chars(['-', '|', '+', '-'])
        self.set_deco(Texttable.HEADER | Texttable.VLINES)  # Texttable.BORDER | Texttable.HLINE
        self.set_precision(3)

        self._title = title
        self._descr = descr
        self._format = export  # outformat in ['plain', 'latex', 'html']
        if header is not None:
            self.header(header)
        if data is not None:
            self.add_rows(data, header=False)
Exemple #4
0
    def __init__(self,
                 title=None,
                 header=None,
                 descr=None,
                 data=None,
                 export='plain',
                 max_width=78):
        Texttable.__init__(self, max_width=max_width)
        if export == 'plain':
            self.set_chars(['-', '|', '+', '-'])
            self.set_deco(Texttable.HEADER | Texttable.VLINES)  # Texttable.BORDER | Texttable.HLINE

        self._title = title
        self._descr = descr
        if header is not None:
            self.header(header)
        if data is not None:
            self.add_rows(data, header=False)
Exemple #5
0
def layout_punto4(nome_A, elem_A, nome_B, elem_B, dim):
    table = Texttable()  # creo oggetto tabella
    table.__init__(0)  # imposto la max_width infinita
    raw_head = [
        "rango", nome_A, nome_B
    ]  # lista contenente le stringhe da inserire nel titolo della tabella non ancora formattati
    head_format = [
        "{:^7}", "{:^22}", "{:^22}"
    ]  # tipo di formattazione da applicare alle stringhe di raw_head
    head = []  # lista in cui inserire le stringhe di raw_head formattate
    for i, j in zip(raw_head, head_format):
        head.append(j.format(i))  # applico la formattazione
    table.header(
        head
    )  # definisco le stringhe titoli della tabella (passate tramite lista)

    j = 0
    for i in range(dim):  # creo le righe in cui inserisco i dati
        # dati da inserire nella riga senza formattazione
        raw_row = [
            i + 1,
            str(elem_A[j][0]),
            str(elem_A[j][1]),
            str(elem_B[j][0]),
            str(elem_B[j][1])
        ]
        row_format = ["{:^7}", "{:^16}", "{:^16}", "{:^16}",
                      "{:^16}"]  # formattazione riga
        row = []  # array che conterra riga di dati formattata
        for i, k in zip(raw_row, row_format):
            row.append(k.format(i))
        row[1] += row[2]  # stessi passaggi come riga subHead
        row[3] += row[4]  # //
        del (row[2])  # //
        del (row[3])  # //
        table.add_row(row)  # aggiunta riga dati alla tabella
        j += 1

    table.set_deco(
        Texttable.VLINES
        | Texttable.HEADER)  # imposto lo stile delle righe e colonne
    print table.draw()  # stampa tabella
Exemple #6
0
def layout_punto3_B(nome_A, hapax_A, nome_B, hapax_B):
    table = Texttable()  # creo oggetto tabella
    table.__init__(0)  # imposto la max_width infinita
    raw_head = [
        "", nome_A, nome_B, ""
    ]  # lista contenente le stringhe da inserire nel titolo della tabella non ancora formattati
    head_format = [
        "{:^6}", "{:^22}", "{:^22}", "{:^6}"
    ]  # tipo di formattazione da applicare alle stringhe di raw_head
    head = []  # lista in cui inserire le stringhe di raw_head formattate
    for i, j in zip(raw_head, head_format):
        head.append(j.format(i))  # applico la formattazione
    table.header(
        head
    )  # definisco le stringhe titoli della tabella (passate tramite lista)

    raw_subHead = ["token", "hapax", "incr", "hapax", "incr",
                   "diff"]  # stringhe sottotitolo non formattate
    subHead_format = [
        "{:^6}", "{:^11}", "{:^11}", "{:^11}", "{:^11}", "{:^6}"
    ]  # formattazione sottotitolo
    subHead = []  # stringhe sottotitolo formattate
    for i, j in zip(raw_subHead, subHead_format):
        subHead.append(j.format(i))
    subHead[1] += subHead[
        2]  # unisco le stringhe [1] e [2] le quali comporranno le il sottotitolo (devo fare questo per via della limitazione di texttable di inserire non piu' elementi della prima riga nelle righe successive)
    subHead[3] += subHead[4]  # come sopra per stringhe [3] e [4]
    del (subHead[2])  # elimino [2] che ho gia' unito alla stringa [1]
    del (
        subHead[3]
    )  # elimino [3] che ho gia' unito alla stringa [2] ([3] e [2] sono rispettivamente [3] e [4] prima della eliminazione della stringa [2])
    table.add_row(subHead)  # aggiungo la riga sottotitolo alla tabella

    len_row = len(hapax_A) if len(hapax_A) > len(hapax_B) else len(
        hapax_B)  # numero righe contenenti dati
    for i in range(len_row):  # creo le righe in cui inserisco i dati
        # dati da inserire nella riga senza formattazione
        raw_row = [
            str(1000 * (i + 1)),  # numero di token in esame 												
            "" if i > (len(hapax_A) - 1) else str(
                hapax_A[i]
            ),  # numero di hapax per token corpus A (la clausola if evita "out of range")
            "" if i > (len(hapax_A) - 1) else
            ("+" + str((hapax_A[i] - hapax_A[i - 1]) if i > 0 else hapax_A[i])
             ),  # incremento rispetto a porzione di token precedente
            "" if i > (len(hapax_B) - 1) else str(
                hapax_B[i]),  # numero di hapax per token corpus B
            "" if i > (len(hapax_B) - 1) else
            ("+" + str((hapax_B[i] - hapax_B[i - 1]) if i > 0 else hapax_B[i])
             ),  # incremento rispetto a porzione di token precedente
            "" if i > (len(hapax_A) - 1) or i > (len(hapax_B) - 1) else
            (str(hapax_A[i] -
                 hapax_B[i] if hapax_A[i] > hapax_B[i] else hapax_B[i] -
                 hapax_A[i]))
        ]  # differenza di hapax tra corpus A e B ogni porzione di token

        row_format = [
            "{:^6}", "{:^11}", "{:^11}", "{:^11}", "{:^11}", "{:^6}"
        ]  # formattazione riga
        row = []  # array che conterra riga di dati formattata
        for i, j in zip(raw_row, row_format):
            row.append(j.format(i))
        row[1] += row[2]  # stessi passaggi come riga subHead
        row[3] += row[4]  # //
        del (row[2])  # //
        del (row[3])  # //
        table.add_row(row)  # aggiunta riga dati alla tabella

    print table.draw()  # stampa tabella
Exemple #7
0
 def __init__(self):
     Texttable.__init__(self)
     # set class attributes so that it'll be more like TRex standard output
     self.set_chars(['-', '|', '-', '-'])
     self.set_deco(Texttable.HEADER | Texttable.VLINES)
Exemple #8
0
 def __init__(self):
     Texttable.__init__(self)
     # set class attributes so that it'll be more like TRex standard output
     self.set_chars(['-', '|', '-', '-'])
     self.set_deco(Texttable.HEADER | Texttable.VLINES)
Exemple #9
0
 def __init__(self, title = None):
     Texttable.__init__(self)
     # set class attributes so that it'll be more like TRex standard output
     self.set_chars(['-', ':', '-', '-'])
     self.set_deco(Texttable.VLINES)
     self.title = title
 def __init__(self):
     Texttable.__init__(self)
     # set class attributes so that it'll be more like TRex standard output
     self.set_chars(["-", ":", "-", "-"])
     self.set_deco(Texttable.VLINES)