2012-09-08 2 views
0

J'ai un problème. Je ne peux pas comprendre ce problème pendant des semaines. Par exemple:Comment obtenir une variable dans Prolog?

parent(john,paul). 
parent(paul,tom). 
parent(tom,mary). 
ancestor(X,Y) :- parent(X,Y). 
ancestor(X,Y) :- parent(X,Z), 
       ancestor(Z,Y). 

requête est:

swipl -s /home/alikoyuncu/pl/ples.pl -g "ancestor(X,'tom')" -t halt. 

sortie:

% library(swi_hooks) compiled into pce_swi_hooks 0.00 sec, 3,856 bytes 
% /home/alikoyuncu/pl/ples.pl compiled 0.01 sec, 119,096 bytes 

[email protected]:/var/www/nlp$ 

Que dois-je faire pour obtenir la variable X?


et j'appelle de php. Mon code php:

<?php 

try 
{ 

    $cmd ="swipl --quiet -s /home/alikoyuncu/pl/ples.pl -g \"forall(f(X,gel),writeln(X))\" -t halt."; 
    $cmd2="/var/www/nlp/betik.sh"; 
    exec($cmd, $output); 


if($output==null) 
{ 
    echo "null"; 
} 
else 
{ 
    foreach($output as $tampon) { echo "$tampon .nci satir <br>"; }; 
} 

} 
catch(Exception $ex) 
{ 
    echo "Error"; 
} 
?> 

Répondre

2

Notez que la façon courante d'interroger le fichier est

$ prolog 

qui vous permet d'entrer dans le Prolog SWI interprer:

Welcome to SWI-Prolog (Multi-threaded, 64 bits, Version 5.10.4) 
Copyright (c) 1990-2011 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). 

où vous pouvez alors la requête:

?- consult(ples.pl). 

(ou [ples].) pour charger le fichier, puis

?- ancestor(X, tom). 

pour obtenir les résultats souhaités.

autre, appeler cela de la ligne de commande, je recommande:

swipl --quiet -s ples.pl -g "forall(ancestor(X, tom), writeln(X)), halt." 
0

Merci, ce code en cours d'exécution à l'ancêtre procudure mais quand je f (X, 'gel') procudere, il était non running.f procudure est:

f(Morphemes,String) :- trav(Morphemes,String,b). 

trav([],'',CurrentState) :- 
    son(CurrentState). 

trav([Morph|Morphs],String,CurrentState):- 
    (nonvar(String) -> 
     (concat(Phon,Rest,String), 
      not(Phon == '')); 
      true), 
    t(CurrentState,Morph:Phon,NextState), 
    trav(Morphs,Rest,NextState), 
    (var(String) -> 
       concat(Phon,Rest,String);true). 

Tout le code: https://docs.google.com/open?id=0B0itKSwxT0gTX0dNUmFobTJqaG8.

Questions connexes