more python interface.
This commit is contained in:
parent
1bcbd5ce15
commit
aba60111cf
@ -5,18 +5,8 @@ from ipykernel.ipkernel import IPythonKernel
|
|||||||
import sys
|
import sys
|
||||||
import signal
|
import signal
|
||||||
import yap
|
import yap
|
||||||
|
#import ipdb
|
||||||
import logging
|
#ipdb,set_trace()
|
||||||
|
|
||||||
logger = logging.getLogger()
|
|
||||||
handler = logging.StreamHandler()
|
|
||||||
formatter = logging.Formatter(
|
|
||||||
'%(asctime)s %(name)-12s %(levelname)-8s %(message)s')
|
|
||||||
handler.setFormatter(formatter)
|
|
||||||
logger.addHandler(handler)
|
|
||||||
logger.setLevel(logging.DEBUG)
|
|
||||||
|
|
||||||
logger.debug('often makes a very good meal of %s', 'visiting tourists')
|
|
||||||
|
|
||||||
kernel_json = {
|
kernel_json = {
|
||||||
"argv": [sys.executable,
|
"argv": [sys.executable,
|
||||||
@ -50,12 +40,7 @@ class YAPKernel(IPythonKernel):
|
|||||||
'file_extension': '.yap',
|
'file_extension': '.yap',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def init_yap(self, **kwargs):
|
||||||
def __init__(self, **kwargs):
|
|
||||||
super(YAPKernel, self).__init__( **kwargs)
|
|
||||||
_start_yap( **kwargs )
|
|
||||||
|
|
||||||
def _start_yap(self, **kwargs):
|
|
||||||
# Signal handlers are inherited by forked processes, and we can't easily
|
# Signal handlers are inherited by forked processes, and we can't easily
|
||||||
# reset it from the subprocess. Since kernelapp ignores SIGINT except in
|
# reset it from the subprocess. Since kernelapp ignores SIGINT except in
|
||||||
# message handlers, we need to temporarily reset the SIGINT handler here
|
# message handlers, we need to temporarily reset the SIGINT handler here
|
||||||
@ -71,11 +56,16 @@ class YAPKernel(IPythonKernel):
|
|||||||
finally:
|
finally:
|
||||||
signal.signal(signal.SIGINT, sig)
|
signal.signal(signal.SIGINT, sig)
|
||||||
|
|
||||||
|
def __init__(self, **kwargs):
|
||||||
|
super(YAPKernel, self).__init__( **kwargs)
|
||||||
|
self.init_yap( **kwargs )
|
||||||
|
self.shell.run_cell = self.yap_run_cell
|
||||||
|
|
||||||
def get_usage(self):
|
def get_usage(self):
|
||||||
return "This is the YAP kernel."
|
return "This is the YAP kernel."
|
||||||
|
|
||||||
|
|
||||||
def run_cell(self, s, store_history=False, silent=False, shell_futures=True):
|
def yap_run_cell(self, s, store_history=False, silent=False, shell_futures=True):
|
||||||
|
|
||||||
if not self.q:
|
if not self.q:
|
||||||
self.q = self.engine.query(s)
|
self.q = self.engine.query(s)
|
||||||
|
@ -1,47 +0,0 @@
|
|||||||
# python commands
|
|
||||||
|
|
||||||
import sys
|
|
||||||
# import collections
|
|
||||||
|
|
||||||
# generated by swig
|
|
||||||
import yap
|
|
||||||
|
|
||||||
# make sure Python knows about engine
|
|
||||||
engine = None
|
|
||||||
|
|
||||||
# Mappings between functors and types
|
|
||||||
#
|
|
||||||
# they are used to have the same type f1or several occurences
|
|
||||||
# of the same functor, and to ensure that an object is indeed
|
|
||||||
# a Prolog compound term.
|
|
||||||
#
|
|
||||||
dictF2P = {}
|
|
||||||
|
|
||||||
|
|
||||||
class A:
|
|
||||||
"""Represents a non-interned Prolog atom"""
|
|
||||||
def __init__(self, s):
|
|
||||||
self.a = s
|
|
||||||
|
|
||||||
def __repr__(self):
|
|
||||||
return "A(" + self.a + ")"
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return self.a
|
|
||||||
|
|
||||||
|
|
||||||
class V:
|
|
||||||
"""Wraps a term, or a reference to a logical variables"""
|
|
||||||
def __init__(self, t):
|
|
||||||
print(type(t))
|
|
||||||
self.v = t
|
|
||||||
|
|
||||||
def __repr__(self):
|
|
||||||
return "V(" + str(self.v) + ")"
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return engine.getTerm(self.v).text()
|
|
||||||
|
|
||||||
def handle(self):
|
|
||||||
return self.v
|
|
||||||
|
|
Reference in New Issue
Block a user