|
14 | 14 | # limitations under the License.
|
15 | 15 | from unittest.mock import MagicMock, call
|
16 | 16 |
|
17 |
| -import neo4j |
18 | 17 | import pytest
|
19 | 18 | from neo4j_graphrag.experimental.components.resolver import (
|
| 19 | + FuzzyMatchResolver, |
20 | 20 | SinglePropertyExactMatchResolver,
|
21 | 21 | SpaCySemanticMatchResolver,
|
22 | 22 | )
|
23 | 23 | from neo4j_graphrag.experimental.components.types import ResolutionStats
|
24 | 24 |
|
| 25 | +import neo4j |
| 26 | + |
25 | 27 |
|
26 | 28 | @pytest.mark.asyncio
|
27 | 29 | async def test_simple_resolver(driver: MagicMock) -> None:
|
@@ -160,3 +162,78 @@ async def test_spacy_resolver_match_on_multiple_text_properties(
|
160 | 162 | assert res.number_of_created_nodes == 1
|
161 | 163 |
|
162 | 164 | assert driver.execute_query.call_count == 2
|
| 165 | + |
| 166 | + |
| 167 | +@pytest.mark.asyncio |
| 168 | +async def test_fuzzy_match_resolver_no_merge(driver: MagicMock) -> None: |
| 169 | + driver.execute_query.side_effect = [ |
| 170 | + ( |
| 171 | + [ |
| 172 | + neo4j.Record( |
| 173 | + { |
| 174 | + "lab": "Person", |
| 175 | + "labelCluster": [ |
| 176 | + {"id": 1, "name": "Alice"}, |
| 177 | + {"id": 2, "name": "Bob"}, |
| 178 | + ], |
| 179 | + } |
| 180 | + ) |
| 181 | + ], |
| 182 | + None, |
| 183 | + None, |
| 184 | + ) |
| 185 | + ] |
| 186 | + |
| 187 | + resolver = FuzzyMatchResolver(driver=driver) |
| 188 | + |
| 189 | + res = await resolver.run() |
| 190 | + assert isinstance(res, ResolutionStats) |
| 191 | + assert res.number_of_nodes_to_resolve == 2 |
| 192 | + assert res.number_of_created_nodes == 0 |
| 193 | + |
| 194 | + assert driver.execute_query.call_count == 1 |
| 195 | + |
| 196 | + |
| 197 | +@pytest.mark.asyncio |
| 198 | +async def test_fuzzy_match_resolver_multiple_properties(driver: MagicMock) -> None: |
| 199 | + driver.execute_query.side_effect = [ |
| 200 | + ( |
| 201 | + [ |
| 202 | + neo4j.Record( |
| 203 | + { |
| 204 | + "lab": "Person", |
| 205 | + "labelCluster": [ |
| 206 | + {"id": 10, "name": "John Smith", "ssn": "123-45-6789"}, |
| 207 | + {"id": 11, "name": "Jon Smith", "ssn": "123-45-6789"}, |
| 208 | + ], |
| 209 | + } |
| 210 | + ) |
| 211 | + ], |
| 212 | + None, |
| 213 | + None, |
| 214 | + ), |
| 215 | + ( |
| 216 | + [neo4j.Record({"id(node)": 10})], |
| 217 | + None, |
| 218 | + None, |
| 219 | + ), |
| 220 | + ] |
| 221 | + |
| 222 | + resolver = FuzzyMatchResolver(driver=driver, resolve_properties=["name", "ssn"]) |
| 223 | + |
| 224 | + res = await resolver.run() |
| 225 | + assert isinstance(res, ResolutionStats) |
| 226 | + |
| 227 | + assert res.number_of_nodes_to_resolve == 2 |
| 228 | + assert res.number_of_created_nodes == 1 |
| 229 | + |
| 230 | + assert driver.execute_query.call_count == 2 |
| 231 | + |
| 232 | + |
| 233 | +@pytest.mark.asyncio |
| 234 | +async def test_fuzzy_match_resolver_normalization(driver: MagicMock) -> None: |
| 235 | + # instantiate with a dummy driver |
| 236 | + resolver = FuzzyMatchResolver(driver=driver) |
| 237 | + |
| 238 | + sim = resolver.compute_similarity(" ALICE ", "alice!") |
| 239 | + assert sim == 1 |
0 commit comments