Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Vít Novotný
pb016-priklady
Commits
1f4b3bfc
Commit
1f4b3bfc
authored
Jan 25, 2017
by
Vít Novotný
Browse files
added example 8.2_20
parent
8a58315b
Changes
3
Hide whitespace changes
Inline
Side-by-side
8.2_20.pl
0 → 100644
View file @
1f4b3bfc
% nacteni:
/*
['8.2_20.pl'].
*/
% pomocne funkce - jen "zaslepky"
% symboly P1, P2, P3
proposition_symbols
([
p1
,
p2
,
p3
],
_
).
% priklad: KB = P2 and P3
% alpha = P2
% beta = P1
pl_true
(
kb
,
[
p3
-
true
,
p2
-
true
,
p1
-
true
]):-!.
pl_true
(
kb
,
[
p3
-
true
,
p2
-
true
,
p1
-
false
]):-!.
pl_true
(
alpha
,[
p3
-
true
,
p2
-
true
,
p1
-
true
]):-!.
pl_true
(
alpha
,[
p3
-
false
,
p2
-
true
,
p1
-
true
]):-!.
pl_true
(
alpha
,[
p3
-
true
,
p2
-
true
,
p1
-
false
]):-!.
pl_true
(
alpha
,[
p3
-
false
,
p2
-
true
,
p1
-
false
]):-!.
pl_true
(
beta
,
[
p3
-
true
,
p2
-
true
,
p1
-
true
]):-!.
pl_true
(
beta
,
[
p3
-
true
,
p2
-
false
,
p1
-
true
]):-!.
pl_true
(
beta
,
[
p3
-
false
,
p2
-
true
,
p1
-
true
]):-!.
pl_true
(
beta
,
[
p3
-
false
,
p2
-
false
,
p1
-
true
]):-!.
% tt_entails(+KB,+Alpha)
tt_entails
(
KB
,
Alpha
):-
proposition_symbols
(
Symbols
,[
KB
,
Alpha
]),
tt_check_all
(
KB
,
Alpha
,
Symbols
,[]).
% tt_check_all(+KB,+Alpha,+Symbols,+Model)
tt_check_all
(
KB
,
Alpha
,[],
Model
):-
pl_true
(
KB
,
Model
),!,
pl_true
(
Alpha
,
Model
).
tt_check_all
(
_KB
,
_Alpha
,[],
_Model
):-!.
tt_check_all
(
KB
,
Alpha
,[
P
|
Symbols
],
Model
):-
tt_check_all
(
KB
,
Alpha
,
Symbols
,[
P
-
true
|
Model
]),
tt_check_all
(
KB
,
Alpha
,
Symbols
,[
P
-
false
|
Model
]).
show_bool
(
Text
,
P
):-
write
(
Text
),
call
(
P
),!,
write
(
'yes'
),
nl
.
show_bool
(
_
,
_
):-
write
(
'no'
),
nl
.
%:- trace,tt_entails(kb,alpha).
:-
show_bool
(
'KB entails Alpha: '
,
tt_entails
(
kb
,
alpha
)),
% true
show_bool
(
'KB entails Beta: '
,
tt_entails
(
kb
,
beta
)).
% false
8.2_20.py
0 → 100644
View file @
1f4b3bfc
#!/usr/bin/env python
# encoding=utf-8 (pep 0263)
from
linked_lists
import
LinkedList
,
Cons
,
Nil
def
preposition_symbols
(
_
):
# zavisi na resenem problemu
return
LinkedList
([
"p1"
,
"p2"
,
"p3"
])
def
pl_true
(
formula
,
model
):
# zavisi na resenem problemu
if
formula
==
"kb"
:
return
model
==
LinkedList
([(
"p3"
,
True
),
(
"p2"
,
True
),
(
"p1"
,
True
)])
or
\
model
==
LinkedList
([(
"p3"
,
True
),
(
"p2"
,
True
),
(
"p1"
,
False
)])
if
formula
==
"alpha"
:
return
model
==
LinkedList
([(
"p3"
,
True
),
(
"p2"
,
True
),
(
"p1"
,
True
)])
or
\
model
==
LinkedList
([(
"p3"
,
False
),
(
"p2"
,
True
),
(
"p1"
,
True
)])
or
\
model
==
LinkedList
([(
"p3"
,
True
),
(
"p2"
,
True
),
(
"p1"
,
False
)])
or
\
model
==
LinkedList
([(
"p3"
,
False
),
(
"p2"
,
True
),
(
"p1"
,
False
)])
if
formula
==
"beta"
:
return
model
==
LinkedList
([(
"p3"
,
True
),
(
"p2"
,
True
),
(
"p1"
,
True
)])
or
\
model
==
LinkedList
([(
"p3"
,
True
),
(
"p2"
,
False
),
(
"p1"
,
True
)])
or
\
model
==
LinkedList
([(
"p3"
,
False
),
(
"p2"
,
True
),
(
"p1"
,
True
)])
or
\
model
==
LinkedList
([(
"p3"
,
False
),
(
"p2"
,
False
),
(
"p1"
,
True
)])
def
tt_entails
(
kb
,
alpha
):
symbols
=
preposition_symbols
(
LinkedList
([
kb
,
alpha
]))
return
tt_check_all
(
kb
,
alpha
,
symbols
,
Nil
)
def
tt_check_all
(
kb
,
alpha
,
symbols
,
model
):
if
symbols
==
Nil
:
if
pl_true
(
kb
,
model
):
return
pl_true
(
alpha
,
model
)
return
True
p
=
symbols
.
head
return
tt_check_all
(
kb
,
alpha
,
symbols
.
tail
,
Cons
((
p
,
True
),
model
))
and
\
tt_check_all
(
kb
,
alpha
,
symbols
.
tail
,
Cons
((
p
,
False
),
model
))
# demonstracni vypis
if
__name__
==
"__main__"
:
print
(
"KB entails Alpha: %s"
%
tt_entails
(
"kb"
,
"alpha"
))
print
(
"KB entails Beta: %s"
%
tt_entails
(
"kb"
,
"beta"
))
8.2_20.py.out
0 → 100644
View file @
1f4b3bfc
KB entails Alpha: True
KB entails Beta: False
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment