-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathszengine.py
949 lines (714 loc) · 32.7 KB
/
szengine.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
#! /usr/bin/env python3
"""
szengine.py is the abstract class for all implementations of SzEngine.
"""
# pylint: disable=C0302
from abc import ABC, abstractmethod
from typing import List, Optional, Tuple
from .szengineflags import SzEngineFlags
from .szhelpers import construct_help
# Metadata
__all__ = ["SzEngine"]
__version__ = "0.0.1" # See https://www.python.org/dev/peps/pep-0396/
__date__ = "2023-10-30"
__updated__ = "2025-01-28"
# -------------------------------------------------------------------------
# Classes
# -------------------------------------------------------------------------
class SzEngine(ABC):
"""
Senzing engine module access library
"""
# -------------------------------------------------------------------------
# Interface definition
# -------------------------------------------------------------------------
# TODO Modify tests from "{}" to ""
@abstractmethod
def add_record(
self,
data_source_code: str,
record_id: str,
record_definition: str,
flags: int = 0,
) -> str:
"""
The `add_record` method adds a record into the Senzing repository.
Can be called as many times as desired and from multiple threads at the same time.
Args:
data_source_code (str): Identifies the provenance of the data.
record_id (str): The unique identifier within the records of the same data source.
record_definition (str): A JSON document containing the record to be added to the Senzing repository.
flags (int, optional): Flags used to control information returned. Defaults to 0.
Returns:
str: If flags are set to return the WITH_INFO response a JSON document containing the details, otherwise an empty string.
Raises:
.. collapse:: Example:
.. literalinclude:: ../../examples/szengine/add_record.py
:linenos:
:language: python
**Output:**
.. literalinclude:: ../../examples/szengine/add_record.txt
:linenos:
:language: json
"""
@abstractmethod
def close_export(self, export_handle: int) -> None:
"""
The `close_export` method closes the exported document created by `export_json_entity_report`.
It is part of the `export_json_entity_report`, `fetch_next`, `close_export`
lifecycle of a list of sized entities.
Args:
export_handle (int): A handle created by `export_json_entity_report` or `export_csv_entity_report`.
Raises:
.. collapse:: Example:
.. literalinclude:: ../../examples/szengine/export_json_fetch_close.py
:linenos:
:language: python
**Output:**
.. literalinclude:: ../../examples/szengine/export_json_fetch_close.txt
:linenos:
:language: json
"""
@abstractmethod
def count_redo_records(self) -> int:
"""
The `count_redo_records` method returns the number of records in need of redo-ing.
Returns:
int: The number of redo records in Senzing's redo queue.
Raises:
.. collapse:: Example:
.. literalinclude:: ../../examples/szengine/count_redo_records.py
:linenos:
:language: python
**Output:**
.. literalinclude:: ../../examples/szengine/count_redo_records.txt
:linenos:
:language: guess
"""
@abstractmethod
def delete_record(
self,
data_source_code: str,
record_id: str,
flags: int = 0,
) -> str:
"""
The `delete_record` method deletes a record from the Senzing repository.
Can be called as many times as desired and from multiple threads at the same time.
Args:
data_source_code (str): Identifies the provenance of the data.
record_id (str): The unique identifier within the records of the same data source.
flags (int, optional): Flags used to control information returned. Defaults to 0.
Returns:
str: If flags are set to return the WITH_INFO response a JSON document containing the details, otherwise an empty string.
Raises:
.. collapse:: Example:
.. literalinclude:: ../../examples/szengine/delete_record.py
:linenos:
**Output:**
.. literalinclude:: ../../examples/szengine/delete_record.txt
:linenos:
:language: json
"""
@abstractmethod
def export_csv_entity_report(
self,
csv_column_list: str,
flags: int = SzEngineFlags.SZ_EXPORT_DEFAULT_FLAGS,
) -> int:
"""
**Warning:** `export_csv_entity_report` is not recommended for large systems as it does not scale.
It is recommended larger systems implement real-time replication to a data warehouse.
The `export_csv_entity_report` method initializes a cursor over a document of exported entities.
It is part of the `export_csv_entity_report`, `fetch_next`, `close_export`
lifecycle of a list of entities to export.
Available CSV columns: RESOLVED_ENTITY_ID, RESOLVED_ENTITY_NAME, RELATED_ENTITY_ID, MATCH_LEVEL,
MATCH_LEVEL_CODE, MATCH_KEY, MATCH_KEY_DETAILS,I S_DISCLOSED, IS_AMBIGUOUS,
DATA_SOURCE, RECORD_ID, JSON_DATA, FIRST_SEEN_DT, LAST_SEEN_DT, UNMAPPED_DATA,
ERRULE_CODE, RELATED_ENTITY_NAME
Suggested CSV columns: RESOLVED_ENTITY_ID, RELATED_ENTITY_ID, RESOLVED_ENTITY_NAME, MATCH_LEVEL,
MATCH_KEY, DATA_SOURCE, RECORD_ID
Args:
csv_column_list (str): A comma-separated list of column names for the CSV export.
flags (int, optional): Flags used to control information returned. Defaults to SzEngineFlags.SZ_EXPORT_DEFAULT_FLAGS.
Returns:
int: A handle that identifies the document to be scrolled through using `fetch_next`.
Raises:
.. collapse:: Example:
.. literalinclude:: ../../examples/szengine/export_csv_fetch_close.py
:linenos:
:language: python
**Output:**
.. literalinclude:: ../../examples/szengine/export_csv_fetch_close.txt
:linenos:
:language: guess
"""
@abstractmethod
def export_json_entity_report(self, flags: int = SzEngineFlags.SZ_EXPORT_DEFAULT_FLAGS) -> int:
"""
**Warning:** `export_json_entity_report` is not recommended for large systems as it does not scale.
It is recommended larger systems implement real-time replication to a data warehouse.
The `export_json_entity_report` method initializes a cursor over a document of exported entities.
It is part of the `export_json_entity_report`, `fetch_next`, `close_export`
lifecycle of a list of entities to export.
Args:
flags (int, optional): Flags used to control information returned. Defaults to SzEngineFlags.SZ_EXPORT_DEFAULT_FLAGS.
Returns:
int: A handle that identifies the document to be scrolled through using `fetch_next`.
Raises:
.. collapse:: Example:
.. literalinclude:: ../../examples/szengine/export_json_fetch_close.py
:linenos:
:language: python
**Output:**
.. literalinclude:: ../../examples/szengine/export_json_fetch_close.txt
:linenos:
:language: json
"""
@abstractmethod
def fetch_next(self, export_handle: int) -> str:
"""
The `fetch_next` method is used to scroll through an exported document one entity at a time.
Successive calls of `fetch_next` will export successive rows of entity data until there is no more.
It is part of the `export_json_entity_report` or `export_json_entity_report`, `fetch_next`, `close_export`
lifecycle of a list of exported entities.
Args:
export_handle (int): A handle created by `export_json_entity_report` or `export_json_entity_report`.
Returns:
str: TODO:
Raises:
.. collapse:: Example:
.. literalinclude:: ../../examples/szengine/export_json_fetch_close.py
:linenos:
:language: python
**Output:**
.. literalinclude:: ../../examples/szengine/export_json_fetch_close.txt
:linenos:
:language: json
"""
# NOTE Included but not to be documented or examples, early adaptor feature, needs manual additions to config
@abstractmethod
def find_interesting_entities_by_entity_id(self, entity_id: int, flags: int = 0) -> str:
"""TODO: Document find_interesting_entities_by_entity_id()"""
# NOTE Included but not to be documented or examples, early adaptor feature, needs manual additions to config
@abstractmethod
def find_interesting_entities_by_record_id(self, data_source_code: str, record_id: str, flags: int = 0) -> str:
"""TODO: Document find_interesting_entities_by_record_id()"""
@abstractmethod
def find_network_by_entity_id(
self,
entity_ids: List[int],
max_degrees: int,
build_out_degrees: int,
build_out_max_entities: int,
flags: int = SzEngineFlags.SZ_FIND_NETWORK_DEFAULT_FLAGS,
) -> str:
"""
The `find_network_by_entity_id` method finds all entities surrounding a requested set of entities.
This includes the requested entities, paths between them, and relations to other nearby entities.
Returns a JSON document that identifies the path between the each set of search entities (if the path exists),
and the information for the entities in the path.
Args:
entity_ids (list(int)): The entity IDs to find the network between.
max_degrees (int): The maximum number of degrees in paths between search entities.
build_out_degrees (int): The number of degrees of relationships to show around each search entity.
build_out_max_entities (int): The maximum number of entities to return in the discovered network.
flags (int, optional): The maximum number of entities to return in the discovered network. Defaults to SzEngineFlags.SZ_FIND_PATH_DEFAULT_FLAGS.
Returns:
str: A JSON document.
Raises:
.. collapse:: Example:
.. literalinclude:: ../../examples/szengine/find_network_by_entity_id.py
:linenos:
:language: python
**Output:**
.. literalinclude:: ../../examples/szengine/find_network_by_entity_id.txt
:linenos:
:language: json
"""
@abstractmethod
def find_network_by_record_id(
self,
record_keys: List[Tuple[str, str]],
max_degrees: int,
build_out_degrees: int,
build_out_max_entities: int,
flags: int = SzEngineFlags.SZ_FIND_NETWORK_DEFAULT_FLAGS,
) -> str:
"""
The `find_network_by_record_id` method finds all entities surrounding a requested set of entities by their RECORD_ID values.
This includes the requested entities, paths between them, and relations to other nearby entities.
Returns a JSON document that identifies the path between the each set of search entities (if the path exists),
and the information for the entities in the path.
Args:
record_keys (list(tuple(str, str))): The data source codes and record IDs to find the network between.
max_degrees (int): The maximum number of degrees in paths between search entities.
build_out_degrees (int): The number of degrees of relationships to show around each search entity.
build_out_max_entities (int): The maximum number of entities to return in the discovered network.
flags (int, optional): Flags used to control information returned. Defaults to SzEngineFlags.SZ_FIND_PATH_DEFAULT_FLAGS.
Returns:
str: A JSON document.
Raises:
.. collapse:: Example:
.. literalinclude:: ../../examples/szengine/find_network_by_record_id.py
:linenos:
:language: python
**Output:**
.. literalinclude:: ../../examples/szengine/find_network_by_record_id.txt
:linenos:
:language: json
"""
@abstractmethod
def find_path_by_entity_id(
self,
start_entity_id: int,
end_entity_id: int,
max_degrees: int,
avoid_entity_ids: Optional[List[int]] = None,
required_data_sources: Optional[List[str]] = None,
flags: int = SzEngineFlags.SZ_FIND_PATH_DEFAULT_FLAGS,
) -> str:
"""
The `find_path_by_entity_id` method finds the most efficient relationship between two entities path based on the parameters
and returns a JSON document with an ENTITY_PATHS section that details the path between the entities.
The ENTITIES sections details information on the entities. Paths are found using known relationships with other entities.
Paths are found using known relationships with other entities.
Args:
start_entity_id (int): The entity ID for the starting entity of the search path.
end_entity_id (int): The entity ID for the ending entity of the search path.
max_degrees (int): The maximum number of degrees in paths between search entities.
avoid_entity_ids (list(int), optional): The entity IDs to avoid when finding a path.
required_data_sources (list(str), optional): The data source code(s) that must be in a path.
flags (int, optional): Flags used to control information returned. Defaults to SzEngineFlags.SZ_FIND_PATH_DEFAULT_FLAGS.
Returns:
str: A JSON document with an ENTITY_PATHS section that details the path between the entities.
Raises:
.. collapse:: Example:
.. literalinclude:: ../../examples/szengine/find_path_by_entity_id.py
:linenos:
:language: python
**Output:**
.. literalinclude:: ../../examples/szengine/find_path_by_entity_id.txt
:linenos:
:language: json
"""
@abstractmethod
def find_path_by_record_id(
self,
start_data_source_code: str,
start_record_id: str,
end_data_source_code: str,
end_record_id: str,
max_degrees: int,
avoid_record_keys: Optional[List[Tuple[str, str]]] = None,
required_data_sources: Optional[List[str]] = None,
flags: int = SzEngineFlags.SZ_FIND_PATH_DEFAULT_FLAGS,
) -> str:
"""
The `find_path_by_record_id` method finds the most efficient relationship between
two entities path based on the parameters by RECORD_ID values
and returns a JSON document with an ENTITY_PATHS section that details the path between the entities.
The ENTITIES sections details information on the entities.
Paths are found using known relationships with other entities.
The entities are identified by starting and ending records.
Args:
start_data_source_code (str): Identifies the provenance of the record for the starting entity of the search path.
start_record_id (str): The unique identifier within the records of the same data source for the starting entity of the search path.
end_data_source_code (str): Identifies the provenance of the record for the ending entity of the search path.
end_record_id (str): The unique identifier within the records of the same data source for the ending entity of the search path.
max_degrees (int): The maximum number of degrees in paths between search entities.
avoid_record_keys (list(tuple(str, str)), optional): The data source codes and record IDs to avoid when finding a path.
required_data_sources (list(str), optional): The data source code(s) that must be in a path.
flags (int, optional): Flags used to control information returned. Defaults to SzEngineFlags.SZ_FIND_PATH_DEFAULT_FLAGS.
Returns:
str: A JSON document.
Raises:
.. collapse:: Example:
.. literalinclude:: ../../examples/szengine/find_path_by_record_id.py
:linenos:
:language: python
**Output:**
.. literalinclude:: ../../examples/szengine/find_path_by_record_id.txt
:linenos:
:language: json
"""
@abstractmethod
def get_active_config_id(self) -> int:
"""
The `get_active_config_id` method returns the identifier of the currently active Senzing engine configuration.
Returns:
int: The identifier of the active Senzing Engine configuration.
Raises:
.. collapse:: Example:
.. literalinclude:: ../../examples/szengine/get_active_config_id.py
:linenos:
:language: python
**Output:**
.. literalinclude:: ../../examples/szengine/get_active_config_id.txt
:linenos:
:language: json
"""
@abstractmethod
def get_entity_by_entity_id(
self,
entity_id: int,
flags: int = SzEngineFlags.SZ_ENTITY_DEFAULT_FLAGS,
) -> str:
"""
The `get_entity_by_entity_id` method returns entity data based on the ID of a resolved identity.
Args:
entity_id (int): The unique identifier of an entity.
flags (int, optional): Flags used to control information returned. Defaults to SzEngineFlags.SZ_ENTITY_DEFAULT_FLAGS.
Returns:
str: A JSON document.
Raises:
.. collapse:: Example:
.. literalinclude:: ../../examples/szengine/get_entity_by_entity_id.py
:linenos:
:language: python
**Output:**
.. literalinclude:: ../../examples/szengine/get_entity_by_entity_id.txt
:linenos:
:language: json
"""
@abstractmethod
def get_entity_by_record_id(
self,
data_source_code: str,
record_id: str,
flags: int = SzEngineFlags.SZ_ENTITY_DEFAULT_FLAGS,
) -> str:
"""
The `get_entity_by_record_id` method returns entity data based on the ID of a record which is a member of the entity.
Args:
data_source_code (str): Identifies the provenance of the data.
record_id (str): The unique identifier within the records of the same data source.
flags (int, optional): Flags used to control information returned. Defaults to SzEngineFlags.SZ_ENTITY_DEFAULT_FLAGS.
Returns:
str: A JSON document.
Raises:
.. collapse:: Example:
.. literalinclude:: ../../examples/szengine/get_entity_by_record_id.py
:linenos:
:language: python
**Output:**
.. literalinclude:: ../../examples/szengine/get_entity_by_record_id.txt
:linenos:
:language: json
"""
@abstractmethod
def get_record(
self,
data_source_code: str,
record_id: str,
flags: int = SzEngineFlags.SZ_RECORD_DEFAULT_FLAGS,
) -> str:
"""
The `get_record` method returns a JSON document of a single record from the Senzing repository.
Can be called as many times as desired and from multiple threads at the same time.
Args:
data_source_code (str): Identifies the provenance of the data.
record_id (str): The unique identifier within the records of the same data source.
flags (int, optional): Flags used to control information returned. Defaults to SzEngineFlags.SZ_RECORD_DEFAULT_FLAGS.
Returns:
str: A JSON document of a single record.
Raises:
.. collapse:: Example:
.. literalinclude:: ../../examples/szengine/get_record.py
:linenos:
:language: python
**Output:**
.. literalinclude:: ../../examples/szengine/get_record.txt
:linenos:
:language: json
"""
@abstractmethod
def get_redo_record(self) -> str:
"""
The `get_redo_record` method returns the next internally queued redo record from the Senzing repository.
The `process_redo_record` method is called to process the redo record retrieved by `get_redo_record`.
Returns:
str: A JSON document.
Raises:
.. collapse:: Example:
.. literalinclude:: ../../examples/szengine/get_redo_record.py
:linenos:
:language: python
**Output:**
.. literalinclude:: ../../examples/szengine/get_redo_record.txt
:linenos:
:language: json
"""
@abstractmethod
def get_stats(self) -> str:
"""
The `get_stats` method retrieves workload statistics for the current process.
These statistics will automatically reset after retrieval.
Returns:
str: A JSON document.
Raises:
.. collapse:: Example:
.. literalinclude:: ../../examples/szengine/get_stats.py
:linenos:
:language: python
**Output:**
.. literalinclude:: ../../examples/szengine/get_stats.txt
:linenos:
:language: json
"""
@abstractmethod
def get_virtual_entity_by_record_id(
self,
record_keys: List[Tuple[str, str]],
flags: int = SzEngineFlags.SZ_VIRTUAL_ENTITY_DEFAULT_FLAGS,
) -> str:
"""
The `get_virtual_entity_by_record_id` method creates a view of a virtual entity
using a list of existing loaded records.
The virtual entity is composed of only those records and their features.
Entity resolution is not performed.
Args:
record_keys (list(tuple(str, str))): The data source codes and record IDs identifying records to create the virtual entity from.
flags (int, optional): Flags used to control information returned. Defaults to SzEngineFlags.SZ_HOW_ENTITY_DEFAULT_FLAGS.
Returns:
str: A JSON document.
Raises:
.. collapse:: Example:
.. literalinclude:: ../../examples/szengine/get_virtual_entity_by_record_id.py
:linenos:
:language: python
**Output:**
.. literalinclude:: ../../examples/szengine/get_virtual_entity_by_record_id.txt
:linenos:
:language: json
"""
@abstractmethod
def how_entity_by_entity_id(
self,
entity_id: int,
flags: int = SzEngineFlags.SZ_HOW_ENTITY_DEFAULT_FLAGS,
) -> str:
"""
The `how_entity_by_entity_id` method determines and details steps-by-step *how* records resolved to a single entity.
In most cases, *how* provides more detailed information than *why* as the resolution is detailed step-by-step.
Args:
entity_id (int): The unique identifier of an entity.
flags (int, optional): Flags used to control information returned. Defaults to SzEngineFlags.SZ_HOW_ENTITY_DEFAULT_FLAGS.
Returns:
str: A JSON document.
Raises:
.. collapse:: Example:
.. literalinclude:: ../../examples/szengine/how_entity_by_entity_id.py
:linenos:
:language: python
**Output:**
.. literalinclude:: ../../examples/szengine/how_entity_by_entity_id.txt
:linenos:
:language: json
"""
@abstractmethod
def preprocess_record(
self,
record_definition: str,
flags: int = SzEngineFlags.SZ_RECORD_DEFAULT_FLAGS,
) -> str:
"""
The `preprocess_record` method tests adding a record into the Senzing datastore.
Args:
record_definition (str): A JSON document containing the record to be tested.
flags (int, optional): Flags used to control information returned. Defaults to 0.
Returns:
str: A JSON document containing metadata as specified by the flags.
Raises:
.. collapse:: Example:
.. literalinclude:: ../../examples/szengine/preprocess_record.py
:linenos:
:language: python
**Output:**
.. literalinclude:: ../../examples/szengine/preprocess_record.txt
:linenos:
:language: json
"""
@abstractmethod
def prime_engine(self) -> None:
"""
The `prime_engine` method initializes high resource consumption components of Senzing
used in some functions. If this call is not made, these resources are initialized the
first time they are needed and can cause unusually long processing times the first time
a function is called that requires these resources.
Raises:
.. collapse:: Example:
.. literalinclude:: ../../examples/szengine/prime_engine.py
:linenos:
:language: python
"""
@abstractmethod
def process_redo_record(self, redo_record: str, flags: int = 0) -> str:
"""
The `process_redo_record` method is called to process the redo record retrieved by `get_redo_record`.
Args:
redo_record (str): A redo record retrieved from get_redo_record.
flags (int, optional): Flags used to control information returned. Defaults to 0.
Raises:
.. collapse:: Example:
.. literalinclude:: ../../examples/szengine/process_redo_record.py
:linenos:
:language: python
**Output:**
.. literalinclude:: ../../examples/szengine/process_redo_record.txt
:linenos:
:language: json
"""
@abstractmethod
def reevaluate_entity(self, entity_id: int, flags: int = 0) -> str:
"""
The `reevaluate_entity` method reevaluates the specified entity.
Args:
entity_id (int): The unique identifier of an entity.
flags (int, optional): Flags used to control information returned. Defaults to 0.
Raises:
.. collapse:: Example:
.. literalinclude:: ../../examples/szengine/reevaluate_entity.py
:linenos:
:language: python
**Output:**
.. literalinclude:: ../../examples/szengine/reevaluate_entity.txt
:linenos:
:language: json
"""
@abstractmethod
def reevaluate_record(self, data_source_code: str, record_id: str, flags: int = 0) -> str:
"""
The `reevaluate_record` method reevaluates a specific record.
Args:
data_source_code (str): Identifies the provenance of the data.
record_id (str): The unique identifier within the records of the same data source.
flags (int, optional): Flags used to control information returned. Defaults to 0.
Returns:
str: If flags are set to return the WITH_INFO response a JSON document containing the details, otherwise an empty string.
Raises:
.. collapse:: Example:
.. literalinclude:: ../../examples/szengine/reevaluate_record.py
:linenos:
:language: python
**Output:**
.. literalinclude:: ../../examples/szengine/reevaluate_record.txt
:linenos:
:language: json
"""
@abstractmethod
def search_by_attributes(
self,
attributes: str,
flags: int = SzEngineFlags.SZ_SEARCH_BY_ATTRIBUTES_DEFAULT_FLAGS,
search_profile: str = "",
) -> str:
"""
The `search_by_attributes` method retrieves entity data based on a user-specified set of entity attributes.
Args:
attributes (str): A JSON document with the attribute data to search for.
flags (int, optional): _description_. Defaults to SzEngineFlags.SZ_SEARCH_BY_ATTRIBUTES_DEFAULT_FLAGS.
search_profile (str): The name of a configured search profile. Defaults to SEARCH.
Returns:
str: A JSON document.
Raises:
.. collapse:: Example:
.. literalinclude:: ../../examples/szengine/search_by_attributes.py
:linenos:
:language: python
**Output:**
.. literalinclude:: ../../examples/szengine/search_by_attributes.txt
:linenos:
:language: json
"""
@abstractmethod
def why_entities(
self,
entity_id_1: int,
entity_id_2: int,
flags: int = SzEngineFlags.SZ_WHY_ENTITIES_DEFAULT_FLAGS,
) -> str:
"""
The `why_entities` method determines why entities did not resolve or why they do relate.
Args:
entity_id_1 (int): The entity ID for the starting entity of the search path.
entity_id_2 (int): The entity ID for the ending entity of the search path.
flags (int, optional): Flags used to control information returned. Defaults to SzEngineFlags.SZ_WHY_ENTITY_DEFAULT_FLAGS.
Returns:
str: A JSON document.
Raises:
.. collapse:: Example:
.. literalinclude:: ../../examples/szengine/why_entities.py
:linenos:
:language: python
**Output:**
.. literalinclude:: ../../examples/szengine/why_entities.txt
:linenos:
:language: json
"""
@abstractmethod
def why_record_in_entity(
self,
data_source_code: str,
record_id: str,
flags: int = SzEngineFlags.SZ_WHY_RECORDS_DEFAULT_FLAGS,
) -> str:
"""
The `why_record_in_entity` method determines why a record is included in an entity.
Args:
data_source_code (str): Identifies the provenance of the data.
record_id (str): The unique identifier within the records of the same data source.
flags (int, optional): Flags used to control information returned. Defaults to SzEngineFlags.SZ_WHY_ENTITY_DEFAULT_FLAGS.
Returns:
str: A JSON document.
Raises:
.. collapse:: Example:
.. literalinclude:: ../../examples/szengine/why_record_in_entity.py
:linenos:
:language: python
**Output:**
.. literalinclude:: ../../examples/szengine/why_record_in_entity.txt
:linenos:
:language: json
"""
@abstractmethod
def why_records(
self,
data_source_code_1: str,
record_id_1: str,
data_source_code_2: str,
record_id_2: str,
flags: int = SzEngineFlags.SZ_WHY_RECORDS_DEFAULT_FLAGS,
) -> str:
"""
The `why_records` determines if any two records can or cannot resolve together, or if they relate.
Args:
data_source_code_1 (str): Identifies the provenance of the data.
record_id_1 (str): The unique identifier within the records of the same data source.
data_source_code_2 (str): Identifies the provenance of the data.
record_id_2 (str): The unique identifier within the records of the same data source.
flags (int, optional): Flags used to control information returned. Defaults to SzEngineFlags.SZ_WHY_ENTITY_DEFAULT_FLAGS.
Returns:
str: A JSON document.
Raises:
.. collapse:: Example:
.. literalinclude:: ../../examples/szengine/why_records.py
:linenos:
:language: python
**Output:**
.. literalinclude:: ../../examples/szengine/why_records.txt
:linenos:
:language: json
"""
# -------------------------------------------------------------------------
# Convenience methods
# -------------------------------------------------------------------------
def help(self, method_name: str = "") -> str:
"""
Return the help for a particular message.
Args:
method_name (str): The name of the method. (e.g. "init"). If empty, a list of methods and descriptions is returned.
Returns:
str: The Help information about the requested method
"""
return construct_help(self, method_name=method_name)