personal_knowledge_library 3.0.0__py3-none-any.whl
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.
Potentially problematic release.
This version of personal_knowledge_library might be problematic. Click here for more details.
- knowledge/__init__.py +91 -0
- knowledge/base/__init__.py +22 -0
- knowledge/base/access.py +167 -0
- knowledge/base/entity.py +267 -0
- knowledge/base/language.py +27 -0
- knowledge/base/ontology.py +2734 -0
- knowledge/base/search.py +473 -0
- knowledge/base/tenant.py +192 -0
- knowledge/nel/__init__.py +11 -0
- knowledge/nel/base.py +495 -0
- knowledge/nel/engine.py +123 -0
- knowledge/ontomapping/__init__.py +667 -0
- knowledge/ontomapping/manager.py +320 -0
- knowledge/public/__init__.py +27 -0
- knowledge/public/cache.py +115 -0
- knowledge/public/helper.py +373 -0
- knowledge/public/relations.py +128 -0
- knowledge/public/wikidata.py +1324 -0
- knowledge/services/__init__.py +128 -0
- knowledge/services/asyncio/__init__.py +7 -0
- knowledge/services/asyncio/base.py +458 -0
- knowledge/services/asyncio/graph.py +1420 -0
- knowledge/services/asyncio/group.py +450 -0
- knowledge/services/asyncio/search.py +439 -0
- knowledge/services/asyncio/users.py +270 -0
- knowledge/services/base.py +533 -0
- knowledge/services/graph.py +1897 -0
- knowledge/services/group.py +819 -0
- knowledge/services/helper.py +142 -0
- knowledge/services/ontology.py +1234 -0
- knowledge/services/search.py +488 -0
- knowledge/services/session.py +444 -0
- knowledge/services/tenant.py +281 -0
- knowledge/services/users.py +445 -0
- knowledge/utils/__init__.py +10 -0
- knowledge/utils/graph.py +417 -0
- knowledge/utils/wikidata.py +197 -0
- knowledge/utils/wikipedia.py +175 -0
- personal_knowledge_library-3.0.0.dist-info/LICENSE +201 -0
- personal_knowledge_library-3.0.0.dist-info/METADATA +1163 -0
- personal_knowledge_library-3.0.0.dist-info/RECORD +42 -0
- personal_knowledge_library-3.0.0.dist-info/WHEEL +4 -0
knowledge/base/search.py
ADDED
|
@@ -0,0 +1,473 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# Copyright © 2024-present Wacom. All rights reserved.
|
|
3
|
+
from typing import List, Any, Dict, Optional
|
|
4
|
+
|
|
5
|
+
from knowledge.base.entity import Label
|
|
6
|
+
from knowledge.base.language import LocaleCode
|
|
7
|
+
from knowledge.base.ontology import OntologyClassReference
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class LabelSearchResult:
|
|
11
|
+
"""
|
|
12
|
+
LabelSearchResult
|
|
13
|
+
=================
|
|
14
|
+
This is a search result model.
|
|
15
|
+
|
|
16
|
+
Properties
|
|
17
|
+
----------
|
|
18
|
+
score: float
|
|
19
|
+
Score of the search result.
|
|
20
|
+
entity_uri: str
|
|
21
|
+
Unique identifier of the entity.
|
|
22
|
+
label: str
|
|
23
|
+
Label of the search result.
|
|
24
|
+
locale: LocaleCode
|
|
25
|
+
Locale of the search result.
|
|
26
|
+
concept_type: OntologyClassReference
|
|
27
|
+
Concept type of the search result.
|
|
28
|
+
metadata: Dict[str, Any]
|
|
29
|
+
Metadata of the search result.
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
def __init__(self, score: float, content_uri: str, metadata: Dict[str, Any], content: str):
|
|
33
|
+
self.__score: float = score
|
|
34
|
+
self.__content_uri: str = content_uri
|
|
35
|
+
self.__metadata: Dict[str, Any] = metadata
|
|
36
|
+
self.__concept_type: OntologyClassReference = OntologyClassReference.parse(
|
|
37
|
+
metadata.get("concept_type", "wacom:core#Topic")
|
|
38
|
+
)
|
|
39
|
+
self.__locale: LocaleCode = LocaleCode(metadata.get("locale", "en_US"))
|
|
40
|
+
if "concept_type" in self.__metadata:
|
|
41
|
+
del self.__metadata["concept_type"]
|
|
42
|
+
if "locale" in self.__metadata:
|
|
43
|
+
del self.__metadata["locale"]
|
|
44
|
+
self.__label: Label = Label(content=content, language_code=self.__locale)
|
|
45
|
+
|
|
46
|
+
@property
|
|
47
|
+
def score(self) -> float:
|
|
48
|
+
"""Score of the search result."""
|
|
49
|
+
return self.__score
|
|
50
|
+
|
|
51
|
+
@property
|
|
52
|
+
def entity_uri(self) -> str:
|
|
53
|
+
"""Unique identifier of the entity."""
|
|
54
|
+
return self.__content_uri
|
|
55
|
+
|
|
56
|
+
@property
|
|
57
|
+
def locale(self) -> LocaleCode:
|
|
58
|
+
"""Locale of the search result."""
|
|
59
|
+
return self.__locale
|
|
60
|
+
|
|
61
|
+
@property
|
|
62
|
+
def metadata(self) -> Dict[str, Any]:
|
|
63
|
+
"""Metadata of the search result."""
|
|
64
|
+
return self.__metadata
|
|
65
|
+
|
|
66
|
+
@property
|
|
67
|
+
def label(self) -> Label:
|
|
68
|
+
"""Label of the search result."""
|
|
69
|
+
return self.__label
|
|
70
|
+
|
|
71
|
+
@property
|
|
72
|
+
def concept_type(self) -> OntologyClassReference:
|
|
73
|
+
"""Concept type of the search result."""
|
|
74
|
+
return self.__concept_type
|
|
75
|
+
|
|
76
|
+
def __repr__(self):
|
|
77
|
+
return (
|
|
78
|
+
f"LabelSearchResult(score={self.score}, entity_uri={self.entity_uri}, label={self.label}, "
|
|
79
|
+
f"locale={self.locale}, concept_type={self.concept_type}, metadata={self.metadata})"
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
class DocumentSearchResult:
|
|
84
|
+
"""
|
|
85
|
+
DocumentSearchResult
|
|
86
|
+
====================
|
|
87
|
+
This is a search result model.
|
|
88
|
+
|
|
89
|
+
Properties
|
|
90
|
+
----------
|
|
91
|
+
score: float
|
|
92
|
+
Score of the search result.
|
|
93
|
+
content_uri: str
|
|
94
|
+
Unique identifier of the entity.
|
|
95
|
+
metadata: Dict[str, Any]
|
|
96
|
+
Metadata of the search result.
|
|
97
|
+
content_chunk: str
|
|
98
|
+
Content chunk of the search result.
|
|
99
|
+
concept_type: OntologyClassReference
|
|
100
|
+
Concept type of the search result.
|
|
101
|
+
locale: LocaleCode
|
|
102
|
+
Locale of the search result.
|
|
103
|
+
"""
|
|
104
|
+
|
|
105
|
+
def __init__(self, score: float, content_uri: str, metadata: Dict[str, Any], content: str):
|
|
106
|
+
self.__score: float = score
|
|
107
|
+
self.__content_uri: str = content_uri
|
|
108
|
+
self.__content: str = content
|
|
109
|
+
self.__metadata: Dict[str, Any] = metadata
|
|
110
|
+
self.__concept_type: OntologyClassReference = OntologyClassReference.parse(
|
|
111
|
+
metadata.get("concept_type", "wacom:core#Thing")
|
|
112
|
+
)
|
|
113
|
+
self.__locale: LocaleCode = LocaleCode(metadata.get("locale", "en_US"))
|
|
114
|
+
if "concept_type" in self.__metadata:
|
|
115
|
+
del self.__metadata["concept_type"]
|
|
116
|
+
if "locale" in self.__metadata:
|
|
117
|
+
del self.__metadata["locale"]
|
|
118
|
+
|
|
119
|
+
@property
|
|
120
|
+
def score(self) -> float:
|
|
121
|
+
"""Score of the search result."""
|
|
122
|
+
return self.__score
|
|
123
|
+
|
|
124
|
+
@property
|
|
125
|
+
def content_uri(self) -> str:
|
|
126
|
+
"""Unique identifier of the content."""
|
|
127
|
+
return self.__content_uri
|
|
128
|
+
|
|
129
|
+
@property
|
|
130
|
+
def content_chunk(self) -> str:
|
|
131
|
+
"""Chunk of the document."""
|
|
132
|
+
return self.__content
|
|
133
|
+
|
|
134
|
+
@property
|
|
135
|
+
def metadata(self) -> Dict[str, Any]:
|
|
136
|
+
"""Metadata of the search result."""
|
|
137
|
+
return self.__metadata
|
|
138
|
+
|
|
139
|
+
@property
|
|
140
|
+
def concept_type(self) -> OntologyClassReference:
|
|
141
|
+
"""Concept type of the search result."""
|
|
142
|
+
return self.__concept_type
|
|
143
|
+
|
|
144
|
+
@property
|
|
145
|
+
def locale(self) -> LocaleCode:
|
|
146
|
+
"""Locale of the search result."""
|
|
147
|
+
return self.__locale
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
class PerformanceStats:
|
|
151
|
+
"""
|
|
152
|
+
PerformanceStats
|
|
153
|
+
================
|
|
154
|
+
This is a performance stats model.
|
|
155
|
+
|
|
156
|
+
Properties
|
|
157
|
+
----------
|
|
158
|
+
locale_code: LocaleCode
|
|
159
|
+
Performance for the model with the given locale.
|
|
160
|
+
model_name: str
|
|
161
|
+
Name of the model used for the search.
|
|
162
|
+
top_k: int
|
|
163
|
+
Top-k results requested.
|
|
164
|
+
model_loading_time: float
|
|
165
|
+
Loading time in milliseconds for the embedding model.
|
|
166
|
+
embedding_time: float
|
|
167
|
+
Embedding time in milliseconds for the search query.
|
|
168
|
+
vector_db_response_time: float
|
|
169
|
+
Response time in milliseconds for the vector database.
|
|
170
|
+
"""
|
|
171
|
+
|
|
172
|
+
def __init__(self, stats: Dict[str, Any]):
|
|
173
|
+
self.__locale: LocaleCode = stats.get("locale")
|
|
174
|
+
self.__model_name: str = stats.get("model-name", "unknown")
|
|
175
|
+
self.__top_k: int = stats.get("top-k", 10)
|
|
176
|
+
self.__loading_time: float = stats.get("loading", 0.0) * 1000
|
|
177
|
+
self.__embedding_time: float = stats.get("embedding", 0.0) * 1000
|
|
178
|
+
self.__vector_db_response_time: float = stats.get("request", 0.0) * 1000
|
|
179
|
+
self.__overall_time: float = stats.get("overall", 0.0) * 1000
|
|
180
|
+
|
|
181
|
+
@property
|
|
182
|
+
def locale_code(self) -> LocaleCode:
|
|
183
|
+
"""Performance for the model with the given locale."""
|
|
184
|
+
return self.__locale
|
|
185
|
+
|
|
186
|
+
@property
|
|
187
|
+
def model_name(self) -> str:
|
|
188
|
+
"""Name of the model used for the search."""
|
|
189
|
+
return self.__model_name
|
|
190
|
+
|
|
191
|
+
@property
|
|
192
|
+
def top_k(self) -> int:
|
|
193
|
+
"""Top-k results requested."""
|
|
194
|
+
return self.__top_k
|
|
195
|
+
|
|
196
|
+
@property
|
|
197
|
+
def model_loading_time(self) -> float:
|
|
198
|
+
"""Loading time in milliseconds for the embedding model."""
|
|
199
|
+
return self.__loading_time
|
|
200
|
+
|
|
201
|
+
@property
|
|
202
|
+
def embedding_time(self) -> float:
|
|
203
|
+
"""Embedding time in milliseconds for the search query."""
|
|
204
|
+
return self.__embedding_time
|
|
205
|
+
|
|
206
|
+
@property
|
|
207
|
+
def vector_db_response_time(self) -> float:
|
|
208
|
+
"""Response time in milliseconds for the vector database."""
|
|
209
|
+
return self.__vector_db_response_time
|
|
210
|
+
|
|
211
|
+
@property
|
|
212
|
+
def overall_time(self) -> float:
|
|
213
|
+
"""Overall time in milliseconds for the search query."""
|
|
214
|
+
return self.__overall_time
|
|
215
|
+
|
|
216
|
+
def __repr__(self):
|
|
217
|
+
return (
|
|
218
|
+
f"PerformanceStats(locale_code={self.locale_code}, model_name={self.model_name}, top_k={self.top_k}, "
|
|
219
|
+
f"model_loading_time={self.model_loading_time}, embedding_time={self.embedding_time}, "
|
|
220
|
+
f"vector_db_response_time={self.vector_db_response_time})"
|
|
221
|
+
)
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
class DocumentSearchStats(PerformanceStats):
|
|
225
|
+
"""
|
|
226
|
+
DocumentSearchStats
|
|
227
|
+
====================
|
|
228
|
+
This is a performance stats model for document search.
|
|
229
|
+
|
|
230
|
+
Properties
|
|
231
|
+
----------
|
|
232
|
+
locale_code: LocaleCode
|
|
233
|
+
Performance for the model with the given locale.
|
|
234
|
+
model_name: str
|
|
235
|
+
Name of the model used for the search.
|
|
236
|
+
top_k: int
|
|
237
|
+
Top-k results requested.
|
|
238
|
+
model_loading_time: float
|
|
239
|
+
Loading time in milliseconds for the embedding model.
|
|
240
|
+
embedding_time: float
|
|
241
|
+
Embedding time in milliseconds for the search query.
|
|
242
|
+
vector_db_response_time: float
|
|
243
|
+
Response time in milliseconds for the vector database.
|
|
244
|
+
preprocessing_time: float
|
|
245
|
+
Preprocessing time in milliseconds for search query.
|
|
246
|
+
|
|
247
|
+
"""
|
|
248
|
+
|
|
249
|
+
def __init__(self, stats: Dict[str, Any]):
|
|
250
|
+
super().__init__(stats)
|
|
251
|
+
self.__preprocessing: float = stats.get("preprocessing", 0.0) * 1000.0
|
|
252
|
+
|
|
253
|
+
@property
|
|
254
|
+
def preprocessing_time(self) -> float:
|
|
255
|
+
"""Preprocessing time in milliseconds for search query."""
|
|
256
|
+
return self.__preprocessing
|
|
257
|
+
|
|
258
|
+
def __repr__(self):
|
|
259
|
+
return (
|
|
260
|
+
f"DocumentSearchStats(locale_code={self.locale_code}, model_name={self.model_name}, "
|
|
261
|
+
f"top_k={self.top_k}, "
|
|
262
|
+
f"model_loading_time={self.model_loading_time}, embedding_time={self.embedding_time}, "
|
|
263
|
+
f"vector_db_response_time={self.vector_db_response_time}, preprocessing_time={self.preprocessing_time})"
|
|
264
|
+
)
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
class LabelSearchStats(PerformanceStats):
|
|
268
|
+
"""
|
|
269
|
+
LabelSearchStats
|
|
270
|
+
================
|
|
271
|
+
This is a performance stats model for label search.
|
|
272
|
+
|
|
273
|
+
Properties
|
|
274
|
+
----------
|
|
275
|
+
locale_code: LocaleCode
|
|
276
|
+
Performance for the model with the given locale.
|
|
277
|
+
model_name: str
|
|
278
|
+
Name of the model used for the search.
|
|
279
|
+
top_k: int
|
|
280
|
+
Top-k results requested.
|
|
281
|
+
model_loading_time: float
|
|
282
|
+
Loading time in milliseconds for the embedding model.
|
|
283
|
+
embedding_time: float
|
|
284
|
+
Embedding time in milliseconds for the search query.
|
|
285
|
+
vector_db_response_time: float
|
|
286
|
+
Response time in milliseconds for the vector database.
|
|
287
|
+
tokenizer_time: float
|
|
288
|
+
Tokenizer time in milliseconds for search query.
|
|
289
|
+
number_of_tokens: int
|
|
290
|
+
Number of tokens in the search query.
|
|
291
|
+
"""
|
|
292
|
+
|
|
293
|
+
def __init__(self, stats: Dict[str, Any]):
|
|
294
|
+
super().__init__(stats)
|
|
295
|
+
self.__tokenizer: float = stats.get("tokenizer")
|
|
296
|
+
self.__number_of_tokens: int = stats.get("number-of-tokens")
|
|
297
|
+
|
|
298
|
+
@property
|
|
299
|
+
def tokenizer_time(self) -> float:
|
|
300
|
+
"""Tokenizer time in milliseconds for search query."""
|
|
301
|
+
return self.__tokenizer
|
|
302
|
+
|
|
303
|
+
@property
|
|
304
|
+
def number_of_tokens(self) -> int:
|
|
305
|
+
"""Number of tokens in the search query."""
|
|
306
|
+
return self.__number_of_tokens
|
|
307
|
+
|
|
308
|
+
def __repr__(self):
|
|
309
|
+
return (
|
|
310
|
+
f"LabelSearchStats(locale_code={self.locale_code}, model_name={self.model_name}, "
|
|
311
|
+
f"top_k={self.top_k}, "
|
|
312
|
+
f"model_loading_time={self.model_loading_time}, embedding_time={self.embedding_time}, "
|
|
313
|
+
f"vector_db_response_time={self.vector_db_response_time}, tokenizer_time={self.tokenizer_time}, "
|
|
314
|
+
f"number_of_tokens={self.number_of_tokens})"
|
|
315
|
+
)
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
class DocumentSearchResponse:
|
|
319
|
+
"""
|
|
320
|
+
DocumentSearchResponse
|
|
321
|
+
======================
|
|
322
|
+
Response model for semantic search service.
|
|
323
|
+
|
|
324
|
+
Properties
|
|
325
|
+
----------
|
|
326
|
+
results: List[DocumentSearchResult]
|
|
327
|
+
Search results
|
|
328
|
+
max_results: int
|
|
329
|
+
Maximum number of results
|
|
330
|
+
stats: Optional[PerformanceStats]
|
|
331
|
+
Performance stats
|
|
332
|
+
"""
|
|
333
|
+
|
|
334
|
+
def __init__(
|
|
335
|
+
self, results: List[DocumentSearchResult], max_results: int = 10, stats: Optional[DocumentSearchStats] = None
|
|
336
|
+
):
|
|
337
|
+
self.__results: List[DocumentSearchResult] = results
|
|
338
|
+
self.__max_results = max_results
|
|
339
|
+
self.__stats: Optional[DocumentSearchStats] = stats
|
|
340
|
+
|
|
341
|
+
@property
|
|
342
|
+
def results(self) -> List[DocumentSearchResult]:
|
|
343
|
+
"""List of search results."""
|
|
344
|
+
return self.__results
|
|
345
|
+
|
|
346
|
+
@property
|
|
347
|
+
def max_results(self) -> int:
|
|
348
|
+
"""Maximum number of results."""
|
|
349
|
+
return self.__max_results
|
|
350
|
+
|
|
351
|
+
@property
|
|
352
|
+
def stats(self) -> Optional[DocumentSearchStats]:
|
|
353
|
+
"""Performance stats."""
|
|
354
|
+
return self.__stats
|
|
355
|
+
|
|
356
|
+
@staticmethod
|
|
357
|
+
def from_dict(data: Dict[str, Any]) -> "DocumentSearchResponse":
|
|
358
|
+
"""
|
|
359
|
+
Create a DocumentSearchResponse from a dictionary.
|
|
360
|
+
Parameters
|
|
361
|
+
----------
|
|
362
|
+
data: Dict[str, Any]
|
|
363
|
+
Dictionary with the response data.
|
|
364
|
+
|
|
365
|
+
Returns
|
|
366
|
+
-------
|
|
367
|
+
DocumentSearchResponse
|
|
368
|
+
SegmentedContent search response.
|
|
369
|
+
"""
|
|
370
|
+
return DocumentSearchResponse(
|
|
371
|
+
results=[DocumentSearchResult(**result) for result in data["results"]],
|
|
372
|
+
max_results=data["max_results"],
|
|
373
|
+
stats=DocumentSearchStats(data["stats"]) if "stats" in data and data["stats"] else None,
|
|
374
|
+
)
|
|
375
|
+
|
|
376
|
+
|
|
377
|
+
class LabelMatchingResponse:
|
|
378
|
+
"""
|
|
379
|
+
SemanticSearchResponse
|
|
380
|
+
======================
|
|
381
|
+
Response model for semantic search service.
|
|
382
|
+
|
|
383
|
+
Properties
|
|
384
|
+
----------
|
|
385
|
+
results: List[LabelSearchResult]
|
|
386
|
+
Search results
|
|
387
|
+
max_results: int
|
|
388
|
+
Maximum number of results
|
|
389
|
+
stats: Optional[LabelSearchStats]
|
|
390
|
+
Performance stats
|
|
391
|
+
"""
|
|
392
|
+
|
|
393
|
+
def __init__(
|
|
394
|
+
self, results: List[LabelSearchResult], max_results: int = 10, stats: Optional[LabelSearchStats] = None
|
|
395
|
+
):
|
|
396
|
+
self.__results = results
|
|
397
|
+
self.__max_results = max_results
|
|
398
|
+
self.__stats: Optional[LabelSearchStats] = stats
|
|
399
|
+
|
|
400
|
+
@property
|
|
401
|
+
def results(self) -> List[LabelSearchResult]:
|
|
402
|
+
"""List of label search results."""
|
|
403
|
+
return self.__results
|
|
404
|
+
|
|
405
|
+
@property
|
|
406
|
+
def max_results(self) -> int:
|
|
407
|
+
"""Maximum number of results."""
|
|
408
|
+
return self.__max_results
|
|
409
|
+
|
|
410
|
+
@property
|
|
411
|
+
def stats(self) -> Optional[LabelSearchStats]:
|
|
412
|
+
"""Performance stats."""
|
|
413
|
+
return self.__stats
|
|
414
|
+
|
|
415
|
+
@staticmethod
|
|
416
|
+
def from_dict(data: Dict[str, Any]):
|
|
417
|
+
"""
|
|
418
|
+
Create a LabelMatchingResponse from a dictionary.
|
|
419
|
+
Parameters
|
|
420
|
+
----------
|
|
421
|
+
data: Dict[str, Any]
|
|
422
|
+
Dictionary with the response data.
|
|
423
|
+
|
|
424
|
+
Returns
|
|
425
|
+
-------
|
|
426
|
+
LabelMatchingResponse
|
|
427
|
+
Label matching response.
|
|
428
|
+
"""
|
|
429
|
+
return LabelMatchingResponse(
|
|
430
|
+
results=[LabelSearchResult(**result) for result in data["results"]],
|
|
431
|
+
max_results=data["max_results"],
|
|
432
|
+
stats=LabelSearchStats(data["stats"]) if "stats" in data and data["stats"] else None,
|
|
433
|
+
)
|
|
434
|
+
|
|
435
|
+
|
|
436
|
+
class VectorDBDocument:
|
|
437
|
+
"""
|
|
438
|
+
VectorDBDocument
|
|
439
|
+
================
|
|
440
|
+
SegmentedContent model for the vector database.
|
|
441
|
+
|
|
442
|
+
Properties
|
|
443
|
+
----------
|
|
444
|
+
"""
|
|
445
|
+
|
|
446
|
+
def __init__(self, data: Dict[str, Any]):
|
|
447
|
+
self.__id: str = data.get("id", "")
|
|
448
|
+
self.__content: str = data.get("content", "")
|
|
449
|
+
self.__uri: str = data.get("uri", "")
|
|
450
|
+
self.__metadata: Dict[str, Any] = data.get("meta", {})
|
|
451
|
+
|
|
452
|
+
@property
|
|
453
|
+
def id(self) -> str:
|
|
454
|
+
"""ID of the document."""
|
|
455
|
+
return self.__id
|
|
456
|
+
|
|
457
|
+
@property
|
|
458
|
+
def content(self) -> str:
|
|
459
|
+
"""Content of the document."""
|
|
460
|
+
return self.__content
|
|
461
|
+
|
|
462
|
+
@property
|
|
463
|
+
def uri(self) -> str:
|
|
464
|
+
"""URI of the document."""
|
|
465
|
+
return self.__uri
|
|
466
|
+
|
|
467
|
+
@property
|
|
468
|
+
def metadata(self) -> Dict[str, Any]:
|
|
469
|
+
"""Metadata of the document."""
|
|
470
|
+
return self.__metadata
|
|
471
|
+
|
|
472
|
+
def __repr__(self):
|
|
473
|
+
return f"VectorDatabaseDocument(content={self.content}, uri={self.uri}, metadata={self.metadata})"
|
knowledge/base/tenant.py
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# Copyright © 2024-present Wacom. All rights reserved.
|
|
3
|
+
from typing import List, Dict, Any
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class TenantConfiguration:
|
|
7
|
+
"""
|
|
8
|
+
Tenant configuration
|
|
9
|
+
====================
|
|
10
|
+
|
|
11
|
+
This class represents the configuration of a tenant.
|
|
12
|
+
The configuration includes the following properties:
|
|
13
|
+
- identifier: str
|
|
14
|
+
- ontology_name: str
|
|
15
|
+
- ontology_version: int
|
|
16
|
+
- is_locked: bool
|
|
17
|
+
- name: str
|
|
18
|
+
- rights: List[str]
|
|
19
|
+
|
|
20
|
+
Parameters
|
|
21
|
+
----------
|
|
22
|
+
identifier: str
|
|
23
|
+
Identifier of the tenant
|
|
24
|
+
ontology_name: str
|
|
25
|
+
Name of the ontology
|
|
26
|
+
ontology_version: int
|
|
27
|
+
Version of the ontology
|
|
28
|
+
is_locked: bool
|
|
29
|
+
Flag to indicate if the tenant is locked
|
|
30
|
+
name: str
|
|
31
|
+
Name of the tenant
|
|
32
|
+
rights: List[str]
|
|
33
|
+
List of rights
|
|
34
|
+
vector_search_data_properties: List[str]
|
|
35
|
+
List of vector search data properties which are used for vector search in the metadata
|
|
36
|
+
vector_search_object_properties: List[str]
|
|
37
|
+
List of vector search object properties which are used for vector search in the metadata
|
|
38
|
+
content_data_property_name: str
|
|
39
|
+
Name of the content data property which is used for vector search to index documents
|
|
40
|
+
|
|
41
|
+
"""
|
|
42
|
+
|
|
43
|
+
def __init__(
|
|
44
|
+
self,
|
|
45
|
+
identifier: str,
|
|
46
|
+
ontology_name: str,
|
|
47
|
+
ontology_version: int,
|
|
48
|
+
is_locked: bool,
|
|
49
|
+
name: str,
|
|
50
|
+
rights: List[str],
|
|
51
|
+
vector_search_data_properties: List[str],
|
|
52
|
+
vector_search_object_properties: List[str],
|
|
53
|
+
content_data_property_name: str,
|
|
54
|
+
):
|
|
55
|
+
# Constructor to initialize the properties
|
|
56
|
+
self.__identifier: str = identifier
|
|
57
|
+
self.__ontology_name: str = ontology_name
|
|
58
|
+
self.__ontology_version: int = ontology_version
|
|
59
|
+
self.__is_locked: bool = is_locked
|
|
60
|
+
self.__name: str = name
|
|
61
|
+
self.__rights: List[str] = rights
|
|
62
|
+
self.__vector_search_data_properties: List[str] = vector_search_data_properties
|
|
63
|
+
self.__vector_search_object_properties: List[str] = vector_search_object_properties
|
|
64
|
+
self.__content_data_property_name: str = content_data_property_name
|
|
65
|
+
|
|
66
|
+
@property
|
|
67
|
+
def identifier(self) -> str:
|
|
68
|
+
"""
|
|
69
|
+
Identifier of the tenant
|
|
70
|
+
Returns
|
|
71
|
+
-------
|
|
72
|
+
str
|
|
73
|
+
Identifier of the tenant
|
|
74
|
+
"""
|
|
75
|
+
return self.__identifier
|
|
76
|
+
|
|
77
|
+
@property
|
|
78
|
+
def ontology_name(self) -> str:
|
|
79
|
+
"""
|
|
80
|
+
Name of the ontology.
|
|
81
|
+
Returns
|
|
82
|
+
-------
|
|
83
|
+
str
|
|
84
|
+
Name of the ontology.
|
|
85
|
+
"""
|
|
86
|
+
return self.__ontology_name
|
|
87
|
+
|
|
88
|
+
@property
|
|
89
|
+
def ontology_version(self) -> int:
|
|
90
|
+
"""
|
|
91
|
+
Version of the ontology.
|
|
92
|
+
"""
|
|
93
|
+
return self.__ontology_version
|
|
94
|
+
|
|
95
|
+
@property
|
|
96
|
+
def is_locked(self) -> bool:
|
|
97
|
+
"""
|
|
98
|
+
Flag to indicate if the tenant is locked.
|
|
99
|
+
"""
|
|
100
|
+
return self.__is_locked
|
|
101
|
+
|
|
102
|
+
@property
|
|
103
|
+
def name(self) -> str:
|
|
104
|
+
"""
|
|
105
|
+
Name of the tenant.
|
|
106
|
+
"""
|
|
107
|
+
return self.__name
|
|
108
|
+
|
|
109
|
+
@name.setter
|
|
110
|
+
def name(self, value):
|
|
111
|
+
self.__name = value
|
|
112
|
+
|
|
113
|
+
@property
|
|
114
|
+
def rights(self):
|
|
115
|
+
"""
|
|
116
|
+
List of rights being assigned to the tenant, and will be added to the user's rights in the token.
|
|
117
|
+
"""
|
|
118
|
+
return self.__rights
|
|
119
|
+
|
|
120
|
+
@rights.setter
|
|
121
|
+
def rights(self, value):
|
|
122
|
+
self.__rights = value
|
|
123
|
+
|
|
124
|
+
@property
|
|
125
|
+
def vector_search_data_properties(self) -> List[str]:
|
|
126
|
+
"""
|
|
127
|
+
List of vector search data properties which are used for vector search in the metadata.
|
|
128
|
+
"""
|
|
129
|
+
return self.__vector_search_data_properties
|
|
130
|
+
|
|
131
|
+
@vector_search_data_properties.setter
|
|
132
|
+
def vector_search_data_properties(self, value):
|
|
133
|
+
self.__vector_search_data_properties = value
|
|
134
|
+
|
|
135
|
+
@property
|
|
136
|
+
def vector_search_object_properties(self):
|
|
137
|
+
"""
|
|
138
|
+
List of vector search object properties which are used for vector search in the metadata.
|
|
139
|
+
"""
|
|
140
|
+
return self.__vector_search_object_properties
|
|
141
|
+
|
|
142
|
+
@vector_search_object_properties.setter
|
|
143
|
+
def vector_search_object_properties(self, value):
|
|
144
|
+
self.__vector_search_object_properties = value
|
|
145
|
+
|
|
146
|
+
@property
|
|
147
|
+
def content_data_property_name(self):
|
|
148
|
+
"""
|
|
149
|
+
Name of the content data property which is used for vector search to index documents.
|
|
150
|
+
"""
|
|
151
|
+
return self.__content_data_property_name
|
|
152
|
+
|
|
153
|
+
@content_data_property_name.setter
|
|
154
|
+
def content_data_property_name(self, value):
|
|
155
|
+
self.__content_data_property_name = value
|
|
156
|
+
|
|
157
|
+
@classmethod
|
|
158
|
+
def from_dict(cls, data_dict: Dict[str, Any]) -> "TenantConfiguration":
|
|
159
|
+
"""
|
|
160
|
+
Create a TenantConfiguration object from a dictionary.
|
|
161
|
+
|
|
162
|
+
Parameters
|
|
163
|
+
----------
|
|
164
|
+
data_dict: Dict[str, Any]
|
|
165
|
+
Dictionary containing the tenant configuration data.
|
|
166
|
+
|
|
167
|
+
Returns
|
|
168
|
+
-------
|
|
169
|
+
TenantConfiguration
|
|
170
|
+
The tenant configuration object.
|
|
171
|
+
"""
|
|
172
|
+
return cls(
|
|
173
|
+
identifier=data_dict.get("id"),
|
|
174
|
+
ontology_name=data_dict.get("ontologyName"),
|
|
175
|
+
ontology_version=data_dict.get("ontologyVersion"),
|
|
176
|
+
is_locked=data_dict.get("isLocked"),
|
|
177
|
+
name=data_dict.get("name"),
|
|
178
|
+
rights=data_dict.get("rights"),
|
|
179
|
+
vector_search_data_properties=data_dict.get("vectorSearchDataProperties"),
|
|
180
|
+
vector_search_object_properties=data_dict.get("vectorSearchObjectProperties"),
|
|
181
|
+
content_data_property_name=data_dict.get("contentDataPropertyName"),
|
|
182
|
+
)
|
|
183
|
+
|
|
184
|
+
def __repr__(self):
|
|
185
|
+
return (
|
|
186
|
+
f"TenantConfiguration(identifier='{self.identifier}', ontology_name='{self.ontology_name}', "
|
|
187
|
+
f"ontology_version={self.ontology_version}, is_locked={self.is_locked}, "
|
|
188
|
+
f"name='{self.name}', rights={self.rights}, "
|
|
189
|
+
f"vector_search_data_properties={self.vector_search_data_properties}, "
|
|
190
|
+
f"vector_search_object_properties={self.vector_search_object_properties}, "
|
|
191
|
+
f"content_data_property_name='{self.content_data_property_name}')"
|
|
192
|
+
)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# Copyright © 2021-present Wacom. All rights reserved.
|
|
3
|
+
"""
|
|
4
|
+
Named Entity Linking
|
|
5
|
+
--------------------
|
|
6
|
+
This module provides the Named Entity Linking (NEL) functionality on top of the knowledge graph entities.
|
|
7
|
+
"""
|
|
8
|
+
from knowledge.nel import base
|
|
9
|
+
from knowledge.nel import engine
|
|
10
|
+
|
|
11
|
+
__all__ = ["base", "engine"]
|