Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
pro
ndl
Commits
eeae0583
Verified
Commit
eeae0583
authored
Jun 02, 2018
by
Marcin Moskal
Browse files
Handle queries with all-constant functors
parent
556ffe75
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/main/scala/pl/edu/agh/kis/eis/ndl/BindingSetX.scala
View file @
eeae0583
...
...
@@ -15,6 +15,9 @@ object BindingSet {
case
Seq
(
_:
Const
[
A
])
=>
BindingSetX
(
Map
.
empty
)
case
Seq
(
_:
Const
[
A
],
_:
Const
[
A
])
=>
BindingSetX
(
Map
.
empty
)
case
Seq
(
v1
:
Variable
[
A
],
v2
:
Variable
[
A
])
=>
BindingSetX
(
Map
(
v1
.
name
.
get
->
kb
.
facts2
.
map
(
_
.
_1
),
...
...
@@ -26,7 +29,6 @@ object BindingSet {
case
class
BindingSetX
[
A
](
m
:
Map
[
String
,
Set
[
A
]])
{
def
expand
(
bs
:
BindingSetX
[
A
])
:
BindingSetX
[
A
]
=
{
// tutaj zbiór jest tworzony zbyt duży
BindingSetX
(
m
++
bs
.
m
.
map
{
case
(
k
,
v
)
=>
k
->
(
v
intersect
m
.
getOrElse
(
k
,
v
))
})
}
}
src/main/scala/pl/edu/agh/kis/eis/ndl/FactSelector.scala
View file @
eeae0583
...
...
@@ -25,7 +25,7 @@ trait FactSelector[A] {
// calculate all possible variable configurations
crossJoin
(
getBindingSetVars
(
bindingSet
)).
map
(
_
.
toSet
)
// bind all variables in query
// bind all variables in query
(adds all-constant facts from query too)
.
map
(
bind
).
toSet
// build facts from bound query and remove facts without evidence in kb
.
filter
(
buildableToKnownFact
)
...
...
src/test/scala/pl/edu/agh/kis/eis/ndl/KnowledgeBaseSpec.scala
View file @
eeae0583
...
...
@@ -162,9 +162,39 @@ class KnowledgeBaseSpec extends FlatSpec with Matchers {
)
}
"Query ((x 1) (y 2))"
should
"be unified"
ignore
{
"Query ((x) (y) (z z))"
should
"be unified"
in
{
val
kb
:
KnowledgeBase
[
Int
]
=
new
KnowledgeBase
[
Int
](
Set
(
Tuple1
(
6
),
(
3
,
4
),
(
4
,
4
),
Tuple1
(
3
),
(
6
,
6
)
))
val
x
=
Variable
[
Int
](
"x"
)
val
y
=
Variable
[
Int
](
"y"
)
val
z
=
Variable
[
Int
](
"z"
)
kb
.
queryAll
(
Functor
(
x
),
Functor
(
y
),
Functor
(
z
,
z
)).
toSeq
should
contain
theSameElementsAs
Set
(
Set
(
Variable
(
"x"
,
6
),
Variable
(
"y"
,
6
),
Variable
(
"z"
,
4
)),
Set
(
Variable
(
"x"
,
6
),
Variable
(
"y"
,
3
),
Variable
(
"z"
,
4
)),
Set
(
Variable
(
"x"
,
3
),
Variable
(
"y"
,
6
),
Variable
(
"z"
,
4
)),
Set
(
Variable
(
"x"
,
3
),
Variable
(
"y"
,
3
),
Variable
(
"z"
,
4
)),
Set
(
Variable
(
"x"
,
6
),
Variable
(
"y"
,
6
),
Variable
(
"z"
,
6
)),
Set
(
Variable
(
"x"
,
6
),
Variable
(
"y"
,
3
),
Variable
(
"z"
,
6
)),
Set
(
Variable
(
"x"
,
3
),
Variable
(
"y"
,
6
),
Variable
(
"z"
,
6
)),
Set
(
Variable
(
"x"
,
3
),
Variable
(
"y"
,
3
),
Variable
(
"z"
,
6
))
)
}
"Query ((x) (3))"
should
"fail to unify on nonexistent unary fact"
in
{
val
kb
:
KnowledgeBase
[
Int
]
=
new
KnowledgeBase
[
Int
](
Set
(
Tuple1
(
5
),
(
1
,
3
)
))
kb
.
queryAll
(
Functor
(
Variable
(
"x"
)),
Functor
(
Const
(
3
)))
should
be
(
empty
)
}
"Query ((x) (y) (z z))"
should
"be unified"
ignore
{
"Query ((x) (4 5))"
should
"fail to unify on nonexistent binary fact"
in
{
val
kb
:
KnowledgeBase
[
Int
]
=
new
KnowledgeBase
[
Int
](
Set
(
Tuple1
(
1
),
(
2
,
5
),
Tuple1
(
4
)
))
kb
.
queryAll
(
Functor
(
Variable
(
"x"
)),
Functor
(
Const
(
4
),
Const
(
5
)))
should
be
(
empty
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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