implica 1.2.1__tar.gz → 1.2.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. {implica-1.2.1 → implica-1.2.2}/Cargo.lock +1 -1
  2. {implica-1.2.1 → implica-1.2.2}/Cargo.toml +1 -1
  3. {implica-1.2.1 → implica-1.2.2}/PKG-INFO +1 -1
  4. {implica-1.2.1 → implica-1.2.2}/src/graph/base.rs +68 -17
  5. {implica-1.2.1 → implica-1.2.2}/src/graph/create.rs +4 -9
  6. {implica-1.2.1 → implica-1.2.2}/tests/test_create.py +3 -3
  7. {implica-1.2.1 → implica-1.2.2}/.githooks/README.md +0 -0
  8. {implica-1.2.1 → implica-1.2.2}/.githooks/pre-commit +0 -0
  9. {implica-1.2.1 → implica-1.2.2}/.github/workflows/CI.yml +0 -0
  10. {implica-1.2.1 → implica-1.2.2}/.github/workflows/test.yml +0 -0
  11. {implica-1.2.1 → implica-1.2.2}/.gitignore +0 -0
  12. {implica-1.2.1 → implica-1.2.2}/LICENSE +0 -0
  13. {implica-1.2.1 → implica-1.2.2}/README.md +0 -0
  14. {implica-1.2.1 → implica-1.2.2}/pyproject.toml +0 -0
  15. {implica-1.2.1 → implica-1.2.2}/python/implica/__init__.py +0 -0
  16. {implica-1.2.1 → implica-1.2.2}/python/implica/__init__.pyi +0 -0
  17. {implica-1.2.1 → implica-1.2.2}/python/implica/py.typed +0 -0
  18. {implica-1.2.1 → implica-1.2.2}/setup-hooks.sh +0 -0
  19. {implica-1.2.1 → implica-1.2.2}/src/constants.rs +0 -0
  20. {implica-1.2.1 → implica-1.2.2}/src/errors.rs +0 -0
  21. {implica-1.2.1 → implica-1.2.2}/src/graph/matches/edge.rs +0 -0
  22. {implica-1.2.1 → implica-1.2.2}/src/graph/matches/node.rs +0 -0
  23. {implica-1.2.1 → implica-1.2.2}/src/graph/matches/path.rs +0 -0
  24. {implica-1.2.1 → implica-1.2.2}/src/graph/matches/properties.rs +0 -0
  25. {implica-1.2.1 → implica-1.2.2}/src/graph/matches/term_schema.rs +0 -0
  26. {implica-1.2.1 → implica-1.2.2}/src/graph/matches/type_schema.rs +0 -0
  27. {implica-1.2.1 → implica-1.2.2}/src/graph/mod.rs +0 -0
  28. {implica-1.2.1 → implica-1.2.2}/src/lib.rs +0 -0
  29. {implica-1.2.1 → implica-1.2.2}/src/macros/ctx.rs +0 -0
  30. {implica-1.2.1 → implica-1.2.2}/src/macros/mod.rs +0 -0
  31. {implica-1.2.1 → implica-1.2.2}/src/matches.rs +0 -0
  32. {implica-1.2.1 → implica-1.2.2}/src/patterns/edge.rs +0 -0
  33. {implica-1.2.1 → implica-1.2.2}/src/patterns/mod.rs +0 -0
  34. {implica-1.2.1 → implica-1.2.2}/src/patterns/node.rs +0 -0
  35. {implica-1.2.1 → implica-1.2.2}/src/patterns/parsing.rs +0 -0
  36. {implica-1.2.1 → implica-1.2.2}/src/patterns/path.rs +0 -0
  37. {implica-1.2.1 → implica-1.2.2}/src/patterns/term_schema.rs +0 -0
  38. {implica-1.2.1 → implica-1.2.2}/src/patterns/type_schema.rs +0 -0
  39. {implica-1.2.1 → implica-1.2.2}/src/properties.rs +0 -0
  40. {implica-1.2.1 → implica-1.2.2}/src/query/base.rs +0 -0
  41. {implica-1.2.1 → implica-1.2.2}/src/query/mod.rs +0 -0
  42. {implica-1.2.1 → implica-1.2.2}/src/query/references/base.rs +0 -0
  43. {implica-1.2.1 → implica-1.2.2}/src/query/references/edge.rs +0 -0
  44. {implica-1.2.1 → implica-1.2.2}/src/query/references/mod.rs +0 -0
  45. {implica-1.2.1 → implica-1.2.2}/src/query/references/node.rs +0 -0
  46. {implica-1.2.1 → implica-1.2.2}/src/query/references/term.rs +0 -0
  47. {implica-1.2.1 → implica-1.2.2}/src/query/references/type.rs +0 -0
  48. {implica-1.2.1 → implica-1.2.2}/src/typing/mod.rs +0 -0
  49. {implica-1.2.1 → implica-1.2.2}/src/typing/term.rs +0 -0
  50. {implica-1.2.1 → implica-1.2.2}/src/typing/types.rs +0 -0
  51. {implica-1.2.1 → implica-1.2.2}/src/utils/cmp.rs +0 -0
  52. {implica-1.2.1 → implica-1.2.2}/src/utils/data_queue.rs +0 -0
  53. {implica-1.2.1 → implica-1.2.2}/src/utils/eval.rs +0 -0
  54. {implica-1.2.1 → implica-1.2.2}/src/utils/hex_to_uid.rs +0 -0
  55. {implica-1.2.1 → implica-1.2.2}/src/utils/mod.rs +0 -0
  56. {implica-1.2.1 → implica-1.2.2}/src/utils/validation.rs +0 -0
  57. {implica-1.2.1 → implica-1.2.2}/tests/conftest.py +0 -0
  58. {implica-1.2.1 → implica-1.2.2}/tests/test_graph_set_properties.py +0 -0
  59. {implica-1.2.1 → implica-1.2.2}/tests/test_match.py +0 -0
  60. {implica-1.2.1 → implica-1.2.2}/tests/test_match_create.py +0 -0
  61. {implica-1.2.1 → implica-1.2.2}/tests/test_set.py +0 -0
@@ -254,7 +254,7 @@ checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
254
254
 
255
255
  [[package]]
256
256
  name = "implica"
257
- version = "1.2.1"
257
+ version = "1.2.2"
258
258
  dependencies = [
259
259
  "dashmap",
260
260
  "error-stack",
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "implica"
3
- version = "1.2.1"
3
+ version = "1.2.2"
4
4
  edition = "2021"
5
5
  readme = "README.md"
6
6
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: implica
3
- Version: 1.2.1
3
+ Version: 1.2.2
4
4
  Classifier: Programming Language :: Rust
5
5
  Classifier: Programming Language :: Python :: Implementation :: CPython
6
6
  Classifier: Programming Language :: Python :: Implementation :: PyPy
@@ -122,33 +122,84 @@ impl Graph {
122
122
  term: Option<Term>,
123
123
  properties: PropertyMap,
124
124
  ) -> ImplicaResult<Uid> {
125
+ let mut expand = false;
125
126
  let type_uid = self.insert_type(&r#type);
126
127
 
127
128
  if let Some(term) = term {
128
- let term_uid = self.insert_term(&term);
129
+ if !self.term_index.contains_key(&type_uid) {
130
+ // TODO: term comparison?
131
+ let term_uid = self.insert_term(&term);
129
132
 
130
- if type_uid != term_uid {
131
- return Err(ImplicaError::InvalidTerm {
132
- reason: "term provided is of a different type than the type provided"
133
- .to_string(),
133
+ if type_uid != term_uid {
134
+ return Err(ImplicaError::InvalidTerm {
135
+ reason: "term provided is of a different type than the type provided"
136
+ .to_string(),
137
+ }
138
+ .into());
134
139
  }
135
- .into());
140
+
141
+ if let Some(arr) = term.r#type().as_arrow() {
142
+ let left_type = self.insert_type(&arr.left);
143
+ let right_type = self.insert_type(&arr.right);
144
+
145
+ if !self.nodes.contains_key(&left_type) {
146
+ let term = self.infer_term(&left_type)?;
147
+ self.add_node(arr.left.as_ref().clone(), term, PropertyMap::default())?;
148
+ }
149
+
150
+ if !self.nodes.contains_key(&right_type) {
151
+ let term = self.infer_term(&right_type)?;
152
+ self.add_node(arr.right.as_ref().clone(), term, PropertyMap::default())?;
153
+ }
154
+
155
+ self.add_edge(term, PropertyMap::default())?;
156
+ }
157
+
158
+ expand = true;
136
159
  }
137
160
  }
138
161
 
139
- if self.nodes.contains_key(&type_uid) {
140
- return Err(ImplicaError::NodeAlreadyExists {
141
- uid: type_uid,
142
- context: Some(ctx!("graph - add node")),
143
- }
144
- .into());
162
+ if !self.nodes.contains_key(&type_uid) {
163
+ self.nodes.insert(type_uid, properties);
164
+ self.start_to_edge_index
165
+ .insert(type_uid, Arc::new(DashSet::new()));
166
+ self.end_to_edge_index
167
+ .insert(type_uid, Arc::new(DashSet::new()));
145
168
  }
146
169
 
147
- self.nodes.insert(type_uid, properties);
148
- self.start_to_edge_index
149
- .insert(type_uid, Arc::new(DashSet::new()));
150
- self.end_to_edge_index
151
- .insert(type_uid, Arc::new(DashSet::new()));
170
+ if expand {
171
+ if let Some(entry) = self.start_to_edge_index.get(&type_uid) {
172
+ let right_edges = entry.value().clone();
173
+
174
+ right_edges.par_iter().try_for_each(|row| -> ImplicaResult<()> {
175
+ let edge = *row.key();
176
+
177
+ if !self.term_index.contains_key(&edge.1) {
178
+ let original_term = self.term_from_uid(&type_uid).attach(ctx!("graph - add node"))?;
179
+ let edge_term = {
180
+ let edge_type = match self.edge_to_type_index.get(&edge) {
181
+ Some(t) => *t,
182
+ None => return Err(ImplicaError::IndexCorruption { message: "edge exists in EdgeIndex without appearing in EdgeToTypeIndex".to_string(), context: Some("graph - add node".to_string()) }.into())
183
+ };
184
+
185
+ self.term_from_uid(&edge_type).attach(ctx!("graph - add node"))
186
+ }?;
187
+
188
+ let new_term = edge_term.apply(&original_term).attach(ctx!("graph - add node"))?;
189
+
190
+ self.add_node(new_term.r#type().as_ref().clone(), Some(new_term), PropertyMap::default()).attach(ctx!("graph - add node"))?;
191
+ }
192
+
193
+ Ok(())
194
+ })?;
195
+ } else {
196
+ return Err(ImplicaError::IndexCorruption {
197
+ message: "node exists without row in the StartToEdgeIndex".to_string(),
198
+ context: Some("graph - add node".to_string()),
199
+ }
200
+ .into());
201
+ }
202
+ }
152
203
 
153
204
  Ok(type_uid)
154
205
  }
@@ -278,7 +278,7 @@ impl Graph {
278
278
 
279
279
  if let Some(r#type) = node_data.r#type.as_ref().or(type_update.as_ref()) {
280
280
 
281
- let type_uid = self.insert_type(r#type);
281
+ let type_uid = self.insert_type(r#type);
282
282
 
283
283
  term_update = match self
284
284
  .infer_term(&type_uid){
@@ -797,10 +797,8 @@ impl Graph {
797
797
 
798
798
  prev_uid = match self.add_node(nd.r#type.unwrap(), nd.term, nd.properties) {
799
799
  Ok(uid) => uid,
800
- Err(e) => {match e.current_context() {
801
- ImplicaError::NodeAlreadyExists { uid, context: _ } => *uid,
802
- _ => return ControlFlow::Break(e.attach(ctx!("graph - create path")))
803
- }}
800
+ Err(e) => return ControlFlow::Break(e.attach(ctx!("graph - create path")))
801
+
804
802
  };
805
803
 
806
804
  match new_match.insert(node_var, MatchElement::Node(prev_uid)) {
@@ -812,10 +810,7 @@ impl Graph {
812
810
  match self.add_node(nd.r#type.unwrap(), nd.term, nd.properties) {
813
811
  Ok(_) => (),
814
812
  Err(e) => {
815
- match e.current_context() {
816
- ImplicaError::NodeAlreadyExists { .. } => (),
817
- _ => return ControlFlow::Break(e.attach(ctx!("graph - create path")))
818
- }
813
+ return ControlFlow::Break(e.attach(ctx!("graph - create path")))
819
814
  }
820
815
  }
821
816
  }
@@ -84,9 +84,9 @@ class TestCreateNodeQuery:
84
84
 
85
85
  graph.query().create("(::@f(C, D))").execute()
86
86
  nodes = graph.nodes()
87
- assert len(nodes) == 1
88
- assert isinstance(nodes[0], implica.Node)
89
- assert str(nodes[0]) == "Node((C -> D):f {})"
87
+ assert len(nodes) == 3
88
+ assert all([isinstance(n, implica.Node) for n in nodes])
89
+ assert {str(n) for n in nodes} == {"Node((C -> D):f {})", "Node(C: {})", "Node(D: {})"}
90
90
 
91
91
  def test_create_more_than_one_node_in_different_queries(self):
92
92
  graph = implica.Graph()
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes