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

Mon programme Discussion :

[ANPE][Ada Neural Prolog Engine] [Open Source] le prototype de la première moitié des programmes Prolog.


Sujet :

Mon programme

  1. #1
    Membre du Club
    Homme Profil pro
    codeur
    Inscrit en
    Mars 2018
    Messages
    158
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 54
    Localisation : France, Gard (Languedoc Roussillon)

    Informations professionnelles :
    Activité : codeur

    Informations forums :
    Inscription : Mars 2018
    Messages : 158
    Points : 64
    Points
    64
    Par défaut [ANPE][Ada Neural Prolog Engine] [Open Source] le prototype de la première moitié des programmes Prolog.
    nom : pnl
    version : 1.0.10
    langue : english
    description : run a english dialog.
    fonctionnalités : construct facts database with dialog.
    compatibilité : Prolog
    nécessite : Prolog
    téléchargement : néant
    licence : néant.
    langage : Prolog
    sources : ci-dessous
    à venir : peut-être l'autre moitié.

    Ce programme entretient un dialog avec l'utilisateur l'informant au fur et a mesure des faits passé grâce à leur mémorisation facultative.

    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
    /******************************************************************************/
    /*                                   Prolog                                   */
    /*                          Linguistic Neuro Program                          */
    /*                               Version 1.0.10                               */
    /******************************************************************************/
    /* Date        : 2018-04-04 22:55:00                                          */
    /* Author      : Arknos                                                       */
    /* Version     : 1.0.10                                                       */
    /* Description : Linguistic Neuro Program                                     */
    /******************************************************************************/
    
    %%:-style_check(-singleton).
    
    %%:- initialization mainpe.
    
    /******************************************************************************/
    /* Prédicats dynamique de la base de faits.                                   */
    :- dynamic ( sujet/1 ).
    :- dynamic ( verbe/1 ).
    :- dynamic ( complément/1 ).
    :- dynamic ( lire/3 ).
    
    /* Décompose une phrase de forme [Sujet, Verbe | Complément]                  */
    defrag([Sujet, Verbe | Complément], Sujet, Verbe, Complément).
    
    /* Ajout des prédicats Sujet/1 et Verbe/1 s'ils n'existe pas et des prédicats */
    /* Complément/1 et lire/3                                                     */
    écrire(Sujet, Verbe, Complément) :-
        (not(verbe(Verbe)) ->
             assertz((verbe(Verbe)));
        true),
        (not(sujet(Sujet)) ->
             assertz((sujet(Sujet)));
         true),
        assertz((complément(Complément))),
        assertz((lire(Sujet, Verbe, Complément))).
    /*                                                                            */
    /******************************************************************************/
    
    subject(i).
    subject(you).
    subject(he).
    subject(she).
    subject(we).
    subject(they).
    
    antinomie(something, nothing).
    antinomie(reality, game).
    antinomie(peace, war).
    antinomie(die, live).
    antinomie(you, i).
    antinomie(we, they).
    antinomie(win, loose).
    
    synonyme(no, negative).
    synonyme(negative, false).
    
    synonyme(yes, positive).
    synonyme(positive, true).
    
    synonyme(affirmative, positive).
    
    synonyme(game, abstract).
    synonyme(i, me).
    synonyme(love, like).
    synonyme(love, peace).
    synonyme(war, die).
    synonyme(kill, war).
    synonyme(win, love).
    
    
    /******************************************************************************/
    /*                                                                            */
    cprint(Sujet, Verbe, List, N) :-
        nth0(N, List, E),
        atomic_list_concat(E, ' ', Comp),     
        atomic_list_concat([Sujet, Verbe, Comp], ' ', Result),
        write(Result), writeln('!').
    
    vprint(Sujet, List, Complément, N) :-
        nth0(N, List, Ver),
        /* writeln("nth0 ok!"), */
        /* atomic_list_concat(E, ' ', Ver), */
        /* write("concat 1 ok!"), */
        atomic_list_concat(Complément, ' ', Comp),
        /* write("concat 2 ok!"), */
        atomic_list_concat([Sujet, Ver, Comp], ' ', Result),
        /* write("concat 3 ok!"), */
        write(Result), writeln('!').
    /*                                                                            */
    /******************************************************************************/
    
    
    
    
    
    
    search_antinomie(Left, Right) :- (antinomie(Left, Right), !
                                      ; antinomie(Right, Left)).
    
    search_synonyme(Left, Right) :- (synonyme(Left, Right), !
                                     ; synonyme(Right, Left)).
    
    
    no_analyze([X|R], S, R) :-
        
        (search_synonyme(X, Y),
         search_antinomie(Y, A),
         search_synonyme(A, S), !
         ;
         search_antinomie(X, S), !
         ;
         S = X).
    
    yes_analyze([X|R], A, R) :-
    
        (search_antinomie(X, Y),
         search_synonyme(Y, S),
         search_antinomie(S, A), !
         ;
         search_synonyme(X, A), !
         ;
         A = X).
    
    no :- write('no, ').
    yes :- write('yes, ').
    
    no([X|L], S) :- no_analyze(L, S).
    yes([X|L], A) :- yes_analyze(L, A).
    
    is_affirmative([Subject, Verb | Complement]) :- subject(Subject).
    is_interrogative([Verb, Subject | Complement]) :- subject(Subject).
    
    
    is_affirmative(List, End) :- (End == 33; End == 46),
                                 is_affirmative(List).
    
    is_interrogative(List, End) :- End == 63,
                                   is_interrogative(List).
    
    
    inverse_affirmative([Subject, Verb | Complement], [S, V, C], Result) :-
        
        yes_analyze([Subject], S, Substring),
    
        yes_analyze([Verb], V, Substring),
        
        yes_analyze(Complement, C, Rest),
    
        yes_analyze([Rest], Result, Substring).
    
    
    inverse_interrogative([Verb, Subject | Complement], [V, S, C], Result) :-
        (yes_analyze([Subject], S, Substring),
         
         yes_analyze([Verb], V, Substring),
         
         yes_analyze(Complement, C, Rest), !,
         
         yes_analyze([Rest], Result, Substring)
    
                
         ;
         no_analyze([Subject], S, Substring),
         
         no_analyze([Verb], V, Substring),
         
         no_analyze(Complement, C, Rest), !,
    
         yes_analyze([Rest], Result, Substring)).
    
    
    words_to_list(Index, Words, List) :-
        nth0(Index, Words, S),
        nth0(Index, List, A),
        atom_codes(A, S).
    
    
    output_to_list(String, List, Sentence) :-
        split_string(String, "-', ", ", ", String_List),
        length(String_List, Length),
        List_Length is Length + 1,
        length(List, List_Length),
        Last is Length - 1,
    
        foreach(between(0, Last, Index),
                words_to_list(Index, String_List, List)),
    
        length(Sentence, Length),
        foreach(between(0, Last, Index),
                words_to_list(Index, String_List, Sentence)).
    
    input_to_list(String, List, Sentence) :-
        split_string(String, "-', ", ", ", String_List),
        length(String_List, Length),
        List_Length is Length + 1,
        length(List, List_Length),
        Last is Length - 1,
    
        foreach(between(0, Last, Index),
                words_to_list(Index, String_List, List)),
    
        length(Sentence, Length),
        foreach(between(0, Last, Index),
                words_to_list(Index, String_List, Sentence)).
    
    pnl :-    
        read_string(user_input, "!?.", """\n", End, String),    
        input_to_list(String, List, Sentence),
        length(List, Length),
        nth1(Length, List, At_End),
        char_code(At_End, End),
        
        nth1(1, Sentence, Veracity),   
        (Veracity == yes -> delete(Sentence, yes, Unexpected);
         Unexpected = Sentence;
         (Veracity == no -> delete(Sentence, no, Unexpected);
          Unexpected = Sentence;
          (Veracity == true -> delete(Sentence, true, Unexpected);
           Unexpected = Sentence;
           (Veracity == false -> delete(Sentence, false, Unexpected);
            Unexpected = Sentence)))),
        
        %%writeln("stop :  0.0.0"),
        (is_affirmative(Unexpected, End) ->
             %%writeln("stop :  0.0.1"),
             %%%write(Unexpected),
             /************************************************/
             /*                                              */
             defrag(Unexpected, Sujet, Verbe, Complément),
             %%writeln("stop :  0.0.2"),
             (lire(Sujet, Verbe, Complément) ->
                  %%writeln("stop :  0.1.0"),
                  /* Affirmation */
                  write("Yes, "),
                  %%writeln("stop :  0.5.1"),
                  inverse_affirmative(Unexpected, Response, Rest),
                  %%writeln("stop :  0.5.2"),
                  inverse_affirmative(Response, Affirmative, Rest1),         
                  %%writeln("stop :  0.5.3"),
                  atomics_to_string(Affirmative, ' ', Affirmation), 
                  %%writeln("stop :  0.5.4"),
                  
                  (is_list(Rest) ->
                       length(Rest, Rest_Length),
                       (Rest_Length \= 0 ->
                            atomics_to_string(Rest, ' ', Complement),
                            
                            write(Affirmation),
                         write(' '),
                         write(Complement), writeln('!') ;
                        
                        write(Affirmation), writeln('!'))
                   ;
                   write(Affirmation), writeln('!'))
            
    
    
                       
                  /***********************************************/
                  /*                                             */
                  /***********************************************/
                  %% inverse_affirmative(Unexpected, Affirmative, Rest),
                  
                  
                  %% %%writeln("stop :  0.1.1"),
                  %% atomics_to_string(Affirmative, ' ', Affirmation),      
                  
                  %% %%writeln("stop :  0.1.2"),          
    
                  %% output_to_list(Affirmation, Full_Request, Request),
                  %% inverse_affirmative(Request, R, Rest),
    
                  %% defrag(R, S, V, C),
                  
                  %% atomic_list_concat(C, ' ', Comp),
                  %% atomic_list_concat([V, Comp, S], ' ', Result)
                  
                  %% (is_list(Rest) ->
                  %%           length(Rest, Rest_Length),
                  %%           (Rest_Length \= 0 ->
                  %%                atomics_to_string(Rest, ' ', Complement),
                            
                  %%                write(Result),
                  %%                write(' '),
                  %%                write(Complement), writeln('!') ;
                        
                  %%            write(Result), writeln('!'))
                  %%  ;
                  %%  write(Result), writeln('!'))
              ;
              %%writeln("stop :  0.2.0"),
              /* Négation */
              findall(C, lire(Sujet, Verbe, C), Goal),
              %writeln("findall(C, ... :  0.2.1"),
              /* lire(Sujet, Verbe, Goal), */
              length(Goal, Len),
              %%writeln("stop :  0.2.2"),
              (Len \= 0 ->
                   writeln("No, but : "),
                   Last is Len - 1,
                   foreach(between(0, Last, X),
                           cprint(Sujet, Verbe, Goal, X)),
                   nl,
                   /* Question */
                   atomic_list_concat(Complément, ' ', Comp),
                   atomic_list_concat([Verbe, Sujet, Comp], ' ', Interrogation),
                   write(Interrogation), writeln("?"),
                   nl,
                   /* écrire nouveau fait */
                   write("yes/no?"),
                   read(X),
                   (X == yes ->  écrire(Sujet, Verbe, Complément) ; true)
               ;
               %%writeln("stop :  0.3.0"),
               findall(V, lire(Sujet, V, _), Goal),
               /* lire(Sujet, Verbe, Goal), */
               %writeln("findall (V, ... :  0.3.1"),
               length(Goal, Len),
               %%writeln("stop :  0.3.2"),
               (Len \= 0 ->
                    writeln("No, but : "),
                    Last is Len - 1,
                    foreach(between(0, Last, X),
                            vprint(Sujet, Goal, Complément, X)),
                    nl,
                    /* Question */
                    atomic_list_concat(Complément, ' ', Comp),
                    atomic_list_concat([Verbe, Sujet, Comp], ' ', Interrogation),
                    write(Interrogation), writeln("?"),
                    nl,
                    /* écrire nouveau fait */
                    write("yes/no?"),
                    read(X),
                    (X == yes ->  écrire(Sujet, Verbe, Complément) ; true))
               ;
               %% %%writeln("stop :  0.4.0"),
               %% %inverse_interrogative([Verbe, Sujet, Complément], R, Rest),
               %% %writeln(R),
               %% %defrag(R, Verb, Subject, Complement),
               
               %% %%%write("No, "),
               %% /* Question */
               %% %writeln(Complement),
               %% %writeln("STOP :  1"),
               %% %%writeln("stop :  0.4.1"),
               %% atomic_list_concat(Complément, ' ', Comp),
               %% %writeln(Comp),
               %% %writeln("STOP :  2"),
               %% %%writeln("stop :  0.4.2"),
               %% atomic_list_concat([Verbe, Sujet, Comp], ' ', Interrogation),
               %% %%writeln("stop :  0.4.3"),
               %% output_to_list(Interrogation, Full_Request, Request),
               %% %%writeln("stop :  0.4.4"),
               %% inverse_interrogative(Request, R, Rest),
               
               %% inverse_interrogative(R, Interrogative, Rest2),
               
               %% %%writeln("stop :  0.4.5"),
               %% %%writeln(Interrogative),
               %% %%writeln("stop :  0.4.6"),
               %% defrag(Interrogative, V, S, C),
               %% %%writeln("stop :  0.4.7"),
               %% %%writeln(C),
               %% %%writeln("stop :  0.4.8"),
               %% /* Question */
               %% atomic_list_concat(C, ' ', Comp2),
               %% %%writeln("stop :  0.4.9"),
               %% atomic_list_concat([V, Comp2, S], ' ', Question),
               %% %%writeln("stop :  0.4.10"),
               %% (is_list(Rest) ->
               %%   length(Rest, Rest_Length),
               %%   (Rest_Length \= 0 ->
               %%        atomics_to_string(Rest, ' ', Complement),
                         
               %%        write(Question),
               %%        write(' '),
               %%        write(Complement), writeln('?') ;
                     
               /***********************/
               /* écrire nouveau fait */
               /*                     */
               /***********************/
               %%write("yes/no?"),
               %%read(X),
               %%(X == yes ->  écrire(Sujet, Verbe, Complément) ; true))),
               écrire(Sujet, Verbe, Complément),
               /*                                                    */
               /******************************************************/
               %%writeln("stop :  0.5.1"),
               inverse_affirmative(Unexpected, Response, Rest),
               %%writeln("stop :  0.5.2"),
               inverse_affirmative(Response, Affirmative, Rest1),    
               %%writeln("stop :  0.5.3"),
               atomics_to_string(Affirmative, ' ', Affirmation),    
               %%writeln("stop :  0.5.4"),
               
               (is_list(Rest) ->
                    length(Rest, Rest_Length),
                    (Rest_Length \= 0 ->
                         atomics_to_string(Rest, ' ', Complement),
                         
                         write(Affirmation),
                         write(' '),
                         write(Complement), writeln('!') ;
                     
                     write(Affirmation), writeln('!'))
                ;
                write(Affirmation), writeln('!'));
               %%writeln("stop :  0.5.1"),
               inverse_affirmative(Unexpected, Response, Rest),
               %%writeln("stop :  0.5.2"),
               inverse_affirmative(Response, Affirmative, Rest1),    
               %%writeln("stop :  0.5.3"),
               atomics_to_string(Affirmative, ' ', Affirmation),    
               %%writeln("stop :  0.5.4"),
               
               (is_list(Rest) ->
                    length(Rest, Rest_Length),
                    (Rest_Length \= 0 ->
                         atomics_to_string(Rest, ' ', Complement),
                         
                         write(Affirmation),
                         write(' '),
                         write(Complement), writeln('!') ;
                     
                     write(Affirmation), writeln('!'))
                ;
                write(Affirmation), writeln('!')));
              %%writeln("stop :  0.5.1"),
               inverse_affirmative(Unexpected, Response, Rest),
               %%writeln("stop :  0.5.2"),
               inverse_affirmative(Response, Affirmative, Rest1),    
               %%writeln("stop :  0.5.3"),
               atomics_to_string(Affirmative, ' ', Affirmation),    
               %%writeln("stop :  0.5.4"),
               
               (is_list(Rest) ->
                    length(Rest, Rest_Length),
                    (Rest_Length \= 0 ->
                         atomics_to_string(Rest, ' ', Complement),
                         
                         write(Affirmation),
                         write(' '),
                         write(Complement), writeln('!') ;
                     
                     write(Affirmation), writeln('!'))
                ;
                write(Affirmation), writeln('!')))
         ;
         %%writeln("stop :  0.6.0"),
         inverse_interrogative(Unexpected, R, Rest),
         %%writeln("stop :  0.6.1"),
         inverse_interrogative(R, Interrogative, Rest2),
         %%writeln("stop :  0.6.2"),
         atomics_to_string(Interrogative, ' ', Result),
         %%writeln("stop :  0.6.3"),
         
         (is_list(Rest), length(Rest, Rest_Length), Rest_Length \= 0 ->
              atomics_to_string(Rest, ' ', Complement),
              
              yes, write(Result), write(' '), write(Complement), writeln('?') ;
          write(Result), writeln('?'))
        ),
        pnl.
    
    
    /* saving database */
    savepe :-
        tell('subjects.pl'), listing(sujet(_)), told,
        tell('verbs.pl'), listing(verbe(_)), told,
        tell('complements.pl'), listing(complément(_)), told,
        tell('facts.pl'), listing(lire(_, _, _)), told.
    
    /* loading database */
    loadpe :-
        consult(subjects),
        consult(verbs),
        consult(complements),
        consult(facts).
    
    /* initialization */
    initpe :-
        write("Initialize with : "),
        read(P),
        writeln(P),
        split_string(P, ' ', "", L),
        defrag(L, Sujet, Verbe, Complément),
        écrire(Sujet, Verbe, Complément).
    
    mainpe :-
        (not(loadpe) -> initpe, savepe,
                        (pnl -> true;
                         savepe)
         ;     
         (pnl -> true;
          savepe),   
         savepe).
    Ce fichier chez moi est nommé : neuro-program.pl.

    Exemple :

    ?- mainpe.
    |: you like me!
    Yes, you like me!
    |: you like game!
    No, but :
    you like me!

    like you game?

    yes/no?|: yes.
    |: .
    you like game!
    |: ..
    Yes, you like game!
    Yes, you like game!
    |: .
    Yes, you like game!
    |: ...
    Yes, you like me!
    Yes, you like me!
    Yes, you like me!
    |: ....

    true.

    ?-
    Il faut créer 4 fichiers vide avant de l'utiliser.
    - verbs.pl
    - subjects.pl
    - complements.pl
    - facts.pl


    En réalité c'est un poil complexe, parce que ça cherche des synonymes et des antinomie pour reformuler les questions, mais peu sont renseigner dans ce fichier.

    Mais ça fait 500ligne parce que j'ai laissé un tas de codes commenté car sans réelle utilité.


    Le prompt yes/no? vous invite à répondre pour confirmer l'enregistrement d'un fait.

    Merci pour vos retours.
    Logique sans matière est matière de logique.

  2. #2
    Membre du Club
    Homme Profil pro
    codeur
    Inscrit en
    Mars 2018
    Messages
    158
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 54
    Localisation : France, Gard (Languedoc Roussillon)

    Informations professionnelles :
    Activité : codeur

    Informations forums :
    Inscription : Mars 2018
    Messages : 158
    Points : 64
    Points
    64
    Par défaut 75 lignes de plus pour tester la logique de votre base (synonymes/antinomies).
    Vous pouvez ajouter les 75 lignes suivantes en fin de votre fichier pour tester la logique de votre base.

    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
    /************************************************************/
    /* the next predicates is just an test of logical traitement */
    full_antinomie(Left, Right) :- (antinomie(Left, Right)
                                    ; antinomie(Right, Left)).
    
    full_synonyme(Left, Right) :- (synonyme(Left, Right)
                                     ; synonyme(Right, Left)).
    
    
    full_no_analyze([X|R], S, R) :-
        
        (search_synonyme(X, Y),
         search_antinomie(Y, A),
         search_synonyme(A, S)
         ;
         search_antinomie(X, S)
         ;
         S = X).
                                                
    full_yes_analyze([X|R], A, R) :-
    
        (search_antinomie(X, Y),
         search_synonyme(Y, S),
         search_antinomie(S, A)
         ;
         search_synonyme(X, A)
         ;
         A = X).
    
    
    
    logic(X, Y) :- full_antinomie(X, A1), full_antinomie(Y, A2), synonyme(A1, A2), not(antinomie(A1, A2)).
    against(X, Y) :- full_synonyme(X, S1), full_antinomie(Y, S1), not(synonyme(S1, S2)).
    
    /*  end test (see main test/3)                           */
    /*******************************************************/
    
    /***************************************************/
    /* Main test :                                     */
    
    full_inverse_affirmative([Subject, Verb | Complement], [C, V, S], Result) :-
        
        full_yes_analyze([Subject], S, Substring),
    
        full_yes_analyze([Verb], V, Substring),
        
        full_yes_analyze(Complement, C, Result),
    
        full_yes_analyze([Rest], Result, Substring).
    
    full_inverse_interrogative([Verb, Subject | Complement], [C, V, S], Result) :-
        (full_yes_analyze([Subject], S, Substring),
             
             full_yes_analyze([Verb], V, Substring),
             
             full_yes_analyze(Complement, C, Rest), !,
             
             full_yes_analyze([Rest], Result, Substring)
                    
         ;
         full_no_analyze([Subject], S, Substring),
         
         full_no_analyze([Verb], V, Substring),
         
         full_no_analyze(Complement, C, Rest), !,
    
         full_yes_analyze([Rest], Result, Substring)).
         
    
    
    logical_test(Subject, Verbe, Complement) :- logic(S_Left, S_Right), logic(V_Left, V_Right), logic(C_Left, C_Right), full_inverse_interrogative([S_Right, V_Right, C_Right], [Subject, Verbe, Complement], R).
    against_test(Subject, Verbe, Complement) :- against(S_Left, S_Right), against(V_Left, V_Right), against(C_Left, C_Right), full_inverse_interrogative([S_Right, V_Right, C_Right], [Subject, Verbe, Complement], R).
    
    test(S, V, C) :- against_test(S, V, C), logical_test(S, V, C).

    En l'état, voici le résultat attendu de test(S, V, C).

    ?- test(S, V, C).
    S = V, V = C, C = die ;
    S = V, V = C, C = peace ;
    false.

    ?-
    Logique sans matière est matière de logique.

  3. #3
    Membre du Club
    Homme Profil pro
    codeur
    Inscrit en
    Mars 2018
    Messages
    158
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 54
    Localisation : France, Gard (Languedoc Roussillon)

    Informations professionnelles :
    Activité : codeur

    Informations forums :
    Inscription : Mars 2018
    Messages : 158
    Points : 64
    Points
    64
    Par défaut Correction des codes de test.
    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
    /************************************************************/
    /* the next predicates is just an test of logical traitement */
    full_antinomie(Left, Right) :- (antinomie(Left, Right)
                                    ; antinomie(Right, Left)).
    
    full_synonyme(Left, Right) :- (synonyme(Left, Right)
                                     ; synonyme(Right, Left)).
    
    
    full_no_analyze([X|R], S, R) :-
        
        (search_synonyme(X, Y),
         search_antinomie(Y, A),
         search_synonyme(A, S)
         ;
         search_antinomie(X, S)
         ;
         S = X).
                                                
    full_yes_analyze([X|R], A, R) :-
    
        (search_antinomie(X, Y),
         search_synonyme(Y, S),
         search_antinomie(S, A)
         ;
         search_synonyme(X, A)
         ;
         A = X).
    
    
    
    logic(X, Y) :- full_antinomie(X, A1), full_antinomie(Y, A2), not(antinomie(A1, A
    2)), synonyme(A1, A2).
    against(X, Y) :- full_synonyme(X, S1), full_antinomie(Y, S1), not(synonyme(S1, S
    2)).
    
    /*  end test (see main test/3)                           */
    /*******************************************************/
    /***************************************************/
    /* Main test :                                     */
    
    full_inverse_affirmative([Subject, Verb | Complement], [S, V, C], Result) :-
        
        full_yes_analyze([Subject], S, Substring),
    
        full_yes_analyze([Verb], V, Substring),
        
        full_yes_analyze(Complement, C, Result),
    
        full_yes_analyze([Rest], Result, Substring).
    
    full_inverse_interrogative([Verb, Subject | Complement], [V, S, C], Result) :-
        (full_yes_analyze([Subject], S, Substring),
             
             full_yes_analyze([Verb], V, Substring),
             
             full_yes_analyze(Complement, C, Rest), !,
             
             full_yes_analyze([Rest], Result, Substring)
                    
         ;
         full_no_analyze([Subject], S, Substring),
         
         full_no_analyze([Verb], V, Substring),
         
         full_no_analyze(Complement, C, Rest), !,
    
         full_yes_analyze([Rest], Result, Substring)).
         
    
    
    logical_affirmative_test(Subject, Verbe, Complement) :- logic(S_Left, S_Right), logic(V_Left, V_Right), logic(C_Left, C_Right), full_inverse_affirmative([S_Right, V_Right, C_Right], [Subject, Verbe, Complement], R).
    against_affirmative_test(Subject, Verbe, Complement) :- against(S_Left, S_Right), against(V_Left, V_Right), against(C_Left, C_Right), full_inverse_affirmative([S_Right, V_Right, C_Right], [Subject, Verbe, Complement], R).
    
    
    
    logical_interrogative_test(Verbe, Subject, Complement) :- logic(S_Left, S_Right), logic(V_Left, V_Right), logic(C_Left, C_Right), full_inverse_interrogative([V_Right, S_Right, C_Right], [Verbe, Subject, Complement], R).
    against_interrogative_test(Verbe, Subject, Complement) :- against(S_Left, S_Right), against(V_Left, V_Right), against(C_Left, C_Right), full_inverse_interrogative([V_Right, S_Right, C_Right], [Verbe, Subject, Complement], R).
    
    
    theory(S, V, C) :- against_interrogative_test(V, S, C), logical_affirmative_test(S, V, C).
    
    antitheory(V, S, C) :- against_affirmative_test(S, V, C), logical_interrogative_test(V, S, C).
    
    test(S, V, C) :- antitheory(V, S, C), theory(S, V, C).
    Resultat :

    ?- test(S, V, C).
    S = V, V = C, C = peace ;
    S = V, V = peace,
    C = live ;
    S = C, C = peace,
    V = live ;
    S = peace,
    V = C, C = live ;
    S = live,
    V = C, C = peace ;
    S = C, C = live,
    V = peace ;
    S = V, V = live,
    C = peace ;
    S = V, V = C, C = live ;
    false.

    ?-
    Logique sans matière est matière de logique.

  4. #4
    Membre du Club
    Homme Profil pro
    codeur
    Inscrit en
    Mars 2018
    Messages
    158
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 54
    Localisation : France, Gard (Languedoc Roussillon)

    Informations professionnelles :
    Activité : codeur

    Informations forums :
    Inscription : Mars 2018
    Messages : 158
    Points : 64
    Points
    64
    Par défaut Extention du dialog à la forme interrogative
    Bonjour,
    Ce fichier complète les prédécent code pour un dialogue dans une forme interrogative et est épuré d'un certain code inutil.

    C'est à dire que même sous une forme interrogative, le programme vérifira s'il trouve une relation.
    Si il n'en trouve pas, enregistrera automatiquement.
    Si il en trouve, il présentera le prompt de confirmation d'enregistrement pour le nouveau fait interrogé.


    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
    643
    644
    645
    646
    647
    648
    649
    650
    651
    652
    653
    654
    655
    656
    657
    658
    659
    660
    661
    662
    663
    664
    665
    666
    667
    668
    669
    670
    671
    672
    673
    674
    675
    676
    677
    678
    679
    680
    681
    682
    683
    684
    685
    686
    687
    688
    689
    690
    691
    692
    693
    694
    695
    696
    697
    698
    699
    700
    701
    702
    703
    704
    705
    706
    707
    708
    709
    710
    711
    712
    713
    714
    715
    716
    717
    718
    719
    720
    721
    722
    723
    724
    725
    726
    727
    728
    729
    730
    731
    732
    733
    734
    735
    736
    737
    738
    739
    740
    741
    742
    743
    744
    745
    746
    747
    748
    749
    750
    751
    752
    753
    754
    755
    756
    757
    758
    759
    760
    761
    762
    763
    764
    765
    766
    767
    768
    769
    770
    771
    772
    773
    774
    775
    776
    777
    778
    779
    780
    781
    782
    783
    784
    785
    786
    787
    788
    789
    790
    791
    792
    793
    794
    795
    796
    797
    798
    799
    800
    801
    802
    803
    804
    805
    806
    807
    808
    809
    810
    811
    812
    813
    814
    815
    816
    817
    818
    819
    820
    821
    822
    823
    824
    825
    826
    827
    828
    829
    830
    831
    832
    833
    834
    835
    836
    837
    838
    839
    840
    841
    842
    843
    844
    845
    846
    847
    848
    /******************************************************************************/
    /*                                   Prolog                                   */
    /*                          Linguistic Neuro Program                          */
    /*                               Version 1.1.1                                */
    /******************************************************************************/
    /* Date        : 2018-04-05 10:46:00                                          */
    /* Author      : Arknos                                                       */
    /* Version     : 1.1.1                                                        */
    /* Description : Linguistic Neuro Program                                     */
    /******************************************************************************/
    
    :- style_check(-singleton).
    
    :- initialization mainpe.
    
    /******************************************************************************/
    /* Prédicats dynamique de la base de faits.                                   */
    :- dynamic ( sujet/1 ).
    :- dynamic ( verbe/1 ).
    :- dynamic ( complément/1 ).
    :- dynamic ( lire/3 ).
    
    /* Décompose une phrase de forme [Sujet, Verbe | Complément]                  */
    defrag([Sujet, Verbe | Complément], Sujet, Verbe, Complément).
    
    /* Ajout des prédicats Sujet/1 et Verbe/1 s'ils n'existe pas et des prédicats */
    /* Complément/1 et lire/3                                                     */
    écrire(Sujet, Verbe, Complément) :-
        (not(verbe(Verbe)) ->
    	 assertz((verbe(Verbe)));
        true),
        (not(sujet(Sujet)) ->
    	 assertz((sujet(Sujet)));
         true),
        assertz((complément(Complément))),
        assertz((lire(Sujet, Verbe, Complément))).
    /*                                                                            */
    /******************************************************************************/
    
    subject(i).
    subject(you).
    subject(he).
    subject(she).
    subject(we).
    subject(they).
    
    antinomie(something, nothing).
    antinomie(reality, game).
    antinomie(peace, war).
    antinomie(die, live).
    antinomie(win, loose).
    antinomie(he, she).
    
    synonyme(no, negative).
    synonyme(negative, false).
    
    synonyme(yes, positive).
    synonyme(positive, true).
    
    synonyme(affirmative, positive).
    
    synonyme(power, love).
    synonyme(freedom, reason).
    synonyme(will, know).
    synonyme(game, abstract).
    synonyme(i, me).
    synonyme(love, like).
    synonyme(peace, love).
    synonyme(war, die).
    synonyme(kill, war).
    synonyme(play, love).
    
    /******************************************************************************/
    /*                                                                            */
    cprint(Sujet, Verbe, List, N) :-
        nth0(N, List, E),
        atomic_list_concat(E, ' ', Comp),	  
        atomic_list_concat([Sujet, Verbe, Comp], ' ', Result),
        write(Result), writeln('!').
    
    vprint(Sujet, List, Complément, N) :-
        nth0(N, List, Ver),
        /* writeln("nth0 ok!"), */
        /* atomic_list_concat(E, ' ', Ver), */
        /* write("concat 1 ok!"), */
        atomic_list_concat(Complément, ' ', Comp),
        /* write("concat 2 ok!"), */
        atomic_list_concat([Sujet, Ver, Comp], ' ', Result),
        /* write("concat 3 ok!"), */
        write(Result), writeln('!').
    /*                                                                            */
    /******************************************************************************/
    
    search_antinomie(Left, Right) :- (antinomie(Left, Right), !
    				  ; antinomie(Right, Left)).
    
    search_synonyme(Left, Right) :- (synonyme(Left, Right), !
    				 ; synonyme(Right, Left)).
    
    
    no_analyze([X|R], S, R) :-
        
        (search_synonyme(X, Y),
         search_antinomie(Y, A),
         search_synonyme(A, S), !
         ;
         search_antinomie(X, S), !
         ;
         S = X).
    
    yes_analyze([X|R], A, R) :-
    
        (search_antinomie(X, Y),
         search_synonyme(Y, S),
         search_antinomie(S, A), !
         ;
         search_synonyme(X, A), !
         ;
         A = X).
    
    no :- write('no, ').
    yes :- write('yes, ').
    
    no([X|L], S) :- no_analyze(L, S).
    yes([X|L], A) :- yes_analyze(L, A).
    
    is_affirmative([Subject, Verb | Complement]) :- subject(Subject).
    is_interrogative([Verb, Subject | Complement]) :- subject(Subject).
    
    
    is_affirmative(List, End) :- (End == 33; End == 46),
    			     is_affirmative(List).
    
    is_interrogative(List, End) :- End == 63,
    			       is_interrogative(List).
    
    
    inverse_affirmative([Subject, Verb | Complement], [S, V, C], Result) :-
        
        yes_analyze([Subject], S, Substring),
    
        yes_analyze([Verb], V, Substring),
        
        yes_analyze(Complement, C, Rest),
    
        yes_analyze([Rest], Result, Substring).
    
    
    inverse_interrogative([Verb, Subject | Complement], [V, S, C], Result) :-
        (yes_analyze([Subject], S, Substring),
         
         yes_analyze([Verb], V, Substring),
         
         yes_analyze(Complement, C, Rest), !,
         
         yes_analyze([Rest], Result, Substring)
    
    	    
         ;
         no_analyze([Subject], S, Substring),
         
         no_analyze([Verb], V, Substring),
         
         no_analyze(Complement, C, Rest), !,
    
         yes_analyze([Rest], Result, Substring)).
    
    
    
    
    words_to_list(Index, Words, List) :-
        nth0(Index, Words, S),
        nth0(Index, List, A),
        atom_codes(A, S).
    
    
    output_to_list(String, List, Sentence) :-
        split_string(String, "-', ", ", ", String_List),
        length(String_List, Length),
        List_Length is Length + 1,
        length(List, List_Length),
        Last is Length - 1,
    
        foreach(between(0, Last, Index),
    	    words_to_list(Index, String_List, List)),
    
        length(Sentence, Length),
        foreach(between(0, Last, Index),
    	    words_to_list(Index, String_List, Sentence)).
    
    input_to_list(String, List, Sentence) :-
        split_string(String, "-', ", ", ", String_List),
        length(String_List, Length),
        List_Length is Length + 1,
        length(List, List_Length),
        Last is Length - 1,
    
        foreach(between(0, Last, Index),
    	    words_to_list(Index, String_List, List)),
    
        length(Sentence, Length),
        foreach(between(0, Last, Index),
    	    words_to_list(Index, String_List, Sentence)).
    
    
    
    %pnl(Round) :-
    pnl :-    
        read_string(user_input, "!?.", """\n", End, String),    
        input_to_list(String, List, Sentence),
        length(List, Length),
        nth1(Length, List, At_End),
        char_code(At_End, End),
        
        nth1(1, Sentence, Veracity),   
        (Veracity == yes -> delete(Sentence, yes, Unexpected);
         Unexpected = Sentence;
         (Veracity == no -> delete(Sentence, no, Unexpected);
          Unexpected = Sentence;
          (Veracity == true -> delete(Sentence, true, Unexpected);
           Unexpected = Sentence;
           (Veracity == false -> delete(Sentence, false, Unexpected);
    	Unexpected = Sentence)))),
        
        %%writeln("stop :  0.0.0"),
        (is_affirmative(Unexpected, End) ->
    	 
    	 /*********************************************************************/
    	 /*                                                                   */
    	 /*                            Affirmative                            */
    	 /*                                                                   */
    	 /*********************************************************************/
    	 
    	 
    	 
    	 %%writeln("stop :  0.0.1"),
    	 %%%write(Unexpected),
    	 /************************************************/
    	 /*                                              */
    	 defrag(Unexpected, Sujet, Verbe, Complément),
    	 %%writeln("stop :  0.0.2"),
    	 (lire(Sujet, Verbe, Complément) ->
    	      %%writeln("stop :  0.1.0"),
    	      /* Affirmation */
    	      write("Yes, "),
    	      %%writeln("stop :  0.5.1"),
    	      inverse_affirmative(Unexpected, Response, Rest),
    	      %%writeln("stop :  0.5.2"),
    	      inverse_affirmative(Response, Affirmative, Rest1),	 
    	      %%writeln("stop :  0.5.3"),
    	      atomics_to_string(Affirmative, ' ', Affirmation),	
    	      %%writeln("stop :  0.5.4"),
    	      
    	      (is_list(Rest) ->
    		   length(Rest, Rest_Length),
    		   (Rest_Length \= 0 ->
    			atomics_to_string(Rest, ' ', Complement),
    			
    			write(Affirmation),
    			write(' '),
    			write(Complement), writeln('!') ;
    		    
    		    write(Affirmation), writeln('!'))
    	       ;
    	       write(Affirmation), writeln('!'))
    		  
    		  
    		  /***********************************************/
    		  /*                                             */
    		  /***********************************************/
    		  %% inverse_affirmative(Unexpected, Affirmative, Rest),
    		  
    		  
    		  %% %%writeln("stop :  0.1.1"),
    		  %% atomics_to_string(Affirmative, ' ', Affirmation),	
    		  
    		  %% %%writeln("stop :  0.1.2"),	      
    
    		  %% output_to_list(Affirmation, Full_Request, Request),
    		  %% inverse_affirmative(Request, R, Rest),
    
    		  %% defrag(R, S, V, C),
    		  
    		  %% atomic_list_concat(C, ' ', Comp),
    		  %% atomic_list_concat([V, Comp, S], ' ', Result)
    		  
    		  %% (is_list(Rest) ->
    		  %% 	   length(Rest, Rest_Length),
    		  %% 	   (Rest_Length \= 0 ->
    		  %% 		atomics_to_string(Rest, ' ', Complement),
    		  
    		  %% 		write(Result),
    		  %% 		write(' '),
    		  %% 		write(Complement), writeln('!') ;
    		  
    		  %% 	    write(Result), writeln('!'))
    		  %%  ;
    		  %%  write(Result), writeln('!'))
    	  ;
    	  %%writeln("stop :  0.2.0"),
    	  /* Négation */
    	  findall(C, lire(Sujet, Verbe, C), Goal),
    	  %writeln("findall(C, ... :  0.2.1"),
    	  /* lire(Sujet, Verbe, Goal), */
    	  length(Goal, Len),
    	  %%writeln("stop :  0.2.2"),
    	  (Len \= 0 ->
    	       writeln("No, but : "),
    	       Last is Len - 1,
    	       foreach(between(0, Last, X),
    		       cprint(Sujet, Verbe, Goal, X)),
    	       nl,
    	       /* Question */
    	       atomic_list_concat(Complément, ' ', Comp),
    	       atomic_list_concat([Verbe, Sujet, Comp], ' ', Interrogation),
    	       write(Interrogation), writeln("?"),
    	       nl,
    	       /* écrire nouveau fait */
    	       write("yes/no?"),
    	       read(X),
    	       (X == yes ->  écrire(Sujet, Verbe, Complément) ; true)
    	   ;
    	   %%writeln("stop :  0.3.0"),
    	   findall(V, lire(Sujet, V, _), Goal),
    	   /* lire(Sujet, Verbe, Goal), */
    	   %%writeln("findall (V, ... :  0.3.1"),
    	   length(Goal, Len),
    	   %%writeln("stop :  0.3.2"),
    	   (Len \= 0 ->
    		writeln("No, but : "),
    		Last is Len - 1,
    		foreach(between(0, Last, X),
    			vprint(Sujet, Goal, Complément, X)),
    		nl,
    		/* Question */
    		atomic_list_concat(Complément, ' ', Comp),
    		atomic_list_concat([Verbe, Sujet, Comp], ' ', Interrogation),
    		write(Interrogation), writeln("?"),
    		nl,
    		/* écrire nouveau fait */
    		write("yes/no?"),
    		read(X),
    		(X == yes ->  écrire(Sujet, Verbe, Complément) ; true))
    	   ;
    	   %% %%writeln("stop :  0.4.0"),
    	   %% %inverse_interrogative([Verbe, Sujet, Complément], R, Rest),
    	   %% %writeln(R),
    	   %% %defrag(R, Verb, Subject, Complement),
    	   
    	   %% %%%write("No, "),
    	   %% /* Question */
    	   %% %writeln(Complement),
    	   %% %writeln("STOP :  1"),
    	   %% %%writeln("stop :  0.4.1"),
    	   %% atomic_list_concat(Complément, ' ', Comp),
    	   %% %writeln(Comp),
    	   %% %writeln("STOP :  2"),
    	   %% %%writeln("stop :  0.4.2"),
    	   %% atomic_list_concat([Verbe, Sujet, Comp], ' ', Interrogation),
    	   %% %%writeln("stop :  0.4.3"),
    	   %% output_to_list(Interrogation, Full_Request, Request),
    	   %% %%writeln("stop :  0.4.4"),
    	   %% inverse_interrogative(Request, R, Rest),
    	   
    	   %% inverse_interrogative(R, Interrogative, Rest2),
    	   
    	   %% %%writeln("stop :  0.4.5"),
    	   %% %%writeln(Interrogative),
    	   %% %%writeln("stop :  0.4.6"),
    	   %% defrag(Interrogative, V, S, C),
    	   %% %%writeln("stop :  0.4.7"),
    	   %% %%writeln(C),
    	   %% %%writeln("stop :  0.4.8"),
    	   %% /* Question */
    	   %% atomic_list_concat(C, ' ', Comp2),
    	   %% %%writeln("stop :  0.4.9"),
    	   %% atomic_list_concat([V, Comp2, S], ' ', Question),
    	   %% %%writeln("stop :  0.4.10"),
    	   %% (is_list(Rest) ->
    	   %% 	length(Rest, Rest_Length),
    	   %% 	(Rest_Length \= 0 ->
    	   %% 	     atomics_to_string(Rest, ' ', Complement),
    	   
    	   %% 	     write(Question),
    	   %% 	     write(' '),
    	   %% 	     write(Complement), writeln('?') ;
    	   
    	   %% 	 write(Question), writeln('?'))
    	   %%  ;
    	   %%  write(Question), writeln('?')),	    
    
    	   /***********************/
    	   /* écrire nouveau fait */
    	   /*                     */
    	   /***********************/
    	   %%write("yes/no?"),
    	   %%read(X),
    	   %%(X == yes ->  écrire(Sujet, Verbe, Complément) ; true))),
    	   écrire(Sujet, Verbe, Complément),
    	   /*                                                    */
    	   /******************************************************/
    	   %%writeln("stop :  0.5.1"),
    	   inverse_affirmative(Unexpected, Response, Rest),
    	   %%writeln("stop :  0.5.2"),
    	   inverse_affirmative(Response, Affirmative, Rest1),	 
    	   %%writeln("stop :  0.5.3"),
    	   atomics_to_string(Affirmative, ' ', Affirmation),	
    	   %%writeln("stop :  0.5.4"),
    	   
    	   (is_list(Rest) ->
    		length(Rest, Rest_Length),
    		(Rest_Length \= 0 ->
    		     atomics_to_string(Rest, ' ', Complement),
    		     
    		     write(Affirmation),
    		     write(' '),
    		     write(Complement), writeln('!') ;
    		 
    		 write(Affirmation), writeln('!'))
    	    ;
    	    write(Affirmation), writeln('!'));
    	   %%writeln("stop :  0.5.1"),
    	   inverse_affirmative(Unexpected, Response, Rest),
    	   %%writeln("stop :  0.5.2"),
    	   inverse_affirmative(Response, Affirmative, Rest1),	 
    	   %%writeln("stop :  0.5.3"),
    	   atomics_to_string(Affirmative, ' ', Affirmation),	
    	   %%writeln("stop :  0.5.4"),
    	   
    	   (is_list(Rest) ->
    		length(Rest, Rest_Length),
    		(Rest_Length \= 0 ->
    		     atomics_to_string(Rest, ' ', Complement),
    		     
    		     write(Affirmation),
    		     write(' '),
    		     write(Complement), writeln('!') ;
    		 
    		 write(Affirmation), writeln('!'))
    	    ;
    	    write(Affirmation), writeln('!')))
    	  ;
    	  %%writeln("stop :  0.5.1"),
    	  inverse_affirmative(Unexpected, Response, Rest),
    	  %%writeln("stop :  0.5.2"),
    	  inverse_affirmative(Response, Affirmative, Rest1),	 
    	  %%writeln("stop :  0.5.3"),
    	  atomics_to_string(Affirmative, ' ', Affirmation),	
    	  %%writeln("stop :  0.5.4"),
    	  
    	  (is_list(Rest) ->
    	       length(Rest, Rest_Length),
    	       (Rest_Length \= 0 ->
    		    atomics_to_string(Rest, ' ', Complement),
    		    
    		    write(Affirmation),
    		    write(' '),
    		    write(Complement), writeln('!') ;
    		
    		write(Affirmation), writeln('!'))
    	   ;
    	   write(Affirmation), writeln('!')))
         ;
    
         /*************************************************************************/
         /*                                                                       */
         /*                          Interrogative                                */
         /*                                                                       */
         /*************************************************************************/
         
         %%writeln("stop :  0.6.0"),
         inverse_interrogative(Unexpected, R, Rest),
         %%writeln("stop :  0.6.1"),
         inverse_interrogative(R, Interrogative, Rest2),
         %%writeln("stop :  0.6.2"),
         /************************************************/
         /*                                              */
         defrag(Interrogative, Verbe1, Sujet1, Complément1),     
         /*                                              */
         /************************************************/
         
         %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
         %% atomics_to_string(Interrogative, ' ', Result),
         %%writeln("stop :  0.6.3"),
         
         %% (is_list(Rest), length(Rest, Rest_Length), Rest_Length \= 0 ->
         %% 	  atomics_to_string(Rest, ' ', Complement),
         
         %% 	  yes, write(Result), write(' '), write(Complement), writeln('?') ;
         %%  write(Result), writeln('?')),
         %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
         
         /*********************************************************************/
         /*                                                                   */
         /*                                                                   */
    
         yes_analyze(Complément1, Perfect, Res),
         Unexpected1 = [Sujet1, Verbe1, Perfect, Res],
         defrag(Unexpected1, Sujet2, Verbe2, Complément2),     
         /*                                                                   */
         /*                                                                   */
         /*********************************************************************/
         (lire(Sujet2, Verbe2, Complément2) ->
    	  %%writeln("stop :  1.1.0"),
    	  /* Affirmation */
    	  write("Yes, "),
    	  %%writeln("stop :  1.5.1"),
    	  inverse_affirmative(Unexpected1, Response, Rest),
    	  %%writeln("stop :  1.5.2"),
    	  inverse_affirmative(Response, Affirmative, Rest1),	 
    	  %%writeln("stop :  1.5.3"),
    	  atomics_to_string(Affirmative, ' ', Affirmation),	
    	  %%writeln("stop :  1.5.4"),
    	  
    	  (is_list(Rest) ->
    	       length(Rest, Rest_Length),
    	       (Rest_Length \= 0 ->
    	  	    atomics_to_string(Rest, ' ', Complement),
    		    
    	  	    write(Affirmation),
    	  	    write(' '),
    	  	    write(Complement), writeln('!') ;
    		
    	  	write(Affirmation), writeln('!'))
    	   ;
    	   write(Affirmation), writeln('!'))
    	      
    	      
    	  %%     /***********************************************/
    	  %%     /*                                             */
    	  %%     /***********************************************/
    	  %%     %% inverse_affirmative(Unexpected1, Affirmative, Rest),
    	      
    	      
    	  %%     %% %%writeln("stop :  1.1.1"),
    	  %%     %% atomics_to_string(Affirmative, ' ', Affirmation),	
    	      
    	  %%     %% %%writeln("stop :  1.1.2"),	      
    
    	  %%     %% output_to_list(Affirmation, Full_Request, Request),
    	  %%     %% inverse_affirmative(Request, R, Rest),
    
    	  %%     %% defrag(R, S, V, C),
    	      
    	  %%     %% atomic_list_concat(C, ' ', Comp),
    	  %%     %% atomic_list_concat([V, Comp, S], ' ', Result)
    	      
    	  %%     %% (is_list(Rest) ->
    	  %%     %% 	   length(Rest, Rest_Length),
    	  %%     %% 	   (Rest_Length \= 0 ->
    	  %%     %% 		atomics_to_string(Rest, ' ', Complement),
    	      
    	  %%     %% 		write(Result),
    	  %%     %% 		write(' '),
    	  %%     %% 		write(Complement), writeln('!') ;
    	      
    	  %%     %% 	    write(Result), writeln('!'))
    	  %%     %%  ;
    	  %%      %%  write(Result), writeln('!'))
          ;
          %%writeln("stop :  1.2.0"),
          /* Négation */
          findall(C, lire(Sujet2, Verbe2, C), Goal),
          %%writeln("findall(C, ... :  1.2.1"),
          /* lire(Sujet2, Verbe2, Goal), */
          length(Goal, Len),
          %%writeln("stop :  1.2.2"),
          (Len \= 0 ->
    	   writeln("No, but : "),
    	   Last is Len - 1,
    	   foreach(between(0, Last, X),
    		   cprint(Sujet2, Verbe2, Goal, X)),
    	   nl,
    	   /* Question */
    	   atomic_list_concat(Complément2, ' ', Comp),
    	   atomic_list_concat([Verbe2, Sujet2, Comp], ' ', Interrogation),
    	   write(Interrogation), writeln("?"),
    	   nl,
    	   /* écrire nouveau fait */
    	   write("yes/no?"),
    	   read(X),
    	   (X == yes ->  écrire(Sujet2, Verbe2, Complément2) ; true)
           ;
           %%writeln("stop :  1.3.0"),
           findall(V, lire(Sujet2, V, Complément2), Goal),
           /* lire(Sujet2, Verbe2, Goal), */
           %%writeln("findall (V, ... :  1.3.1"),
           length(Goal, Len),
           %%writeln("stop :  1.3.2"),
           (Len \= 0 ->
    	    writeln("No, but : "),
    	    Last is Len - 1,
    	    foreach(between(0, Last, X),
    		    vprint(Sujet2, Goal, Complément2, X)),
    	    nl,
    	    /* Question */
    	    atomic_list_concat(Complément2, ' ', Comp),
    	    atomic_list_concat([Verbe2, Sujet2, Comp], ' ', Interrogation),
    	    write(Interrogation), writeln("?"),
    	    nl,
    	    /* écrire nouveau fait */
    	    write("yes/no?"),
    	    read(X),
    	    (X == yes ->  écrire(Sujet2, Verbe2, Complément2) ; true)
           ;
           %% %%writeln("stop :  1.4.0"),
           %% %inverse_interrogative([Verbe1, Sujet1, Complément1], R, Rest),
           %% %writeln(R),
           %% %defrag(R, Verb, Subject, Complement),
           
           %% %%%write("No, "),
           %% /* Question */
           %% %writeln(Complement),
           %% %writeln("STOP :  1"),
           %% %%writeln("stop :  1.4.1"),
           %% atomic_list_concat(Complément1, ' ', Comp),
           %% %writeln(Comp),
           %% %writeln("STOP :  2"),
           %% %%writeln("stop :  1.4.2"),
           %% atomic_list_concat([Verbe1, Sujet1, Comp], ' ', Interrogation),
           %% %%writeln("stop :  1.4.3"),
           %% output_to_list(Interrogation, Full_Request, Request),
           %% %%writeln("stop :  1.4.4"),
           %% inverse_interrogative(Request, R, Rest),
           
           %% inverse_interrogative(R, Interrogative, Rest2),
           
           %% %%writeln("stop :  1.4.5"),
           %% %%writeln(Interrogative),
           %% %%writeln("stop :  1.4.6"),
           %% defrag(Interrogative, V, S, C),
           %% %%writeln("stop :  1.4.7"),
           %% %%writeln(C),
           %% %%writeln("stop :  1.4.8"),
           %% /* Question */
           %% atomic_list_concat(C, ' ', Comp2),
           %% %%writeln("stop :  1.4.9"),
           %% atomic_list_concat([V, Comp2, S], ' ', Question),
           %% %%writeln("stop :  1.4.10"),
           %% (is_list(Rest) ->
           %% 	length(Rest, Rest_Length),
           %% 	(Rest_Length \= 0 ->
           %% 	     atomics_to_string(Rest, ' ', Complement),
           
           %% 	     write(Question),
           %% 	     write(' '),
           %% 	     write(Complement), writeln('?') ;
           
           %% 	 write(Question), writeln('?'))
           %%  ;
           %%  write(Question), writeln('?')),	    
    
           /***********************/
           /* écrire nouveau fait */
           /*                     */
           /***********************/
           %%write("yes/no?"),
           %%read(X),
           %%(X == yes ->  écrire(Sujet1, Verbe1, Complément1) ; true))),
           écrire(Sujet2, Verbe2, Complément2),
           /*                                                    */
           /******************************************************/
           %%writeln("stop :  1.5.1"),
           inverse_affirmative(Unexpected1, Response, Rest),
           %%writeln("stop :  1.5.2"),
           inverse_affirmative(Response, Affirmative, Rest1),	 
           %%writeln("stop :  1.5.3"),
           atomics_to_string(Affirmative, ' ', Affirmation),	
           %%writeln("stop :  1.5.4"),
           
           (is_list(Rest) ->
    	    length(Rest, Rest_Length),
    	    (Rest_Length \= 0 ->
    		 atomics_to_string(Rest, ' ', Complement),
    		 
    		 write(Affirmation),
    		 write(' '),
    		 write(Complement), writeln('!') ;
    	     
    	     write(Affirmation), writeln('!'))
    	;
    	write(Affirmation), writeln('!'));
           %%writeln("stop :  1.5.1"),
           inverse_affirmative(Unexpected1, Response, Rest),
           %%writeln("stop :  1.5.2"),
           inverse_affirmative(Response, Affirmative, Rest1),	 
           %%writeln("stop :  1.5.3"),
           atomics_to_string(Affirmative, ' ', Affirmation),	
           %%writeln("stop :  1.5.4"),
           
           (is_list(Rest) ->
    	    length(Rest, Rest_Length),
    	    (Rest_Length \= 0 ->
    		 atomics_to_string(Rest, ' ', Complement),
    		 
    		 write(Affirmation),
    		 write(' '),
    		 write(Complement), writeln('!') ;
    	     
    	     write(Affirmation), writeln('!'))
    	;
    	write(Affirmation), writeln('!')))
          ;
          %%writeln("stop :  1.5.1"),
          inverse_affirmative(Unexpected1, Response, Rest),
          %%writeln("stop :  1.5.2"),
          inverse_affirmative(Response, Affirmative, Rest1),	 
          %%writeln("stop :  1.5.3"),
          atomics_to_string(Affirmative, ' ', Affirmation),	
          %%writeln("stop :  1.5.4"),
          
          (is_list(Rest) ->
    	   length(Rest, Rest_Length),
    	   (Rest_Length \= 0 ->
    		atomics_to_string(Rest, ' ', Complement),
    		
    		write(Affirmation),
    		write(' '),
    		write(Complement), writeln('!') ;
    	    
    	    write(Affirmation), writeln('!'))
           ;
           write(Affirmation), writeln('!'))))
    	 /*                                                                   */
    	 /*********************************************************************/
    	 
        ),
        pnl.
    
    
    /* saving database */
    savepe :-
        tell('subjects.pl'), listing(sujet(_)), told,
        tell('verbs.pl'), listing(verbe(_)), told,
        tell('complements.pl'), listing(complément(_)), told,
        tell('facts.pl'), listing(lire(_, _, _)), told.
    
    /* loading database */
    loadpe :-
        consult(subjects),
        consult(verbs),
        consult(complements),
        consult(facts).
    
    /* initialization */
    initpe :-
        write("Initialize with : "),
        read(P),
        writeln(P),
        split_string(P, ' ', "", L),
        defrag(L, Sujet, Verbe, Complément),
        écrire(Sujet, Verbe, Complément).
    
    mainpe :-
        (not(loadpe) -> initpe, savepe,
    		    (pnl -> true;
    		     savepe)
         ;     
         (pnl -> true;
          savepe),
         savepe).
    
    
    /************************************************************/
    /* the next predicates is just an test of logical traitement */
    full_antinomie(Left, Right) :- (antinomie(Left, Right)
    				; antinomie(Right, Left)).
    
    full_synonyme(Left, Right) :- (synonyme(Left, Right)
    				 ; synonyme(Right, Left)).
    
    
    full_no_analyze([X|R], S, R) :-
        
        (search_synonyme(X, Y),
         search_antinomie(Y, A),
         search_synonyme(A, S)
         ;
         search_antinomie(X, S)
         ;
         S = X).
    					    
    full_yes_analyze([X|R], A, R) :-
    
        (search_antinomie(X, Y),
         search_synonyme(Y, S),
         search_antinomie(S, A)
         ;
         search_synonyme(X, A)
         ;
         A = X).
    
    
    
    logic(X, Y) :- full_antinomie(X, A1), full_antinomie(Y, A2), not(antinomie(A1, A2)), synonyme(A1, A2).
    against(X, Y) :- full_synonyme(X, S1), full_antinomie(Y, S1), not(synonyme(S1, S2)).
    
    /*  end test (see main test/3)                           */
    /*******************************************************/
    
    /***************************************************/
    /* Main test :                                     */
    
    full_inverse_affirmative([Subject, Verb | Complement], [S, V, C], Result) :-
        
        full_yes_analyze([Subject], S, Substring),
    
        full_yes_analyze([Verb], V, Substring),
        
        full_yes_analyze(Complement, C, Result),
    
        full_yes_analyze([Rest], Result, Substring).
    
    full_inverse_interrogative([Verb, Subject | Complement], [V, S, C], Result) :-
        (full_yes_analyze([Subject], S, Substring),
    	 
    	 full_yes_analyze([Verb], V, Substring),
    	 
    	 full_yes_analyze(Complement, C, Rest), !,
    	 
    	 full_yes_analyze([Rest], Result, Substring)
    		
         ;
         full_no_analyze([Subject], S, Substring),
         
         full_no_analyze([Verb], V, Substring),
         
         full_no_analyze(Complement, C, Rest), !,
    
         full_yes_analyze([Rest], Result, Substring)).
         
    
    
    logical_affirmative_test(Subject, Verbe, Complement) :- logic(S_Left, S_Right), logic(V_Left, V_Right), logic(C_Left, C_Right), full_inverse_affirmative([S_Right, V_Right, C_Right], [Subject, Verbe, Complement], R).
    against_affirmative_test(Subject, Verbe, Complement) :- against(S_Left, S_Right), against(V_Left, V_Right), against(C_Left, C_Right), full_inverse_affirmative([S_Right, V_Right, C_Right], [Subject, Verbe, Complement], R).
    
    
    
    logical_interrogative_test(Verbe, Subject, Complement) :- logic(S_Left, S_Right), logic(V_Left, V_Right), logic(C_Left, C_Right), full_inverse_interrogative([V_Right, S_Right, C_Right], [Verbe, Subject, Complement], R).
    against_interrogative_test(Verbe, Subject, Complement) :- against(S_Left, S_Right), against(V_Left, V_Right), against(C_Left, C_Right), full_inverse_interrogative([V_Right, S_Right, C_Right], [Verbe, Subject, Complement], R).
    
    
    theory(S, V, C) :- against_interrogative_test(V, S, C), logical_affirmative_test(S, V, C).
    
    antitheory(V, S, C) :- against_affirmative_test(S, V, C), logical_interrogative_test(V, S, C).
    
    test(S, V, C) :- antitheory(V, S, C), theory(S, V, C).

    Edit : En l'état, n'oubliez pas d'utiliser le précicat savepe/0 avant de quitter Prolog.

    Edit 2 : le jeudi 05 avril 2018 : 13:00 je corrige les codes, mais avec du code inuti

    J'avais oublié de changer les nom de Verbe1 Sujet1 Complément1 en Sujet2, Verbe2 Complément2 dans la partie interogative.
    Logique sans matière est matière de logique.

  5. #5
    Membre du Club
    Homme Profil pro
    codeur
    Inscrit en
    Mars 2018
    Messages
    158
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 54
    Localisation : France, Gard (Languedoc Roussillon)

    Informations professionnelles :
    Activité : codeur

    Informations forums :
    Inscription : Mars 2018
    Messages : 158
    Points : 64
    Points
    64
    Par défaut Complétion et Correction
    Bonjour,
    Je poste un nouveau listing des code du programme corrigeant un certain nombre de section de traitement.

    J'ai corrigé au mieux cependant le programme présente un problème récurent de répétition de code.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    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
    643
    644
    645
    646
    647
    648
    649
    650
    651
    652
    653
    654
    655
    656
    657
    658
    659
    660
    661
    662
    663
    664
    665
    666
    667
    668
    669
    670
    671
    672
    673
    674
    675
    676
    677
    678
    679
    680
    681
    682
    683
    684
    685
    686
    687
    688
    689
    690
    691
    692
    693
    694
    695
    696
    697
    698
    699
    700
    701
    702
    703
    704
    705
    706
    707
    708
    709
    710
    711
    712
    713
    714
    715
    716
    717
    718
    719
    720
    721
    722
    723
    724
    725
    726
    727
    728
    729
    730
    731
    732
    733
    734
    735
    736
    737
    738
    739
    740
    741
    742
    
    /******************************************************************************/
    /*                                   Prolog                                   */
    /*                          Linguistic Neuro Program                          */
    /*                               Version 1.1.2                                */
    /******************************************************************************/
    /* Date        : 2018-04-05 14:55:00                                          */
    /* Author      : Arknos                                                       */
    /* Version     : 1.1.2                                                        */
    /* Description : Linguistic Neuro Program                                     */
    /******************************************************************************/
    
    %%:- style_check(-singleton).
    
    %%:- initialization mainpe.
    
    /******************************************************************************/
    /* Prédicats dynamique de la base de faits.                                   */
    :- dynamic ( sujet/1 ).
    :- dynamic ( verbe/1 ).
    :- dynamic ( complément/1 ).
    :- dynamic ( lire/3 ).
    
    /* Décompose une phrase de forme [Sujet, Verbe | Complément]                  */
    defrag([Sujet, Verbe | Complément], Sujet, Verbe, Complément).
    
    /* Ajout des prédicats Sujet/1 et Verbe/1 s'ils n'existe pas et des prédicats */
    /* Complément/1 et lire/3                                                     */
    écrire(Sujet, Verbe, Complément) :-
        (not(verbe(Verbe)) ->
    	 assertz((verbe(Verbe)));
        true),
        (not(sujet(Sujet)) ->
    	 assertz((sujet(Sujet)));
         true),
        assertz((complément(Complément))),
        assertz((lire(Sujet, Verbe, Complément))).
    /*                                                                            */
    /******************************************************************************/
    
    subject(i).
    subject(you).
    subject(he).
    subject(she).
    subject(we).
    subject(they).
    
    antinomie(something, nothing).
    antinomie(reality, game).
    antinomie(peace, war).
    antinomie(die, live).
    antinomie(win, loose).
    antinomie(he, she).
    
    synonyme(no, negative).
    synonyme(negative, false).
    
    synonyme(yes, positive).
    synonyme(positive, true).
    
    synonyme(affirmative, positive).
    
    synonyme(power, love).
    synonyme(freedom, reason).
    synonyme(will, know).
    synonyme(game, abstract).
    synonyme(i, me).
    synonyme(love, like).
    synonyme(peace, love).
    synonyme(war, die).
    synonyme(kill, war).
    synonyme(play, love).
    
    /******************************************************************************/
    /*                                                                            */
    cprint(Sujet, Verbe, List, N) :-
        nth0(N, List, E),
        %%write("concat E..."),
        atomic_list_concat(E, ' ', Comp),
        %%write("concat E ok!"),
        atomic_list_concat([Sujet, Verbe, Comp], ' ', Result),
        %%write("concat Result ok!"),
        write(Result), writeln('!').
    
    vprint(Sujet, List, Complément, N) :-
        nth0(N, List, Ver),
        /* writeln("nth0 ok!"), */
        /* atomic_list_concat(E, ' ', Ver), */
        /* write("concat 1 ok!"), */
        atomic_list_concat(Complément, ' ', Comp),
        /* write("concat 2 ok!"), */
        atomic_list_concat([Sujet, Ver, Comp], ' ', Result),
        /* write("concat 3 ok!"), */
        write(Result), writeln('!').
    /*                                                                            */
    /******************************************************************************/
    
    search_antinomie(Left, Right) :- (antinomie(Left, Right), !
    				  ; antinomie(Right, Left)).
    
    search_synonyme(Left, Right) :- (synonyme(Left, Right), !
    				 ; synonyme(Right, Left)).
    
    
    no_analyze([X|R], S, R) :-
        
        (search_synonyme(X, Y),
         search_antinomie(Y, A),
         search_synonyme(A, S), !
         ;
         search_antinomie(X, S), !
         ;
         S = X).
    
    yes_analyze([X|R], A, R) :-
    
        (search_antinomie(X, Y),
         search_synonyme(Y, S),
         search_antinomie(S, A), !
         ;
         search_synonyme(X, A), !
         ;
         A = X).
    
    no :- write('no, ').
    yes :- write('yes, ').
    
    no([X|L], S) :- no_analyze(L, S).
    yes([X|L], A) :- yes_analyze(L, A).
    
    is_affirmative([Subject, Verb | Complement]) :- subject(Subject).
    is_interrogative([Verb, Subject | Complement]) :- subject(Subject).
    
    
    is_affirmative(List, End) :- (End == 33; End == 46),
    			     is_affirmative(List).
    
    is_interrogative(List, End) :- End == 63,
    			       is_interrogative(List).
    
    
    inverse_affirmative([Subject, Verb | Complement], [S, V, C], Result) :-
        
        yes_analyze([Subject], S, Substring),
    
        yes_analyze([Verb], V, Substring),
        
        yes_analyze(Complement, C, Rest),
    
        yes_analyze([Rest], Result, Substring).
    
    
    inverse_interrogative([Verb, Subject | Complement], [V, S, C], Result) :-
        (yes_analyze([Subject], S, Substring),
         
         yes_analyze([Verb], V, Substring),
         
         yes_analyze(Complement, C, Rest), !,
         
         yes_analyze([Rest], Result, Substring)
    
    	    
         ;
         no_analyze([Subject], S, Substring),
         
         no_analyze([Verb], V, Substring),
         
         no_analyze(Complement, C, Rest), !,
    
         yes_analyze([Rest], Result, Substring)).
    
    
    
    
    words_to_list(Index, Words, List) :-
        nth0(Index, Words, S),
        nth0(Index, List, A),
        atom_codes(A, S).
    
    
    output_to_list(String, List, Sentence) :-
        split_string(String, "-', ", ", ", String_List),
        length(String_List, Length),
        List_Length is Length + 1,
        length(List, List_Length),
        Last is Length - 1,
    
        foreach(between(0, Last, Index),
    	    words_to_list(Index, String_List, List)),
    
        length(Sentence, Length),
        foreach(between(0, Last, Index),
    	    words_to_list(Index, String_List, Sentence)).
    
    input_to_list(String, List, Sentence) :-
        split_string(String, "-', ", ", ", String_List),
        length(String_List, Length),
        List_Length is Length + 1,
        length(List, List_Length),
        Last is Length - 1,
    
        foreach(between(0, Last, Index),
    	    words_to_list(Index, String_List, List)),
    
        length(Sentence, Length),
        foreach(between(0, Last, Index),
    	    words_to_list(Index, String_List, Sentence)).
    
    
    
    %pnl(Round) :-
    pnl :-    
        read_string(user_input, "!?.", """\n", End, String),    
        input_to_list(String, List, Sentence),
        length(List, Length),
        nth1(Length, List, At_End),
        char_code(At_End, End),
        
        nth1(1, Sentence, Veracity),   
        (Veracity == yes -> delete(Sentence, yes, Unexpected);
         Unexpected = Sentence;
         (Veracity == no -> delete(Sentence, no, Unexpected);
          Unexpected = Sentence;
          (Veracity == true -> delete(Sentence, true, Unexpected);
           Unexpected = Sentence;
           (Veracity == false -> delete(Sentence, false, Unexpected);
    	Unexpected = Sentence)))),
        
        %%writeln("stop :  0.0.0"),
        (is_affirmative(Unexpected, End) ->
    	 
    	 /*********************************************************************/
    	 /*                                                                   */
    	 /*                            Affirmative                            */
    	 /*                                                                   */
    	 /*********************************************************************/
    	 
    	 
    	 
    	 %%writeln("stop :  0.0.1"),
    	 %%%write(Unexpected),
    	 /************************************************/
    	 /*                                              */
    	 defrag(Unexpected, Sujet, Verbe, Complément),
    	 %%writeln("stop :  0.0.2"),
    	 (lire(Sujet, Verbe, Complément) ->
    	      %%writeln("stop :  0.1.0"),
    	      /* Affirmation */
    	      write("Yes, "),
    	      %%writeln("stop :  0.5.1"),
    	      inverse_affirmative(Unexpected, Response, Rest),
    	      %%writeln("stop :  0.5.2"),
    	      inverse_affirmative(Response, Affirmative, Rest1),	 
    	      %%writeln("stop :  0.5.3"),
    	      atomics_to_string(Affirmative, ' ', Affirmation),	
    	      %%writeln("stop :  0.5.4"),
    	      
    	      (is_list(Rest) ->
    		   length(Rest, Rest_Length),
    		   (Rest_Length \= 0 ->
    			atomics_to_string(Rest, ' ', Complement),
    			
    			write(Affirmation),
    			write(' '),
    			write(Complement), writeln('!') ;
    		    
    		    write(Affirmation), writeln('!'))
    	       ;
    	       write(Affirmation), writeln('!'))
    		  
    		  
    		  /***********************************************/
    		  /*                                             */
    		  /***********************************************/
    		  
    	  ;
    	  %%writeln("stop :  0.2.0"),
    	  /* Négation */
    	  findall(C, lire(Sujet, Verbe, C), Goal),
    	  %writeln("findall(C, ... :  0.2.1"),
    	  /* lire(Sujet, Verbe, Goal), */
    	  length(Goal, Len),
    	  %%writeln("stop :  0.2.2"),
    	  (Len \= 0 ->
    	       writeln("No, but : "),
    	       Last is Len - 1,
    	       foreach(between(0, Last, X),
    		       cprint(Sujet, Verbe, Goal, X)),
    	       nl,
    	       /* Question */
    	       atomic_list_concat(Complément, ' ', Comp),
    	       atomic_list_concat([Verbe, Sujet, Comp], ' ', Interrogation),
    	       write(Interrogation), writeln("?"),
    	       nl,
    	       /* écrire nouveau fait */
    	       write("yes/no?"),
    	       read(X),
    	       (X == yes ->  écrire(Sujet, Verbe, Complément) ; true)
    	   ;
    	   %%writeln("stop :  0.3.0"),
    	   findall(V, lire(Sujet, V, _), Goal),
    	   /* lire(Sujet, Verbe, Goal), */
    	   %%writeln("findall (V, ... :  0.3.1"),
    	   length(Goal, Len),
    	   %%writeln("stop :  0.3.2"),
    	   (Len \= 0 ->
    		writeln("No, but : "),
    		Last is Len - 1,
    		foreach(between(0, Last, X),
    			vprint(Sujet, Goal, Complément, X)),
    		nl,
    		/* Question */
    		atomic_list_concat(Complément, ' ', Comp),
    		atomic_list_concat([Verbe, Sujet, Comp], ' ', Interrogation),
    		write(Interrogation), writeln("?"),
    		nl,
    		/* écrire nouveau fait */
    		write("yes/no?"),
    		read(X),
    		(X == yes ->  écrire(Sujet, Verbe, Complément) ; true))
    	   ;
    
    	   /***********************/
    	   /* écrire nouveau fait */
    	   /*                     */
    	   /***********************/
    	   %%write("yes/no?"),
    	   %%read(X),
    	   %%(X == yes ->  écrire(Sujet, Verbe, Complément) ; true))),
    	   écrire(Sujet, Verbe, Complément),
    	   /*                                                    */
    	   /******************************************************/
    	   %%writeln("stop :  0.5.1"),
    	   inverse_affirmative(Unexpected, Response, Rest),
    	   %%writeln("stop :  0.5.2"),
    	   inverse_affirmative(Response, Affirmative, Rest1),	 
    	   %%writeln("stop :  0.5.3"),
    	   atomics_to_string(Affirmative, ' ', Affirmation),	
    	   %%writeln("stop :  0.5.4"),
    	   
    	   (is_list(Rest) ->
    		length(Rest, Rest_Length),
    		(Rest_Length \= 0 ->
    		     atomics_to_string(Rest, ' ', Complement),
    		     
    		     write(Affirmation),
    		     write(' '),
    		     write(Complement), writeln('!') ;
    		 
    		 write(Affirmation), writeln('!'))
    	    ;
    	    write(Affirmation), writeln('!'));
    	   %%writeln("stop :  0.5.1"),
    	   inverse_affirmative(Unexpected, Response, Rest),
    	   %%writeln("stop :  0.5.2"),
    	   inverse_affirmative(Response, Affirmative, Rest1),	 
    	   %%writeln("stop :  0.5.3"),
    	   atomics_to_string(Affirmative, ' ', Affirmation),	
    	   %%writeln("stop :  0.5.4"),
    	   
    	   (is_list(Rest) ->
    		length(Rest, Rest_Length),
    		(Rest_Length \= 0 ->
    		     atomics_to_string(Rest, ' ', Complement),
    		     
    		     write(Affirmation),
    		     write(' '),
    		     write(Complement), writeln('!') ;
    		 
    		 write(Affirmation), writeln('!'))
    	    ;
    	    write(Affirmation), writeln('!')))
    	  ;
    	  %%writeln("stop :  0.5.1"),
    	  inverse_affirmative(Unexpected, Response, Rest),
    	  %%writeln("stop :  0.5.2"),
    	  inverse_affirmative(Response, Affirmative, Rest1),	 
    	  %%writeln("stop :  0.5.3"),
    	  atomics_to_string(Affirmative, ' ', Affirmation),	
    	  %%writeln("stop :  0.5.4"),
    	  
    	  (is_list(Rest) ->
    	       length(Rest, Rest_Length),
    	       (Rest_Length \= 0 ->
    		    atomics_to_string(Rest, ' ', Complement),
    		    
    		    write(Affirmation),
    		    write(' '),
    		    write(Complement), writeln('!') ;
    		
    		write(Affirmation), writeln('!'))
    	   ;
    	   write(Affirmation), writeln('!')))
         ;
    
         /*************************************************************************/
         /*                                                                       */
         /*                          Interrogative                                */
         /*                                                                       */
         /*************************************************************************/
         
         %%writeln("stop :  0.6.0"),
         inverse_interrogative(Unexpected, R, Rest),
         %%writeln("stop :  0.6.1"),
         inverse_interrogative(R, Interrogative, Rest2),
         %%writeln("stop :  0.6.2"),
         /************************************************/
         /*                                              */
         defrag(Interrogative, Verbe1, Sujet1, Complément1),     
         /*                                              */
         /************************************************/
         
         %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
         %% atomics_to_string(Interrogative, ' ', Result),
         %%writeln("stop :  0.6.3"),
         
         %% (is_list(Rest), length(Rest, Rest_Length), Rest_Length \= 0 ->
         %% 	  atomics_to_string(Rest, ' ', Complement),
         
         %% 	  yes, write(Result), write(' '), write(Complement), writeln('?') ;
         %%  write(Result), writeln('?')),
         %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
         
         /*********************************************************************/
         /*                                                                   */
         /*                                                                   */
    
         %yes_analyze(Complément1, Perfect, Res),
         Unexpected1 = [Sujet1, Verbe1, Complément1],
         defrag(Unexpected1, Sujet2, Verbe2, Complément2),     
         /*                                                                   */
         /*                                                                   */
         /*********************************************************************/
         (lire(Sujet2, Verbe2, Complément1) ->
    	  %%writeln("stop :  1.1.0"),
    	  /* Affirmation */
    	  write("Yes, "),
    	  %%writeln("stop :  1.5.1"),
    	  inverse_affirmative(Unexpected1, Response, Rest),
    	  %%writeln("stop :  1.5.2"),
    	  inverse_affirmative(Response, Affirmative, Rest1),	 
    	  %%writeln("stop :  1.5.3"),
    
    	  %%atomics_to_string(Affirmative, ' ', Affirmation),	
    	  %%writeln("stop :  1.5.4"),
    
    	  atomic_list_concat(Complément1, ' ', Comp),
    	  %%writeln("stop :  1.3.5"),
    	  atomic_list_concat([Sujet2, Verbe2, Comp], ' ', Affirmation),
    	  %%writeln("stop :  1.3.6"),                     
    	  
    
    	  
    	  (is_list(Rest) ->
    	       length(Rest, Rest_Length),
    	       (Rest_Length \= 0 ->
    	  	    atomics_to_string(Rest, ' ', Complement),
    		    
    	  	    write(Affirmation),
    	  	    write(' '),
    	  	    write(Complement), writeln('!') ;
    		
    	  	write(Affirmation), writeln('!'))
    	   ;
    	   write(Affirmation), writeln('!'))
    	      
    	      
          ;
          %%writeln("stop :  1.2.0"),
          /* Négation */
          findall(C, lire(Sujet2, Verbe2, C), Goal),
          %%writeln("findall(C, ... :  1.2.1"),
          /* lire(Sujet2, Verbe2, Goal), */
          length(Goal, Len),
          %%writeln("stop :  1.2.2"),
          (Len \= 0 ->
    	   writeln("No, but : "),
    	   Last is Len - 1,
    	   %%writeln("stop :  1.2.3"),
    	   foreach(between(0, Last, X),
    		   cprint(Sujet2, Verbe2, Goal, X)),
    	   %%writeln("stop :  1.2.4"),
    	   nl,
    	   /* Question */
    	   atomic_list_concat(Complément1, ' ', Comp),
    	   %%writeln("stop :  1.2.5"),
    	   atomic_list_concat([Verbe2, Sujet2, Comp], ' ', Interrogation),
    	   %%writeln("stop :  1.2.6"),
    	   write(Interrogation), writeln("?"),
    	   nl,
    	   /* écrire nouveau fait */
    	   write("yes/no?"),
    	   read(X),
    	   (X == yes ->  écrire(Sujet2, Verbe2, Complément1) ; true)
           ;
           %%writeln("stop :  1.3.0"),
           findall(V, lire(Sujet2, V, Complément1), Goal),
           /* lire(Sujet2, Verbe2, Goal), */
           %%writeln("findall (V, ... :  1.3.1"),
    
           length(Goal, Len),
           %%writeln("stop :  1.3.2"),
           (Len \= 0 ->
    	    %%writeln("No, but : "),
    	    Last is Len - 1,
    	    %%writeln("stop :  1.3.3"),
    	    foreach(between(0, Last, X),
    		    vprint(Sujet2, Goal, Complément1, X)),
    	    %%writeln("stop :  1.3.4"),
    	    nl,
    	    /* Question */
    	    atomic_list_concat(Complément1, ' ', Comp),
    	    %%writeln("stop :  1.3.5"),
    	    atomic_list_concat([Verbe2, Sujet2, Comp], ' ', Interrogation),
    	    %%writeln("stop :  1.3.6"),
    	    write(Interrogation), writeln("?"),
    	    nl,
    	    /* écrire nouveau fait */
    	    write("yes/no?"),
    	    read(X),
    	    (X == yes ->  écrire(Sujet2, Verbe2, Complément1) ; true)
    	;
    
    	/***********************/
    	/* écrire nouveau fait */
    	/*                     */
    	/***********************/
    	%%write("yes/no?"),
    	%%read(X),
    	%%(X == yes ->  écrire(Sujet1, Verbe1, Complément1) ; true))),
    	écrire(Sujet2, Verbe2, Complément1),
    	/*                                                    */
    	/******************************************************/
    	%%writeln("stop :  1.5.1"),
    	inverse_affirmative(Unexpected1, Response, Rest),
    	%%writeln("stop :  1.5.2"),
    	inverse_affirmative(Response, Affirmative, Rest1),	 
    	%%writeln("stop :  1.5.3"),
    	
    	%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    	%% defrag(Affirmative, V
    
    	atomic_list_concat(Complément1, ' ', Comp),
    	%%writeln("stop :  1.3.5"),
    	atomic_list_concat([Sujet2, Verbe2, Comp], ' ', Affirmation),
    	%%writeln("stop :  1.3.6"),                     
    	
    	(is_list(Rest) ->
    	     length(Rest, Rest_Length),
    	     (Rest_Length \= 0 ->
    		  atomics_to_string(Rest, ' ', Complement),
    		  write(Affirmation),
    		  
    		  write(' '),
    		  write(Complement), writeln('!') ;
    	      
    	      write(Affirmation), writeln('!'))
    	 ;
    	 write(Affirmation), writeln('!')),
    	%%writeln("stop :  1.5.1"),
    	inverse_affirmative(Unexpected1, Response, Rest),
    	%%writeln("stop :  1.5.2"),
    	inverse_affirmative(Response, Affirmative, Rest1),	 
    	%%writeln("stop :  1.5.3"),
    
    	%atomics_to_string(Affirmative, ' ', Affirmation),	
    	%%writeln("stop :  1.5.4"),
    	
    	atomic_list_concat(Complément1, ' ', Comp),
    	%%writeln("stop :  1.3.5"),
    	atomic_list_concat([Sujet2, Verbe2, Comp], ' ', Affirmation),
    	%%writeln("stop :  1.3.6"),                     
    	
    	
    	(is_list(Rest) ->
    	     length(Rest, Rest_Length),
    	     (Rest_Length \= 0 ->
    		  atomics_to_string(Rest, ' ', Complement),
    		  
    		  write(Affirmation),
    		  write(' '),
    		  write(Complement), writeln('!') ;
    	      
    	      write(Affirmation), writeln('!'))
    	 ;
    	 write(Affirmation), writeln('!')))
           ;
           %%writeln("stop :  1.5.1"),
           inverse_affirmative(Unexpected1, Response, Rest),
           %%writeln("stop :  1.5.2"),
           inverse_affirmative(Response, Affirmative, Rest1),	 
           %%writeln("stop :  1.5.3"),
    
    
           %%atomics_to_string(Affirmative, ' ', Affirmation),	
           %%writeln("stop :  1.5.4"),
    
    
           atomic_list_concat(Complément1, ' ', Comp),
           %%writeln("stop :  1.3.5"),
           atomic_list_concat([Sujet2, Verbe2, Comp], ' ', Affirmation),
           %%writeln("stop :  1.3.6"),                     
           
           
           (is_list(Rest) ->
    	    length(Rest, Rest_Length),
    	    (Rest_Length \= 0 ->
    		 atomics_to_string(Rest, ' ', Complement),
    		 
    		 write(Affirmation),
    		 write(' '),
    		 write(Complement), writeln('!') ;
    	     
    	     write(Affirmation), writeln('!'))
    	;
    	write(Affirmation), writeln('!'))
          )
    	  /*                                                                   */
    	  /*********************************************************************/
         )
        ),
        pnl.
    
    
    /* saving database */
    savepe :-
        tell('subjects.pl'), listing(sujet(_)), told,
        tell('verbs.pl'), listing(verbe(_)), told,
        tell('complements.pl'), listing(complément(_)), told,
        tell('facts.pl'), listing(lire(_, _, _)), told.
    
    /* loading database */
    loadpe :-
        consult(subjects),
        consult(verbs),
        consult(complements),
        consult(facts).
    
    /* initialization */
    initpe :-
        write("Initialize with : "),
        read(P),
        writeln(P),
        split_string(P, ' ', "", L),
        defrag(L, Sujet, Verbe, Complément),
        écrire(Sujet, Verbe, Complément).
    
    mainpe :-
        (not(loadpe) -> initpe, savepe,
    		    (pnl -> true;
    		     savepe)
         ;     
         (pnl -> true;
          savepe),
         savepe).
    
    
    /************************************************************/
    /* the next predicates is just an test of logical traitement */
    full_antinomie(Left, Right) :- (antinomie(Left, Right)
    				; antinomie(Right, Left)).
    
    full_synonyme(Left, Right) :- (synonyme(Left, Right)
    				 ; synonyme(Right, Left)).
    
    
    full_no_analyze([X|R], S, R) :-
        
        (search_synonyme(X, Y),
         search_antinomie(Y, A),
         search_synonyme(A, S)
         ;
         search_antinomie(X, S)
         ;
         S = X).
    					    
    full_yes_analyze([X|R], A, R) :-
    
        (search_antinomie(X, Y),
         search_synonyme(Y, S),
         search_antinomie(S, A)
         ;
         search_synonyme(X, A)
         ;
         A = X).
    
    
    
    logic(X, Y) :- full_antinomie(X, A1), full_antinomie(Y, A2), not(antinomie(A1, A2)), synonyme(A1, A2).
    against(X, Y) :- full_synonyme(X, S1), full_antinomie(Y, S1), not(synonyme(S1, S2)).
    
    /*  end test (see main test/3)                           */
    /*******************************************************/
    
    /***************************************************/
    /* Main test :                                     */
    
    full_inverse_affirmative([Subject, Verb | Complement], [S, V, C], Result) :-
        
        full_yes_analyze([Subject], S, Substring),
    
        full_yes_analyze([Verb], V, Substring),
        
        full_yes_analyze(Complement, C, Result),
    
        full_yes_analyze([Rest], Result, Substring).
    
    full_inverse_interrogative([Verb, Subject | Complement], [V, S, C], Result) :-
        (full_yes_analyze([Subject], S, Substring),
    	 
    	 full_yes_analyze([Verb], V, Substring),
    	 
    	 full_yes_analyze(Complement, C, Rest), !,
    	 
    	 full_yes_analyze([Rest], Result, Substring)
    		
         ;
         full_no_analyze([Subject], S, Substring),
         
         full_no_analyze([Verb], V, Substring),
         
         full_no_analyze(Complement, C, Rest), !,
    
         full_yes_analyze([Rest], Result, Substring)).
         
    
    
    logical_affirmative_test(Subject, Verbe, Complement) :- logic(S_Left, S_Right), logic(V_Left, V_Right), logic(C_Left, C_Right), full_inverse_affirmative([S_Right, V_Right, C_Right], [Subject, Verbe, Complement], R).
    against_affirmative_test(Subject, Verbe, Complement) :- against(S_Left, S_Right), against(V_Left, V_Right), against(C_Left, C_Right), full_inverse_affirmative([S_Right, V_Right, C_Right], [Subject, Verbe, Complement], R).
    
    
    
    logical_interrogative_test(Verbe, Subject, Complement) :- logic(S_Left, S_Right), logic(V_Left, V_Right), logic(C_Left, C_Right), full_inverse_interrogative([V_Right, S_Right, C_Right], [Verbe, Subject, Complement], R).
    against_interrogative_test(Verbe, Subject, Complement) :- against(S_Left, S_Right), against(V_Left, V_Right), against(C_Left, C_Right), full_inverse_interrogative([V_Right, S_Right, C_Right], [Verbe, Subject, Complement], R).
    
    
    theory(S, V, C) :- against_interrogative_test(V, S, C), logical_affirmative_test(S, V, C).
    
    antitheory(V, S, C) :- against_affirmative_test(S, V, C), logical_interrogative_test(V, S, C).
    
    test(S, V, C) :- antitheory(V, S, C), theory(S, V, C).
    Les version suivantes seront ici : https://sourceforge.net/projects/psys/
    Logique sans matière est matière de logique.

  6. #6
    Membre du Club
    Homme Profil pro
    codeur
    Inscrit en
    Mars 2018
    Messages
    158
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 54
    Localisation : France, Gard (Languedoc Roussillon)

    Informations professionnelles :
    Activité : codeur

    Informations forums :
    Inscription : Mars 2018
    Messages : 158
    Points : 64
    Points
    64
    Par défaut
    Bonjour,
    Je reviens parce que j'ai posté, un peu trop top.
    Je débute avec Prolog et la complexité du langage m'avait un peu perdu.

    Dans les version suivante, j'ai supprimé la majorité des reformulation des forme affirmative et interrogative.

    Le programme perd un peu de charme pour le moment mais est fonctionnel à peu près dans la version 1.1.4 disponible en suivant le lien ci-dessus.

    Je reviens dans quelque jours avec la suite du programme ; Je l'espère.
    Merci pour votre compréhension.

    Merci pour vos retours dont je suis gourmant.

    Bons tests. Et bonnes continuations.
    Logique sans matière est matière de logique.

  7. #7
    Membre du Club
    Homme Profil pro
    codeur
    Inscrit en
    Mars 2018
    Messages
    158
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 54
    Localisation : France, Gard (Languedoc Roussillon)

    Informations professionnelles :
    Activité : codeur

    Informations forums :
    Inscription : Mars 2018
    Messages : 158
    Points : 64
    Points
    64
    Par défaut Demonstration de psys-2.2.4.a ré-integration de pnl à psys.
    Bonjour,
    Je poste une démonstration avec la version 2.2.4.a.

    Le programme affiche 2.2.3.a mais j'ai changé la version avant de poster le paquet tgz sur sourceforge.

    Comme je l'explique plus bas les fichiers contenu dans l'archives ne sont pas vide ; Il contienne les fait suivant.


    Exécution avec Swi-Prolog : "swipl goals.pl"

    psys/0 is user control to access shell written with Prolog.
    Program name : [psys]
    Release : 2.2.3.a
    who are you?
    username : arknos.
    what machine are you?
    [animal,computer]
    |: animal.
    what animal are you?
    [human]
    |: human.
    What human are you?
    [men,woman]
    |: men.
    Assertion men(X)
    what machine are you?
    [animal,computer]
    |: animal.
    What language are you?
    [bash,tcsh,csh,prolog,other]
    |: other.
    Hello sir arknos!
    We are compatible systems!
    |: shall i play game?
    shall i play game?
    yes/no?|: yes.
    |: shall you play game?
    shall you play game?
    yes/no?|: yes.
    |: shall we play game?
    shall we play game?
    yes/no?|: yes.
    |: i shall play game!
    Yes, i shall like game!
    |: shall we like game?
    No, but :
    we shall play game!

    shall we like game?

    yes/no?|: no.
    |: i like play game!
    No, like i play game?
    yes/no?|: no.
    |: ERROR: /home/manu/psys/goals.pl:23: Initialization goal raised exception:
    ERROR: char_code/2: Cannot represent due to `character_code'
    Welcome to SWI-Prolog (Multi-threaded, 64 bits, Version 7.2.3)
    Copyright (c) 1990-2015 University of Amsterdam, VU Amsterdam
    SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software,
    and you are welcome to redistribute it under certain conditions.
    Please visit http://www.swi-prolog.org for details.

    For help, use ?- help(Topic). or ?- apropos(Word).

    ?- savepe.
    true.
    what machine are you?
    [animal,computer]
    |: animal.
    what animal are you?
    [human]
    |: human.
    What human are you?
    [men,woman]
    |: men.
    Assertion men(X)
    what machine are you?
    [animal,computer]
    |: animal.
    What language are you?
    [bash,tcsh,csh,prolog,other]
    |: other.
    Hello sir arknos!
    We are compatible systems!
    |: shall i play game?
    shall i play game?
    yes/no?|: yes.
    |: shall you play game?
    shall you play game?
    yes/no?|: yes.
    |: shall we play game?
    shall we play game?
    yes/no?|: yes.
    |: i shall play game!
    Yes, i shall like game!
    |: shall we like game?
    No, but :
    we shall play game!

    shall we like game?

    yes/no?|: no.
    |: i like play game!
    No, like i play game?
    yes/no?|: no.
    |: ERROR: /home/manu/psys/goals.pl:23: Initialization goal raised exception:
    ERROR: char_code/2: Cannot represent due to `character_code'
    Welcome to SWI-Prolog (Multi-threaded, 64 bits, Version 7.2.3)
    Copyright (c) 1990-2015 University of Amsterdam, VU Amsterdam
    SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software,
    and you are welcome to redistribute it under certain conditions.
    Please visit http://www.swi-prolog.org for details.

    For help, use ?- help(Topic). or ?- apropos(Word).

    ?- savepe.
    true.

    ?- savepsys.
    true.

    ?-
    Après quoi j'ai corrigé sensiblement mais je ne me souviens pas très bien dquoi exactement si ce n'est d'avoir ajouté le write("No, ") dans le traitement (interrogative ou affirmative me souviens pas non plus).

    Mais ça semble fonctionner correctement.


    Voici ce à quoi vous attendre si vous copier les même requête donc en cas de réutilisation des fichier subjects, verbs, complements, facts.

    psys/0 is user control to access shell written with Prolog.
    Program name : [psys]
    Release : 2.2.3.a
    who are you?
    username : arknos.
    what machine are you?
    [animal,computer]
    |: animal.
    What language are you?
    [bash,tcsh,csh,prolog,other]
    |: other.
    Hello sir arknos!
    We are compatible systems!
    |: shall i play game?
    Yes, i shall play game!
    |: shall you play with me?
    No, but :
    you shall play game!

    shall you play with me?

    yes/no?|: yes.
    |: shall i play first?
    No, but :
    i shall play game!

    shall i play first?

    yes/no?|: yes.
    |: i shall play with you!
    No, but :
    i shall play game!
    i shall play first!

    shall i play with you?

    yes/no?|: yes.
    |: shall you play second?
    No, but :
    you shall play game!
    you shall play with me!

    shall you play second?

    yes/no?|: no.
    |: ERROR: /home/manu/devel/Projects/All/Prolog/psys/psys/goals.pl:23: Initialization goal raised exception:
    ERROR: char_code/2: Cannot represent due to `character_code'
    Welcome to SWI-Prolog (Multi-threaded, 64 bits, Version 7.2.3)
    Copyright (c) 1990-2015 University of Amsterdam, VU Amsterdam
    SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software,
    and you are welcome to redistribute it under certain conditions.
    Please visit http://www.swi-prolog.org for details.

    For help, use ?- help(Topic). or ?- apropos(Word).

    ?-
    Voilà, vous savez tout pour l'instant T vendredi 06 avril 2018 19:30:00 CET.


    Le programme dans un premier temps afficher les information sur le programme,
    Demande en suite un nom d'utilisteur afin de vous reconnaître à l'utilisation suivante (a condition d'utiliser savepsys/0
    Il demande en suite si vous êtes un ordinateur ou un animal, puis un homme ou une femme dans un cas ou un langage dans l'autre.
    Les divers langage présenté ici sont bash csh tcsh Prolog other.

    Les 4 premier vous conduise à un nouvel interpréteur peut-être pour la vie.

    Le dernier vous conduit à l'interpréteur pnl ; Ici, le programme attend une phrase ponctué d'un caracter final de forme affirmative ou interrogative :
    - Sujet verbe complément. ou !
    - verbe sujet complément?

    Le programme vous réponds en fonction de ses connaissance,
    Si il connaît le fait exact, il confirme, le fait. Si non ;
    Si il connais un fait formé du même verbe ou complément il les affiche avant de demander confirmation pour l'ajout du fait proposé en cours.
    Si non, il demande confirmation pour ajouter le fait en cours.

    Au cas ou vos soyez (comme moi) débutant avec Prolog, le prédicat psys/0 est le prédicat principal.
    Le prédicat savepsys/0 sauvegarde les prédicat men/1 et woman/1 dans machines.pl.
    le prédicat savepe/0 sauvegarde les sujet les verbe et les complément dans les fichiers corespondant par leurs nom ; Ainsi que le prédicat lire/3 dans facts.pl


    Si je peu vous renseigner ?
    Logique sans matière est matière de logique.

  8. #8
    Membre du Club
    Homme Profil pro
    codeur
    Inscrit en
    Mars 2018
    Messages
    158
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 54
    Localisation : France, Gard (Languedoc Roussillon)

    Informations professionnelles :
    Activité : codeur

    Informations forums :
    Inscription : Mars 2018
    Messages : 158
    Points : 64
    Points
    64
    Par défaut Reintegration de no_analyze/3 pour convertir le sujet.
    Bonjour ou bonsoir à présent.
    Je me suis dit puisque ça à l'air de marcher comme ça.
    J'ai réintroduit la conversion pour le sujet d'une phrase grâce au prédicat no_analyze/3 dans chacun des bloc conditionel du prédicat pnl/0 au moment d'interroger l'utilisateur, et à l'écriture du fait ; Dans la version 2.2.5.a donc.

    Maintenant il faux que j'écrive le reste du système.

    A bientôt.


    Edit : entre temps je réintègre également un yes_analyze/3 pour convertir le verbe dans la version 1.3.1.a.
    J'ai également stadardisé l'utilisation des predicats subject/1 verb/1 complement/1 et fact/3 depuis la 2.3.0.a
    Logique sans matière est matière de logique.

  9. #9
    Membre du Club
    Homme Profil pro
    codeur
    Inscrit en
    Mars 2018
    Messages
    158
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 54
    Localisation : France, Gard (Languedoc Roussillon)

    Informations professionnelles :
    Activité : codeur

    Informations forums :
    Inscription : Mars 2018
    Messages : 158
    Points : 64
    Points
    64
    Par défaut
    Bonjour,


    Rapidement, je vous poste le Change.log pour la version 2.4.2.b.
    ChangeLog :

    Saise de la chaîne de ceractères dans pnl/0 précédant l'appel à pnl_dialog/2.

    Suppression des synonyme et antinomie portant sur les sujets (ex : synonyme(me, i)).

    Utilisation de "yes_analyze" pour le sujet à l'instar de "no_analyze" dans pnl_dialog/2.

    Revision des code de tests et listing :
    - utilisation des prédicats "inverse_*" à l'instar des "full_invers_*"
    - correction et complétion des prédicats de tests appelants pnl_dialog/2.
    J'ai oeuvré principalement pour ouvrir le champ de la sémantique possible avec ce programme.

    Evidemment, encore, je n'ai pas tout testé.

    J'espère que vous aurrez aujoud'hui entendu le principe proposé.

    Je vous invite à lire ou relire les codes dans leur entièreté (c'est pas bien long).

    Si je n'ai pas pensé à quelque chose, merci de me retourner le quelque chose !

    Attention les fichiers de faits ne son pas vide. Laissez au moins la spécification dynamique des prédicat au cas ou vous souhaiteriez les vider.

    La dernière version 2.4.2.b : une petite prise de vu avec le prédicat synthesis_list/0

    ultimate:~/psys$ swipl goals.pl
    Welcome to SWI-Prolog (Multi-threaded, 64 bits, Version 7.2.3)
    Copyright (c) 1990-2015 University of Amsterdam, VU Amsterdam
    SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software,
    and you are welcome to redistribute it under certain conditions.
    Please visit http://www.swi-prolog.org for details.

    For help, use ?- help(Topic). or ?- apropos(Word).

    ?- loadpe.
    true.

    ?- synthesis_list.
    [he,love,die]
    [he,love,game]
    [he,love,love]
    [i,love,die]
    [i,love,game]
    [i,love,love]
    [she,love,die]
    [she,love,game]
    [she,love,love]
    [they,love,die]
    [they,love,game]
    [they,love,love]
    [we,love,die]
    [we,love,game]
    [we,love,love]
    [you,love,die]
    [you,love,game]
    [you,love,love]
    true.

    ?-
    synthesis_list, ça devrait retourner la liste des combinaison de [tous les sujet subject/1, les verbe anyant un synonyme et une antinomie commune, un complément ayant un synonyme et une antinomie commune).
    (Mais c'est pas certain).

    Bon, c'est pas parfait encore. (sur l'instant je me demande comment je pourait trouver game et love ou die en même temps.

    Mais je vous tiens au courant.

    bon dimanche.
    Logique sans matière est matière de logique.

  10. #10
    Membre du Club
    Homme Profil pro
    codeur
    Inscrit en
    Mars 2018
    Messages
    158
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 54
    Localisation : France, Gard (Languedoc Roussillon)

    Informations professionnelles :
    Activité : codeur

    Informations forums :
    Inscription : Mars 2018
    Messages : 158
    Points : 64
    Points
    64
    Par défaut Sémantique de synthesis_list et autre prédicats
    Bonjour, ou bien rebonjour,

    Je reviens pour la sémantique du prédicat synthesis_list.

    Normalement enfin, pour moi pour le moment, je pense que Prolog devrait retourner false, ou no.

    Je viens de renforcer ma base de faits de synonyme et antinomie et synthesis list est vide par défaut intuitivement.

    Par contre, logical, renvoie bien la liste voulue, ainsi que against.

    Voici ma base perso pour les synonymes et antinomie pour commencer rapidement une base.

    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
    /* against terms */
    antinomie(reality, game).
    antinomie(peace, war).
    antinomie(he, she).
    antinomie(something, nothing).
    antinomie(false, true).
    
    /*against verbs */
    antinomie(win, loose).
    antinomie(die, live).
    
    
    /* yes -> True -> Positive / no -> False -> Negative */
    synonyme(no, negative).
    synonyme(negative, false).
    synonyme(yes, positive).
    synonyme(positive, true).
    synonyme(affirmative, positive).
    
    
    /* same terms */
    synonyme(life, game).
    synonyme(forever, eternaly).
    synonyme(intelligent, genial).
    synonyme(power, will).
    synonyme(freedom, reason).
    synonyme(game, abstract).
    
    /* same verbs */
    
    synonyme(love, like).
    synonyme(play, love).
    synonyme(live, like).


    Parce que j'ai pas terminer, imaginez que vous deviez entré les synonyme et antinomies à la main c'est peut-être pas pratique.

    Enfin, je cherche encore.

    Bonne continuations à nouveau.

    J'ai oublié dans le change.log de mentioner l'abandon de is_affirmative/2,;
    J'utilise is_affirmative/1 dans dialog_pnl/2


    Edit 4, finalement après les dernière correction, ça change tout.

    Revoilà la base corrigé ou du moins presuqe parfaite.
    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
    /* against terms */
    antinomie(reality, game).
    antinomie(peace, war).
    antinomie(he, she).
    antinomie(something, nothing).
    antinomie(false, true).
    
    /*against verbs */
    antinomie(win, loose).
    antinomie(die, live).
    
    
    /* yes -> True -> Positive / no -> False -> Negative */
    synonyme(no, negative).
    synonyme(negative, false).
    synonyme(yes, positive).
    synonyme(positive, true).
    synonyme(affirmative, positive).
    
    
    /* same terms */
    synonyme(life, game).
    synonyme(forever, eternaly).
    synonyme(intelligent, genial).
    synonyme(power, will).
    synonyme(freedom, reason).
    synonyme(game, abstract).
    
    /* same verbs */
    
    synonyme(love, like).
    synonyme(play, live).
    Et voici la liste synthesis_list.
    ?- synthesis_list.
    [he,live,false]
    [he,live,game]
    [he,live,live]
    [he,live,true]
    [i,live,false]
    [i,live,game]
    [i,live,live]
    [i,live,true]
    [she,live,false]
    [she,live,game]
    [she,live,live]
    [she,live,true]
    [they,live,false]
    [they,live,game]
    [they,live,live]
    [they,live,true]
    [we,live,false]
    [we,live,game]
    [we,live,live]
    [we,live,true]
    [you,live,false]
    [you,live,game]
    [you,live,live]
    [you,live,true]
    true.

    ?-
    Alors ?????

    Ben elle est pas vide.

    je sais plus ou j'en était ! Bon j'ai une liaison Prolog/ Ada à écrire.
    Logique sans matière est matière de logique.

  11. #11
    Membre du Club
    Homme Profil pro
    codeur
    Inscrit en
    Mars 2018
    Messages
    158
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 54
    Localisation : France, Gard (Languedoc Roussillon)

    Informations professionnelles :
    Activité : codeur

    Informations forums :
    Inscription : Mars 2018
    Messages : 158
    Points : 64
    Points
    64
    Par défaut pre version 3.1.1.a : les révisions s'imposaient !
    Bonsoir à l'heure qu'il est !

    Les révision s'imposaitent encore, je pense avoir fait le tour de cette pré - version.

    Entre autre une erreur de syntaxe dans is_affirmative/1

    Plus une erreur de parenthèse mais bon les code on beaucoup bouger pour faire les tests.

    toujour consult(goals).

    puis psys, ou loadpe puis pnl pour accéder directement à la base de faits.

    Les prédicat de test ne donnent rien par défaut normalement.
    Il faut d'abord renseigner la base, et eventuellement les faits synonyme et antinomie supplémentaire ou retirer les exédants.

    Merci pour votre écoute en tout cas.
    Logique sans matière est matière de logique.

  12. #12
    Membre du Club
    Homme Profil pro
    codeur
    Inscrit en
    Mars 2018
    Messages
    158
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 54
    Localisation : France, Gard (Languedoc Roussillon)

    Informations professionnelles :
    Activité : codeur

    Informations forums :
    Inscription : Mars 2018
    Messages : 158
    Points : 64
    Points
    64
    Par défaut Il aura fallu attendre la version 3.3.0 pour enfin avoir un protoype fonctionnel et ...
    Bonjour, ou bonsoir.

    Il aura fallu attendre le version 3.3.0 pour enfin avoir un protoype fonctionnel et ... peut-être quelque chose de parfait ; En tout cas dans son état.

    Je vous laisse découvrir les nouveaux codes dont voici un extrait :


    Alors le changement important, c'est l'utilisation d'un prédicat no_parse ou yes_parse, pour parser le complément en entier avec la logique des synonymes et antinomies.
    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
    /******************************************************************************/
    /*                      Parsing list for Complement                           */
    /*                                                                            */
    
    yes_parse([], []).
    yes_parse([S|L], [T|Vide]) :-
        yes_analyze(S, T),
        yes_parse(L, Vide).
    
    no_parse([], []).
    no_parse([S|L], [T|Vide]) :-
        no_analyze(S, T),
        no_parse(L, Vide).
    /*                                                                            */
    /*                                                                            */
    /******************************************************************************/

    Avec les prédicats no_parse et yes_parse j'otenait des list imbriquées, alors j'uilise unlist :
    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
    /******************************************************************************/
    /* extracting list from list of list of list                                  */
    list([E], E).
    unlist(Lists, List) :-
        nth0(0, Lists, E),
        (is_list(E) ->
             list(Lists, List),
             nth0(0, List, F),
             (is_list(F) ->
                  unlist(List);
              true);
         true).
    /*                                                                            */
    /*                                                                            */
    /******************************************************************************/
    Et le plus important j'ai écrit quelque commentaires de ce genre :
    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
    /******************************************************************************/
    /*                                                                            */
    /*                                                                            */
    /*                                                                            */
    /*                   psys is prototype Prolog part of anpe                    */
    /*                                                                            */
    /*                                                                            */
    /*                                                                            */
    /******************************************************************************/
    /*                                                                            */
    /*                                                                            */
    /*     This program is written             ********  *****  **    **  *****   */
    /*     with Prolog programming language.   **    ** **   **  **  **  **   **  */
    /*     The text before the character '%'   **    **  ***      ***     ***     */
    %%     or between '/*' '*/' is an comment. ********    ***     **       ***   */
    /*     An comment have no effect over      ***      **   **     **   **   **  */
    /*     the program.                        ***       *****       **   *****   */
    /*                                                                            */
    /*                                                                            */
    /******************************************************************************/
    Le fichier principale de ce programme est nommé goals.pl.

    Il s'exécute en appelement consult(goals) depuis l'invite Prolog.

    une commandehelp liste l'ensemble des prédicat écrit à l'attention de l'utilisateur.

    si non il faut lire les sources.

    ou tester psys/0.


    Si vous trouvez un bug, je suis preneur.


    3.3.1.a, j'ai une autre modification à apporter : je doit revalider les ligne d'inversion dans les prédicat de listing.

    J'ajoute donc des ligne de ce genre dans les predicat de listing entre les ligne 1042 et 1120.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
        inverse_affirmative([S_1, V_1, C_1],
                            [Subject, Verbe, Complement], R),
        inverse_affirmative([Subject, Verbe, Complement], [S, V, C], Rest).
    Les prédicat les utilisant ne renvoyant pas le même résultat.

    La durer de traitement peut variez selon les prédicats de 2s, à 10minutes.

    attention au prédicat synthésis sur lequel je suis indéci pour l'ordre d'appel.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    synthesis(S, V, C) :- logical_theory(S, V, C), against_theory(S, V, C).
    Renvoyez false dans la version 3.3.0.a.

    Suite à l'insertiondes lignes précédente, le résultat est une asser long liste des combinaisons.

    Voilà, cette fois je crois que je reviens pas après un bon moi de travail.
    Logique sans matière est matière de logique.

  13. #13
    Membre du Club
    Homme Profil pro
    codeur
    Inscrit en
    Mars 2018
    Messages
    158
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 54
    Localisation : France, Gard (Languedoc Roussillon)

    Informations professionnelles :
    Activité : codeur

    Informations forums :
    Inscription : Mars 2018
    Messages : 158
    Points : 64
    Points
    64
    Par défaut version 3.3.2.a
    Version finale finalement 3.3.2.a de ce prototype.

    Le prédicat synthesis_list prends environ une demi heure en l'état.

    Si non, vous pouvez utiliser pnl normalement.

    Quelque astuce intra programme pour faire des requêtes sans avoir à sortir du prompt :

    ?- pnl.
    |: love how what?
    No, but :
    i love computer!
    Ada love London!
    Ada love abstract!
    Ada love compatible!
    Ada love computer!
    Ada love freedom!
    Ada love game!
    Ada love life!
    Ada love power!
    Ada love reality!
    Ada love reason!
    Ada love war!
    Ada love will!

    like how what?

    yes/no?|: no.
    |: live who where?
    No, but :
    i live New York!
    i live in USA!
    Ada live London!
    Ada live abstract!
    Ada live compatible!
    Ada live computer!
    Ada live freedom!
    Ada live game!
    Ada live life!
    Ada live power!
    Ada live reality!
    Ada live reason!
    Ada live war!
    Ada live will!

    play who where?

    yes/no?|: no.
    |: Prolog is what?
    No, but :
    Prolog is my friends!
    Ada is my friends!

    is Prolog what?

    yes/no?|: no.
    |: arknos is the best!
    No, but :
    Prolog is my friends!
    Ada is my friends!

    is arknos the best?

    yes/no?|: yes.
    |: is who the best?
    No, but :
    Prolog is my friends!
    Ada is my friends!
    arknos is the best!

    is who the best?

    yes/no?|: no.
    |: ...

    false.


    Bon il y a un fait qui tache un peu j'ai fait une erreur de traitement lors d'un test.

    Bonne vacance.

    N'oubliez pas de sauvegarder avant de sortir de Prolog. avec savepsys et savepe.
    Logique sans matière est matière de logique.

  14. #14
    Membre du Club
    Homme Profil pro
    codeur
    Inscrit en
    Mars 2018
    Messages
    158
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 54
    Localisation : France, Gard (Languedoc Roussillon)

    Informations professionnelles :
    Activité : codeur

    Informations forums :
    Inscription : Mars 2018
    Messages : 158
    Points : 64
    Points
    64
    Par défaut A venir : version 5.0.0 : l'architecture du système.
    Bonjour, parce que du coup je suis passé à la version 4.0.1.b donc la prochaine sera plus proche de 5 ou 6.

    Pour vous exposer au mieu l'idée, j'ai fait un graphe structural du système anpe dans sont entiéreté.

    Les blocs "local database", "remote Neural network" et remote database représente la dépence du système aux fichier de données "sur disques".

    anpe client est un client anpe écrit avec Prolog.
    anpe server est un serveur anpe écrit avec Ada.
    anpe engine est un serveur anpe écrit avec Prolog.

    anpe server est fil d'exécution aliant service local et appel à un service distant (ici le serveur Prolog anpe engine).

    En image :
    Nom : anpe-architecture.png
Affichages : 192
Taille : 4,7 Ko

    Un prototype de fil d'exécution côté anpe serveur avec Ada à présent :


    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
    task body An_Thread is
    
          Command       : String_Access;
    
          -- when command = "sample-add"                                           
          Sample_Input  : String_Access;
          Sample_Output : String_Access;
    
          -- when command = "respond"                                              
          Request : String_Access;
          Response : String_Access;
    
          Channel : Stream_Access := Stream(Socket.all);
    
       begin
          accept Get_Id(Id : out Task_Id) do
             Id := Current_Task;
          end Get_Id;
          -- begin client Anp.                                                     
          loop
             Command := new String ' (String'Input(Channel));
             Put_Line("Command : " & Command.all);
             if Command.all = "sample-add" then
                Sample_input := new String ' (String'Input(Channel));
                Sample_Output := new String ' (String'Input(Channel));
    
                Put_Line("Add samples : ");
                Put_Line("              input  => " & Sample_Input.all);
                Put_Line("              output => " & Sample_Input.all);
                New_Line;
                Put_Line("Adding sample...");
    
                -- add(Sample_Input, Sample_Output);                               
    
                Put_Line(" done.");
    
             elsif Command.all = "respond" then
                Request := new String ' (String'Input(Channel));
                Put_Line("Respond : ");
                Put_Line("              request  => " & Request.all);
                --------------------------------                                   
                --             ECHO           --                                   
                --                            --                                   
                -- Just an echo for test.     --                                   
                --                            --                                   
                Response := new String ' (Request.all);
                -- Anservice.Respond(Request, Response);                           
                --                            --                                   
                --                            --                                   
                --------------------------------                                   
                Put_Line("              response  => " & Response.all);
                String'output(Channel, Response.all);
             end if;
          end loop;
       exception
          when others =>
             -- End anp client.                                                    
             raise;
       end An_Thread;
    Ce thread ayant vocation à sevir un système neurol-linguistique et en même temps d'être client d'un service logico-linguistique :
    Comme vous pouvez le lire, seul deux mode d'exploitation sont prévu pour le moment :
    - sample-add devant assurer l'ajout d'un exemple pour le réseau de neurones ;
    - respond devant assurer une réponse linguistique en réponse à une requête linguistique.

    Au plaisir de vous lire.



    Edit : j'ajoute pour votre entendement un exemple de dialogue (virtuel) attendu en fin de projet.

    E1 et R1 est un utilisateur écrivant et lisant le text à destination et en provenance de la machine notée E2 et E3 ; E2 et E3 étant deux machine distantes de E1 ; E2 écrivant à E3 et E3 répondant à E2, puis finalement E2 répondant à l'utilistaeur.

    E1 : i know what you think!
    E2 : i think what you build!
    E3 : build i what you say?
    E2 : say i what you think?
    R1 : i think what you know!

    dans le cas d'un simple écho prévu à l'état initial du programme, E1 est la requête utilisateur et R1 la réponse attendu.
    Logique sans matière est matière de logique.

  15. #15
    Membre du Club
    Homme Profil pro
    codeur
    Inscrit en
    Mars 2018
    Messages
    158
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 54
    Localisation : France, Gard (Languedoc Roussillon)

    Informations professionnelles :
    Activité : codeur

    Informations forums :
    Inscription : Mars 2018
    Messages : 158
    Points : 64
    Points
    64
    Par défaut anpe-0.1.1a, première liaison établi antre un Client avec Prolog et un serveur avec Ada
    Et l'intelligence artificiellle fut ?

    ?- loadpe.
    true.

    ?- pnl.
    |: you keep what i want!
    No, maintain what want want?

    yes/no?|: no.
    |: do i maintain what you maintain?
    No, i do what what you?

    yes/no?|:
    Ici le programme lit simplement une ligne de texte, l'envoie à un réseau de neurones artificiel qui retourne un text qui est traité en suite localement.


    Il reste un serveur avec Prolog à écrire.

    Ce programme est disponible désomais sous son nom anpe sur sourceforge.net : https://sourceforge.net/projects/anpe

    Merci pour vos retours.
    Logique sans matière est matière de logique.

  16. #16
    Membre du Club
    Homme Profil pro
    codeur
    Inscrit en
    Mars 2018
    Messages
    158
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 54
    Localisation : France, Gard (Languedoc Roussillon)

    Informations professionnelles :
    Activité : codeur

    Informations forums :
    Inscription : Mars 2018
    Messages : 158
    Points : 64
    Points
    64
    Par défaut Bug connu : recherche de la cause.
    Bonjour,

    Bienvenu sur le fil.
    Je viens vous demander votre contribution pour trouver la cause du bug.

    Le bug est le suivant : selon la réponse du serveur Ada, il manque le prémier caractère de la réponse au moment de l'affichage de celle ci.

    Merci pour votre contribution, en vous souhaitant bonnes continuations et bon dimanche.


    Edit, des atomes en lieu et places des caractères, parce que c'est une liste Prolog,


    Exemple :
    ?- pnl.
    |: do you maintain what i deduce?
    i dont know, do you you what i force
    but :
    i do what you become!

    do you maintain what i deduce?

    yes/no?|: no.
    |: do i want what you are forcing?
    no, do i stand what you you?
    but :
    i do what you become!

    do i want what you are forcing?

    yes/no?|: no.
    |: do you want what i want?
    no, o you understand what i ?
    but :
    i do what you become!

    do you want what i want?

    yes/no?|:
    Alors que côté serveur, j'ai une ligne complète
    Respond :
    request => do you want what i want?
    do you want what i want?
    service call...
    Anpe engine call(input, output
    i maintain what you i
    service call...
    response => do you understand what i ?
    Response length => 27
    :


    Enigme, "je supprime l'utilisation de list_tail/2 et même de output_to_list qui n'est pas utile ici. dans la prochaine version : 0.4.2b." Mais le problème reste le même donc.

    Edit 2
    Et parfois : un caractère est présent avant la chîne originelle.

    yes/no?|: no.
    |: do you deduce what i maintain?
    i dont know, "do you constrain what i foreseeyou
    but :
    i do what you become!
    ici le double-guillemets.
    Logique sans matière est matière de logique.

  17. #17
    Membre du Club
    Homme Profil pro
    codeur
    Inscrit en
    Mars 2018
    Messages
    158
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 54
    Localisation : France, Gard (Languedoc Roussillon)

    Informations professionnelles :
    Activité : codeur

    Informations forums :
    Inscription : Mars 2018
    Messages : 158
    Points : 64
    Points
    64
    Par défaut nouveaux prédicats pour les appels à pnl_dialog en mode semi automatique pour test et autres applications
    Bonjour,
    J'ai écrit 7 prédicats supplémentaire d'arité 3.

    Les prédicats sont ceux des tests dont le nom est précédé de 'p_' tel que : p_logical_test/3.

    les trois parametre des prédicat de test sont soit : le sujet le verbe le complément dans une forme affirmative, soit le verbe le suje et complement dans une forme interrogative.

    Ce qui pemet de faire des test de ce genre :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    ?- p_synthesis_test(i, V, C).
    En version 0.4.4b, ou i pourrait être un S pour Subject, V est le Verbe, C, le Complément.

    Bonne continuations.
    Logique sans matière est matière de logique.

  18. #18
    Membre du Club
    Homme Profil pro
    codeur
    Inscrit en
    Mars 2018
    Messages
    158
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 54
    Localisation : France, Gard (Languedoc Roussillon)

    Informations professionnelles :
    Activité : codeur

    Informations forums :
    Inscription : Mars 2018
    Messages : 158
    Points : 64
    Points
    64
    Par défaut set d'exemples supplémentaire.
    Vous pouvez joindre le fichier suivant par exemple aux exemples pour le réseau de neurones.

    Vous pouvez donner en seconde passe le fichier suivant a votre réseau de neurone par exemple.

    i live where i am!
    i think what you live!
    you live where i think!
    i think what you like!
    you like what is beautiful!
    i like what is life!
    you prefer what is good!
    i like what is love!
    you want what is good!
    like you what is peace?
    i hope what is great!
    know you what is reason?
    i have what is wonderful!
    you know what is freedom!
    i have what is will!
    i know what is power!
    Ce qui peut amener à une logique purement intra- neural network.

    exemple avec pnl : (ou je lui répète un peu ce qu'il dit pour avoir l'inverse.

    histoire de refléter ma propre pensée.

    |: good is what is not bad!
    i dont know, i what life ! i
    is good what is not bad?

    yes/no?|: no.
    |: you are what is life!
    i dont know, i willyou what life ! what
    are you what is life?

    yes/no?|: no.
    |: i will you what life !
    i dont know, "? beautiful what good freedom! i
    will i you what life?

    yes/no?|: no.
    |: you constrain what i stand!
    i dont know, ? beautiful deduce good ! what
    |: i deduce what you want!
    i dont know, i reason what is freedom! i
    but :
    you deduce what i stand!

    deduce i what you want?

    yes/no?|: no.
    |: you reason what is freedom!
    i dont know, ? reason deduce peace ! what
    reason you what is freedom?

    yes/no?|:
    Un petit dernier pour l'exemple :
    ?- pnl.
    |: i have what is life!
    Yes, i hope what is reason!
    have i what is life?

    yes/no?|: yes.
    |:

    Il vous faudra modifier les source du service Ada pour effectuer l'apprnetissage necéssaire en modifiant la valeur de max_epoch à l'initialisation.

    Edit : ou donnez plutôt celui ci : avec une fomrulation smemblable à celle du premier set.

    i live where i am!
    i think what you live!
    you live where i think!
    i think what you like!
    you like what beautiful is!
    i like what life is!
    you prefer what good is!
    i like what love is!
    you want what good is!
    like you what peace is?
    i hope what great is!
    know you what reason is ?
    i have what wonderful is!
    you know what freedom is!
    i have what will is!
    i know what power is!
    Mettez 6500 epochs pour le train initial et 2500 pour la seconde passe.
    Logique sans matière est matière de logique.

  19. #19
    Membre du Club
    Homme Profil pro
    codeur
    Inscrit en
    Mars 2018
    Messages
    158
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 54
    Localisation : France, Gard (Languedoc Roussillon)

    Informations professionnelles :
    Activité : codeur

    Informations forums :
    Inscription : Mars 2018
    Messages : 158
    Points : 64
    Points
    64
    Par défaut Variante 0.5.1a : double appel au serveur par requête. Ce qui fait 4.
    Bonjour, ou bonsoir,

    Vous trouverez à l'endroit habituel, les sources de la version 0.5.1a sensiblemetn différente.

    En effet, le programme exécute un double appel au serveur avant de traiter en local cette fois la seconde réponse du seveur à la place de celle de l'utilistaur ; Le dialog sensiblement différent toujours avec autant de répartie, mais beaucoup d'erreur de syntaxe (manque d'espaces).

    Exemple :
    |: what are you doing?
    Yes, i love what love isyouam!
    live you want i want?

    yes/no?|: no.
    |: yes, i live where i am!
    Yes, i conceive read great life building whatyou!
    what i will isyou?

    yes/no?|:
    En vous souhaitant bonnes continuations !
    Logique sans matière est matière de logique.

Discussions similaires

  1. Réponses: 25
    Dernier message: 21/05/2017, 13h59
  2. Réponses: 0
    Dernier message: 01/04/2014, 19h02
  3. Réponses: 1
    Dernier message: 09/03/2014, 15h09
  4. Réponses: 5
    Dernier message: 05/12/2012, 13h43

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