Package spade :: Module pyxf :: Class swipl
[hide private]
[frames] | no frames]

Class swipl

source code

Python interface to SWI Prolog (http://www.swi-prolog.org)

Instance Methods [hide private]
 
__init__(self, path='swipl', args='-q +tty')
Constructor method Usage: swipl( path, args ) path - path to SWI executable (default: 'swipl') args - command line arguments (default: '-q +tty')
source code
 
load(self, module)
Loads module into self.engine Usage: instance.load( path ) path - path to module file
source code
 
query(self, query)
Queries current engine state Usage: instance.query( query ) query - usual SWI Prolog query (example: 'likes( X, Y )')
source code
 
_printer(self, lvars, query)
Private method for constructing a result printing query.
source code
Method Details [hide private]

__init__(self, path='swipl', args='-q +tty')
(Constructor)

source code 

Constructor method Usage: swipl( path, args ) path - path to SWI executable (default: 'swipl') args - command line arguments (default: '-q +tty')

self.engine becomes pexpect spawn instance of SWI Prolog shell

Raises: SWIExecutableNotFound

load(self, module)

source code 

Loads module into self.engine Usage: instance.load( path ) path - path to module file

Raises: SWICompileError

query(self, query)

source code 
Queries current engine state
Usage: instance.query( query )
query - usual SWI Prolog query (example: 'likes( X, Y )')

Returns:
  True - if yes/no query and answer is yes
  False - if yes/no query and answer is no
  List of dictionaries - if normal query. Dictionary keys are returned
  variable names. Example:
  >>> instance.query( 'likes( Person, Food )' )
  [{'Person': 'john', 'Food': 'curry'}, {'Person': 'sandy', 'Food': 'mushrooms'}]

Raises: SWIQueryError

_printer(self, lvars, query)

source code 

Private method for constructing a result printing query. Usage: instance._printer( lvars, query ) lvars - list of logical variables to print query - query containing the variables to be printed

Returns: string of the form 'query, writeln( res( 'VarName1', VarName1 ) ) ... writeln( res( 'VarNameN', VarNameN ) ),nl,fail.'