Queste sono le differenze tra la revisione selezionata e la versione attuale della pagina.
| Entrambe le parti precedenti la revisione Revisione precedente Prossima revisione | Revisione precedente | ||
|
ud_treebank [2021/10/25 13:58] 65.21.180.48 versione precedente ripristinata (2021/06/03 10:34) |
ud_treebank [2026/03/31 12:08] (versione attuale) admin |
||
|---|---|---|---|
| Linea 1: | Linea 1: | ||
| - | ====== Struttura di un treebank | + | ====== Struttura di un treebank “Universal Dependencies” ====== |
| + | ===== Scaricare il treebank di copto ===== | ||
| Copiate nella cartella " | Copiate nella cartella " | ||
| - | Nel formato “Universal Dependencies” i record relativi alle singole parole unità corrispondono a singoli righi di testo con campi separati da TAB (caratteri di tabulazione), | + | ===== Struttura dei record ===== |
| + | Nel formato “Universal Dependencies” | ||
| < | < | ||
| - | 8 ⲛⲧⲟⲕ ⲛⲧⲟⲕ PRON PPERI Definite=Def|Gender=Masc|Number=Sing|Person=2|PronType=Prs 3 acl _ Orig=ⲛ̄ⲧⲟⲕ | + | 15 ⲕ ⲛⲧⲟⲕ PRON PPERS Definite=Def|Gender=Masc|Number=Sing|Person=2|PronType=Prs 16 nsubj _ _ |
| + | |||
| + | |||
| + | 33 ⲭⲣⲓⲥⲧⲟⲥ ⲭⲣⲓⲥⲧⲟⲥ NOUN N Foreign=Yes 30 nmod _ Entity=person)person)|Orig=ⲭ︤ⲥ︥|OrigLang=grc | ||
| </ | </ | ||
| Disponendo in verticale i campi abbiamo: | Disponendo in verticale i campi abbiamo: | ||
| - | < | + | - posizione della parola unita' nella frase; |
| - | 8 ⲛⲧⲟⲕ ⲛⲧⲟⲕ PRON PPERI Definite=Def|Gender=Masc|Number=Sing|Person=2|PronType=Prs 3 acl _ Orig=ⲛ̄ⲧⲟⲕ | + | - significante grafico della parola unità; |
| - | </ | + | - lessema; |
| + | - parte del discorso secondo una classificazione universale; | ||
| + | - parte del discorso secondo una classificazione elaborata specificamente per la lingua in esame; | ||
| + | - insieme di sottocampi comprendente i valori delle categorie grammaticali; | ||
| + | - posizione nella frase della parola da cui la parola in esame dipende sintatticamente; | ||
| + | - relazione sintattica tra la parola in esame e la parola da cui essa dipende sintatticamente; | ||
| + | - campo eventualmente utilizzabile per l' | ||
| + | - altre note. | ||
| - | <code python ud_explorer.py> | ||
| - | # -*- coding: utf-8 -*- | ||
| - | #Copyright 2021 P. Milizia CC-BY 4.0 (https:// | ||
| - | import re | ||
| - | import glob | ||
| + | <code python> | ||
| + | 1) 15 #posizione della parola unita' nella frase | ||
| + | 2) ⲕ # | ||
| + | 3) ⲛⲧⲟⲕ # | ||
| + | 4) PRON #parte del discorso secondo una classificazione universale | ||
| + | 5) PPERS #parte del discorso secondo una classificazione elaborata specificamente per la lingua in esame | ||
| + | 6) Definite=Def|Gender=Masc|Number=Sing|Person=2|PronType=Prs #insieme di sottocampi comprendente i valori delle categorie grammaticali | ||
| + | 7) 16 #posizione nella frase della parola da cui la parola in esame dipende sintatticamente | ||
| + | 8) nsubj #relazione sintattica tra la parola in esame e la parola da cui essa dipende sintatticamente (qui " | ||
| + | 9) _ #campo eventualmente utilizzabile per l' | ||
| + | 10) _ #altre note | ||
| - | #CLASSE PYTHON PER LA LETTURA DI UN TREEBANK UD | ||
| - | class UD: | ||
| - | def __init__(self, | ||
| - | self.data=self.add_sent_id(data) | ||
| - | self.tokens=self.create_tokens(self.data) | ||
| - | self.sentences=self.create_sentences(self.tokens) | ||
| - | |||
| - | #aggiunge il campo sent_id | ||
| - | def add_sent_id(self, | ||
| - | sid_expr=re.compile(' | ||
| - | text=re.split(' | ||
| - | output='' | ||
| - | sid='' | ||
| - | for line in text: | ||
| - | found=re.search(sid_expr, | ||
| - | if found != None: | ||
| - | sid=found.group() | ||
| - | if line !='' | ||
| - | line = line+' | ||
| - | output += line+' | ||
| - | return output | ||
| - | |||
| - | #crea la lista dei tokens | ||
| - | def create_tokens(self, | ||
| - | expr=re.compile(' | ||
| - | tokens = re.findall(expr, | ||
| - | for i in range(len(tokens)): | ||
| - | tokens[i]=list(tokens[i]) | ||
| - | for ii in (5,9): | ||
| - | tokens[i][ii]=re.split(' | ||
| - | try: | ||
| - | tokens[i][0]=int(tokens[i][0]) | ||
| - | except ValueError: | ||
| - | pass | ||
| - | try: | ||
| - | tokens[i][6]=int(tokens[i][6]) | ||
| - | except ValueError: | ||
| - | pass | ||
| - | return tokens | ||
| - | #crea il dizionario delle frasi | + | 1) 33 #posizione della parola unita' nella frase |
| - | def create_sentences(self, | + | 2) ⲭⲣⲓⲥⲧⲟⲥ # |
| - | sentences={} | + | 3) ⲭⲣⲓⲥⲧⲟⲥ #lessema |
| - | sid='' | + | 4) NOUN #parte del discorso secondo una classificazione universale |
| - | for t in tokens: | + | 5) N #parte del discorso secondo una classificazione elaborata specificamente per la lingua |
| - | if t[10] != sid: | + | 6) Foreign=Yes #insieme di sottocampi comprendente i valori delle categorie grammaticali (qui contiene un valore relativo allo strato lessicale) |
| - | sid=t[10] | + | 7) 30 #posizione nella frase della parola da cui la parola in esame dipende sintatticamente |
| - | sentences[sid]=['root'] | + | 8) nmod #relazione sintattica tra la parola in esame e la parola da cui essa dipende sintatticamente (qui " |
| - | if type(t[0])==int: | + | 9) _ #campo eventualmente utilizzabile per l'indicazione combinata della posizione della parola reggente e della relazione sintattica |
| - | tt=t[:] | + | 10) Entity=person)person)|Orig=ⲭ︤ⲥ︥|OrigLang=grc #altre note |
| - | sentences[sid].append(tt) | + | </ |
| - | return sentences | + | Inoltre all' |
| + | < | ||
| + | # sent_id = shenoute_fox-XH204-216_s0006 | ||
| + | </ | ||
| - | def parent_of(self, | + | Esempio di frase completa: |
| - | x=self.sentences[occurrence[10]][occurrence[0]] | + | < |
| - | return self.sentences[x[10]][x[6]] | + | # sent_id |
| - | + | # text_en = ... | |
| - | def grandparent_of(self, | + | # text = ⲁⲩⲱ ⲉⲩⲧⲛⲧⲱⲛ ⲉⲡⲟⲩⲟⲉⲓⲛ ⲙⲡⲉϩⲟⲟⲩ · |
| - | return self.parent_of(self.parent_of(occurrence)) | + | 1 ⲁⲩⲱ ⲁⲩⲱ CCONJ CONJ _ 4 cc _ _ |
| - | + | 2-4 ⲉⲩⲧⲛⲧⲱⲛ _ _ _ _ _ _ _ _ | |
| - | def subsequent_of(self, | + | 2 ⲉ ⲉⲣⲉ PART CFOC _ 4 mark _ _ |
| - | try: | + | 3 ⲩ ⲛⲧⲟⲟⲩ PRON PPERS Definite=Def|Number=Plur|Person=3|PronType=Prs 4 nsubj _ _ |
| - | outp=self.sentences[occurrence[10]][occurrence[0]+1] | + | 4 ⲧⲛⲧⲱⲛ ⲧⲟⲛⲧⲛ VERB VSTAT Mood=Ind|VerbForm=Fin 0 root _ Orig=ⲧ︤ⲛ︥ⲧⲱⲛ` |
| - | except IndexError: | + | 5-7 ⲉⲡⲟⲩⲟⲉⲓⲛ _ _ _ _ _ _ _ _ |
| - | outp=None | + | 5 ⲉ ⲉ ADP PREP _ 7 case _ _ |
| - | return outp | + | 6 ⲡ ⲡ DET ART Definite=Def|Gender=Masc|Number=Sing|PronType=Art 7 det _ Entity=(abstract |
| - | + | 7 ⲟⲩⲟⲉⲓⲛ ⲟⲩⲟⲉⲓⲛ NOUN N _ 4 obl _ _ | |
| - | def precedent_of(self, | + | 8-10 ⲙⲡⲉϩⲟⲟⲩ _ _ _ _ _ _ _ _ |
| - | try: | + | 8 ⲙ ⲛ ADP PREP _ 10 case _ Orig=ⲙ̄ |
| - | outp=self.sentences[occurrence[10]][occurrence[0]-1] | + | 9 ⲡⲉ ⲡ DET ART Definite=Def|Gender=Masc|Number=Sing|PronType=Art 10 det _ Entity=(time |
| - | except IndexError: | + | 10 ϩⲟⲟⲩ ϩⲟⲟⲩ NOUN N _ 7 nmod _ Entity=time)abstract)|Orig=ϩⲟⲟⲩ` |
| - | outp=None | + | 11 · · PUNCT PUNCT _ 4 punct _ _ |
| - | except TypeError: | + | |
| - | outp=None | + | |
| - | return outp | + | |
| - | + | ||
| - | def children_of(self, | + | |
| - | x=self.sentences[occurrence[10]][occurrence[0]] | + | |
| - | return [t for t in self.sentences[occurrence[10]][1: | + | |
| - | + | ||
| - | def ancestors_of(self, | + | |
| - | x=self.sentences[occurrence[10]][occurrence[0]] | + | |
| - | output = [x] | + | |
| - | while x != 'root': | + | |
| - | y=self.parent_of(x) | + | |
| - | output.append(y) | + | |
| - | x=y | + | |
| - | return output | + | |
| - | + | ||
| - | def get_sentence(self, | + | |
| - | return [j[1] for j in self.sentences[x][1: | + | |
| - | + | ||
| - | + | ||
| - | # | + | |
| - | + | ||
| - | #lettura file | + | |
| - | directory_name=' | + | |
| - | path = directory_name+'/ | + | |
| - | files=glob.glob(path) | + | |
| - | data='' | + | |
| - | for filepath in files: | + | |
| - | with open(filepath, | + | |
| - | file_data=file.read() | + | |
| - | data+=file_data | + | |
| - | #ordina i file e crea una variabile text_list con l' | + | |
| - | data=data.split('# newdoc ')[1:] | + | |
| - | data.sort() | + | |
| - | data='# | + | |
| - | text_list=re.findall('# | + | |
| - | + | ||
| - | + | ||
| - | #ESEMPIO DI UTILIZZO | + | |
| - | + | ||
| - | #trova tutte le occorrenze di 'ⲙⲙⲟ' | + | |
| - | #alle seguenti condizioni: | + | |
| - | #1) che la frase sia al passato perfettivo positivo | + | |
| - | #2) che almeno un elemento sia interposto tra verbo e preposizione | + | |
| - | + | ||
| - | coptic=UD(data) | + | |
| - | + | ||
| - | found_tokens=[] | + | |
| - | + | ||
| - | def is_past(o): | + | |
| - | answer | + | |
| - | for child in coptic.children_of(o): | + | |
| - | if child[1]==' | + | |
| - | answer = True | + | |
| - | break | + | |
| - | return answer | + | |
| - | + | ||
| - | for token in coptic.tokens: | + | |
| - | if (token[1] == ' | + | |
| - | try: | + | |
| - | regens = coptic.grandparent_of(token) | + | |
| - | noun_pronoun = coptic.parent_of(token) | + | |
| - | if noun_pronoun[7]==' | + | |
| - | found_tokens.append(token) | + | |
| - | except: | + | |
| - | pass | + | |
| - | for o in found_tokens: | ||
| - | print(o) | ||
| </ | </ | ||