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

Visual C++ Discussion :

un passage de paramètre qui échoue


Sujet :

Visual C++

  1. #1
    Débutant
    Profil pro
    Développeur informatique
    Inscrit en
    Décembre 2008
    Messages
    1 022
    Détails du profil
    Informations personnelles :
    Localisation : France, Mayenne (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2008
    Messages : 1 022
    Points : 332
    Points
    332
    Par défaut un passage de paramètre qui échoue
    bonjour,
    j'ai un passage de paramètre qui donne un résultat incorrect :
    dans le code suivant :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    char** FinalStateTagger( char **buf, int numSen, Registry seenTagging, Registry words, Darray cRuleArray, char* buff)
    avec le résultat suivant:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    0x2f656854 <Ptr> incorrect
    alors que dans l'appelant avant l'appel,le contenu était bon:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    FinalStateTagger( (char**)&buff, 1, seenTagging_hash, lexicon_hash, cRuleArray, bufsortie);
    avec un buff qui est déclaré:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    static char buff[BUF_SIZE];
    J'ai le même résultat si je déclare buff en automatique
    celui qui m'aidera sera

  2. #2
    Membre chevronné

    Homme Profil pro
    Développeur informatique
    Inscrit en
    Avril 2013
    Messages
    610
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Finance

    Informations forums :
    Inscription : Avril 2013
    Messages : 610
    Points : 1 878
    Points
    1 878
    Billets dans le blog
    21
    Par défaut
    Déjà appeler un paramètre buff et un paramètre buf, c'est barbare.
    Et quand le paramètre buf est l'adresse d'une variable buff, c'est carrément animal.
    Surtout si buf est un char** et buff un static char[]

    Est-ce que ça suffit à faire de moi un ?

  3. #3
    Débutant
    Profil pro
    Développeur informatique
    Inscrit en
    Décembre 2008
    Messages
    1 022
    Détails du profil
    Informations personnelles :
    Localisation : France, Mayenne (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2008
    Messages : 1 022
    Points : 332
    Points
    332
    Par défaut Je ne vois pas
    quel limitation il y a dans les symboles: que buff dans le premier soit appelé buf dans le second.
    Je rappelle qu'il s'agit d'un shareware et que je ne le modifie que à la marge pour le faire marcher

  4. #4
    Expert éminent sénior
    Avatar de Médinoc
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2005
    Messages
    27 369
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2005
    Messages : 27 369
    Points : 41 519
    Points
    41 519
    Par défaut
    Un tableau n'est pas un pointeur. Le cast de &buff en char** n'est pas une conversion valide. Le vrai type de &buff est char (*)[BUF_SIZE].
    SVP, pas de questions techniques par MP. Surtout si je ne vous ai jamais parlé avant.

    "Aw, come on, who would be so stupid as to insert a cast to make an error go away without actually fixing the error?"
    Apparently everyone.
    -- Raymond Chen.
    Traduction obligatoire: "Oh, voyons, qui serait assez stupide pour mettre un cast pour faire disparaitre un message d'erreur sans vraiment corriger l'erreur?" - Apparemment, tout le monde. -- Raymond Chen.

  5. #5
    Débutant
    Profil pro
    Développeur informatique
    Inscrit en
    Décembre 2008
    Messages
    1 022
    Détails du profil
    Informations personnelles :
    Localisation : France, Mayenne (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2008
    Messages : 1 022
    Points : 332
    Points
    332
    Par défaut bonjour, j'ai déclaré
    J'ai donc déclaré:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    char buff (*)[BUF_SIZE];
    // Ligne 122
    et le compilateur m'a répondu :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1>..\..\..\..\Linguistic\ParserManager\src\BTaggerc.cpp(122): error C2059: erreur de syntaxe*: ')'

  6. #6
    Expert éminent sénior
    Avatar de Médinoc
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2005
    Messages
    27 369
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2005
    Messages : 27 369
    Points : 41 519
    Points
    41 519
    Par défaut
    La bonne déclaration pour cela est char (*buff)[BUF_SIZE], mais es-tu sûr que ce soit ce que tu cherches à faire?

    Qu'est censée faire ta fonction FinalStateTagger(), quels paramètres sont en entrée et devraient être marqués const, quels paramètres sont en sortie?
    char**buf est-il censé représenter un pointeur modifiable, ou un tableau bidimensionnel? etc. etc.
    SVP, pas de questions techniques par MP. Surtout si je ne vous ai jamais parlé avant.

    "Aw, come on, who would be so stupid as to insert a cast to make an error go away without actually fixing the error?"
    Apparently everyone.
    -- Raymond Chen.
    Traduction obligatoire: "Oh, voyons, qui serait assez stupide pour mettre un cast pour faire disparaitre un message d'erreur sans vraiment corriger l'erreur?" - Apparemment, tout le monde. -- Raymond Chen.

  7. #7
    Débutant
    Profil pro
    Développeur informatique
    Inscrit en
    Décembre 2008
    Messages
    1 022
    Détails du profil
    Informations personnelles :
    Localisation : France, Mayenne (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2008
    Messages : 1 022
    Points : 332
    Points
    332
    Par défaut J'ai codé
    et ça a marché

  8. #8
    Expert éminent sénior
    Avatar de Médinoc
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2005
    Messages
    27 369
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2005
    Messages : 27 369
    Points : 41 519
    Points
    41 519
    Par défaut
    Es-tu conscient qu'il s'agit là d'un tableau de BUF_SIZE pointeurs sur char?
    SVP, pas de questions techniques par MP. Surtout si je ne vous ai jamais parlé avant.

    "Aw, come on, who would be so stupid as to insert a cast to make an error go away without actually fixing the error?"
    Apparently everyone.
    -- Raymond Chen.
    Traduction obligatoire: "Oh, voyons, qui serait assez stupide pour mettre un cast pour faire disparaitre un message d'erreur sans vraiment corriger l'erreur?" - Apparemment, tout le monde. -- Raymond Chen.

  9. #9
    Débutant
    Profil pro
    Développeur informatique
    Inscrit en
    Décembre 2008
    Messages
    1 022
    Détails du profil
    Informations personnelles :
    Localisation : France, Mayenne (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2008
    Messages : 1 022
    Points : 332
    Points
    332
    Par défaut J' ai codé
    et ça a compilé.
    il y a une erreur d'exécution plus loin.
    Ça plante dans l'instruction
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    		strcpy_s( *buffe, len2 + 1, buffer);
    alors que len2 + 1 est consistent et buffer aussi
    avec le status :La bibliothèque Microsoft Visual Studio C Runtime a détecté une erreur irrécupérable dans SpecificationLoader.exe.
    Je suppose que la longueur de buffer est trop grande > 800 caractères

  10. #10
    Expert éminent sénior
    Avatar de Médinoc
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2005
    Messages
    27 369
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2005
    Messages : 27 369
    Points : 41 519
    Points
    41 519
    Par défaut
    Les pointeurs contenus dans ton tableau de BUF_SIZE pointeurs, les initialises-tu à un point ou un autre?
    SVP, pas de questions techniques par MP. Surtout si je ne vous ai jamais parlé avant.

    "Aw, come on, who would be so stupid as to insert a cast to make an error go away without actually fixing the error?"
    Apparently everyone.
    -- Raymond Chen.
    Traduction obligatoire: "Oh, voyons, qui serait assez stupide pour mettre un cast pour faire disparaitre un message d'erreur sans vraiment corriger l'erreur?" - Apparemment, tout le monde. -- Raymond Chen.

  11. #11
    Débutant
    Profil pro
    Développeur informatique
    Inscrit en
    Décembre 2008
    Messages
    1 022
    Détails du profil
    Informations personnelles :
    Localisation : France, Mayenne (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2008
    Messages : 1 022
    Points : 332
    Points
    332
    Par défaut
    la longueur de la chaine est de 818 octets.pour réserver de la mémoire dans la pile j'ai codé :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
      char* bu[BUF_SIZE];
      char** buffe;
      char* b[BUF_SIZE];
    ne sachant pas si il fallait réserver de la place en dessus ou en dessous j'ai fit les deux. Mais ça n'a rien changé. En outre j'ai codé :
    et :
    pour initialiser la variable

  12. #12
    Expert éminent sénior
    Avatar de Médinoc
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2005
    Messages
    27 369
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2005
    Messages : 27 369
    Points : 41 519
    Points
    41 519
    Par défaut
    Oh là là, le bordel...

    Je crois que tu n'es pas fait pour le C++. Et encore moins le C++/CLI.
    Tu devrais essayer un langage plus simple, comme C#.
    SVP, pas de questions techniques par MP. Surtout si je ne vous ai jamais parlé avant.

    "Aw, come on, who would be so stupid as to insert a cast to make an error go away without actually fixing the error?"
    Apparently everyone.
    -- Raymond Chen.
    Traduction obligatoire: "Oh, voyons, qui serait assez stupide pour mettre un cast pour faire disparaitre un message d'erreur sans vraiment corriger l'erreur?" - Apparemment, tout le monde. -- Raymond Chen.

  13. #13
    Débutant
    Profil pro
    Développeur informatique
    Inscrit en
    Décembre 2008
    Messages
    1 022
    Détails du profil
    Informations personnelles :
    Localisation : France, Mayenne (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2008
    Messages : 1 022
    Points : 332
    Points
    332
    Par défaut ???
    J'ai essayé des tas de choses mais ça ne marche pas
    depuis que j'ai codé :
    c'est sur cette ligne que ça passe en carafe avec le message :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    Une exception de première chance de type 'System.NullReferenceException' s'est produite dans SpecificationLoader.exe
     
    Informations supplémentaires*: La référence d'objet n'est pas définie à une instance d'un objet.

  14. #14
    Expert éminent sénior
    Avatar de Médinoc
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2005
    Messages
    27 369
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2005
    Messages : 27 369
    Points : 41 519
    Points
    41 519
    Par défaut
    Wow, t'es toujours en .Net?

    Pourquoi tu t'emmerdes avec des char*, alors? Utilise des String^ ou des List<String^>^ selon tes besoins réels...
    SVP, pas de questions techniques par MP. Surtout si je ne vous ai jamais parlé avant.

    "Aw, come on, who would be so stupid as to insert a cast to make an error go away without actually fixing the error?"
    Apparently everyone.
    -- Raymond Chen.
    Traduction obligatoire: "Oh, voyons, qui serait assez stupide pour mettre un cast pour faire disparaitre un message d'erreur sans vraiment corriger l'erreur?" - Apparemment, tout le monde. -- Raymond Chen.

  15. #15
    Débutant
    Profil pro
    Développeur informatique
    Inscrit en
    Décembre 2008
    Messages
    1 022
    Détails du profil
    Informations personnelles :
    Localisation : France, Mayenne (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2008
    Messages : 1 022
    Points : 332
    Points
    332
    Par défaut J'utilise un shareware
    C'est le parser de Brill,et je ne le change que sur des points locaux les pointeurs ** char sont défini par Brill,et je ne peut les changer sous peine de reprendre toute la logique que je ne maitrise pas;
    la méthode qui ne marche pas est l'interface avec le parser de Brill et donc utilise les types de Brill.
    je vous met la méthode et l'analyse de ce qui marche et de ce qui ne marche pas.
    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
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    static char buffer[BUF_SIZE];
    static char bufsortie[BUF_SIZE];
    char* WorkTagger( char* buf)
    {
      int len = 0;
      int len2 = 0;
      char* pWord;
      char* bufsec;
      char** buftemp;
      char* buff[BUF_SIZE];
      char** buffe;
      int i;
     
    	try
    	{
    		buffe = new char*();
    		pWord = strtok_s( buf, " ", &bufsec);
    		len = 1;
    		i = 0;
    		while( pWord != nullptr)
    		{
    			buftemp = StartStateTagger( &pWord, 1, lexicon_hash, good_right_hash, good_left_hash, bigramArray, lRuleArray);
    			len += strlen( *buftemp);
    			strcat_s( buffer, len, *buftemp);
    			pWord = strtok_s( NULL, " ", &bufsec);
    			i++;
    		}
    		*buffe = (char*)"";
    		len2 = strlen( buffer);
    		strcpy_s( (char*)*buffe, len2 + 1, buffer);
    		FinalStateTagger( buffe, 1, seenTagging_hash, lexicon_hash, cRuleArray, bufsortie);
    		len = strlen( bufsortie);
    		strcpy_s( *buffe, len + 1, bufsortie);
    		delete *buffe;
    	}
      catch( ...)
      {
    	  buffe[0] = (char*)-1;
    	  buffe[1] = 0;
    	  delete *buffe;
      }
      return( *buffe);
    }
    après l'affectation de la chaine vide *buffe = (char*)""; buffe = 0x0D37AEF0 ( sur la pile) est un pointeur qui pointe sur un pointeur *buffe = 0x00101476 (sur le tas) lequel est 0;
    sa ça marche.
    le strcpy_s a en entrée len = 832 et buffer avec une chaine consistante et buffe = 0x0037AEF0, *buffe = 0x00101476, et **buffe = 0 et la ça plante

  16. #16
    Expert éminent sénior
    Avatar de Médinoc
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2005
    Messages
    27 369
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2005
    Messages : 27 369
    Points : 41 519
    Points
    41 519
    Par défaut
    En clair, tu as un code du Brill tagger en C (ou en très mauvais C++) et tu cherches à l'utiliser/le modifier dans un programme en mauvais C++, que tu compiles accidentellement en tant que C++/CLI, alors que tu ne comprends aucun de ces trois langages?
    SVP, pas de questions techniques par MP. Surtout si je ne vous ai jamais parlé avant.

    "Aw, come on, who would be so stupid as to insert a cast to make an error go away without actually fixing the error?"
    Apparently everyone.
    -- Raymond Chen.
    Traduction obligatoire: "Oh, voyons, qui serait assez stupide pour mettre un cast pour faire disparaitre un message d'erreur sans vraiment corriger l'erreur?" - Apparemment, tout le monde. -- Raymond Chen.

  17. #17
    Débutant
    Profil pro
    Développeur informatique
    Inscrit en
    Décembre 2008
    Messages
    1 022
    Détails du profil
    Informations personnelles :
    Localisation : France, Mayenne (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2008
    Messages : 1 022
    Points : 332
    Points
    332
    Par défaut je connais
    un peu le C++ que j'utilise depuis longtemps, un peu le C++/CLI que j'utilise depuis 2 ans. Quand je ne sais pas je le dis.
    mon programme comprend 80% de code managé et deux sharware (WordNet et Brill) WordNet est en C et Brill en C++.

  18. #18
    Expert éminent sénior
    Avatar de Médinoc
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2005
    Messages
    27 369
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2005
    Messages : 27 369
    Points : 41 519
    Points
    41 519
    Par défaut
    Puis-je voir la documentation et/ou le code de StartStateTagger() et FinalStateTagger()?
    SVP, pas de questions techniques par MP. Surtout si je ne vous ai jamais parlé avant.

    "Aw, come on, who would be so stupid as to insert a cast to make an error go away without actually fixing the error?"
    Apparently everyone.
    -- Raymond Chen.
    Traduction obligatoire: "Oh, voyons, qui serait assez stupide pour mettre un cast pour faire disparaitre un message d'erreur sans vraiment corriger l'erreur?" - Apparemment, tout le monde. -- Raymond Chen.

  19. #19
    Expert éminent sénior
    Avatar de Médinoc
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2005
    Messages
    27 369
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2005
    Messages : 27 369
    Points : 41 519
    Points
    41 519
    Par défaut
    Addendum: Oh là là, ta fonction retourne un pointeur sur une zone mémoire que tu viens de libérer!
    SVP, pas de questions techniques par MP. Surtout si je ne vous ai jamais parlé avant.

    "Aw, come on, who would be so stupid as to insert a cast to make an error go away without actually fixing the error?"
    Apparently everyone.
    -- Raymond Chen.
    Traduction obligatoire: "Oh, voyons, qui serait assez stupide pour mettre un cast pour faire disparaitre un message d'erreur sans vraiment corriger l'erreur?" - Apparemment, tout le monde. -- Raymond Chen.

  20. #20
    Débutant
    Profil pro
    Développeur informatique
    Inscrit en
    Décembre 2008
    Messages
    1 022
    Détails du profil
    Informations personnelles :
    Localisation : France, Mayenne (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2008
    Messages : 1 022
    Points : 332
    Points
    332
    Par défaut le pointeur sur le tas
    Je viens de l'allouer et je ne le détruit qu'après usage. sinon c'est que je ne sait pas ce que je fais.
    J'ai déplacé le new pour le mettre juste avant de l'utiliser
    J'ai le message (comme si l'allocation s'était faite sur un endroit protégé) :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    Exception de première chance à 0x740948e2 (msvcr100.dll) dans SpecificationLoader.exe*: 0xC0000005: Violation d'accès lors de l'écriture à l'emplacement 0x00251476.
    Une exception de première chance de type 'System.AccessViolationException' s'est produite dans SpecificationLoader.exe
     
    Informations supplémentaires*: Tentative de lecture ou d'écriture de mémoire protégée. Cela indique souvent qu'une autre mémoire est endommagée.
    je vous met le code de BTaggerc.cpp
    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
    34
    35
    36
    37
    38
    39
    40
    41
    42
    char* WorkTagger( char* buf)
    {
      int len = 0;
      int len2 = 0;
      char* pWord;
      char* bufsec;
      char** buftemp;
      char* buff[BUF_SIZE];
      char** buffe;
      int i;
     
    	try
    	{
     
    		pWord = strtok_s( buf, " ", &bufsec);
    		len = 1;
    		i = 0;
    		while( pWord != nullptr)
    		{
    			buftemp = StartStateTagger( &pWord, 1, lexicon_hash, good_right_hash, good_left_hash, bigramArray, lRuleArray);
    			len += strlen( *buftemp);
    			strcat_s( buffer, len, *buftemp);
    			pWord = strtok_s( NULL, " ", &bufsec);
    			i++;
    		}
    		buffe = new char*();
    		*buffe = (char*)"";
    		len2 = strlen( buffer);
    		strcpy_s( (char*)*buffe, len2 + 1, buffer);
    		FinalStateTagger( buffe, 1, seenTagging_hash, lexicon_hash, cRuleArray, bufsortie);
    		len = strlen( bufsortie);
    		strcpy_s( *buffe, len + 1, bufsortie);
    		delete *buffe;
    	}
      catch( ...)
      {
    	  buffe[0] = (char*)-1;
    	  buffe[1] = 0;
    	  delete *buffe;
      }
      return( *buffe);
    }
    je vous met le code des deux primitives que vous avez demandé StartStateTagger :
    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
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    540
    541
    542
    543
    544
    545
    546
    547
    548
    549
    550
    551
    552
    553
    554
    555
    556
    557
    558
    559
    560
    561
    562
    563
    564
    565
    566
    567
    568
    569
    570
    571
    572
    573
    574
    575
    576
    577
    578
    579
    580
    581
    582
    583
    584
    585
    586
    587
    588
    589
    590
    591
    592
    593
    594
    595
    596
    597
    598
    599
    600
    601
    602
    603
    604
    605
    606
    607
    608
    609
    610
    611
    612
    613
    614
    615
    616
    617
    618
    619
    620
    621
    622
    623
    624
    625
    626
    627
    628
    629
    630
    631
    632
    633
    634
    635
    636
    637
    638
    639
    640
    641
    642
    char **StartStateTagger(char **buffer, int numSen, Registry lexicon_hash,
    			Registry good_right_hash, Registry good_left_hash,
    			Darray bigramArray, Darray lRuleArray)
    {
    	char *bufp;
    	char *atempptr;
    	char line[MAXLINELEN];      /* input line buffer */
    	char *linecopy;
        Darray_rep tarrayK;
        Darray_rep tarrayV;
        Darray tag_array_key;
    	Darray tag_array_val;
    	char *tempstr, *tempstr2;
    	char **perl_split_ptr,**temp_perl_split_ptr,**therule,**therule2;
    	char bigram1[MAXWORDLEN],bigram2[MAXWORDLEN];
    	char noun[10],proper[10];
    	int count,count2,count3,rulesize,tempcount, numwords, i, j;
    	char tempstr_space[MAXWORDLEN+MAXAFFIXLEN],bigram_space[MAXWORDLEN*2];
    	int temp;
        int len;
    	Registry tag_hash,ntot_hash,bigram_hash;
    	// added by Benjamin Han for freeing all allocated char*
    	int first;
        Darray_rep fptr;
    	Darray freeptrs;
        char *assigned;
     
        *OldBuffer = "";
        tag_array_key = &tarrayK;
        tag_array_val = &tarrayV;
        freeptrs = &fptr;
    	ntot_hash = Registry_create(Registry_strcmp,Registry_strhash);
    	bigram_hash = Registry_create(Registry_strcmp,Registry_strhash);
    	/* Read in corpus to be tagged.  Actually, just record word list, */
    	/* since each word will get the same tag, regardless of context. */
    	for( i=0; i < numSen; i++)
        {
    	  temp = strlen(buffer[i]);
    	  len = (temp+1)*(sizeof(char));
    	  linecopy = new char[ len];
    	  strcpy_s(linecopy, temp + 1, buffer[i]);
    	  if (not_just_blank(linecopy))
          {
    	    len = ((temp=num_words(linecopy)+1)*sizeof(char));
            assigned = new char[ len];
    	    perl_split_ptr = perl_split_independent(linecopy);
    	    for (temp_perl_split_ptr = perl_split_ptr, j=0; *temp_perl_split_ptr != NULL; j++,++temp_perl_split_ptr)
            {
    	      if (Registry_get(lexicon_hash,(char *)*temp_perl_split_ptr) == NULL)
              {
    			if (Registry_add(ntot_hash,(char *)*temp_perl_split_ptr, (char *)1) == Bool_FALSE)
    				assigned[j]=0;
    			else
    				assigned[j]=1;
    		  // Added by Benjamin Han: it's not part of Brill's algorithm.
    		  //                        Doe it help?
    		  // for the words not found in the lexicon we add the
    		  // surrounding bigrams into bigram_hash for the
    		  // good_left/right and fgood_left/right lexical rules
    		  size_t len;
    		  if (j!=0 && j!=temp-1)
    		  {
    		      // int sprintf_s( char *buffer, size_t sizeOfBuffer, const char *format [, argument] ...);
    			  len = strlen( bigram_space);
    			  len += strlen( *temp_perl_split_ptr);
    			  len += strlen( *(temp_perl_split_ptr+1));
    			  sprintf_s( bigram_space, len + 2, "%s %s", (char *)*temp_perl_split_ptr, (char *)*(temp_perl_split_ptr+1));
    		      len = strlen( bigram_space);
    			  len += strlen( *(temp_perl_split_ptr-1));
    			  len += strlen( *temp_perl_split_ptr);
    			  Registry_add( bigram_hash, mystrdup(bigram_space), (char *)1);
    		      sprintf_s( bigram_space, len + 2, "%s %s", (char *)*(temp_perl_split_ptr-1), (char *)*temp_perl_split_ptr);
    		      Registry_add(bigram_hash,mystrdup(bigram_space), (char *)1);
    		  }
    		  else if (j!=temp-1)
    		  {
    		    len = strlen( bigram_space);
    			len += strlen( *temp_perl_split_ptr);
    			if( (temp_perl_split_ptr+1) == nullptr)
    				len += strlen( *(temp_perl_split_ptr+1));     
    			sprintf_s( bigram_space, len + 2, "%s %s", (char *)*temp_perl_split_ptr, (char *)*(temp_perl_split_ptr+1));
    		    Registry_add( bigram_hash, mystrdup(bigram_space), (char *)1);
    		  }
    		  else if (j!=0)
    		  {
    		      len = strlen( bigram_space);
    			  len += strlen( *temp_perl_split_ptr);
    			  len += strlen( *(temp_perl_split_ptr-1));  
    			  sprintf_s( bigram_space, len + 2, "%s %s", (char *)*(temp_perl_split_ptr-1), (char *)*temp_perl_split_ptr);
    		      Registry_add(bigram_hash,mystrdup(bigram_space), (char *)1);
    		  }
    	      }
    	      else
                    assigned[j]=0;
            } // end for
    	    for (temp_perl_split_ptr = perl_split_ptr,j=0;j<temp; j++,++temp_perl_split_ptr)
    	      if (!assigned[j])
                     delete(*temp_perl_split_ptr);
    	    delete(perl_split_ptr);
                delete(assigned);
    	  }
    	  delete(linecopy);;
    	}
    	Darray_create( tag_array_key);
        Darray_create( tag_array_val);
    	Registry_fetch_contents(ntot_hash,tag_array_key,tag_array_val);
    	// Benjamin Han: Now tag_array_val contains a bunch of (char*)1
    	/*  READ IN THE BIGRAM HERE (from bigramArray) */
    	// Benjamin Han: we're sure that every element in bigramArray
    	// is of length > 1, as initialized in function Tagger
    	for(i=0; i < (int)Darray_len(bigramArray); i++)
    	{
    	  // int sscanf_s( const char *buffer, const char *format [, argument ] ...);
    	  sscanf( (char*)Darray_get(bigramArray,i), "%s%s", bigram1, bigram2);
    	  if (Registry_get(good_right_hash,bigram1) && Registry_get(ntot_hash,bigram2))
    	  {
    	    len = strlen( bigram_space);
    		len += strlen( bigram1);
    		len += strlen( bigram2);
    		sprintf_s( bigram_space, len, "%s %s", bigram1, bigram2);
    	    Registry_add(bigram_hash,mystrdup(bigram_space), (char *)1);
    	  }
    	  if (Registry_get(good_left_hash,bigram2) &&
    	      Registry_get(ntot_hash,bigram1)) {
    	     len = strlen( bigram_space);
    		 len += strlen( bigram1);
    		 len += strlen( bigram2);
    	     sprintf_s( bigram_space, len, "%s %s", bigram1, bigram2);
    	     Registry_add(bigram_hash,mystrdup(bigram_space),(char *)1);
    	  }
    	}
    /********** START STATE ALGORITHM
      YOU CAN USE OR EDIT ONE OF THE TWO START STATE ALGORITHMS BELOW, 
      # OR REPLACE THEM WITH YOUR OWN ************************/
    	strcpy_s( noun, 3, "NN");
    	strcpy_s( proper, 4, "NNP");
    /* UNCOMMENT THIS AND COMMENT OUT START STATE 2 IF ALL UNKNOWN WORDS
       SHOULD INITIALLY BE ASSUMED TO BE TAGGED WITH "NN".
       YOU CAN ALSO CHANGE "NN" TO A DIFFERENT TAG IF APPROPRIATE. */
          /*** START STATE 1 ***/
    /*   for (count=0; count < Darray_len(tag_array_val);++count) 
    	Darray_set(tag_array_val,count,noun); */
    /* THIS START STATE ALGORITHM INITIALLY TAGS ALL UNKNOWN WORDS WITH TAG
       "NN" (singular common noun) UNLESS THEY BEGIN WITH A CAPITAL LETTER, 
       IN WHICH CASE THEY ARE TAGGED WITH "NNP" (singular proper noun)
       YOU CAN CHANGE "NNP" and "NN" TO DIFFERENT TAGS IF APPROPRIATE.*/
         /*** START STATE 2 ***/
    	for (count=0; count < (int)Darray_len(tag_array_val);++count)
    	{
    		if (((char *)Darray_get(tag_array_key,count))[0] >='A' && ((char *)Darray_get(tag_array_key,count))[0] <= 'Z') 
    			Darray_set(tag_array_val,count,proper); 
    		else
    		Darray_set(tag_array_val,count,noun);  
    	}
    /******************* END START STATE ALGORITHM ****************/
        Darray_create( freeptrs);
    	for (count=0,first=1;count < (int)Darray_len(lRuleArray);++count,first=1)
    	{
    		len = strlen( (char*)Darray_get(lRuleArray,count));
    		strcpy_s( line, len + 1, (char *)Darray_get(lRuleArray,count));
    		/*fprintf(stderr,"RULE IS: %s\n",line);*/
    		/*fprintf(stderr,"s");*/
    		therule = perl_split_independent(line);
    		// Benjamin Han: the following comment is TOTALLY UNTRUE!
    		/* we don't worry about freeing "rule" space, as this is a small fraction
    		of total memory used */
    		therule2 = &therule[1];
    		rulesize=0;
    		perl_split_ptr = therule;
    		while(*(++perl_split_ptr) != NULL)
    		{
    			++rulesize;
    		}
    		// Benjamin Han: STRANGE THING: rulesize is actually one
    		// less than the real rule size -- that explains why in
    		// LEXICALRULEFILE we have those trailing useless x's and
    		// why we always use therule[rulesize-1] in Darray_set()
    		// Also note perl_split_independent does strange things
    		// also: it allocates 1 more elem beyond the one storing
    		// NULL (NULL is used to signal the end of the array)
    		if (strcmp(therule[1],"char") == 0)
    		{
    			for (count2=0;count2<(int)Darray_len(tag_array_key);++count2)
    			{
    				if (strcmp((const char*)Darray_get(tag_array_val,count2),(const char*)therule[rulesize-1]) !=0)
    				{
    					if(strpbrk((char*)Darray_get(tag_array_key,count2), (const char*)therule[0]) != NULL)
    					{
    						SetTagVal(tag_array_val,freeptrs,count2,therule[rulesize-1],&first);
    					}
    				}
    			}
    		}
    		else if (strcmp(therule2[1],"fchar") == 0)
    		{
    			for (count2=0;count2<(int)Darray_len(tag_array_key);++count2)
    			{
    				if (strcmp((const char*)Darray_get(tag_array_val,count2),(const char*)therule[0]) ==0)
    				{
    					if(strpbrk((const char*)Darray_get(tag_array_key,count2), (const char*)therule2[0]) != NULL)
    					{
    						SetTagVal(tag_array_val,freeptrs,count2,therule[rulesize-1],&first);
    					}
    				}
    			}
    		}
    		else if (strcmp(therule[1],"deletepref") == 0)
    		{
    			for (count2=0;count2<(int)Darray_len(tag_array_key);++count2)
    			{
    				if (strcmp((const char*)Darray_get(tag_array_val,count2),(const char*)therule[rulesize-1])!=0)
    				{
    					tempstr = (char*)Darray_get(tag_array_key,count2);
    					for (count3=0;count3<atoi(therule[2]);++count3)
    					{
    						if (tempstr[count3] != therule[0][count3])
    							break;
    					}
    					if (count3 == atoi(therule[2]))
    					{
    						tempstr += atoi(therule[2]);
    						if (Registry_get(lexicon_hash,(char *)tempstr) != NULL)
    						{
    							SetTagVal(tag_array_val,freeptrs,count2,therule[rulesize-1],&first);
    						}
    					}
    				}
    			}
    		}
    		else if (strcmp(therule2[1],"fdeletepref") == 0)
    		{
    			for (count2=0;count2<(int)Darray_len(tag_array_key);++count2)
    			{
    				if (strcmp((const char*)Darray_get(tag_array_val,count2),(const char*)therule[0]) == 0)
    				{
    					tempstr=(char*)Darray_get(tag_array_key,count2);
    					for (count3=0;count3<atoi(therule2[2]);++count3)
    					{
    						if (tempstr[count3] != therule2[0][count3])
    							break;
    					}
    					if (count3 == atoi(therule2[2]))
    					{
    						tempstr += atoi(therule2[2]);
    						if (Registry_get(lexicon_hash,(char *)tempstr) != NULL)
    						{
    							SetTagVal(tag_array_val,freeptrs,count2,therule[rulesize-1],&first);
    						}
    					}
    				}
    			}
    		}
    		else if (strcmp(therule[1],"haspref") == 0)
    		{
    			for (count2=0;count2<(int)Darray_len(tag_array_key);++count2)
    			{
    				if (strcmp((const char*)Darray_get(tag_array_val,count2),(const char*)therule[rulesize-1])!=0)
    				{
    					tempstr = (char*)Darray_get(tag_array_key,count2);
    					for (count3=0;count3<atoi(therule[2]);++count3)
    					{
    						if (tempstr[count3] != therule[0][count3])
    							break;
    					}
    					if (count3 == atoi(therule[2]))
    					{
    						SetTagVal(tag_array_val,freeptrs,count2,therule[rulesize-1],&first);
    					}
    				}
    			}
    		}
    		else if (strcmp(therule2[1],"fhaspref") == 0)
    		{
    			for (count2=0;count2<(int)Darray_len(tag_array_key);++count2)
    			{
    				if (strcmp((const char*)Darray_get(tag_array_val,count2),(const char*)therule[0]) == 0)
    				{
    					tempstr=(char*)Darray_get(tag_array_key,count2);
    					for (count3=0;count3<atoi(therule2[2]);++count3)
    					{
    						if (tempstr[count3] != therule2[0][count3])
    							break;
    					}
    					if (count3 == atoi(therule2[2]))
    					{
    						SetTagVal(tag_array_val,freeptrs,count2,therule[rulesize-1],&first);
    					}
    				}
    			}
    		}
    		else if (strcmp(therule[1],"deletesuf") == 0)
    		{
    			for (count2=0;count2<(int)Darray_len(tag_array_key);++count2)
    			{
    				if (strcmp((const char*)Darray_get(tag_array_val,count2),(const char*)therule[rulesize-1])!=0)
    				{
    					tempstr = (char*)Darray_get(tag_array_key,count2);
    					tempcount=strlen(tempstr)-atoi(therule[2]);
    					for (count3=tempcount;count3<(int)strlen(tempstr); ++count3)
    					{
    						if (tempstr[count3] != therule[0][count3-tempcount])
    							break;
    					}
    					if (count3 == (int)strlen(tempstr))
    					{
    						tempstr2 = mystrdup(tempstr);
    						tempstr2[tempcount] = '\0';
    						if (Registry_get(lexicon_hash,(char *)tempstr2) != NULL)
    						{
    							SetTagVal(tag_array_val,freeptrs,count2,therule[rulesize-1],&first);
    						}
    						delete(tempstr2);
    					}
    				}
    			}
    		}
    		else if (strcmp(therule2[1],"fdeletesuf") == 0)
    		{
    			for (count2=0;count2<(int)Darray_len(tag_array_key);++count2)
    			{
    				if (strcmp((const char*)Darray_get(tag_array_val,count2),(const char*)therule[0]) == 0)
    				{
    					tempstr=(char*)Darray_get(tag_array_key,count2);
    					tempcount=strlen(tempstr)-atoi(therule2[2]);
    					for (count3=tempcount;count3<(int)strlen(tempstr); ++count3)
    					{
    						if (tempstr[count3] != therule2[0][count3-tempcount])
    							break;
    					}
    					if (count3 == (int)strlen(tempstr))
    					{
    						tempstr2 = mystrdup(tempstr);
    						tempstr2[tempcount] = '\0';
    						if (Registry_get(lexicon_hash,(char *)tempstr2) != NULL)
    						{
    							SetTagVal(tag_array_val,freeptrs,count2,therule[rulesize-1],&first);
    						}
    						delete(tempstr2);
    					}
    				}
    			}
    		}
    		else if (strcmp(therule[1],"hassuf") == 0)
    		{
    			for (count2=0;count2<(int)Darray_len(tag_array_key);++count2)
    			{
    				if (strcmp((const char*)Darray_get(tag_array_val,count2),(const char*)therule[rulesize-1])!=0)
    				{
    					tempstr = ( char*)Darray_get(tag_array_key,count2);
    					tempcount=strlen(tempstr)-atoi(therule[2]);
    					for (count3=tempcount;count3<(int)strlen(tempstr); ++count3)
    					{
    						if (tempstr[count3] != therule[0][count3-tempcount])
    						break;
    					}
    					if (count3 == (int)strlen(tempstr))
    					{
    						SetTagVal(tag_array_val,freeptrs,count2,therule[rulesize-1],&first);
    					}
    				}
    			}
    		}
    		else if (strcmp(therule2[1],"fhassuf") == 0)
    		{
    			for (count2=0;count2<(int)Darray_len(tag_array_key);++count2)
    			{
    				if (strcmp((const char*)Darray_get(tag_array_val,count2),(const char*)therule[0]) == 0)
    				{
    					tempstr=(char*)Darray_get(tag_array_key,count2);
    					tempcount = strlen(tempstr)-atoi(therule2[2]);
    					for (count3=tempcount;count3<(int)strlen(tempstr); ++count3)
    					{
    						if (tempstr[count3] != therule2[0][count3-tempcount])
    							break;
    					}
    					if (count3 == (int)strlen(tempstr))
    					{
    						SetTagVal(tag_array_val,freeptrs,count2,therule[rulesize-1],&first);
    					}
    				}
    			}
    		}
    		else if (strcmp(therule[1],"addpref") == 0)
    		{
    			for (count2=0;count2<(int)Darray_len(tag_array_key);++count2)
    			{
    				if (strcmp((const char*)Darray_get(tag_array_val,count2),(const char*)therule[rulesize-1]) == 0)
    				{
    					len = strlen( tempstr_space);
    					len += strlen( therule[0]);
    					len += strlen( (char*)Darray_get(tag_array_key,count2));
    					sprintf_s( tempstr_space, len + 1, "%s%s", therule[0], (const char*)Darray_get(tag_array_key,count2));
    					if (Registry_get(lexicon_hash,(char *)tempstr_space) != NULL)
    					{
    						SetTagVal(tag_array_val,freeptrs,count2,therule[rulesize-1],&first);
    					}
    				}
    			}
    		}
    		else if (strcmp(therule2[1],"faddpref") == 0)
    		{
    			for (count2=0;count2<(int)Darray_len(tag_array_key);++count2)
    			{
    				if (strcmp((const char*)Darray_get(tag_array_val,count2),therule[rulesize-1]) == 0)
    				{
    					len = strlen( tempstr_space);
    					len += strlen( therule2[0]);
    					len += strlen( (char*)Darray_get(tag_array_key,count2));
    					sprintf_s( tempstr_space, len + 1, "%s%s", therule2[0], (const char*)Darray_get(tag_array_key,count2));
    					if (Registry_get(lexicon_hash,(char *)tempstr_space) != NULL)
    					{
    						SetTagVal( tag_array_val, freeptrs, count2, therule[rulesize-1], &first);
    					}
    				}
    			}
    		}
    		else if (strcmp(therule[1],"addsuf") == 0)
    		{
    			for (count2=0;count2<(int)Darray_len(tag_array_key);++count2)
    			{
    				if (strcmp((const char*)Darray_get(tag_array_val,count2),(const char*)therule[rulesize-1])!=0)
    				{
    					len = strlen( tempstr_space);
    					len += strlen( therule[0]);
    					len += strlen( (char*)Darray_get(tag_array_key,count2));
    					sprintf_s( tempstr_space, len + 1, "%s%s", Darray_get(tag_array_key,count2), therule[0]);
    					if (Registry_get(lexicon_hash,(char *)tempstr_space) != NULL)
    					{
    						SetTagVal(tag_array_val,freeptrs,count2,therule[rulesize-1],&first);
    					}
    				}
    			}
    		}
    		else if (strcmp(therule2[1],"faddsuf") == 0)
    		{
    			for (count2=0;count2<(int)Darray_len(tag_array_key);++count2)
    			{
    				if (strcmp((const char*)Darray_get(tag_array_val,count2),(const char*)therule[0])==0)
    				{
    					len = strlen( tempstr_space);
    					len += strlen( therule2[0]);
    					len += strlen( (char*)Darray_get(tag_array_key,count2));
    					sprintf_s( tempstr_space, len, "%s%s", (const char*)Darray_get(tag_array_key,count2), therule2[0]);
    					if (Registry_get(lexicon_hash,(char *)tempstr_space) != NULL)
    					{
    						SetTagVal(tag_array_val,freeptrs,count2,therule[rulesize-1],&first);
    					}
    				}
    			}
    		}
    		else if (strcmp(therule[1],"goodleft") == 0)
    		{
    			for (count2=0;count2<(int)Darray_len(tag_array_key);++count2)
    			{
    				if (strcmp((const char*)Darray_get(tag_array_val,count2),(const char*)therule[rulesize-1])!=0)
    				{
    					len = strlen( tempstr_space);
    					len += strlen( therule[0]);
    					len += strlen( (char*)Darray_get(tag_array_key,count2));
    					sprintf_s( bigram_space, len + 1, "%s %s", (const char*)Darray_get( tag_array_key, count2), therule[0]);
    					if (Registry_get(bigram_hash,(char *)bigram_space) != NULL)
    					{
    						SetTagVal(tag_array_val,freeptrs,count2,therule[rulesize-1],&first);
    					}
    				}
    			}
    		}
    		else if (strcmp(therule2[1],"fgoodleft") == 0)
    		{
    			for (count2=0;count2<(int)Darray_len(tag_array_key);++count2)
    			{
    				if (strcmp((const char*)Darray_get(tag_array_val,count2),(const char*)therule[0])==0)
    				{
    					len = strlen( tempstr_space);
    					len += strlen( therule2[0]);
    					len += strlen( (char*)Darray_get(tag_array_key,count2));
    					sprintf_s( bigram_space, len + 1, "%s %s", (const char*)Darray_get(tag_array_key,count2), therule2[0]);
    					if (Registry_get(bigram_hash,(char *)bigram_space) != NULL)
    					{
    						SetTagVal(tag_array_val,freeptrs,count2,therule[rulesize-1],&first);
    					}
    				}
    			}
    		}
    		else if (strcmp(therule[1],"goodright") == 0)
    		{
    			for (count2=0;count2<(int)Darray_len(tag_array_key);++count2)
    			{
    				if (strcmp((const char*)Darray_get(tag_array_val,count2),(const char*)therule[rulesize-1])!=0)
    				{
    					len = strlen( tempstr_space);
    					len += strlen( therule[0]);
    					len += strlen( (char*)Darray_get(tag_array_key,count2));
    					sprintf_s( bigram_space, len + 1, "%s %s", therule[0], (const char*)Darray_get(tag_array_key,count2));
    					if (Registry_get(bigram_hash,(char *)bigram_space) != NULL)
    					{
    						SetTagVal(tag_array_val,freeptrs,count2,therule[rulesize-1],&first);
    					}
    				}
    			}
    		}
    		else if (strcmp(therule2[1],"fgoodright") == 0)
    		{
    			for (count2=0;count2<(int)Darray_len(tag_array_key);++count2)
    			{
    				if (strcmp((const char*)Darray_get(tag_array_val,count2),(const char*)therule[0])==0)
    				{
    					len = strlen( tempstr_space);
    					len += strlen( therule[0]);
    					len += strlen( (char*)Darray_get(tag_array_key,count2));
    					sprintf_s( bigram_space, len + 1, "%s %s", therule2[0], (const char*)Darray_get(tag_array_key,count2));
    					if (Registry_get(bigram_hash,(char *)bigram_space) != NULL)
    					{
    						SetTagVal(tag_array_val,freeptrs,count2,therule[rulesize-1],&first);
    					}
    				}
    			}
    		}
    		// Benjamin Han: he didn't clean after use
    		for (i=0;i<rulesize-1;i++) delete(therule[i]);
    		// Benjamin Han: first==1 indicates that we never set
    		// therule[rulesize-1] to tag_array_val
    		if (first) delete (therule[rulesize-1]);
    		// Benjamin Han: oh my it's an additional (and useless) allocation
    		delete(therule[rulesize]);
    		delete(therule);
    	}
    	/* now go from darray to hash table */
    	tag_hash = Registry_create(Registry_strcmp,Registry_strhash);
    	for (count=0;count<(int)Darray_len(tag_array_key);++count)
            {
    	  Registry_add(tag_hash,(char *)Darray_get(tag_array_key,count),(char *)Darray_get(tag_array_val,count));
            }
    	count=0;
    	for(i=0; i<numSen; i++)
            {
    	  if(not_just_blank(buffer[i]))
              {
    	    // Benjamin Han: STRANGE! num_words returns one less than
    	    // the real count!  what is on earth the difference
    	    // between this and numspaces in Utils/lex.c? oh my.
    	    numwords = num_words(buffer[i])+1;
                len = sizeof(char) * (strlen(buffer[i])+1+(numwords*MAXTAGLEN));
    	    bufp = (char *)new char[ len];
    	    bufp[0]=0;
     	    perl_split_ptr = perl_split(buffer[i]);
    	    temp_perl_split_ptr = perl_split_ptr;
    	    errno_t errno;
    		while (*temp_perl_split_ptr != NULL)
                {
    	      if ((atempptr = strchr(*temp_perl_split_ptr,'/')) != NULL && *(atempptr+1) == '/')
              {
    	        /* a word can be pretagged by putting two slashes between the */
    	        /* word and the tag ::  The boy//NN ate . */
                /* if a word is pretagged, we just spit out the pretagging */
    		    len = strlen( bufp);
    			len += strlen( *temp_perl_split_ptr);
    			errno = strcat_s( bufp, len + 1, *temp_perl_split_ptr);
    		    errno = strcat_s(bufp, len + 1, " ");
              }
    	      else if ((tempstr = (char*)Registry_get(lexicon_hash,*temp_perl_split_ptr)) != NULL)
              {
    		     len = strlen( bufp);
    			 len += strlen( *temp_perl_split_ptr);
    			 errno = strcat_s( bufp, len + 1, *temp_perl_split_ptr);
    			 len++;
    		     errno = strcat_s( bufp, len + 1, "/");
    			 len += strlen( tempstr);
    		     errno = strcat_s( bufp, len + 1, tempstr);
    			 len++;
    	      	 errno = strcat_s( bufp, len + 1, " ");
              }
    	      else
              {
                    char* tempbuf;
    				len = strlen( bufp);
    			    len += strlen( *temp_perl_split_ptr);
    		        errno = strcat_s( bufp, len + 1, *temp_perl_split_ptr);
    				len++;
    		        errno = strcat_s( bufp, len + 1, "/");
                    tempbuf = (char*)Registry_get( tag_hash, *temp_perl_split_ptr );
    				len += strlen( tempbuf);
    		        errno = strcat_s( bufp, len + 1, tempbuf);
    		        errno = strcat_s( bufp, len + 2, " ");
              }
              ++temp_perl_split_ptr;
    	    }
    	    delete(*perl_split_ptr);
    	    delete(perl_split_ptr);
    	    buffer[i] = bufp;
    	  }
    	}
    	// Benjamin Han: the content of tag_hash came from tag_array_*
    	// -- it'll be freed by the later two for-loops on tag_array_*
    	Registry_destroy(tag_hash);
    	// Benjamin Han: the content of ntot_hash was duplicated in
    	// tag_array_key -- it will be deallocated in the for loop
    	// below
    	Registry_destroy(ntot_hash);
    	// Benjamin Han: we DO need to free the content of bigram_hash
    	Registry_traverse(bigram_hash,FreeRegistryEntry,NULL);
    	Registry_destroy(bigram_hash);
    	// Benjamin Han: tag_array_key is first initialized by
    	// Registry_fetch_contents(ntot_hash,tag_array_key,tag_array_val);
    	// and ntot_hash is initialized by
    	// Registry_add(ntot_hash,(char *)*temp_perl_split_ptr,
    	//              (char *)1). NOTE THAT (char *)1 -- IT'S BAD!
    	// Conclusion: it's safe to free every tag_array_key element.
    	for (count=0;count<(int)Darray_len(tag_array_key);++count)
    	  delete((char *)Darray_get(tag_array_key,count));
    	// Benjamin Han: now free all allocated tag values
    	for (count=0;count<(int)Darray_len(freeptrs);++count)
    	  delete((char *)Darray_get(freeptrs,count));
     
       try
            {
               OldBuffer[0] = (char*)&bufferdegarde1;
               // if( *((VOIDP)tag_array_key->storage) != 0xCDCDCDCD)
    		   //{
    		      Darray_destroy(tag_array_key);
    		   //}
               size_t isize;
               if( strcmp(  OldBuffer[0], *buffer) != 0)
               {
                  char * pBuffer = (char*)OldBuffer[0];
                  len = strlen( *buffer);
    			  strcpy_s( pBuffer, len + 1, *buffer);
                  isize = strlen( pBuffer);
                  if( isize > 213)
                  {
    				Darray_destroy(tag_array_val);
    				Darray_destroy(freeptrs);
                  }
               }
               return( buffer);
            }
     
       catch (...)
            {
               return( buffer);
            }
    }
    et FinalStateTagger:
    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
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    540
    541
    542
    543
    544
    545
    546
    547
    548
    549
    550
    551
    552
    553
    554
    555
    556
    557
    558
    559
    560
    561
    562
    563
    564
    565
    566
    567
    568
    569
    570
    571
    572
    573
    574
    575
    576
    577
    578
    579
    580
    581
    582
    583
    584
    585
    586
    587
    588
    589
    590
    591
    592
    593
    594
    595
    596
    597
    598
    599
    600
    601
    602
    603
    604
    605
    606
    607
    608
    609
    610
    611
    612
    613
    614
    615
    616
    617
    618
    619
    620
    char** FinalStateTagger( char **buf, int numSen, Registry seenTagging, Registry words, Darray cRuleArray, char* buff)
    {
            size_t          len;
    		bool            b10 = false;
    		bool            b11 = false;
    		bool            b12 = false;
    		bool            b13 = false;
    		bool            b14 = false;
    		bool            b15 = false;
    		bool            b16 = false;
    		bool            b17 = false;
    		bool            b18 = false;
    		bool            b19 = false;
            char*           temp;
            char            *atempstrptr;
        	char            **word_corpus_array,**tag_corpus_array;
    		int            word_corpus_array_index,tag_corpus_array_index;
    		char          **split_ptr,**split_ptr2;
    		int             corpus_size;
    		int             i = 0;
    		int             count,tempcount1,tempcount2,arraySize;
    		char            old[MAXTAGLEN], newer[MAXTAGLEN], when[50],
    	                tag[MAXTAGLEN], lft[MAXTAGLEN], rght[MAXTAGLEN],
    	                prev1[MAXTAGLEN], prev2[MAXTAGLEN], next1[MAXTAGLEN],
    	                next2[MAXTAGLEN], curtag[MAXTAGLEN],
    	                curwd[MAXWORDLEN],
    	                tempstr[MAXWORDLEN],word[MAXWORDLEN],atempstr2[256];
    	// IMPORTANT: numSen=0 will CAUSE DISASTER!
     
     
    	i = 0;
    	arraySize = 0;
    	while( i < numSen)
    	{
    		if( not_just_blank( buf[0]))
    		{
    			arraySize +=2;
    			arraySize += num_words(buf[0]) + 1;
    		}
    		i++;
    	}
    	len = (sizeof(char *) * arraySize);
    	temp = new char[ len];
    	word_corpus_array = (char**)temp;
    	len = (sizeof(char *) * arraySize);
    	temp = new char[ len];
    	tag_corpus_array = (char**)temp;
    	word_corpus_array_index = tag_corpus_array_index = 0;
    /* read in corpus from buf.  This corpus has already been tagged (output of */
    /* the start state tagger) */
    	for(count=0; count<numSen; count++)
            {
    	  if (not_just_blank(buf[count]))
              {
    	    word_corpus_array[word_corpus_array_index++] = staart;
    	    word_corpus_array[word_corpus_array_index++] = staart;
    	    tag_corpus_array[tag_corpus_array_index++] = staart;
    	    tag_corpus_array[tag_corpus_array_index++] = staart;
    	    split_ptr = perl_split(buf[count]);
    	    split_ptr2 = split_ptr;
    	    while (*split_ptr != NULL)
                {
    	      atempstrptr = strrchr(*split_ptr,'/');
    	      if (atempstrptr == NULL)
                  {
                    // we abort the final state tagger when it makes
                    // errors to dispose of the first state tagger result
                    delete(*split_ptr2);
                    delete(split_ptr2);
                    delete( word_corpus_array);
                    delete(tag_corpus_array);
    		return(buf);
                  }
    	      *atempstrptr = '\0';
    	      ++atempstrptr;
    	      word_corpus_array[word_corpus_array_index++] =
    		mystrdup(*split_ptr);
    	      tag_corpus_array[tag_corpus_array_index++] =
    		mystrdup(atempstrptr);
    	      ++split_ptr;
    	    }
    	    delete(*split_ptr2);
                delete(split_ptr2);
    	  }
    	}
    	// read in rule from cRuleArray, and process each rule
    	corpus_size = tag_corpus_array_index - 1;
    	for( i = 0; i < Darray_len(cRuleArray); i++)
        {
    	  split_ptr = perl_split((char*)Darray_get(cRuleArray,(unsigned int)i));
    	  len = strlen( split_ptr[0]);
    	  strcpy_s( old, len + 1, split_ptr[0]);
    	  len = strlen( split_ptr[1]);
    	  strcpy_s( newer, len + 1, split_ptr[1]);
    	  len = strlen( split_ptr[2]);
    	  strcpy_s( when, len + 1, split_ptr[2]);
    	  if (strcmp(when, "NEXTTAG") == 0 || strcmp(when, "NEXT2TAG") == 0 || strcmp(when, "NEXT1OR2TAG") == 0 || strcmp(when, "NEXT1OR2OR3TAG") == 0 || strcmp(when, "PREVTAG") == 0 || strcmp(when, "PREV2TAG") == 0 || strcmp(when, "PREV1OR2TAG") == 0 || strcmp(when, "PREV1OR2OR3TAG") == 0)
          {
    	      len = strlen( split_ptr[3]);
    		  strcpy_s( tag, len + 1, split_ptr[3]);
    	  }
    	  else if (strcmp(when, "NEXTWD") == 0 || strcmp(when,"CURWD") == 0 || strcmp(when, "NEXT2WD") == 0 || strcmp(when, "NEXT1OR2WD") == 0 || strcmp(when, "NEXT1OR2OR3WD") == 0 || strcmp(when, "PREVWD") == 0 || strcmp(when, "PREV2WD") == 0 || strcmp(when, "PREV1OR2WD") == 0 || strcmp(when, "PREV1OR2OR3WD") == 0)
          {
          }
    	  else if (strcmp(when, "SURROUNDTAG") == 0)
          {
    	     len = strlen( split_ptr[3]);
    		 strcpy_s( lft, len + 1, split_ptr[3]);
    		 len = strlen( split_ptr[4]);
    	     strcpy_s( rght, len + 1, split_ptr[4]);
    	  }
          else if( strcmp(when, "PREVBIGRAM") == 0)
          {
    		  len = strlen( split_ptr[3]);
    		  strcpy_s( prev1, len + 1, split_ptr[3]);
    		  len = strlen( split_ptr[4]);
    	      strcpy_s( prev2, len + 1, split_ptr[4]);
    	  }
          else if( strcmp(when, "NEXTBIGRAM") == 0)
    	  {
    		  len = strlen( split_ptr[3]);
    	      strcpy_s( next1, len + 1, split_ptr[3]);
    		  len = strlen( split_ptr[4]);
     	      strcpy_s(next2, len + 1, split_ptr[4]);
    	  }
          else if( strcmp(when,"LBIGRAM") == 0||strcmp(when,"WDPREVTAG") == 0)
          {
    		  len = strlen( split_ptr[3]);
    	      strcpy_s( prev1, len + 1, split_ptr[3]);
    		  len = strlen( split_ptr[4]);
    	      strcpy_s( word, len + 1, split_ptr[4]);
    	  }
          else if (strcmp(when,"RBIGRAM") == 0 ||strcmp(when,"WDNEXTTAG") == 0)
          {
    		  len = strlen( split_ptr[3]);
    	      strcpy_s( word, len + 1, split_ptr[3]);
    		  len = strlen( split_ptr[4]);
    	      strcpy_s(next1, len + 1, split_ptr[4]);
    	  }
          else if (strcmp(when,"WDAND2BFR")== 0 ||strcmp(when,"WDAND2TAGBFR")== 0)
          {
    		  len = strlen( split_ptr[3]);
    	      strcpy_s( prev2, len + 1, split_ptr[3]);
    		  len = strlen( split_ptr[4]);
    	      strcpy_s( word, len + 1, split_ptr[4]);
     
          }
    	  else if (strcmp(when,"WDAND2AFT")== 0 ||strcmp(when,"WDAND2TAGAFT")== 0)
          {
    		  len = strlen( split_ptr[3]);
    	      strcpy_s( next2, len + 1, split_ptr[3]);
    		  len = strlen( split_ptr[4]);
    	      strcpy_s( word, len + 1, split_ptr[4]);
          }
    	  for (count = 0; count <= corpus_size; ++count)
          {
    		  len = strlen( tag_corpus_array[count]);
    	      strcpy_s( curtag, len + 1, tag_corpus_array[count]);
    	      if (strcmp(curtag, old) == 0)
              {
    	         len = strlen( word_corpus_array[count]);
    			 strcpy_s( curwd, len+1, word_corpus_array[count]);
    	         // int sprintf_s( char *buffer, size_t sizeOfBuffer, const char *format [, argument] ...);
    			 len += strlen( newer);
    			 len += strlen( atempstr2);
    			 sprintf_s( atempstr2, len + 2, "%s %s", curwd, newer);
    			 if (! RESTRICT_MOVE ||! Registry_get(words,curwd) || Registry_get(seenTagging,atempstr2))
    			{
    				if (strcmp(when, "SURROUNDTAG") == 0)
    				{
    					if (count < corpus_size && count > 0)
    					{
    						if (strcmp(lft, tag_corpus_array[count - 1]) == 0 && strcmp(rght, tag_corpus_array[count + 1]) == 0)
    							change_the_tag(tag_corpus_array, newer, count);
    					}
    				}
                    else if (strcmp(when, "NEXTTAG") == 0)
                    {
    					if (count < corpus_size)
    					{
    						if (strcmp(tag,tag_corpus_array[count + 1]) == 0)
    							change_the_tag(tag_corpus_array, newer, count);
    					}
    				}
    				else if (strcmp(when, "CURWD") == 0)
                    {
    					if (strcmp(word, word_corpus_array[count]) == 0)
    						change_the_tag(tag_corpus_array, newer, count);
    				}
    				else if (strcmp(when, "NEXTWD") == 0)
                    {
    					if (count < corpus_size)
    					{
    						if (strcmp(word, word_corpus_array[count + 1]) == 0)
    							change_the_tag(tag_corpus_array, newer, count);
    					}
    				}
    				else if (strcmp(when, "RBIGRAM") == 0)
                    {
    					if (count < corpus_size)
    					{
    						if (strcmp(word, word_corpus_array[count]) == 0 && strcmp(next1, word_corpus_array[count+1]) == 0)
    							change_the_tag(tag_corpus_array, newer, count);
    					}
    				}
    				else if (strcmp(when, "WDNEXTTAG") == 0)
                    {
    					if (count < corpus_size)
    					{
    						if (strcmp(word, word_corpus_array[count]) == 0 && strcmp(next1, tag_corpus_array[count+1]) == 0)
    							change_the_tag(tag_corpus_array, newer, count);
    					}
    				}
    				else if (strcmp(when, "WDAND2AFT") == 0)
                    {
    					if (count < corpus_size-1)
    					{
    						if (strcmp(word, word_corpus_array[count]) == 0 && strcmp(next2, word_corpus_array[count+2]) == 0)
    						change_the_tag(tag_corpus_array, newer, count);
    					}
    				}
    				else if (strcmp(when, "WDAND2TAGAFT") == 0)
                    {
    					if (count < corpus_size-1)
    					{
    						if (strcmp(word, word_corpus_array[count]) == 0 && strcmp(next2, tag_corpus_array[count+2]) == 0)
    							change_the_tag(tag_corpus_array, newer, count);
    					}
    				}
    				else if (strcmp(when, "NEXT2TAG") == 0)
                    {
    					if (count < corpus_size - 1)
    					{
    						if (strcmp(tag, tag_corpus_array[count + 2]) == 0)
    							change_the_tag(tag_corpus_array, newer, count);
    					}
    				}
                    else if (strcmp(when, "NEXT2WD") == 0)
                    {
    					if (count < corpus_size - 1)
    					{
    						if (strcmp(word, word_corpus_array[count + 2]) == 0)
    							change_the_tag(tag_corpus_array, newer, count);
    					}
    				}
                    else if (strcmp(when, "NEXTBIGRAM") == 0)
                    {
    					if (count < corpus_size - 1)
    					{
    						if (strcmp(next1, tag_corpus_array[count + 1]) == 0 && strcmp(next2, tag_corpus_array[count + 2]) == 0)
    							change_the_tag(tag_corpus_array, newer, count);
    					}
    				}
                    else if (strcmp(when, "NEXT1OR2TAG") == 0)
                    {
    					if (count < corpus_size)
    					{
    						if (count < corpus_size-1)
    							tempcount1 = count+2;
    						else
    							tempcount1 = count+1;
    						if (strcmp(tag, tag_corpus_array[count + 1]) == 0 || strcmp(tag, tag_corpus_array[tempcount1]) == 0)
    							change_the_tag(tag_corpus_array, newer, count);
    					}
    				}
                    else if (strcmp(when, "NEXT1OR2WD") == 0)
                    {
    					if (count < corpus_size)
    					{
    						if (count < corpus_size-1)
    							tempcount1 = count+2;
    						else
    							tempcount1 = count+1;
    						if (strcmp(word, word_corpus_array[count + 1]) == 0 || strcmp(word, word_corpus_array[tempcount1]) == 0)
    							change_the_tag(tag_corpus_array, newer, count);
    					}
    				}
                    else if (strcmp(when, "NEXT1OR2OR3TAG") == 0)
                    {
    					if (count < corpus_size)
    					{
    						if (count < corpus_size -1)
    							tempcount1 = count+2;
    						else
    							tempcount1 = count+1;
    						if (count < corpus_size-2)
    							tempcount2 = count+3;
    						else
    							tempcount2 =count+1;
    						if (strcmp(tag, tag_corpus_array[count + 1]) == 0 || strcmp(tag, tag_corpus_array[tempcount1]) == 0 || strcmp(tag, tag_corpus_array[tempcount2]) == 0)
    							change_the_tag(tag_corpus_array, newer, count);
    					}
    				}
                    else if (strcmp(when, "NEXT1OR2OR3WD") == 0)
                    {
    					if (count < corpus_size)
    					{
    						if (count < corpus_size -1)
    							tempcount1 = count+2;
    						else
    							tempcount1 = count+1;
    						if (count < corpus_size-2)
    							tempcount2 = count+3;
    						else
    							tempcount2 =count+1;
    						if (strcmp(word, word_corpus_array[count + 1]) == 0 || strcmp(word, word_corpus_array[tempcount1]) == 0 || strcmp(word, word_corpus_array[tempcount2]) == 0)
    							change_the_tag(tag_corpus_array, newer, count);
    					}
    				}
                    else if (strcmp(when, "PREVTAG") == 0)
                    {
    		  if (count > 0)
                      {
    		    if (strcmp(tag, tag_corpus_array[count - 1]) == 0)
                        {
    		      change_the_tag(tag_corpus_array, newer, count);
    		    }
    		  }
    		}
                    else if (strcmp(when, "PREVWD") == 0)
                    {
    		  if (count > 0)
                      {
    		    if (strcmp(word, word_corpus_array[count - 1]) == 0)
                        {
    		      change_the_tag(tag_corpus_array, newer, count);
    		    }
    		  }
    		}
    		else if (strcmp(when, "LBIGRAM") == 0)
                    {
    		  if (count > 0)
                      {
    		    if (strcmp(word, word_corpus_array[count]) == 0 && strcmp(prev1, word_corpus_array[count-1]) == 0)
    		      change_the_tag(tag_corpus_array, newer, count);
    		  }
    		}
    		else if (strcmp(when, "WDPREVTAG") == 0)
                    {
    		  if (count > 0)
                      {
    		    if (strcmp(word, word_corpus_array[count]) == 0 && strcmp(prev1, tag_corpus_array[count-1]) == 0)
    		      change_the_tag(tag_corpus_array, newer, count);
    		  }
    		}
    		else if (strcmp(when, "WDAND2BFR") == 0)
                    {
    		  if (count > 1)
                      {
    		    if (strcmp(word, word_corpus_array[count]) == 0 && strcmp(prev2, word_corpus_array[count-2]) == 0)
    		      change_the_tag(tag_corpus_array, newer, count);
    		  }
    		}
    		else if (strcmp(when, "WDAND2TAGBFR") == 0)
                    {
    		  if (count > 1)
                      {
    		    if (strcmp(word, word_corpus_array[count]) == 0 && strcmp(prev2, tag_corpus_array[count-2]) == 0)
    		      change_the_tag(tag_corpus_array, newer, count);
    		  }
    		}
    		else if (strcmp(when, "PREV2TAG") == 0)
                    {
    		  if (count > 1)
                      {
    		    if (strcmp(tag, tag_corpus_array[count - 2]) == 0)
    		      change_the_tag(tag_corpus_array, newer, count);
    		  }
    		}
                    else if (strcmp(when, "PREV2WD") == 0)
                    {
    		  if (count > 1)
                      {
    		    if (strcmp(word, word_corpus_array[count - 2]) == 0)
    		      change_the_tag(tag_corpus_array, newer, count);
    		  }
    		}
                    else if (strcmp(when, "PREV1OR2TAG") == 0)
                    {
    		  if (count > 0)
                      {
    		    if (count > 1)
    		      tempcount1 = count-2;
    		    else
    		      tempcount1 = count-1;
    		    if (strcmp(tag, tag_corpus_array[count - 1]) == 0 || strcmp(tag, tag_corpus_array[tempcount1]) == 0)
    		      change_the_tag(tag_corpus_array, newer, count);
    		  }
    		}
                    else if (strcmp(when, "PREV1OR2WD") == 0)
                    {
    		  if (count > 0)
                      {
    		    if (count > 1)
    		      tempcount1 = count-2;
    		    else
    		      tempcount1 = count-1;
    		    if (strcmp(word, word_corpus_array[count - 1]) == 0 || strcmp(word, word_corpus_array[tempcount1]) == 0)
    		      change_the_tag(tag_corpus_array, newer, count);
    		  }
    		}
                    else if (strcmp(when, "PREV1OR2OR3TAG") == 0)
                    {
    		  if (count > 0)
                      {
    		      if (count>1)
    			tempcount1 = count-2;
    		      else
    			tempcount1 = count-1;
    		      if (count >2)
    			tempcount2 = count-3;
    		      else
    			tempcount2 = count-1;
    		      if (strcmp(tag, tag_corpus_array[count - 1]) == 0 || strcmp(tag, tag_corpus_array[tempcount1]) == 0 || strcmp(tag, tag_corpus_array[tempcount2]) == 0)
    			change_the_tag(tag_corpus_array, newer, count);
    		    }
    		}
                    else if (strcmp(when, "PREV1OR2OR3WD") == 0)
                    {
    		  if (count > 0)
                      {
    		    if (count>1)
    		      tempcount1 = count-2;
    		    else
    		      tempcount1 = count-1;
    		    if (count >2)
    		      tempcount2 = count-3;
    		    else
    		      tempcount2 = count-1;
    		    if (strcmp(word, word_corpus_array[count - 1]) == 0 || strcmp(word, word_corpus_array[tempcount1]) == 0 || strcmp(word, word_corpus_array[tempcount2]) == 0)
    		      change_the_tag(tag_corpus_array, newer, count);
    		  }
    		}
                    else if (strcmp(when, "PREVBIGRAM") == 0)
                    {
    		  if (count > 1)
                      {
    		    if (strcmp(prev2, tag_corpus_array[count - 1]) == 0 && strcmp(prev1, tag_corpus_array[count - 2]) == 0)
    		      change_the_tag(tag_corpus_array, newer, count);
    		  }
    		}
    		else
    		  fprintf(stderr, "ERROR: %s is not an allowable transform type\n", when);
    	      }
    	    }
    	  }  /* end: for (count =0; count <= corpus_size; ++count) */
    	  delete(*split_ptr);      // leak plugged by Benjamin Han
    	  delete(split_ptr);
    	}  /* end: for (i=0;i<Darray_get(cRuleArray);i++) */
            i=0;
    		len = strlen( buf[i]);
    		strcpy_s( buff, len + 1, buf[i]);
            buff[0]=0;
    		bool bwordadded = false;
    		for (count = 0; count <= corpus_size; ++count)
            {
    		  len = strlen( tag_corpus_array[count]);
    		  b13 = strcmp( oldwd, "to") == 0 && strcmp( olderwd, "set") == 0;
    		  b14 = strcmp( oldwd, "button") == 0 && strcmp( olderwd, "the") == 0;
    		  b15 = strcmp( oldwd, "(") == 0 && strcmp( olderwd, "buttons") == 0;
    		  b16 = strcmp( oldwd, "is") == 0 && strcmp( olderwd, "PLCM") == 0;
    		  b17 = strcmp( oldwd, "(") == 0 && strcmp( olderwd, "the") == 0;
    		  b18 = strcmp( oldwd, "and") == 0 && strcmp( olderwd, "open") == 0;
    		  b19 = strcmp( oldwd, "button") == 0 && strcmp( olderwd, "open") == 0;
    		  b11 = b13 || b14  || b15 || b16 || b17 || b18 || b19;
    		  b12 = strcmp( word_corpus_array[count], "open" ) == 0 || strcmp( word_corpus_array[count], "close" ) == 0;
    		  strcpy_s( tempstr, len + 1, tag_corpus_array[count]);
              if (strcmp(tempstr,"STAART")==0 && strcmp(tag_corpus_array[count + 1],"STAART")==0 && count)
              {
                ++i;
                len = strlen( buf[i]);
    		    strcpy_s( buff, len + 1, buf[i]);
    	        buff[0]=0;
              }
              else if (strcmp(tempstr,"STAART"))
              {
                // ici on implante les exceptions
                // on a dans word_corpus_array[count] le terme à traiter et dans tempsstr le tag correspondant
                if( strcmp( word_corpus_array[count], "drives") == 0)
                {
                   if( strcmp( tempstr, "NNS") == 0)
    			   {
                      strcpy_s( tempstr, 4, "VBZ");
    			   }
                }
    			else if( strcmp( word_corpus_array[count], "DRL001-A-v1when") == 0)
    			{
    				// il faut faire avancer count de 1 pour séparer les deux mots
    				strcpy_s( word_corpus_array[count], 12, "DRL001-A-v1");
    				strcpy_s( tempstr, 3 , "CD");
    				len = strlen( word_corpus_array[count]);
    				len += strlen( buff);
    				errno = strcat_s( buff, len + 1, word_corpus_array[count]);
    				len++;
    				errno = strcat_s(buff, len + 1, "/");
    				len += strlen( tempstr) + 1;
    				errno = strcat_s( buff, len + 1, tempstr);
    				len++;
    				errno = strcat_s(buff, len + 1, " ");
    				count++;
    				bwordadded = true;
    				strcpy_s( word_corpus_array[count], 5, "when");
    				strcpy_s( tempstr, 3, "WR");
    			}
    			else if( strcmp( word_corpus_array[count], "Can" ) == 0)
                {
                   if( strcmp( tempstr, "MD") == 0)
                      strcpy_s( tempstr, 4, "NNP");
                }
                else if( strcmp( word_corpus_array[count], "CAN" ) == 0)
                {
                   if( strcmp( tempstr, "MD") == 0)
                      strcpy_s( tempstr, 4, "NNP");
                }
                else if( strcmp( word_corpus_array[count], "state" ) == 0)
                {
                   if( strcmp( tempstr, "NN") == 0 && !strcmp( oldwd, "current") == 0)
    					strcpy_s( tempstr, 3, "VB");
                }
    			else if( strcmp( word_corpus_array[count], "returns" ) == 0)
    			{
    				if( strcmp( tempstr, "NNS") == 0)
                      strcpy_s( tempstr, 3,"VB");
    			}
    			else if( strcmp( word_corpus_array[count], "changes" ) == 0)
                {
                   if( strcmp( tempstr, "NNS") == 0)
                      strcpy_s( tempstr, 3,"VB");
                }
    			else if( strcmp( word_corpus_array[count], "ON" ) == 0)
                {
                      strcpy_s( tempstr, 4,"NNP");
                }
    			else if( strcmp( word_corpus_array[count], "states" ) == 0)
                {
                   if( strcmp( tempstr, "NNS") == 0 && !isdigit( oldwd[0]))
                      strcpy_s( tempstr, 3,"VB");
                }
    			else if( strcmp( word_corpus_array[count], "links" ) == 0)
                {
                   if( strcmp( tempstr, "NNS") == 0)
                      strcpy_s( tempstr, 3,"VB");
                }
    			else if( strcmp( word_corpus_array[count], "works" ) == 0)
    			{
    				if( strcmp( tempstr, "NNS") == 0)
    					strcpy_s(tempstr, 3, "VB");
    			}
    			else if( strcmp( word_corpus_array[count], "sets" ) == 0)
                {
                   if( strcmp( tempstr, "NNS") == 0)
                      strcpy_s( tempstr, 3, "VB");
                }
                else if( strcmp( word_corpus_array[count], "T_tailgate_longpress_timer" ) == 0)
                {
                      strcpy_s( tempstr, 4, "NNP");
                }
                else if( strcmp( word_corpus_array[count], "T_EnableDecklidRelease" ) == 0)
                {
                      strcpy_s( tempstr, 4, "NNP");
                }//    1 2      3                                  2               3                                  2     1     2       3            2               3               2               3           2               3                   2          3             2               3                210
                else if( b12 == true && b11 == true)
    			{//   1  2     3              2               3               210
    				strcpy_s(tempstr, 4, "NNP");
    			}
    			else if( strcmp( word_corpus_array[count], "open" ) == 0)
                {
                   strcpy_s( tempstr, 3, "VB");
                }
                else if( strcmp( word_corpus_array[count], "Lift" ) == 0)
                {
                   if( strcmp( tempstr, "VB") == 0)
                      strcpy_s( tempstr, 3, "NN");
                }
                else if( strcmp( word_corpus_array[count], "CRM_TaillatchOpeningCnt" ) == 0 || strcmp( word_corpus_array[count], "CRM_TaillatchOpening" ) == 0)
                {
                   if( strcmp( tempstr, "IN") == 0 || strcmp( tempstr, "VBG") == 0)
                      strcpy_s( tempstr, 4, "NNP");
                }
    			else if( strcmp( word_corpus_array[count], "increase")  == 0 || strcmp( word_corpus_array[count], "increases")  == 0 || strcmp( word_corpus_array[count], "decrease") == 0 || strcmp( word_corpus_array[count], "decreases") == 0)
                {
                   if( strcmp( tempstr, "NN") == 0 || strcmp( tempstr, "NNS") == 0 )
                      strcpy_s( tempstr, 3, "VB");
                }
                else if( isdigit( word_corpus_array[count][0]) > 0)
                {
                   if( strcmp( tempstr, "NN") == 0)
                      strcpy_s( tempstr, 3, "CD");
                }
                len = strlen( word_corpus_array[count]);
    			len += strlen( buff);
    			errno = strcat_s( buff, len + 1, word_corpus_array[count]);
    			len++;
                errno = strcat_s(buff, len + 1, "/");
    			len += strlen( tempstr) + 1;
                errno = strcat_s( buff, len + 1, tempstr);
    			len++;
    			errno = strcat_s(buff, len + 1, " ");
    			if( bwordadded == true)
    			{
    				count--;
    				bwordadded = false;
    			}
              }
    		  len = strlen( oldwd);
    		  strcpy_s( olderwd, len+1, oldwd);
    		  len = strlen( word_corpus_array[count]);
    		  strcpy_s( oldwd, len + 1, word_corpus_array[count]);
            }
    	// Benjamin Han: Gee... these puppies need to be freed...
    	for (i=0;i<arraySize;i++)
            {
    	    if (word_corpus_array[i]!=staart) delete(word_corpus_array[i]);
    	    if (tag_corpus_array[i]!=staart && tag_corpus_array[i]!= newer)
    	      delete(tag_corpus_array[i]);
            }
    	delete(word_corpus_array);
    	delete(tag_corpus_array);
    	return( (char**)&buff);
    }

+ Répondre à la discussion
Cette discussion est résolue.
Page 1 sur 2 12 DernièreDernière

Discussions similaires

  1. [Débutant] Passage de paramètre qui ne fonctionne pas
    Par Stef999 dans le forum C#
    Réponses: 1
    Dernier message: 09/11/2015, 14h22
  2. Réponses: 2
    Dernier message: 02/11/2015, 14h26
  3. le passage de paramètre échoue dans une application managée
    Par JeanNoel53 dans le forum Visual C++
    Réponses: 1
    Dernier message: 02/11/2015, 14h23
  4. Réponses: 2
    Dernier message: 14/02/2008, 19h31
  5. Passage de paramètres en url qui marche pas
    Par debilemaniac dans le forum Langage
    Réponses: 9
    Dernier message: 30/05/2006, 16h29

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