Senzing C++ SDK
C++ SDK for Senzing v4, patterned after the official C# SDK
Loading...
Searching...
No Matches
SzCoreEngine.hpp
Go to the documentation of this file.
1// SzCoreEngine.hpp -- native-backed SzEngine implementation.
2//
3// Ports core/SzCoreEngine.cs. Owns the native engine (`Sz_*`) module,
4// initialized with the owning environment's settings. Constructed and
5// lifecycle-managed by SzCoreEnvironment (obtain via GetEngine).
6//
7// Flag handling mirrors the C# SDK: the SzWithInfo bit is an SDK-level flag and
8// is masked out of the value passed to the native helpers (SdkFlagMask). Every
9// SDK method always passes flags, so the highest native variant carrying all
10// args (the `_V2`/`_V3`/`*WithInfo_helper` forms) is the one called.
11#ifndef SENZING_SDK_CORE_SZCOREENGINE_HPP
12#define SENZING_SDK_CORE_SZCOREENGINE_HPP
13
14#include <cstdint>
15#include <mutex>
16#include <set>
17#include <string>
18#include <utility>
19
21
22namespace senzing::sdk::core {
23
24class SzCoreEnvironment;
25
27class SzCoreEngine final : public SzEngine {
28public:
32 ~SzCoreEngine() override = default;
33
34 SzCoreEngine(const SzCoreEngine&) = delete;
36
37 void PrimeEngine() override;
38 std::string GetStats() override;
39
40 std::string AddRecord(const std::string& dataSourceCode,
41 const std::string& recordID,
42 const std::string& recordDefinition,
43 SzFlags flags = SzAddRecordDefaultFlags) override;
44 std::string GetRecordPreview(
45 const std::string& recordDefinition,
46 SzFlags flags = SzRecordPreviewDefaultFlags) override;
47 std::string DeleteRecord(const std::string& dataSourceCode,
48 const std::string& recordID,
49 SzFlags flags = SzDeleteRecordDefaultFlags) override;
50 std::string ReevaluateRecord(
51 const std::string& dataSourceCode, const std::string& recordID,
52 SzFlags flags = SzReevaluateRecordDefaultFlags) override;
53 std::string ReevaluateEntity(
54 int64_t entityID,
55 SzFlags flags = SzReevaluateEntityDefaultFlags) override;
56
57 std::string SearchByAttributes(
58 const std::string& attributes, const std::string& searchProfile,
59 SzFlags flags = SzSearchByAttributesDefaultFlags) override;
60 std::string SearchByAttributes(
61 const std::string& attributes,
62 SzFlags flags = SzSearchByAttributesDefaultFlags) override;
63 std::string WhySearch(const std::string& attributes, int64_t entityID,
64 const std::string& searchProfile = "",
65 SzFlags flags = SzWhySearchDefaultFlags) override;
66
67 std::string GetEntity(int64_t entityID,
68 SzFlags flags = SzEntityDefaultFlags) override;
69 std::string GetEntity(const std::string& dataSourceCode,
70 const std::string& recordID,
71 SzFlags flags = SzEntityDefaultFlags) override;
72 std::string GetRecord(const std::string& dataSourceCode,
73 const std::string& recordID,
74 SzFlags flags = SzRecordDefaultFlags) override;
75
77 int64_t entityID,
78 SzFlags flags = SzFindInterestingEntitiesDefaultFlags) override;
80 const std::string& dataSourceCode, const std::string& recordID,
81 SzFlags flags = SzFindInterestingEntitiesDefaultFlags) override;
82
83 std::string FindPath(
84 int64_t startEntityID, int64_t endEntityID, int32_t maxDegrees,
85 const std::set<int64_t>& avoidEntityIDs = {},
86 const std::set<std::string>& requiredDataSources = {},
87 SzFlags flags = SzFindPathDefaultFlags) override;
88 std::string FindPath(
89 const std::string& startDataSourceCode, const std::string& startRecordID,
90 const std::string& endDataSourceCode, const std::string& endRecordID,
91 int32_t maxDegrees,
92 const std::set<std::pair<std::string, std::string>>& avoidRecordKeys = {},
93 const std::set<std::string>& requiredDataSources = {},
94 SzFlags flags = SzFindPathDefaultFlags) override;
95
96 std::string FindNetwork(
97 const std::set<int64_t>& entityIDs, int32_t maxDegrees,
98 int32_t buildOutDegrees, int32_t buildOutMaxEntities,
99 SzFlags flags = SzFindNetworkDefaultFlags) override;
100 std::string FindNetwork(
101 const std::set<std::pair<std::string, std::string>>& recordKeys,
102 int32_t maxDegrees, int32_t buildOutDegrees, int32_t buildOutMaxEntities,
103 SzFlags flags = SzFindNetworkDefaultFlags) override;
104
105 std::string WhyRecordInEntity(
106 const std::string& dataSourceCode, const std::string& recordID,
107 SzFlags flags = SzWhyRecordInEntityDefaultFlags) override;
108 std::string WhyRecords(const std::string& dataSourceCode1,
109 const std::string& recordID1,
110 const std::string& dataSourceCode2,
111 const std::string& recordID2,
112 SzFlags flags = SzWhyRecordsDefaultFlags) override;
113 std::string WhyEntities(int64_t entityID1, int64_t entityID2,
114 SzFlags flags = SzWhyEntitiesDefaultFlags) override;
115 std::string HowEntity(int64_t entityID,
116 SzFlags flags = SzHowEntityDefaultFlags) override;
117 std::string GetVirtualEntity(
118 const std::set<std::pair<std::string, std::string>>& recordKeys,
119 SzFlags flags = SzVirtualEntityDefaultFlags) override;
120
122 SzFlags flags = SzExportDefaultFlags) override;
124 const std::string& csvColumnList,
125 SzFlags flags = SzExportDefaultFlags) override;
126 std::string FetchNext(SzExportHandle exportHandle) override;
127 void CloseExportReport(SzExportHandle exportHandle) override;
128
129 std::string ProcessRedoRecord(const std::string& redoRecord,
130 SzFlags flags = SzRedoDefaultFlags) override;
131 std::string GetRedoRecord() override;
132 int64_t CountRedoRecords() override;
133
136 void Destroy();
137
139 [[nodiscard]] bool IsDestroyed();
140
141 // ---- Internal JSON encode helpers (mirror C# SzCoreEngine encoders) ----
142 // Exposed for unit verification; build the arg JSON the native helpers want.
143
145 static std::string EncodeEntityIDs(const std::set<int64_t>& entityIDs);
146
149 static std::string EncodeRecordKeys(
150 const std::set<std::pair<std::string, std::string>>& recordKeys);
151
153 static std::string EncodeDataSources(
154 const std::set<std::string>& dataSources);
155
156private:
157 SzCoreEnvironment& env_;
158 std::mutex monitor_;
159 bool destroyed_{false};
160};
161
162} // namespace senzing::sdk::core
163
164#endif // SENZING_SDK_CORE_SZCOREENGINE_HPP
The core Senzing entity-resolution engine.
Definition SzEngine.hpp:28
Core implementation of SzEngine backed by the native Sz_* module.
Definition SzCoreEngine.hpp:27
SzCoreEngine(const SzCoreEngine &)=delete
std::string HowEntity(int64_t entityID, SzFlags flags=SzHowEntityDefaultFlags) override
std::string WhySearch(const std::string &attributes, int64_t entityID, const std::string &searchProfile="", SzFlags flags=SzWhySearchDefaultFlags) override
static std::string EncodeEntityIDs(const std::set< int64_t > &entityIDs)
Encodes a set of entity IDs as {"ENTITIES":[{"ENTITY_ID":n},...]}.
SzCoreEngine(SzCoreEnvironment &env)
Constructs and initializes the native engine module using the owning environment's settings.
std::string ProcessRedoRecord(const std::string &redoRecord, SzFlags flags=SzRedoDefaultFlags) override
std::string WhyEntities(int64_t entityID1, int64_t entityID2, SzFlags flags=SzWhyEntitiesDefaultFlags) override
std::string FindInterestingEntities(const std::string &dataSourceCode, const std::string &recordID, SzFlags flags=SzFindInterestingEntitiesDefaultFlags) override
void CloseExportReport(SzExportHandle exportHandle) override
int64_t CountRedoRecords() override
std::string FindNetwork(const std::set< int64_t > &entityIDs, int32_t maxDegrees, int32_t buildOutDegrees, int32_t buildOutMaxEntities, SzFlags flags=SzFindNetworkDefaultFlags) override
std::string GetStats() override
Returns JSON workload statistics for this engine instance.
std::string ReevaluateEntity(int64_t entityID, SzFlags flags=SzReevaluateEntityDefaultFlags) override
std::string DeleteRecord(const std::string &dataSourceCode, const std::string &recordID, SzFlags flags=SzDeleteRecordDefaultFlags) override
std::string SearchByAttributes(const std::string &attributes, const std::string &searchProfile, SzFlags flags=SzSearchByAttributesDefaultFlags) override
std::string GetRecordPreview(const std::string &recordDefinition, SzFlags flags=SzRecordPreviewDefaultFlags) override
static std::string EncodeRecordKeys(const std::set< std::pair< std::string, std::string > > &recordKeys)
Encodes a set of (dataSource, recordID) keys as {"RECORDS":[{"DATA_SOURCE":..,"RECORD_ID":....
std::string FindPath(int64_t startEntityID, int64_t endEntityID, int32_t maxDegrees, const std::set< int64_t > &avoidEntityIDs={}, const std::set< std::string > &requiredDataSources={}, SzFlags flags=SzFindPathDefaultFlags) override
std::string ReevaluateRecord(const std::string &dataSourceCode, const std::string &recordID, SzFlags flags=SzReevaluateRecordDefaultFlags) override
SzExportHandle ExportJsonEntityReport(SzFlags flags=SzExportDefaultFlags) override
std::string SearchByAttributes(const std::string &attributes, SzFlags flags=SzSearchByAttributesDefaultFlags) override
bool IsDestroyed()
True once the native module has been destroyed.
void PrimeEngine() override
Pre-loads engine resources to reduce first-call latency.
std::string GetEntity(const std::string &dataSourceCode, const std::string &recordID, SzFlags flags=SzEntityDefaultFlags) override
static std::string EncodeDataSources(const std::set< std::string > &dataSources)
Encodes a set of data source codes as {"DATA_SOURCES":[..]}.
void Destroy()
Destroys the native engine module.
std::string AddRecord(const std::string &dataSourceCode, const std::string &recordID, const std::string &recordDefinition, SzFlags flags=SzAddRecordDefaultFlags) override
std::string GetVirtualEntity(const std::set< std::pair< std::string, std::string > > &recordKeys, SzFlags flags=SzVirtualEntityDefaultFlags) override
std::string FetchNext(SzExportHandle exportHandle) override
~SzCoreEngine() override=default
std::string FindInterestingEntities(int64_t entityID, SzFlags flags=SzFindInterestingEntitiesDefaultFlags) override
std::string GetRedoRecord() override
SzExportHandle ExportCsvEntityReport(const std::string &csvColumnList, SzFlags flags=SzExportDefaultFlags) override
std::string WhyRecords(const std::string &dataSourceCode1, const std::string &recordID1, const std::string &dataSourceCode2, const std::string &recordID2, SzFlags flags=SzWhyRecordsDefaultFlags) override
SzCoreEngine & operator=(const SzCoreEngine &)=delete
std::string WhyRecordInEntity(const std::string &dataSourceCode, const std::string &recordID, SzFlags flags=SzWhyRecordInEntityDefaultFlags) override
std::string GetRecord(const std::string &dataSourceCode, const std::string &recordID, SzFlags flags=SzRecordDefaultFlags) override
std::string FindPath(const std::string &startDataSourceCode, const std::string &startRecordID, const std::string &endDataSourceCode, const std::string &endRecordID, int32_t maxDegrees, const std::set< std::pair< std::string, std::string > > &avoidRecordKeys={}, const std::set< std::string > &requiredDataSources={}, SzFlags flags=SzFindPathDefaultFlags) override
std::string FindNetwork(const std::set< std::pair< std::string, std::string > > &recordKeys, int32_t maxDegrees, int32_t buildOutDegrees, int32_t buildOutMaxEntities, SzFlags flags=SzFindNetworkDefaultFlags) override
std::string GetEntity(int64_t entityID, SzFlags flags=SzEntityDefaultFlags) override
Core implementation of SzEnvironment backed by the native libSz modules.
Definition SzCoreEnvironment.hpp:29
Definition SzCoreConfig.hpp:20
std::uintptr_t SzExportHandle
Opaque export-report handle, mirroring the C# IntPtr.
Definition SzEngine.hpp:25