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

C++Builder Discussion :

manipuler les balises dans fichier xml


Sujet :

C++Builder

  1. #1
    Membre du Club
    Inscrit en
    Mars 2009
    Messages
    61
    Détails du profil
    Informations personnelles :
    Âge : 36

    Informations forums :
    Inscription : Mars 2009
    Messages : 61
    Points : 65
    Points
    65
    Par défaut manipuler les balises dans fichier xml
    slt,je voudrais écrire dans un fichier xml pour faire le groupage des phrases,exemple:
    l'oiseau pose ses pattes sur une brache;
    mon fichier xml
    Code xml : 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
    <phrase>
     
    <GN> // groupe nominal 1
       <det nombre=" l' ">
           <NOM nombre="oiseau">
    <\GN> //groupe nominal 1
                                      <GN>  //groupe verbale 3
    <GV> // groupe verbale 1
         <verbe nombre="pose">
     
    <GV>  // groupe verbale 2
     
         <GN> //groupe nominal 2
             <det nombre="ses"> <NOM nombre="pattes"> 
                        <\GN> //groupe nominal 2
     
               <\GV> // groupe verbale 2
     
    <GP> //groupe prépositionnel 1
           <pré nombre="sur">
     
        <GN>  //groupe nominal 3
                   <det nombre="une">
                   <NOM nombre="brache">
                 <\GN>  //groupe nominal 3
     
           <\GP> //groupe prépositionnel 1
                                                   <\GV>  //groupe verbale 3
    <\phrase>
    merci d'avance

  2. #2
    Expert éminent sénior
    Avatar de ShaiLeTroll
    Homme Profil pro
    Développeur C++\Delphi
    Inscrit en
    Juillet 2006
    Messages
    13 576
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Seine Saint Denis (Île de France)

    Informations professionnelles :
    Activité : Développeur C++\Delphi
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2006
    Messages : 13 576
    Points : 25 216
    Points
    25 216
    Par défaut

    cela fonctionne aussi pour le XML, il suffit de faire [ CODE=xml]
    Code xml : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    <phrase>
      <GN> // groupe nominal 1
        <det nombre=" l' ">

    Peux-tu fournir une tentative de code ? Je suppose que tu as commencé avec le TXMLDocument fourni par C++Builder qui souvent utilise comme Vendor MSXML - XML DOM Objects/Interfaces

    Quelle est la question ?
    Où en es-tu dans ton développement ?
    As-tu déjà découpé la phrase, par un SplitString ou ExtractStrings ?

    Comment as-tu prévu de gérer la détection du groupe de chaque Mot ? C'est assez proche de la phase de "analyse lexicale" d'un compilateur !
    Cela utilise une sorte de dictionnaire ! C'est possible à faire pour un langage humain mais cela demande une Énorme base de données !

    En fait, tu vas passer aussi par la phase Analyse sémantique pour générer ton arbre ! Effectivement deux mots présents dans le dictionnaire en fonction de leur emplacement pourra être un verve, un mot, tout dépend du contexte !
    On est toujours dans la compilation !

    Il pourrait y avoir une méthode plus simple de groupage qui ne fonctionnerait que pour des phrases ayant la même structure (même nombre de mot !) donc peu intéressante !

    Dans quelle cadre, tu prévois de développer cela ? Tu veux faire yn programme genre "Correcteur Grammatical" ou un "Chatterbot - Agent conversationnel", le truc à la mode avec la reconnaissance vocale de iPhone 4S

  3. #3
    Membre du Club
    Inscrit en
    Mars 2009
    Messages
    61
    Détails du profil
    Informations personnelles :
    Âge : 36

    Informations forums :
    Inscription : Mars 2009
    Messages : 61
    Points : 65
    Points
    65
    Par défaut
    Citation Envoyé par ShaiLeTroll Voir le message

    cela fonctionne aussi pour le XML, il suffit de faire [ CODE=xml]
    Code xml : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    <phrase>
      <GN> // groupe nominal 1
        <det nombre=" l' ">

    Peux-tu fournir une tentative de code ? Je suppose que tu as commencé avec le TXMLDocument fourni par C++Builder qui souvent utilise comme Vendor MSXML - XML DOM Objects/Interfaces

    Quelle est la question ?
    Où en es-tu dans ton développement ?
    As-tu déjà découpé la phrase, par un SplitString ou ExtractStrings ?

    Comment as-tu prévu de gérer la détection du groupe de chaque Mot ? C'est assez proche de la phase de "analyse lexicale" d'un compilateur !
    Cela utilise une sorte de dictionnaire ! C'est possible à faire pour un langage humain mais cela demande une Énorme base de données !

    En fait, tu vas passer aussi par la phase Analyse sémantique pour générer ton arbre ! Effectivement deux mots présents dans le dictionnaire en fonction de leur emplacement pourra être un verve, un mot, tout dépend du contexte !
    On est toujours dans la compilation !

    Il pourrait y avoir une méthode plus simple de groupage qui ne fonctionnerait que pour des phrases ayant la même structure (même nombre de mot !) donc peu intéressante !

    Dans quelle cadre, tu prévois de développer cela ? Tu veux faire yn programme genre "Correcteur Grammatical" ou un "Chatterbot - Agent conversationnel", le truc à la mode avec la reconnaissance vocale de iPhone 4S
    j'ai comme entrée un texte j'ai fait une analyse lexicale détécté les phrases aprés ses mots,en suite grace a une base de données de 2000 mots défférent j'ai défini la gramatical de chaque mot aprés je doit faire le groupage
    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
     
    #include <vcl.h>
    #pragma hdrstop
    #include "Unit2.h"
    #include "Unit1.h"
    //---------------------------------------------------------------------------
    #pragma package(smart_init)
    #pragma resource "*.dfm"
    TForm2 *Form2;   AnsiString text;
    	 // static int nb=0;
    //---------------------------------------------------------------------------
    __fastcall TForm2::TForm2(TComponent* Owner)
    	: TForm(Owner)
    {
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm2::Chargeruntext1Click(TObject *Sender)
    {
     
    if (OpenDialog1->Execute())
     
      Memo1->Lines->LoadFromFile(OpenDialog1->FileName);
    else Memo1->Clear();
     
     
     
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm2::Prtraitemant1Click(TObject *Sender)
    {      int static count=0;
     
    	 text= Memo1->Lines->Text;
     //AnsiString phrase;
     int i;
     while (text.Length()>1)
     {
     i=0;
     do
     {
     
     i++;
     }
     while(text[i]!='.'&&text[i]!=','&&text[i]!=';'&&text[i]!='?'&&text[i]!='!'&&text[i]!='('&&text[i]!=')'&&text[i]!='-'&&text[i]!='_');
     rest.resize(count+1);
     //rest[count].phrase= LeftStr(text,i-1);
     //AnsiString f=text.SubString(1,i-1);
    			 // ShowMessage( f);
     if(!text.SubString(1,i-1).IsEmpty())  {
    	 rest[count].phrase= text.SubString(1,i-1);
    	 Mots(rest[count].phrase);
    		 count++;}
    	  text=text.Delete(1,i);
     
     
       }
     int j;
     Form2->StringGrid1->Cells[0][0]="  référence";
     Form2->StringGrid1->Cells[1][0]="  Phrases";
     Form2->StringGrid1->Cells[2][0]="  Unités Textuelles";
    Form2->StringGrid1->RowCount=count+1;
       //	 int y=1; int t=1;
    for(int i=1;i<StringGrid1->RowCount;i++)
    	{
    	//if(rest[y-1].phrase!="") {
    	Form2->StringGrid1->Cells[0][i]=IntToStr(i-1);
    	Form2->StringGrid1->Cells[1][i]=rest[i-1].phrase; //t++;
    	 //}
    	// y++;
    	}
    	for(int i=1;i<Form2->StringGrid1->RowCount;i++)  {
    	for(j=0;j<30;j++) {
       if(!rest[i-1].mot[j].IsEmpty())
    StringGrid1->Cells[2][i]=StringGrid1->Cells[2][i]+","+rest[i-1].mot[j];}
    	Form2->StringGrid1->Cells[2][i]=Form2->StringGrid1->Cells[2][i].Delete(1,1);
    	  j=0;
    	}
     
     
     }
    //---------------------------------------------------------------------------
    void __fastcall TForm2::Mots(AnsiString phrase) {
    phrase=phrase+" ";
    static int k=0; int j=0; int i;
    while (phrase.Length()>1)
     {
     i=0;
     do
     {
     i++;
     }
     while(phrase[i]!=' '&&phrase[i]!='\'');
    //if(phrase[i]=='\'') rest[k].mot[j]= LeftStr(phrase,i);
     rest[k].mot[j]= LeftStr(phrase,i-1);
    //nb++;
    //ShowMessage(rest[k].mot[j]);
     phrase.Delete(1,i);
     
      j++;
       }
       k++;
      }
     
     //-----------------------------------------------------------------------------
     
    void __fastcall TForm2::Classifier1Click(TObject *Sender)
    {
      Form1->Show();
    }
    //---------------------------------------------------------------------------
    //============analyse syntaxique groupage
    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
     
    #include <vcl.h>
    #pragma hdrstop
     
    #include "Unit1.h"
    #include "Unit2.h"
    //---------------------------------------------------------------------------
    #pragma package(smart_init)
    #pragma resource "*.dfm"
    TForm1 *Form1;
    //---------------------------------------------------------------------------
    __fastcall TForm1::TForm1(TComponent* Owner)
    	: TForm(Owner)
    {
    }
    //---------------------------------------------------------------------------
     
    void __fastcall TForm1::Button1Click(TObject *Sender)
    {        int k=1;  int nb=0;
    //ShowMessage(Form2->nb);
     
    //if(is_int("4664")) ShowMessage("good");
    	for(int i=0;i<Form2->rest.size();i++)  {
    	for(int j=0;j<30;j++)  {
    	if(!Form2->rest[i].mot[j].IsEmpty()) {
     
    		  //Form1->ADOTable1->Filter="lemme=Form2->rest[i].mot[j];
    		 TLocateOptions Option; // Creer un objet option
     
    Option << loCaseInsensitive; // Rajout de l'option "ne fait pas attention à la casse"
     if(!Form1->is_int(Form2->rest[i].mot[j])&&ADOTable1->Locate("ortho",Form2->rest[i].mot[j],Option)==true) {
     
     
     nb++;
     Form1->StringGrid1->RowCount=nb+1;
     Form1->StringGrid1->Cells[0][k]=IntToStr(i);
     Form1->StringGrid1->Cells[1][k]=ADOTable1->FieldByName("lemme")->AsString;
      Form1->StringGrid1->Cells[2][k]=ADOTable1->FieldByName("ortho")->AsString;
       Form1->StringGrid1->Cells[3][k]=ADOTable1->FieldByName("cgram")->AsString;
    	Form1->StringGrid1->Cells[4][k]=ADOTable1->FieldByName("ID")->AsString;
    	Form1->StringGrid1->Cells[5][k]=ADOTable1->FieldByName("nombre")->AsString;
     k++;
     
    		}
    		else if(Form1->is_int(Form2->rest[i].mot[j])==true) {
    		   //	ShowMessage(Form2->rest[i].mot[j]);
    		 nb++;
    			  Form1->StringGrid1->RowCount=nb+1;
           Form1->StringGrid1->Cells[0][k]=IntToStr(i);
    	   Form1->StringGrid1->Cells[1][k]=Form2->rest[i].mot[j];
    	   Form1->StringGrid1->Cells[2][k]=Form2->rest[i].mot[j];
    		Form1->StringGrid1->Cells[3][k]="chiffre";
    			k++;
    		}
    		else {
    		//ShowMessage(Form2->rest[i].mot[j]);
    			   nb++;
    			  Form1->StringGrid1->RowCount=nb+1;
    			  Form1->StringGrid1->Cells[0][k]=IntToStr(i);
    	   Form1->StringGrid1->Cells[1][k]=Form2->rest[i].mot[j];
    	   Form1->StringGrid1->Cells[2][k]=Form2->rest[i].mot[j];
    	    Form1->StringGrid1->Cells[3][k]="inconnu";
    	   k++;
     
    		}
     
    		}
     
     
    		//if(is_int(Form2->rest[i].mot[j])) 	 {
    		//ShowMessage(Form2->rest[i].mot[j]);
    		//Form1->StringGrid1->Cells[0][j]=IntToStr(i);
    		//Form1->StringGrid1->Cells[1][j]=Form2->rest[i].mot[j];
    		//Form1->StringGrid1->Cells[2][j]="oui";
    	//}
     
    	}
    	}
     
     
    }
    //---------------------------------------------------------------------------
     
    void __fastcall TForm1::FormCreate(TObject *Sender)
    {
     Form1->StringGrid1->Cells[0][0]="référance de mot";
      Form1->StringGrid1->Cells[1][0]="Mot";
    	 Form1->StringGrid1->Cells[2][0]="ortho";
    	 Form1->StringGrid1->Cells[3][0]="cgram";
    		 Form1->StringGrid1->Cells[4][0]="ID";
     Form1->StringGrid1->Cells[5][0]="nombre";
    }
    //---------------------------------------------------------------------------
    	 bool __fastcall TForm1::is_int(AnsiString mot)
    {
    int i;   bool R=true;
     for(i=1;i<=mot.Length();i++)
     {
     if(isalpha(mot[i])||mot=="à")  return false;
     
     }
      return R;
    }
    void __fastcall TForm1::BitBtn1Click(TObject *Sender)
    {
     if (!Edit1->Text.IsEmpty()) // test pour voir si le Edit est vide
      {
       TLocateOptions Option; // Creer un objet option
       Option << loCaseInsensitive; // Rajout de l'option "ne fait pas attention à la casse"
       ADOTable1->Locate("ortho",Edit1->Text,Option); /* Recherche l'enregistrement suivant
       les critères */
      }
    }
    //---------------------------------------------------------------------------
     
    void __fastcall TForm1::BitBtn2Click(TObject *Sender)
    {
     
    Form1->XMLDocument1->Active = true;  // Activer le document avant d'écrire dedans
    Form1->XMLDocument1->Version = "1.0";
    Form1->XMLDocument1->Encoding = "UTF-8";
    AnsiString mot=""; int k=0;
    int i=1;
    int j=0;
    while(j<Form2->rest.size()){
      XMLDocument1->DocumentElement = XMLDocument1->CreateElement("phrase"+IntToStr(j),"");
    while(i<Form1->StringGrid1->RowCount&&Form1->StringGrid1->Cells[0][i].ToInt()==j)  {
    AnsiString ART=StringGrid1->Cells[3][i];
    AnsiString NOM=StringGrid1->Cells[3][i+1];
    AnsiString PER=StringGrid1->Cells[3][i-1];
    int p=StringGrid1->RowCount;
    if(i+1<p &&i!=0&&PER=="ADJ"&&ART=="ART:def" && NOM=="NOM")
    {
      //_di_IXMLNode NewStock = XMLDocument1->DocumentElement->AddChild(WideString("GN"+IntToStr(k)));
    //NewStock ->Text = WideString(StringGrid1->Cells[1][i]+" "+StringGrid1->Cells[1][i+1]);
    //NewStock->SetAttribute(WideString("det"),WideString(StringGrid1->Cells[1][i]));
     //NewStock->SetAttribute(WideString("NOM"),WideString(StringGrid1->Cells[1][i+1]));
     
     
     
      _di_IXMLNode New = XMLDocument1->DocumentElement->AddChild(WideString("GP"));
       _di_IXMLNode ValueNode = New->AddChild(WideString("GN"+IntToStr(k)));
       //  Ne = NewStock->AddChild(WideString("price"));
    ValueNode ->Text = WideString(StringGrid1->Cells[1][i]+" "+StringGrid1->Cells[1][i+1]);
    ValueNode ->SetAttribute(WideString("det"),WideString(StringGrid1->Cells[1][i]));
    ValueNode ->SetAttribute(WideString("NOM"),WideString(StringGrid1->Cells[1][i+1]));
     //New ->Text = WideString(StringGrid1->Cells[1][i]+" "+StringGrid1->Cells[1][i+1]);
    New->SetAttribute(WideString("ADJ"),WideString(StringGrid1->Cells[1][i-1]));
     New->SetAttribute(WideString("NOM"),WideString("GN"+IntToStr(k)));
    k++;
     
     
      }
      else if(i+1<p &&i!=0&&PER=="VER"&&ART=="ART:def" && NOM=="NOM" ) {
    	 _di_IXMLNode New = XMLDocument1->DocumentElement->AddChild(WideString("GV"));
       _di_IXMLNode ValueNode = New->AddChild(WideString("GN"+IntToStr(k)));
       //  Ne = NewStock->AddChild(WideString("price"));
    ValueNode ->Text = WideString(StringGrid1->Cells[1][i]+" "+StringGrid1->Cells[1][i+1]);
    ValueNode ->SetAttribute(WideString("det"),WideString(StringGrid1->Cells[1][i]));
    ValueNode ->SetAttribute(WideString("NOM"),WideString(StringGrid1->Cells[1][i+1]));
     //New ->Text = WideString(StringGrid1->Cells[1][i]+" "+StringGrid1->Cells[1][i+1]);
    New->SetAttribute(WideString("VER"),WideString(StringGrid1->Cells[1][i-1]));
     New->SetAttribute(WideString("NOM"),WideString("GN"+IntToStr(k)));
    k++;
     
      }
       else if(ART=="ART:def" && NOM=="NOM") {
    		 _di_IXMLNode New = XMLDocument1->DocumentElement->AddChild(WideString("GN"));
    		  New ->Text = WideString(StringGrid1->Cells[1][i]+" "+StringGrid1->Cells[1][i+1]);
    		 New ->SetAttribute(WideString("det"),WideString(StringGrid1->Cells[1][i]));
    New ->SetAttribute(WideString("NOM"),WideString(StringGrid1->Cells[1][i+1]));// k++;
       }
      else if(ART=="VER" && NOM=="NOM") {
      _di_IXMLNode New = XMLDocument1->DocumentElement->AddChild(WideString("GV"));
     New ->Text = WideString(StringGrid1->Cells[1][i]+" "+StringGrid1->Cells[1][i+1]);
    		 New ->SetAttribute(WideString("VER"),WideString(StringGrid1->Cells[1][i]));
    New ->SetAttribute(WideString("NOM"),WideString(StringGrid1->Cells[1][i+1]));// k++;
      }
     
     
     Form1->XMLDocument1->SaveToFile("C:\\Users\\Joker\\Desktop\\XML\\TestXml"+IntToStr(j)+".xml");
    mot+=Form1->StringGrid1->Cells[3][i]+" ";
    i++;
    }
      //_di_IXMLNode BorlandStock = XMLDocument1->DocumentElement->ChildNodes->GetNode(0);
      //int h=XMLDocument1->DocumentElement
     // Form1->ListBox1->Items->Strings[j]=mot; // ShowMessage(XML);
      _di_IXMLNode Racine = XMLDocument1->DocumentElement;
    	int Nb =  Racine->ChildNodes->GetCount();
       // Récupérer le nom d'un noeud (ici le nom de la racine)
     
     AnsiString Nom = Racine->GetNodeName(); //ShowMessage(Nb);
    	for(int i=0;i<Nb-1;i++)  {
    	  _di_IXMLNode BorlandStock = XMLDocument1->DocumentElement->ChildNodes->GetNode(i);
    		  _di_IXMLNode Borland = XMLDocument1->DocumentElement->ChildNodes->GetNode(i+1);
    	   AnsiString GV= BorlandStock->GetNodeName(); ShowMessage(GV);
    		AnsiString GP = Borland->GetNodeName();ShowMessage(GP);
    	   if(GV=="GV"&&GP=="GP") {
    		  _di_IXMLNode New = XMLDocument1->DocumentElement->AddChild(WideString("GV"));
    		   BorlandStock=New->AddChild(WideString("GV"));
    		   Borland=New->AddChild(WideString("GP"));
    	   }
    	    Form1->XMLDocument1->SaveToFile("C:\\Users\\Joker\\Desktop\\XML\\TestXml"+IntToStr(j)+".xml");
    	}
     
       mot="";
     
      j++;
    }
     
     
    }
    ma question je voudrai inserer un noeud en position i
    expl:

    [code]
    <phrase>
    < === inserer noeud <GV>
    <GV>
    <\GV>
    <GP>
    <\GP>
    <== la fin du noeud <\GV>
    <phrase>
    [\code]

  4. #4
    Membre du Club
    Inscrit en
    Mars 2009
    Messages
    61
    Détails du profil
    Informations personnelles :
    Âge : 36

    Informations forums :
    Inscription : Mars 2009
    Messages : 61
    Points : 65
    Points
    65
    Par défaut
    [QUOTE=farid0031;6409151]j'ai comme entrée un texte j'ai fait une analyse lexicale détécté les phrases aprés ses mots,en suite grace a une base de données de 2000 mots défférent j'ai défini la gramatical de chaque mot aprés je doit faire le groupage
    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
     
    #include <vcl.h>
    #pragma hdrstop
    #include "Unit2.h"
    #include "Unit1.h"
    //---------------------------------------------------------------------------
    #pragma package(smart_init)
    #pragma resource "*.dfm"
    TForm2 *Form2;   AnsiString text;
    	 // static int nb=0;
    //---------------------------------------------------------------------------
    __fastcall TForm2::TForm2(TComponent* Owner)
    	: TForm(Owner)
    {
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm2::Chargeruntext1Click(TObject *Sender)
    {
     
    if (OpenDialog1->Execute())
     
      Memo1->Lines->LoadFromFile(OpenDialog1->FileName);
    else Memo1->Clear();
     
     
     
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm2::Prtraitemant1Click(TObject *Sender)
    {      int static count=0;
     
    	 text= Memo1->Lines->Text;
     //AnsiString phrase;
     int i;
     while (text.Length()>1)
     {
     i=0;
     do
     {
     
     i++;
     }
     while(text[i]!='.'&&text[i]!=','&&text[i]!=';'&&text[i]!='?'&&text[i]!='!'&&text[i]!='('&&text[i]!=')'&&text[i]!='-'&&text[i]!='_');
     rest.resize(count+1);
     //rest[count].phrase= LeftStr(text,i-1);
     //AnsiString f=text.SubString(1,i-1);
    			 // ShowMessage( f);
     if(!text.SubString(1,i-1).IsEmpty())  {
    	 rest[count].phrase= text.SubString(1,i-1);
    	 Mots(rest[count].phrase);
    		 count++;}
    	  text=text.Delete(1,i);
     
     
       }
     int j;
     Form2->StringGrid1->Cells[0][0]="  référence";
     Form2->StringGrid1->Cells[1][0]="  Phrases";
     Form2->StringGrid1->Cells[2][0]="  Unités Textuelles";
    Form2->StringGrid1->RowCount=count+1;
       //	 int y=1; int t=1;
    for(int i=1;i<StringGrid1->RowCount;i++)
    	{
    	//if(rest[y-1].phrase!="") {
    	Form2->StringGrid1->Cells[0][i]=IntToStr(i-1);
    	Form2->StringGrid1->Cells[1][i]=rest[i-1].phrase; //t++;
    	 //}
    	// y++;
    	}
    	for(int i=1;i<Form2->StringGrid1->RowCount;i++)  {
    	for(j=0;j<30;j++) {
       if(!rest[i-1].mot[j].IsEmpty())
    StringGrid1->Cells[2][i]=StringGrid1->Cells[2][i]+","+rest[i-1].mot[j];}
    	Form2->StringGrid1->Cells[2][i]=Form2->StringGrid1->Cells[2][i].Delete(1,1);
    	  j=0;
    	}
     
     
     }
    //---------------------------------------------------------------------------
    void __fastcall TForm2::Mots(AnsiString phrase) {
    phrase=phrase+" ";
    static int k=0; int j=0; int i;
    while (phrase.Length()>1)
     {
     i=0;
     do
     {
     i++;
     }
     while(phrase[i]!=' '&&phrase[i]!='\'');
    //if(phrase[i]=='\'') rest[k].mot[j]= LeftStr(phrase,i);
     rest[k].mot[j]= LeftStr(phrase,i-1);
    //nb++;
    //ShowMessage(rest[k].mot[j]);
     phrase.Delete(1,i);
     
      j++;
       }
       k++;
      }
     
     //-----------------------------------------------------------------------------
     
    void __fastcall TForm2::Classifier1Click(TObject *Sender)
    {
      Form1->Show();
    }
    //---------------------------------------------------------------------------
    //============analyse syntaxique groupage
    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
     
    #include <vcl.h>
    #pragma hdrstop
     
    #include "Unit1.h"
    #include "Unit2.h"
    //---------------------------------------------------------------------------
    #pragma package(smart_init)
    #pragma resource "*.dfm"
    TForm1 *Form1;
    //---------------------------------------------------------------------------
    __fastcall TForm1::TForm1(TComponent* Owner)
    	: TForm(Owner)
    {
    }
    //---------------------------------------------------------------------------
     
    void __fastcall TForm1::Button1Click(TObject *Sender)
    {        int k=1;  int nb=0;
    //ShowMessage(Form2->nb);
     
    //if(is_int("4664")) ShowMessage("good");
    	for(int i=0;i<Form2->rest.size();i++)  {
    	for(int j=0;j<30;j++)  {
    	if(!Form2->rest[i].mot[j].IsEmpty()) {
     
    		  //Form1->ADOTable1->Filter="lemme=Form2->rest[i].mot[j];
    		 TLocateOptions Option; // Creer un objet option
     
    Option << loCaseInsensitive; // Rajout de l'option "ne fait pas attention à la casse"
     if(!Form1->is_int(Form2->rest[i].mot[j])&&ADOTable1->Locate("ortho",Form2->rest[i].mot[j],Option)==true) {
     
     
     nb++;
     Form1->StringGrid1->RowCount=nb+1;
     Form1->StringGrid1->Cells[0][k]=IntToStr(i);
     Form1->StringGrid1->Cells[1][k]=ADOTable1->FieldByName("lemme")->AsString;
      Form1->StringGrid1->Cells[2][k]=ADOTable1->FieldByName("ortho")->AsString;
       Form1->StringGrid1->Cells[3][k]=ADOTable1->FieldByName("cgram")->AsString;
    	Form1->StringGrid1->Cells[4][k]=ADOTable1->FieldByName("ID")->AsString;
    	Form1->StringGrid1->Cells[5][k]=ADOTable1->FieldByName("nombre")->AsString;
     k++;
     
    		}
    		else if(Form1->is_int(Form2->rest[i].mot[j])==true) {
    		   //	ShowMessage(Form2->rest[i].mot[j]);
    		 nb++;
    			  Form1->StringGrid1->RowCount=nb+1;
           Form1->StringGrid1->Cells[0][k]=IntToStr(i);
    	   Form1->StringGrid1->Cells[1][k]=Form2->rest[i].mot[j];
    	   Form1->StringGrid1->Cells[2][k]=Form2->rest[i].mot[j];
    		Form1->StringGrid1->Cells[3][k]="chiffre";
    			k++;
    		}
    		else {
    		//ShowMessage(Form2->rest[i].mot[j]);
    			   nb++;
    			  Form1->StringGrid1->RowCount=nb+1;
    			  Form1->StringGrid1->Cells[0][k]=IntToStr(i);
    	   Form1->StringGrid1->Cells[1][k]=Form2->rest[i].mot[j];
    	   Form1->StringGrid1->Cells[2][k]=Form2->rest[i].mot[j];
    	    Form1->StringGrid1->Cells[3][k]="inconnu";
    	   k++;
     
    		}
     
    		}
     
     
    		//if(is_int(Form2->rest[i].mot[j])) 	 {
    		//ShowMessage(Form2->rest[i].mot[j]);
    		//Form1->StringGrid1->Cells[0][j]=IntToStr(i);
    		//Form1->StringGrid1->Cells[1][j]=Form2->rest[i].mot[j];
    		//Form1->StringGrid1->Cells[2][j]="oui";
    	//}
     
    	}
    	}
     
     
    }
    //---------------------------------------------------------------------------
     
    void __fastcall TForm1::FormCreate(TObject *Sender)
    {
     Form1->StringGrid1->Cells[0][0]="référance de mot";
      Form1->StringGrid1->Cells[1][0]="Mot";
    	 Form1->StringGrid1->Cells[2][0]="ortho";
    	 Form1->StringGrid1->Cells[3][0]="cgram";
    		 Form1->StringGrid1->Cells[4][0]="ID";
     Form1->StringGrid1->Cells[5][0]="nombre";
    }
    //---------------------------------------------------------------------------
    	 bool __fastcall TForm1::is_int(AnsiString mot)
    {
    int i;   bool R=true;
     for(i=1;i<=mot.Length();i++)
     {
     if(isalpha(mot[i])||mot=="à")  return false;
     
     }
      return R;
    }
    void __fastcall TForm1::BitBtn1Click(TObject *Sender)
    {
     if (!Edit1->Text.IsEmpty()) // test pour voir si le Edit est vide
      {
       TLocateOptions Option; // Creer un objet option
       Option << loCaseInsensitive; // Rajout de l'option "ne fait pas attention à la casse"
       ADOTable1->Locate("ortho",Edit1->Text,Option); /* Recherche l'enregistrement suivant
       les critères */
      }
    }
    //---------------------------------------------------------------------------
     
    void __fastcall TForm1::BitBtn2Click(TObject *Sender)
    {
     
    Form1->XMLDocument1->Active = true;  // Activer le document avant d'écrire dedans
    Form1->XMLDocument1->Version = "1.0";
    Form1->XMLDocument1->Encoding = "UTF-8";
    AnsiString mot=""; int k=0;
    int i=1;
    int j=0;
    while(j<Form2->rest.size()){
      XMLDocument1->DocumentElement = XMLDocument1->CreateElement("phrase"+IntToStr(j),"");
    while(i<Form1->StringGrid1->RowCount&&Form1->StringGrid1->Cells[0][i].ToInt()==j)  {
    AnsiString ART=StringGrid1->Cells[3][i];
    AnsiString NOM=StringGrid1->Cells[3][i+1];
    AnsiString PER=StringGrid1->Cells[3][i-1];
    int p=StringGrid1->RowCount;
    if(i+1<p &&i!=0&&PER=="ADJ"&&ART=="ART:def" && NOM=="NOM")
    {
      //_di_IXMLNode NewStock = XMLDocument1->DocumentElement->AddChild(WideString("GN"+IntToStr(k)));
    //NewStock ->Text = WideString(StringGrid1->Cells[1][i]+" "+StringGrid1->Cells[1][i+1]);
    //NewStock->SetAttribute(WideString("det"),WideString(StringGrid1->Cells[1][i]));
     //NewStock->SetAttribute(WideString("NOM"),WideString(StringGrid1->Cells[1][i+1]));
     
     
     
      _di_IXMLNode New = XMLDocument1->DocumentElement->AddChild(WideString("GP"));
       _di_IXMLNode ValueNode = New->AddChild(WideString("GN"+IntToStr(k)));
       //  Ne = NewStock->AddChild(WideString("price"));
    ValueNode ->Text = WideString(StringGrid1->Cells[1][i]+" "+StringGrid1->Cells[1][i+1]);
    ValueNode ->SetAttribute(WideString("det"),WideString(StringGrid1->Cells[1][i]));
    ValueNode ->SetAttribute(WideString("NOM"),WideString(StringGrid1->Cells[1][i+1]));
     //New ->Text = WideString(StringGrid1->Cells[1][i]+" "+StringGrid1->Cells[1][i+1]);
    New->SetAttribute(WideString("ADJ"),WideString(StringGrid1->Cells[1][i-1]));
     New->SetAttribute(WideString("NOM"),WideString("GN"+IntToStr(k)));
    k++;
     
     
      }
      else if(i+1<p &&i!=0&&PER=="VER"&&ART=="ART:def" && NOM=="NOM" ) {
    	 _di_IXMLNode New = XMLDocument1->DocumentElement->AddChild(WideString("GV"));
       _di_IXMLNode ValueNode = New->AddChild(WideString("GN"+IntToStr(k)));
       //  Ne = NewStock->AddChild(WideString("price"));
    ValueNode ->Text = WideString(StringGrid1->Cells[1][i]+" "+StringGrid1->Cells[1][i+1]);
    ValueNode ->SetAttribute(WideString("det"),WideString(StringGrid1->Cells[1][i]));
    ValueNode ->SetAttribute(WideString("NOM"),WideString(StringGrid1->Cells[1][i+1]));
     //New ->Text = WideString(StringGrid1->Cells[1][i]+" "+StringGrid1->Cells[1][i+1]);
    New->SetAttribute(WideString("VER"),WideString(StringGrid1->Cells[1][i-1]));
     New->SetAttribute(WideString("NOM"),WideString("GN"+IntToStr(k)));
    k++;
     
      }
       else if(ART=="ART:def" && NOM=="NOM") {
    		 _di_IXMLNode New = XMLDocument1->DocumentElement->AddChild(WideString("GN"));
    		  New ->Text = WideString(StringGrid1->Cells[1][i]+" "+StringGrid1->Cells[1][i+1]);
    		 New ->SetAttribute(WideString("det"),WideString(StringGrid1->Cells[1][i]));
    New ->SetAttribute(WideString("NOM"),WideString(StringGrid1->Cells[1][i+1]));// k++;
       }
      else if(ART=="VER" && NOM=="NOM") {
      _di_IXMLNode New = XMLDocument1->DocumentElement->AddChild(WideString("GV"));
     New ->Text = WideString(StringGrid1->Cells[1][i]+" "+StringGrid1->Cells[1][i+1]);
    		 New ->SetAttribute(WideString("VER"),WideString(StringGrid1->Cells[1][i]));
    New ->SetAttribute(WideString("NOM"),WideString(StringGrid1->Cells[1][i+1]));// k++;
      }
     
     
     Form1->XMLDocument1->SaveToFile("C:\\Users\\Joker\\Desktop\\XML\\TestXml"+IntToStr(j)+".xml");
    mot+=Form1->StringGrid1->Cells[3][i]+" ";
    i++;
    }
      //_di_IXMLNode BorlandStock = XMLDocument1->DocumentElement->ChildNodes->GetNode(0);
      //int h=XMLDocument1->DocumentElement
     // Form1->ListBox1->Items->Strings[j]=mot; // ShowMessage(XML);
      _di_IXMLNode Racine = XMLDocument1->DocumentElement;
    	int Nb =  Racine->ChildNodes->GetCount();
       // Récupérer le nom d'un noeud (ici le nom de la racine)
     
     AnsiString Nom = Racine->GetNodeName(); //ShowMessage(Nb);
    	for(int i=0;i<Nb-1;i++)  {
    	  _di_IXMLNode BorlandStock = XMLDocument1->DocumentElement->ChildNodes->GetNode(i);
    		  _di_IXMLNode Borland = XMLDocument1->DocumentElement->ChildNodes->GetNode(i+1);
    	   AnsiString GV= BorlandStock->GetNodeName(); ShowMessage(GV);
    		AnsiString GP = Borland->GetNodeName();ShowMessage(GP);
    	   if(GV=="GV"&&GP=="GP") {
    		  _di_IXMLNode New = XMLDocument1->DocumentElement->AddChild(WideString("GV"));
    		   BorlandStock=New->AddChild(WideString("GV"));
    		   Borland=New->AddChild(WideString("GP"));
    	   }
    	    Form1->XMLDocument1->SaveToFile("C:\\Users\\Joker\\Desktop\\XML\\TestXml"+IntToStr(j)+".xml");
    	}
     
       mot="";
     
      j++;
    }
     
     
    }
    ma question je voudrai inserer un noeud en position i
    expl:

    [code]
    <phrase>
    < === inserer noeud <GV>
    <GV>
    <\GV>
    <GP>
    <\GP>
    <== la fin du noeud <\GV>
    <phrase>
    [\code]
    mon code
    [code]
    _di_IXMLNode Racine = XMLDocument1->DocumentElement;
    int Nb = Racine->ChildNodes->GetCount();
    // Récupérer le nom d'un noeud (ici le nom de la racine)

    AnsiString Nom = Racine->GetNodeName(); //ShowMessage(Nb);

    for(int i=0;i<Nb-1;i++) { //parcours les noeuds
    di_IXMLNode BorlandStock = XMLDocument1->DocumentElement->ChildNodes->GetNode(i);

    _di_IXMLNode Borland = XMLDocument1->DocumentElement->ChildNodes->GetNode(i+1);
    AnsiString GV= BorlandStock->GetNodeName(); ShowMessage(GV);
    AnsiString GP = Borland->GetNodeName();ShowMessage(GP);
    if(GV=="GV"&&GP=="GP") {
    _di_IXMLNode New = XMLDocument1->DocumentElement->AddChild(WideString("GV")); //inser noeud GV
    // les filles de ce noeud : i,et i+1
    BorlandStock=New->AddChild(WideString("GV"));
    Borland=New->AddChild(WideString("GP"));
    }
    Form1->XMLDocument1->SaveToFile("C:\\Users\\Joker\\Desktop\\XML\\TestXml.xml");
    }
    [\code]
    svp aide moi ,merci ts monde

  5. #5
    Expert éminent sénior
    Avatar de ShaiLeTroll
    Homme Profil pro
    Développeur C++\Delphi
    Inscrit en
    Juillet 2006
    Messages
    13 576
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Seine Saint Denis (Île de France)

    Informations professionnelles :
    Activité : Développeur C++\Delphi
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2006
    Messages : 13 576
    Points : 25 216
    Points
    25 216
    Par défaut
    Il est drôle que tu fasse la même erreur sur / et \ dans le XML et les codes du Forum

    c'est bien
    [CODE ] et [/CODE ] et non [\CODE ]
    ou encore
    <GV> et </GV> et non <\GV>

    Tu ne te relis même pas en plus, tu n'as même pas vu que tes balises n'avaient eu aucun effet

    le XML ne gère pas l'insertion en lieu précis dans le texte, peux ajouter des noeuds, des attributs, l'ordre n'a AUCUNE importance, c'est l'un des fondements du XML !
    Utilise plutôt un attribut pour numéroté les élements !

    Sinon, tu peux doit recopier l'ensemble du noeud (et sous-noeuds) dans un arbre temporaire, supprimer ce noeud, puis ré-inserer dans l'ordre souhaité, c'est une vilaine bidouille !

Discussions similaires

  1. Récupérer valeur balise dans fichier XML
    Par jamy69 dans le forum VBScript
    Réponses: 3
    Dernier message: 24/05/2012, 16h45
  2. ne pas interpréter les "<" et ">" dans fichier xml
    Par Kirua76 dans le forum XML/XSL et SOAP
    Réponses: 7
    Dernier message: 13/07/2011, 15h03
  3. Stocker les variables dans fichier XML
    Par cdoctora dans le forum Langage
    Réponses: 4
    Dernier message: 16/11/2008, 10h48
  4. [DOM] organiser les balises du fichier XML
    Par nadiaflamingenierie dans le forum Bibliothèques et frameworks
    Réponses: 10
    Dernier message: 08/01/2008, 14h59
  5. Pb de balises dans fichier XML
    Par allstar dans le forum XMLRAD
    Réponses: 2
    Dernier message: 10/06/2005, 13h59

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