python
This commit is contained in:
parent
732adf9f43
commit
ea099c83bb
@ -12,14 +12,9 @@ include(CMakeToolsHelpers OPTIONAL)
|
||||
project( YAP )
|
||||
|
||||
|
||||
if (ANDROID)
|
||||
set(YAP_APP_DIR "${CMAKE_SOURCE_DIR}/../..")
|
||||
set(YAP_APP_DIR "${CMAKE_SOURCE_DIR}/../..")
|
||||
cmake_policy(VERSION 3.4)
|
||||
|
||||
else ()
|
||||
cmake_minimum_required(VERSION 2.8)
|
||||
endif()
|
||||
|
||||
set(
|
||||
CMAKE_MODULE_PATH
|
||||
"${CMAKE_SOURCE_DIR}"
|
||||
|
@ -731,7 +731,8 @@ PyObject *term_to_nametuple(const char *s, arity_t arity, PyObject *tuple) {
|
||||
Py_INCREF(typp);
|
||||
}
|
||||
o = PyStructSequence_New(typp);
|
||||
for (arity_t i = 0; i < arity; i++) {
|
||||
arity_t i;
|
||||
for (i=0; i < arity; i++) {
|
||||
PyObject *pArg = PyTuple_GET_ITEM(tuple, i);
|
||||
Py_INCREF(pArg);
|
||||
if (pArg)
|
||||
|
@ -23,10 +23,10 @@ restore_python_output(OldOutput,OldError) :-
|
||||
close(OldOutput),
|
||||
close(OldError).
|
||||
|
||||
jupyter_query( VarNames, Dict ) :-
|
||||
%set_python_output(OldOutput,OldError),
|
||||
writeln(my:String),
|
||||
show_answer( VarNames, user_error, Dict),
|
||||
writeln(my:VarNames),
|
||||
%restore_python_output(OldOutput,OldError).
|
||||
jupyter_query(String, Dict ) :-
|
||||
set_python_output(OldOutput,OldError),
|
||||
writeln(my:String),
|
||||
yapi_query( String, Dict),
|
||||
writeln(my:Dict),
|
||||
restore_python_output(OldOutput,OldError),
|
||||
true.
|
||||
|
@ -39,7 +39,7 @@ from IPython.core import oinspect
|
||||
from IPython.core import magic
|
||||
from IPython.core import page
|
||||
from IPython.core import prefilter
|
||||
from IPython.core import shadowns
|
||||
# from IPython.core import shadows
|
||||
from IPython.core import ultratb
|
||||
from IPython.core import interactiveshell
|
||||
from IPython.core.alias import Alias, AliasManager
|
||||
@ -168,12 +168,12 @@ rquwer
|
||||
result.execution_count = self.shell.execution_count
|
||||
|
||||
try:
|
||||
if self.q = query_prolog(s):
|
||||
if self.q == jupyter_query(s, Dict):
|
||||
self.shell.last_execution_succeeded = True
|
||||
result.result = True
|
||||
result.result = (True, Dict)
|
||||
else:
|
||||
self.shell.last_execution_succeeded = True
|
||||
result.result = True
|
||||
result.result = (True, {})
|
||||
except Exception as e:
|
||||
print(e)
|
||||
self.shell.last_execution_succeeded = False
|
||||
@ -208,12 +208,12 @@ rquwer
|
||||
#
|
||||
# construct a query from a one-line string
|
||||
# q is opaque to Python
|
||||
q = engine.query(s)
|
||||
q = jupyter_query(s,dict)
|
||||
# vs is the list of variables
|
||||
# you can print it out, the left-side is the variable name,
|
||||
# the right side wraps a handle to a variable
|
||||
# pdb.set_trace()
|
||||
vs = q.namedVarsVector()
|
||||
#vs = q.namedVarsVector()
|
||||
#pdb.set_trace()
|
||||
# atom match either symbols, or if no symbol exists, sttrings, In this case
|
||||
# variable names should match strings
|
||||
@ -225,26 +225,5 @@ rquwer
|
||||
# launch the query
|
||||
while answer(q):
|
||||
# this new vs should contain bindings to vars
|
||||
vs= q.namedVars()
|
||||
print( vs )
|
||||
gs = numbervars( engine, vs)
|
||||
print(gs)
|
||||
i=0
|
||||
# iterate
|
||||
for eq in gs:
|
||||
name = eq[0]
|
||||
binding = eq[1]
|
||||
# this is tricky, we're going to bind the variables in the term so thay we can
|
||||
# output X=Y. The Python way is to use dictionares.
|
||||
#Instead, we use the T function to tranform the Python term back to Prolog
|
||||
if name != binding:
|
||||
print(name + " = " + str(binding))
|
||||
#ok, that was Prolog code
|
||||
print("yes")
|
||||
# deterministic = one solution
|
||||
if q.deterministic():
|
||||
# done
|
||||
q.close()
|
||||
return
|
||||
q.close()
|
||||
return
|
||||
print( dict )
|
||||
|
||||
|
Reference in New Issue
Block a user