Bonjour,
j'ai plusieurs texte qui ont le meme format :
voici un exemple
Il faut savoir que c'est une phrase par ligne (pour faciliter).
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 TITLE:A State-Transition Grammar for Data-Oriented Parsing ABSTRACT: This paper presents a grammar formalism designed for use in data-oriented approaches to language processing. It goes on to investigate ways in which a corpus pre-parsed with this formalism may be processed to provide a probabilistic language model for use in the parsing of fresh texts. HEADER: Introduction Recent years have seen a resurgence of interest in probabilistic techniques for automatic language analysis. In particular, there has arisen a distinct paradigm of processing on the basis of pre-analyzed data which has taken the name Data-Oriented Parsing. HEADER: A Formalism for DOP Given that we are attempting to construct a formalism that will do justice to both the statistical and structural aspects of language, the features that we would wish to maximize will include the following: . HEADER: Accounting for Linguistic Structure If a finite-state grammar is chosen however, the third criterion, that of linguistic adequacy, seems to present an insurmountable stumbling block. How can such a simple formalism, in which syntax is reduced to a string of category-states, hope to capture even the basic hierarchical structure, the familiar ``tree structure'', of linguistic expressions? . HEADER: Coverage The criterion that remains to be satisfied is that of width of coverage: can the formalism cope with the many ``peripheral'' structures found in real written and spoken texts? As it stands the formalism is weakly equivalent to a context-free grammar and as such will have problems dealing with phenomena like discontinuous constituents, non-constituent coordination and gapping. Fortunately if extensions are made to the formalism, necessarily taking it outside weak equivalence to a context-free grammar, natural and general analyses present themselves for such constructions.
Donc le but est de récupérer le contenu du texte (toutes phrases entre les balises HEADER) pour effectuer un résumé automatique et ensuite comparer le résumé automatique à celui qui se trouve juste en dessous de ABSTRACT.
Il est obligatoire de découper chaque phrase par token (mot).
On a un liste stopwordlist (qui n'ont aucune signification) qui contient les mots qu'on ne veut pas stocker comme in, on .....
le résultat attendu après le découpage en token phrase :
je garde les phrases commençant par header pour un traitement futur
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11 {0: ['header', 'introduction'], 1: ['recent', 'seen', 'resurgence', 'probabilist ic', 'techniques', 'automatic', 'language', 'analysis'], 2: ['particular', 'aris en', 'distinct', 'paradigm', 'processing', 'basis', 'pre', 'analyzed', 'data', ' name', 'data', 'oriented', 'parsing'], 3: ['header', 'formalism', 'dop'], 4: ['a ttempting', 'construct', 'formalism', 'justice', 'statistical', 'structural', 'a spects', 'language', 'features', 'wish', 'maximize', 'include', 'following'], 5: ['header', 'accounting', 'linguistic', 'structure'], 6: ['finite', 'grammar', ' chosen', 'third', 'criterion', 'linguistic', 'adequacy', 'insurmountable', 'stum bling', 'block'], 7: ['simple', 'formalism', 'syntax', 'reduced', 'string', 'cat etc....
donc voici mon code :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33 def constructionPhrase: debutTexte = False f = open(article,'rU') liste = f.readlines() count={} n=0 listeToken=[] l = [projectile.strip("\n") for projectile in liste] for phrase in l: if filtre(phrase) == False: if phrase.startswith("HEADER"): debutTexte = True if debutTexte == True: for j in tokenize(phrase): if j.lower() not in loadList("/home/Ekrem/statrech/stopwordlist/list.txt"): listeToken.append(j.lower()) count[n] = listeToken listeToken=[] n+=1 return count def filtre(token): liste = ["TITLE","ABSTRACT"] for i in liste: if token.startswith(i): return True return False def tokenize(phrase): p = re.compile(r'\W+') return p.split(phrase)
là je fais juste pour un article.
Le but étant de faire pour tout un dossier contenant des fichiers textes sous ce format
donc le temps total pour traiter tous les articles, c'est à peu près 1min 30.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10 def listePhraseCollection(dossier): articles = {} os.chdir("/home/Ekrem/statrech/texte") listeFichiers=glob.glob("*.txt") n=0 for fichier in listeFichiers: articles[n]=constructionPhrase(fichier) n+=1 return articles
est-ce normal ou cela vient -il d'un défaut de mon algo.
merci
Partager