我有一套规则;
family(Mother,Father,Children).
儿童是一个清单(例如[ag, bg]
)。
parent(X,Y) :-
family(X,_,_) -> mother(X,Y); father(X,Y).
根据上面的条款,如果我放入父母,它会正确地给我孩子。但是,如果我把孩子放进去,我就无法得到父母。
我也尝试为Child制定一个条款;
child(X,Y) :-
mother(A,X),
father(B,X),
Y=A,B.
母亲和父亲的工作正常,但我需要两个变量才能转到Y
。
有什么建议吗?
答案 0 :(得分:2)
您可以简化子谓词:
>>> from shortener.models import KirrURL
>>> from django.shortcuts import get_object_or_404
>>> obj = get_object_or_404(KirrURL,shortcode='pric3e')
Traceback (most recent call last):File"/Users/phil/Desktop/django110/lib/python3.5/site
packages/django/shortcuts.py", line 85, in get_object_or_404
return queryset.get(*args, **kwargs)
File "/Users/phil/Desktop/django110/lib/python3.5/site-packages/django/db/models/query.py", line 385, in get
self.model._meta.object_name
shortener.models.DoesNotExist: KirrURL matching query does not exist.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/Users/phil/Desktop/django110/lib/python3.5/site-packages/django/shortcuts.py", line 93, in get_object_or_404
raise Http404('No %s matches the given query.' % queryset.model._meta.object_name)
django.http.response.Http404: No KirrURL matches the given query.
>>> obj = KirrURL.objects.get(shortcode='pric3e')
>>> obj
<KirrURL: http://google.com>
>>> obj.id
1
>>> obj.url
'http://google.com'