Comments (4)
I have the same problem:
det(the).
adjective(brown).
noun(fox).
generate_output(X) :- maplist(call,[det,adjective,noun],X).
In swiprolog the query works fine. But if I make a query with
result = list(prolog.query('generate_output(X)'))
print(result)
The output is:
[{'X': [Atom('396421'), Atom('397317'), Atom('393093')]}, ....
I work with swipl 7.6.0-rc2, python 3.6.2 and pyswip 0.2.3.
@manraog did you find a workaround?
from pyswip.
I am facing a similar problem,
In [1]: from pyswip import Prolog, registerForeign
In [2]: prolog = Prolog()
In [3]: prolog.consult("geoquery")
Warning: /home/vimos/git/visualjoyce/zoonlp/data/geoquery/geoquery:57:
Singleton variables: [R]
Warning: /home/vimos/git/visualjoyce/zoonlp/data/geoquery/geoquery:348:
Local definition of user:subtract/3 overrides weak import from lists
In [4]: for l in open('geoqueries250'):
...: if l.strip():
...: try:
...: a = list(prolog.query("answer{}".format(l.strip().split(', answer')[1])[:-2]))
...: print(a)
...: except:
...: pass
...:
Answer = [arkansas,canadian,cimarron,colorado,gila,green,neosho,north platte,pecos,red,republican,rio grande,san juan,smoky hill,south platte,washita]
[{'A': Variable(67), 'B': Variable(70), 'C': Variable(73)}]
Answer = [granite peak]
[{'A': Variable(67), 'B': Variable(70)}]
I used the geoquery dataset, the output for a is
[{'A': Variable(67), 'B': Variable(70)}]
I tried to debug, I found that if we run examples from the repo, the printed mapped terms are
/opt/anaconda/anaconda3/bin/python3.6 /home/vimos/git/pyswip/examples/create_term.py
mappedTerms {}
mappedTerms {}
mappedTerms {}
mappedTerms {70: Atom('361349')}
mappedTerms {70: Atom('361349'), 71: Atom('360709'), 69: Functor(373005,2,X,gnu)}
mappedTerms {70: Atom('361349'), 71: Atom('360709'), 69: Functor(373005,2,X,gnu)}
mappedTerms {70: Atom('361349'), 71: Atom('360709'), 69: Functor(373005,2,X,gnu), 73: Atom('361477')}
[{'X': 'gnu', 'Y': 50}]
But for the geoquery case, it will be
/opt/anaconda/anaconda3/bin/python3.6 /home/vimos/git/pyswip/examples/geoquery.py
Warning: /home/vimos/git/visualjoyce/zoonlp/data/geoquery/geoquery:57:
Singleton variables: [R]
mappedTerms {}
Answer = [arkansas,canadian,cimarron,colorado,gila,green,neosho,north platte,pecos,red,republican,rio grande,san juan,smoky hill,south platte,washita]
mappedTerms {63: []}
mappedTerms {63: []}
mappedTerms {63: []}
mappedTerms {63: [], 66: Atom('405637')}
mappedTerms {63: [], 66: Atom('405637'), 67: Variable(67)}
mappedTerms {63: [], 66: Atom('405637'), 67: Variable(67), 65: Functor(373005,2,A,_G1073)}
mappedTerms {63: [], 66: Atom('405637'), 67: Variable(67), 65: Functor(373005,2,A,_G1073)}
mappedTerms {63: [], 66: Atom('405637'), 67: Variable(67), 65: Functor(373005,2,A,_G1073), 69: Atom('517893')}
mappedTerms {63: [], 66: Atom('405637'), 67: Variable(67), 65: Functor(373005,2,A,_G1073), 69: Atom('517893'), 70: Variable(70)}
mappedTerms {63: [], 66: Atom('405637'), 67: Variable(67), 65: Functor(373005,2,A,_G1073), 69: Atom('517893'), 70: Variable(70), 68: Functor(373005,2,B,_G1076)}
mappedTerms {63: [], 66: Atom('405637'), 67: Variable(67), 65: Functor(373005,2,A,_G1073), 69: Atom('517893'), 70: Variable(70), 68: Functor(373005,2,B,_G1076)}
mappedTerms {63: [], 66: Atom('405637'), 67: Variable(67), 65: Functor(373005,2,A,_G1073), 69: Atom('517893'), 70: Variable(70), 68: Functor(373005,2,B,_G1076), 72: Atom('505989')}
mappedTerms {63: [], 66: Atom('405637'), 67: Variable(67), 65: Functor(373005,2,A,_G1073), 69: Atom('517893'), 70: Variable(70), 68: Functor(373005,2,B,_G1076), 72: Atom('505989'), 73: Variable(73)}
[{'A': Variable(67), 'B': Variable(70), 'C': Variable(73)}]
After some debuging, the problem of showing Atom may be fixed by changing _unifier function to:
def _unifier(arity, *args):
assert arity == 2
#if PL_is_variable(args[0]):
# args[0].unify(args[1])
if hasattr(args[0], 'value'):
args_0 = args[0].value
else:
args_0 = args[0]
if hasattr(args[1], 'value'):
args_1 = args[1].value
else:
args_1 = args[1]
if type(args_1) is list:
for i, item in enumerate(args_1):
if hasattr(item, 'value'):
args_1[i] = item.value
return {args_0: args_1}
But this does not fix the Variable case.
I found a topic on stackoverflow, maybe Variable case is not easy to resolve.
from pyswip.
This is fixed in the rewrite/refactoring of PySwip in the refactor
branch. E.g.,: https://github.com/yuce/pyswip/blob/refactor/tests/test_prolog.py
from pyswip.
Cant access the above link, can you share the updated link @yuce
from pyswip.
Related Issues (20)
- Errors on queries
- Powered by PySwip HOT 2
- Swipl DCG does not appear to function HOT 1
- Problem running the quick test code on Windows 11 HOT 2
- Compatibility with Mac M1 chip HOT 6
- How to clean prolog ?
- Error with SWI-Prolog v8.5.3 and pyswipl 0.2.10
- Error by using char '¬' as operator in prolog and translate it with pyswip
- pyswip cannot work with flask HOT 1
- Operating with dictionaries in pyswip
- Please provide support for M1 Macs HOT 2
- Core dump HOT 9
- pyswip incompatible with swi-prolog 9.0.0? HOT 6
- Could not find the SWI-Prolog library in this platform. HOT 3
- efficient way of adding and removing facts
- How do I use prolog's debug/trace mode in python HOT 1
- Reviewers
- Redefined static procedure after clearing Prolog() object HOT 1
- Problem in representing incomplete structures
- Powered by Pyswip HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pyswip.