yap4py stuff
This commit is contained in:
parent
d0b2924322
commit
ee9e596368
@ -78,6 +78,7 @@ add_custom_target( YAP4PY_SETUP_DIRS
|
|||||||
)
|
)
|
||||||
|
|
||||||
add_custom_target( YAP4PY ALL
|
add_custom_target( YAP4PY ALL
|
||||||
|
COMMAND ${PYTHON_EXECUTABLE} -m pip uninstall -y YAP4PY
|
||||||
COMMAND ${SWIG_EXECUTABLE} -python -modern -c++ -py3 -DX_API -I${CMAKE_SOURCE_DIR}/CXX -I${CMAKE_SOURCE_DIR}/include -I${CMAKE_SOURCE_DIR}/H -I${CMAKE_SOURCE_DIR}/H/generated -I${CMAKE_SOURCE_DIR}/OPTYap -I../../.. -o yap_wrap.cpp yap.i
|
COMMAND ${SWIG_EXECUTABLE} -python -modern -c++ -py3 -DX_API -I${CMAKE_SOURCE_DIR}/CXX -I${CMAKE_SOURCE_DIR}/include -I${CMAKE_SOURCE_DIR}/H -I${CMAKE_SOURCE_DIR}/H/generated -I${CMAKE_SOURCE_DIR}/OPTYap -I../../.. -o yap_wrap.cpp yap.i
|
||||||
COMMAND ${PYTHON_EXECUTABLE} setup.py sdist bdist_wheel
|
COMMAND ${PYTHON_EXECUTABLE} setup.py sdist bdist_wheel
|
||||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||||
@ -85,8 +86,9 @@ DEPENDS YAP4PY_SETUP)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
install(CODE "execute_process(COMMAND ${PYTHON_EXECUTABLE} -m pip install --force --no-index -f dist yap4py
|
install(CODE "execute_process(
|
||||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})"
|
COMMAND ${PYTHON_EXECUTABLE} -m pip install --force --no-index -f packages/python/swig/dist YAP4PY
|
||||||
|
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})"
|
||||||
DEPENDS Py4YAP ${CMAKE_BINARY_DIR}/${YAP_STARTUP} ${dlls} )
|
DEPENDS Py4YAP ${CMAKE_BINARY_DIR}/${YAP_STARTUP} ${dlls} )
|
||||||
|
|
||||||
install(FILES ${PROLOG_SOURCES} DESTINATION ${libpl})
|
install(FILES ${PROLOG_SOURCES} DESTINATION ${libpl})
|
||||||
|
@ -7,11 +7,12 @@ from collections import namedtuple
|
|||||||
|
|
||||||
from yap import *
|
from yap import *
|
||||||
|
|
||||||
|
|
||||||
class Engine( YAPEngine ):
|
class Engine( YAPEngine ):
|
||||||
def __init__(self, args=None):
|
def __init__(self, args=None,**kwargs):
|
||||||
# type: (object) -> object
|
# type: (object) -> object
|
||||||
if not args:
|
if not args:
|
||||||
args = YAPEngineArgs()
|
args = EngineArgs(**kwargs)
|
||||||
yap_lib_path = os.path.dirname(__file__)
|
yap_lib_path = os.path.dirname(__file__)
|
||||||
args.setYapShareDir(os.path.join(yap_lib_path,"prolog"))
|
args.setYapShareDir(os.path.join(yap_lib_path,"prolog"))
|
||||||
args.setYapLibDir(yap_lib_path)
|
args.setYapLibDir(yap_lib_path)
|
||||||
@ -32,11 +33,55 @@ class Engine( YAPEngine ):
|
|||||||
|
|
||||||
class EngineArgs( YAPEngineArgs ):
|
class EngineArgs( YAPEngineArgs ):
|
||||||
""" Interface to Engine Options class"""
|
""" Interface to Engine Options class"""
|
||||||
|
def __init__(self, args=None,**kwargs):
|
||||||
|
super().__init__()
|
||||||
|
|
||||||
|
|
||||||
class Predicate( YAPPredicate ):
|
class Predicate( YAPPredicate ):
|
||||||
""" Interface to Generic Predicate"""
|
""" Interface to Generic Predicate"""
|
||||||
|
|
||||||
|
class Predicate:
|
||||||
|
"""Goal is a predicate instantiated under a specific environment """
|
||||||
|
def __init__( self, name, args, module=None, engine = None):
|
||||||
|
self = namedtuple( name, args )
|
||||||
|
if module:
|
||||||
|
self.p = YAPPredicate( name, len(self), module )
|
||||||
|
else:
|
||||||
|
self.p = YAPPredicate( name, len(self) )
|
||||||
|
self.e = engine
|
||||||
|
|
||||||
|
def goals( self, engine):
|
||||||
|
self.e = engine
|
||||||
|
|
||||||
|
def __iter__(self):
|
||||||
|
return PrologTableIter(self.e, self.p)
|
||||||
|
|
||||||
|
def holds(self):
|
||||||
|
return self.e.run(self._make_())
|
||||||
|
|
||||||
|
class PrologTableIter:
|
||||||
|
|
||||||
|
def __init__(self, e, goal):
|
||||||
|
try:
|
||||||
|
self.e = e
|
||||||
|
self.q = e.YAPQuery(goal)
|
||||||
|
except:
|
||||||
|
print('Error')
|
||||||
|
|
||||||
|
def __iter__(self):
|
||||||
|
# Iterators are iterables too.
|
||||||
|
# Adding this functions to make them so.
|
||||||
|
return self
|
||||||
|
|
||||||
|
def next(self):
|
||||||
|
if self.q.next():
|
||||||
|
return goal
|
||||||
|
else:
|
||||||
|
self.q.close()
|
||||||
|
self.q = None
|
||||||
|
raise StopIteration()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class PrologPredicate( YAPPrologPredicate ):
|
class PrologPredicate( YAPPrologPredicate ):
|
||||||
""" Interface to Prolog Predicate"""
|
""" Interface to Prolog Predicate"""
|
||||||
@ -163,6 +208,17 @@ def live(**kwargs):
|
|||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
||||||
|
def boot_yap(**kwargs):
|
||||||
|
args = EngineArgs(**kwarg)
|
||||||
|
yap_lib_path = os.path.dirname(__file__)
|
||||||
|
args.setYapShareDir(os.path.join(yap_lib_path,"prolog"))
|
||||||
|
args.setYapLibDir(yap_lib_path)
|
||||||
|
args.setSavedState(os.path.join(yap_lib_path,"startup.yss"))
|
||||||
|
engine = YAPEngine(args)
|
||||||
|
engine.goal( set_prolog_flag('verbose', 'silent' ) )
|
||||||
|
engine.goal( use_module(library('yapi') ) )
|
||||||
|
return engine
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
engine = boot_yap()
|
engine = boot_yap()
|
||||||
handler = numbervars
|
handler = numbervars
|
||||||
|
Reference in New Issue
Block a user