Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

Implement LogicManager and Explanation #46

Merged
merged 64 commits into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
0f63919
fmt
dmikhalin May 31, 2023
79d06f2
fmt
dmikhalin May 31, 2023
02c0051
wip: get_rule(s), put_rule
dmikhalin Jun 1, 2023
ede7983
get_rules isn't async
dmikhalin Jun 2, 2023
80cf00c
"rules do not contain" step
dmikhalin Jun 2, 2023
d10f36f
Explanations
dmikhalin Jun 5, 2023
e1064fc
`rules are` step
dmikhalin Jun 5, 2023
6621ca9
Add `inferred` field
dmikhalin Jun 7, 2023
2931c5a
explanation test (wip)
dmikhalin Jun 7, 2023
87cc6ca
PartialEq trait for Concept
dmikhalin Jun 8, 2023
68f82a1
test_disjunction_explainable
dmikhalin Jun 8, 2023
1a9b4f2
Empty Explainables -> None
dmikhalin Jun 8, 2023
189a2d4
test_relation_explainable
dmikhalin Jun 8, 2023
04dce46
test_relation_explainable_multiple_ways
dmikhalin Jun 8, 2023
ff2bbf5
test_has_explicit_explainable_two_ways
dmikhalin Jun 8, 2023
ac4e714
fmt
dmikhalin Jun 8, 2023
6665d13
Cleanup
dmikhalin Jun 8, 2023
77488de
fmt
dmikhalin Jun 8, 2023
ebddff0
Run logic tests on Cluster
dmikhalin Jun 8, 2023
b688097
127.0.0.1 -> localhost in the Cluster connection
dmikhalin Jun 8, 2023
165489f
Reasoner steps
dmikhalin Jun 9, 2023
56af7ee
Fix imports after rebase
dmikhalin Jun 9, 2023
2bc131e
rename logic.rs to logic_manager.rs
dmikhalin Jun 9, 2023
3891d3a
Refactoring
dmikhalin Jun 13, 2023
113b2c3
Cleanup
dmikhalin Jun 13, 2023
6372a67
Refactor
dmikhalin Jun 13, 2023
a5f38e2
Option<Explainables> -> Empty Explainables
dmikhalin Jun 13, 2023
12f811a
Default Explainables
dmikhalin Jun 14, 2023
a704652
Remove concepts_to_vec()
dmikhalin Jun 14, 2023
8420aee
inferred -> is_inferred
dmikhalin Jun 14, 2023
7cd4ed9
Deconstruction + fmt
dmikhalin Jun 14, 2023
9bc06a9
RuleRequest, RuleResponse
dmikhalin Jun 14, 2023
a09f3a3
logic.logic_manager -> transaction.logic.manager
dmikhalin Jun 14, 2023
2817df9
RuleAPI
dmikhalin Jun 14, 2023
1e79084
BDD steps for rules
dmikhalin Jun 14, 2023
4218ffa
fmt
dmikhalin Jun 14, 2023
879ace8
Rules BDD tests
dmikhalin Jun 14, 2023
b3ad787
Extract reasoner tests
dmikhalin Jun 14, 2023
42f488f
Reordering
dmikhalin Jun 14, 2023
1b2169e
Remove redundant clone()
dmikhalin Jun 15, 2023
2b90c9a
Refactoring
dmikhalin Jun 15, 2023
1342e75
Fix rebase
dmikhalin Jun 15, 2023
c83c108
typeql BDD test regrouping
dmikhalin Jun 15, 2023
0a6110c
Add comment to do_nothing()
dmikhalin Jun 15, 2023
c6094e0
fmt
dmikhalin Jun 15, 2023
8a67c03
Fix error types
dmikhalin Jun 15, 2023
7f681d9
Remove redundant check
dmikhalin Jun 15, 2023
3c200c8
explainables_count -> 1
dmikhalin Jun 15, 2023
c7ce907
Simplify
dmikhalin Jun 19, 2023
84d902c
Cleanup
dmikhalin Jun 19, 2023
4dc3727
Refactor
dmikhalin Jun 19, 2023
63a54a4
Separate reasoner tests
dmikhalin Jun 19, 2023
7a3ae3e
word -> label
dmikhalin Jun 19, 2023
0e78574
str in step table identifiers
dmikhalin Jun 20, 2023
59f6022
Remove redundant map_err
dmikhalin Jun 20, 2023
38d5a76
Refactor
dmikhalin Jun 20, 2023
a9854e2
Refactor
dmikhalin Jun 20, 2023
6a7ef99
Remove trimming
dmikhalin Jun 21, 2023
7506acc
Refactor
dmikhalin Jun 21, 2023
cc7ca76
fmt
dmikhalin Jun 21, 2023
fd0cc10
Simplification
dmikhalin Jun 21, 2023
006972c
TransactionRequest reordering
dmikhalin Jun 22, 2023
f6ec58d
Tests refactoring
dmikhalin Jun 22, 2023
3f2bb57
Check only one db existance
dmikhalin Jun 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions src/answer/concept_map.rs
dmikhalin marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,6 @@ pub struct Explainables {
}

impl Explainables {
pub(crate) fn new(
relations: HashMap<String, Explainable>,
attributes: HashMap<String, Explainable>,
ownerships: HashMap<(String, String), Explainable>,
) -> Self {
Self { relations, attributes, ownerships }
}

pub fn is_empty(&self) -> bool {
self.relations.is_empty() && self.attributes.is_empty() && self.ownerships.is_empty()
}
Expand Down
22 changes: 7 additions & 15 deletions src/connection/network/proto/concept.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,9 @@ impl TryFromProto<ConceptMapGroupProto> for ConceptMapGroup {
impl TryFromProto<ConceptMapProto> for ConceptMap {
fn try_from_proto(proto: ConceptMapProto) -> Result<Self> {
let ConceptMapProto { map: map_proto, explainables: explainables_proto } = proto;
let mut map = HashMap::with_capacity(map_proto.len());
for (k, v) in map_proto {
map.insert(k, Concept::try_from_proto(v)?);
}
let Some(explainables) = explainables_proto else { return Err(ConnectionError::MissingResponseField("explainables").into()) };
let map = map_proto.into_iter().map(|(k, v)| Concept::try_from_proto(v).map(|v| (k, v))).try_collect()?;
let explainables = explainables_proto
.ok_or::<ConnectionError>(ConnectionError::MissingResponseField("explainables").into())?;
Ok(Self { map, explainables: Explainables::from_proto(explainables) })
}
}
Expand Down Expand Up @@ -379,22 +377,16 @@ impl FromProto<ExplainablesProto> for Explainables {
attributes: attributes_proto,
ownerships: ownerships_proto,
} = proto;
let mut relations = HashMap::with_capacity(relations_proto.len());
for (k, v) in relations_proto {
relations.insert(k, Explainable::from_proto(v));
}
let mut attributes = HashMap::with_capacity(attributes_proto.len());
for (k, v) in attributes_proto {
attributes.insert(k, Explainable::from_proto(v));
}
let relations = relations_proto.into_iter().map(|(k, v)| (k, Explainable::from_proto(v))).collect();
let attributes = attributes_proto.into_iter().map(|(k, v)| (k, Explainable::from_proto(v))).collect();
let mut ownerships = HashMap::new();
for (k1, owned) in ownerships_proto {
for (k2, v) in owned.owned {
ownerships.insert((k1.clone(), k2), Explainable::from_proto(v));
}
}

Self::new(relations, attributes, ownerships)
Self { relations, attributes, ownerships }
}
}

Expand All @@ -410,7 +402,7 @@ impl TryFromProto<ExplanationProto> for Explanation {
let ExplanationProto { rule, conclusion, condition, var_mapping } = proto;
let mut variable_mapping = HashMap::with_capacity(var_mapping.len());
for (k, v) in var_mapping {
variable_mapping.insert(k, v.vars.clone());
variable_mapping.insert(k, v.vars);
}
dmikhalin marked this conversation as resolved.
Show resolved Hide resolved

Ok(Self {
Expand Down
7 changes: 3 additions & 4 deletions src/connection/network/proto/logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@ use crate::{common::Result, error::ConnectionError, logic::Rule};
impl TryFromProto<RuleProto> for Rule {
fn try_from_proto(proto: RuleProto) -> Result<Self> {
let RuleProto { label: label_proto, when: when_proto, then: then_proto } = proto;
let when = match parse_pattern(&when_proto) {
Ok(Pattern::Conjunction(conjunction)) => conjunction,
Ok(_) => return Err(ConnectionError::InvalidResponseField("when").into()),
Err(error) => return Err(error.into()),
let when = match parse_pattern(&when_proto)? {
Pattern::Conjunction(conjunction) => conjunction,
_ => return Err(ConnectionError::InvalidResponseField("when").into()),
};
let then = match parse_variable(&then_proto) {
Ok(Variable::Thing(thing)) => thing,
Expand Down
33 changes: 33 additions & 0 deletions tests/behaviour/typeql/reasoner/attribute_attachment/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (C) 2022 Vaticle
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

use serial_test::serial;

use crate::behaviour::Context;

#[tokio::test]
#[serial]
async fn test() {
// Bazel specific path: when running the test in bazel, the external data from
// @vaticle_typedb_behaviour is stored in a directory that is a sibling to
// the working directory.
assert!(Context::test("../vaticle_typedb_behaviour/typeql/reasoner/attribute-attachment.feature").await);
}
33 changes: 33 additions & 0 deletions tests/behaviour/typeql/reasoner/compound_queries/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (C) 2022 Vaticle
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

use serial_test::serial;

use crate::behaviour::Context;

#[tokio::test]
#[serial]
async fn test() {
// Bazel specific path: when running the test in bazel, the external data from
// @vaticle_typedb_behaviour is stored in a directory that is a sibling to
// the working directory.
assert!(Context::test("../vaticle_typedb_behaviour/typeql/reasoner/compound-queries.feature").await);
}
33 changes: 33 additions & 0 deletions tests/behaviour/typeql/reasoner/concept_inequality/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (C) 2022 Vaticle
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

use serial_test::serial;

use crate::behaviour::Context;

#[tokio::test]
#[serial]
async fn test() {
// Bazel specific path: when running the test in bazel, the external data from
// @vaticle_typedb_behaviour is stored in a directory that is a sibling to
// the working directory.
assert!(Context::test("../vaticle_typedb_behaviour/typeql/reasoner/concept-inequality.feature").await);
}
33 changes: 11 additions & 22 deletions tests/behaviour/typeql/reasoner/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,14 @@
* under the License.
*/

use serial_test::serial;

use crate::behaviour::Context;

#[tokio::test]
#[serial]
async fn test() {
// Bazel specific path: when running the test in bazel, the external data from
// @vaticle_typedb_behaviour is stored in a directory that is a sibling to
// the working directory.
assert!(Context::test("../vaticle_typedb_behaviour/typeql/reasoner/attribute-attachment.feature").await);
assert!(Context::test("../vaticle_typedb_behaviour/typeql/reasoner/compound-queries.feature").await);
assert!(Context::test("../vaticle_typedb_behaviour/typeql/reasoner/concept-inequality.feature").await);
assert!(Context::test("../vaticle_typedb_behaviour/typeql/reasoner/negation.feature").await);
assert!(Context::test("../vaticle_typedb_behaviour/typeql/reasoner/recursion.feature").await);
assert!(Context::test("../vaticle_typedb_behaviour/typeql/reasoner/relation-inference.feature").await);
assert!(Context::test("../vaticle_typedb_behaviour/typeql/reasoner/rule-interaction.feature").await);
assert!(Context::test("../vaticle_typedb_behaviour/typeql/reasoner/schema-queries.feature").await);
assert!(Context::test("../vaticle_typedb_behaviour/typeql/reasoner/type-hierarchy.feature").await);
assert!(Context::test("../vaticle_typedb_behaviour/typeql/reasoner/value-predicate.feature").await);
assert!(Context::test("../vaticle_typedb_behaviour/typeql/reasoner/variable-roles.feature").await);
}
mod attribute_attachment;
mod compound_queries;
mod concept_inequality;
mod negation;
mod recursion;
mod relation_inference;
mod rule_interaction;
mod schema_queries;
mod type_hierarchy;
mod value_predicate;
mod variable_roles;
33 changes: 33 additions & 0 deletions tests/behaviour/typeql/reasoner/negation/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (C) 2022 Vaticle
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

use serial_test::serial;

use crate::behaviour::Context;

#[tokio::test]
#[serial]
async fn test() {
// Bazel specific path: when running the test in bazel, the external data from
// @vaticle_typedb_behaviour is stored in a directory that is a sibling to
// the working directory.
assert!(Context::test("../vaticle_typedb_behaviour/typeql/reasoner/negation.feature").await);
}
33 changes: 33 additions & 0 deletions tests/behaviour/typeql/reasoner/recursion/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (C) 2022 Vaticle
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

use serial_test::serial;

use crate::behaviour::Context;

#[tokio::test]
#[serial]
async fn test() {
// Bazel specific path: when running the test in bazel, the external data from
// @vaticle_typedb_behaviour is stored in a directory that is a sibling to
// the working directory.
assert!(Context::test("../vaticle_typedb_behaviour/typeql/reasoner/recursion.feature").await);
}
33 changes: 33 additions & 0 deletions tests/behaviour/typeql/reasoner/relation_inference/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (C) 2022 Vaticle
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

use serial_test::serial;

use crate::behaviour::Context;

#[tokio::test]
#[serial]
async fn test() {
// Bazel specific path: when running the test in bazel, the external data from
// @vaticle_typedb_behaviour is stored in a directory that is a sibling to
// the working directory.
assert!(Context::test("../vaticle_typedb_behaviour/typeql/reasoner/relation-inference.feature").await);
}
33 changes: 33 additions & 0 deletions tests/behaviour/typeql/reasoner/rule_interaction/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (C) 2022 Vaticle
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

use serial_test::serial;

use crate::behaviour::Context;

#[tokio::test]
#[serial]
async fn test() {
// Bazel specific path: when running the test in bazel, the external data from
// @vaticle_typedb_behaviour is stored in a directory that is a sibling to
// the working directory.
assert!(Context::test("../vaticle_typedb_behaviour/typeql/reasoner/rule-interaction.feature").await);
}
33 changes: 33 additions & 0 deletions tests/behaviour/typeql/reasoner/schema_queries/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (C) 2022 Vaticle
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

use serial_test::serial;

use crate::behaviour::Context;

#[tokio::test]
#[serial]
async fn test() {
// Bazel specific path: when running the test in bazel, the external data from
// @vaticle_typedb_behaviour is stored in a directory that is a sibling to
// the working directory.
assert!(Context::test("../vaticle_typedb_behaviour/typeql/reasoner/schema-queries.feature").await);
}
Loading