IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Python Discussion :

algo python liste


Sujet :

Python

Vue hybride

ekremyilmaz algo python liste 29/01/2009, 14h24
ekremyilmaz j'ai oublié de préciser, j'ai... 29/01/2009, 15h09
ekremyilmaz le calcul sur un article se... 29/01/2009, 15h15
ekremyilmaz c résolu ;) !!!! ça venait... 29/01/2009, 15h43
dividee debutTexte = True if... 29/01/2009, 21h11
Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé
    Profil pro
    Inscrit en
    Juillet 2007
    Messages
    358
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2007
    Messages : 358
    Par défaut algo python liste
    Bonjour,
    j'ai plusieurs texte qui ont le meme format :
    voici un exemple
    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.
    Il faut savoir que c'est une phrase par ligne (pour faciliter).

    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 :

    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....
    je garde les phrases commençant par header pour un traitement futur

    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

    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
    donc le temps total pour traiter tous les articles, c'est à peu près 1min 30.

    est-ce normal ou cela vient -il d'un défaut de mon algo.

    merci

  2. #2
    Membre éclairé
    Profil pro
    Inscrit en
    Juillet 2007
    Messages
    358
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2007
    Messages : 358
    Par défaut
    j'ai oublié de préciser, j'ai 181 fichiers, c'est peut être normal alors !!!! vu que j'effectue le même traitement pour chaque fichier

  3. #3
    Membre éclairé
    Profil pro
    Inscrit en
    Juillet 2007
    Messages
    358
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2007
    Messages : 358
    Par défaut
    le calcul sur un article se fait en 0,46 s pour un fichier de 7Ko

    pour le plus gros article 36ko, 2,68 s.

    je pense que c énorme quand meme

  4. #4
    Membre éclairé
    Profil pro
    Inscrit en
    Juillet 2007
    Messages
    358
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2007
    Messages : 358
    Par défaut
    c résolu !!!!

    ça venait de la fonction loadlist, je l'appelais à chaque boucle !!!!!

    je l'ai sorti, je l'ai mis au début du pg,
    maintenant ça tourne pour le gros fichier en 0,078s et pour la totalité en 2,6s

  5. #5
    Membre Expert
    Homme Profil pro
    Inscrit en
    Mars 2007
    Messages
    941
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations forums :
    Inscription : Mars 2007
    Messages : 941
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    debutTexte = True
    if debutTexte == True:
    Comme ce test pourrait-il échouer ??

  6. #6
    Membre éclairé
    Profil pro
    Inscrit en
    Juillet 2007
    Messages
    358
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2007
    Messages : 358
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    debutTexte = True
    if debutTexte == True:
    sachant que je ne veux pas prendre le début du texte qui comporte le titre et l'abstract, donc je ne récupère pas le début.
    Donc dès que je commence à avoir un header, je passe la variable debutTexte à True, ça veut dire que je récupère le contenu du texte.

    par ex dans l'exemple cité dans mon premier post.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    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: .
    je souhaite récuperer le texte à partir de "HEADER: Introduction Recent years have seen a resurgence of interest in probabilistic techniques" et jusqu'à la fin du texte etc.....

    je me demande si y a pas moyen avec une expression regulière ?

Discussions similaires

  1. explication sur cet algo de liste chaînée
    Par keokaz dans le forum Algorithmes et structures de données
    Réponses: 1
    Dernier message: 26/03/2012, 11h21
  2. [Algo] + [Python] Analyse d'une formule
    Par WAKAKA dans le forum Général Python
    Réponses: 10
    Dernier message: 12/11/2011, 20h50
  3. Erreur Python : list index out of range
    Par mmmppp dans le forum Général Python
    Réponses: 4
    Dernier message: 15/10/2011, 21h59
  4. segfault sur une boost::python::list
    Par psycofdj dans le forum Boost
    Réponses: 1
    Dernier message: 15/10/2008, 00h41

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo