gedcom-x 0.5.6__py3-none-any.whl → 0.5.8__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.
Files changed (64) hide show
  1. {gedcom_x-0.5.6.dist-info → gedcom_x-0.5.8.dist-info}/METADATA +1 -1
  2. gedcom_x-0.5.8.dist-info/RECORD +56 -0
  3. gedcomx/Extensions/__init__.py +1 -0
  4. gedcomx/Extensions/rs10/__init__.py +1 -0
  5. gedcomx/Extensions/rs10/rsLink.py +116 -0
  6. gedcomx/TopLevelTypeCollection.py +1 -1
  7. gedcomx/__init__.py +43 -41
  8. gedcomx/{Address.py → address.py} +13 -13
  9. gedcomx/{Agent.py → agent.py} +52 -24
  10. gedcomx/{Attribution.py → attribution.py} +36 -9
  11. gedcomx/{Conclusion.py → conclusion.py} +49 -21
  12. gedcomx/converter.py +1049 -0
  13. gedcomx/coverage.py +55 -0
  14. gedcomx/{Date.py → date.py} +11 -4
  15. gedcomx/{Document.py → document.py} +27 -8
  16. gedcomx/{Event.py → event.py} +102 -27
  17. gedcomx/{EvidenceReference.py → evidence_reference.py} +2 -2
  18. gedcomx/{Fact.py → fact.py} +45 -34
  19. gedcomx/{Gedcom5x.py → gedcom5x.py} +78 -61
  20. gedcomx/gedcom7/Exceptions.py +9 -0
  21. gedcomx/gedcom7/Gedcom7.py +160 -0
  22. gedcomx/gedcom7/GedcomStructure.py +94 -0
  23. gedcomx/gedcom7/Specification.py +347 -0
  24. gedcomx/gedcom7/__init__.py +26 -0
  25. gedcomx/gedcom7/g7interop.py +205 -0
  26. gedcomx/gedcom7/logger.py +19 -0
  27. gedcomx/gedcomx.py +501 -0
  28. gedcomx/{Gender.py → gender.py} +29 -17
  29. gedcomx/group.py +63 -0
  30. gedcomx/{Identifier.py → identifier.py} +13 -16
  31. gedcomx/{LoggingHub.py → logging_hub.py} +21 -0
  32. gedcomx/{Mutations.py → mutations.py} +50 -26
  33. gedcomx/name.py +396 -0
  34. gedcomx/{Note.py → note.py} +17 -10
  35. gedcomx/{OnlineAccount.py → online_account.py} +1 -1
  36. gedcomx/{Person.py → person.py} +52 -29
  37. gedcomx/place_description.py +123 -0
  38. gedcomx/place_reference.py +62 -0
  39. gedcomx/qualifier.py +54 -0
  40. gedcomx/{Relationship.py → relationship.py} +33 -13
  41. gedcomx/resource.py +85 -0
  42. gedcomx/serialization.py +815 -0
  43. gedcomx/{SourceDescription.py → source_description.py} +144 -85
  44. gedcomx/{SourceReference.py → source_reference.py} +15 -14
  45. gedcomx/{Subject.py → subject.py} +30 -28
  46. gedcomx/{GedcomX.py → translation.py} +283 -446
  47. gedcomx/{URI.py → uri.py} +42 -26
  48. gedcom_x-0.5.6.dist-info/RECORD +0 -45
  49. gedcomx/Coverage.py +0 -36
  50. gedcomx/Group.py +0 -37
  51. gedcomx/Name.py +0 -276
  52. gedcomx/PlaceDescription.py +0 -70
  53. gedcomx/PlaceReference.py +0 -30
  54. gedcomx/Qualifier.py +0 -27
  55. gedcomx/Resource.py +0 -75
  56. gedcomx/Serialization.py +0 -401
  57. gedcomx/Translation.py +0 -219
  58. {gedcom_x-0.5.6.dist-info → gedcom_x-0.5.8.dist-info}/WHEEL +0 -0
  59. {gedcom_x-0.5.6.dist-info → gedcom_x-0.5.8.dist-info}/top_level.txt +0 -0
  60. /gedcomx/{Exceptions.py → exceptions.py} +0 -0
  61. /gedcomx/{ExtensibleEnum.py → extensible_enum.py} +0 -0
  62. /gedcomx/{Gedcom.py → gedcom.py} +0 -0
  63. /gedcomx/{SourceCitation.py → source_citation.py} +0 -0
  64. /gedcomx/{TextValue.py → textvalue.py} +0 -0
gedcomx/Resource.py DELETED
@@ -1,75 +0,0 @@
1
- from typing import List, Optional
2
-
3
-
4
- from .URI import URI
5
-
6
- class Resource:
7
- """
8
- Class used to track and resolve URIs and references between datastores.
9
-
10
- Parameters
11
- ----------
12
-
13
- Raises
14
- ------
15
- ValueError
16
- If `id` is not a valid UUID.
17
- """
18
- def __init__(self,uri: Optional[URI|str] = None, id:Optional[str] = None,top_lvl_object: Optional[object] = None,target= None) -> None:
19
-
20
- self.resource = URI.from_url(uri.value) if isinstance(uri,URI) else URI.from_url(uri) if isinstance(uri,str) else None
21
- self.Id = id
22
-
23
- self.type = None
24
- self.resolved = False
25
- self.target: object = target
26
- self.remote: bool | None = None # is the resource pointed to persitent on a remote datastore?
27
-
28
- if target:
29
- self.resource = target._uri
30
- self.Id = target.id
31
- self.type = type(target)
32
-
33
- @property
34
- def _as_dict_(self):
35
- from .Serialization import Serialization
36
- typ_as_dict = {'resource':self.resource.value if self.resource else None,
37
- 'resourceId':self.Id}
38
- return Serialization.serialize_dict(typ_as_dict)
39
-
40
- @classmethod
41
- def _from_json_(cls,data):
42
- # TODO This is not used but taken care of in Serialization
43
- r = Resource(uri=data.get('resource'),id=data.get('resourceId',None))
44
- #return r
45
-
46
- def __repr__(self) -> str:
47
- return f"Resource(uri={self.resource}, id={self.Id}, target={self.target})"
48
-
49
- def __str__(self) -> str:
50
- return f"{self.resource}{f', id={self.Id}' if self.Id else ''}"
51
-
52
- def get_resource_as_dict(value):
53
- """
54
- If value is truthy:
55
- - If it's already a Resource, return it.
56
- - Otherwise, wrap it in Resource using (value._uri, value.id).
57
- Returns None if value is falsy.
58
- """
59
-
60
- if not value:
61
- return None
62
-
63
- if isinstance(value, Resource):
64
- return value._as_dict_
65
-
66
- try:
67
- return Resource(
68
- getattr(value, "uri", None),
69
- getattr(value, "id", None)
70
- )._as_dict_
71
- except AttributeError:
72
- print('get_resource_as_dict',type(value),value)
73
- print((f"value: {value} as inproper attributes"))
74
- exit()
75
-
gedcomx/Serialization.py DELETED
@@ -1,401 +0,0 @@
1
- from typing import Dict
2
-
3
- from .Logging import get_logger
4
-
5
- log = get_logger(__name__)
6
- log.setLevel("DEBUG")
7
- log.info("Logger initialized.")
8
-
9
- from collections.abc import Sized
10
- from typing import Any, get_origin, get_args, List, Set, Tuple, Dict, Union, ForwardRef, Annotated
11
- import types
12
-
13
- import enum
14
- from .Resource import Resource
15
- from .Identifier import IdentifierList
16
- from .URI import URI
17
-
18
- _PRIMITIVES = (str, int, float, bool, type(None))
19
-
20
- def _has_parent_class(obj) -> bool:
21
- return hasattr(obj, '__class__') and hasattr(obj.__class__, '__bases__') and len(obj.__class__.__bases__) > 0
22
-
23
-
24
- class Serialization:
25
-
26
- @staticmethod
27
- def serialize_dict(dict_to_serialize: dict) -> dict:
28
- """
29
- Iterates through the dict, serilaizing all Gedcom Types into a json compatible value
30
-
31
- Parameters
32
- ----------
33
- dict_to_serialize: dict
34
- dict that has been created from any Gedcom Type Object's _as_dict_ property
35
-
36
- Raises
37
- ------
38
- ValueError
39
- If `id` is not a valid UUID.
40
- """
41
- def _serialize(value):
42
- if isinstance(value, (str, int, float, bool, type(None))):
43
- return value
44
- elif isinstance(value, dict):
45
- return {k: _serialize(v) for k, v in value.items()}
46
- elif isinstance(value, (list, tuple, set)):
47
- return [_serialize(v) for v in value]
48
- elif hasattr(value, "_as_dict_"):
49
- return value._as_dict_
50
- else:
51
- return str(value) # fallback for unknown objects
52
-
53
- if dict_to_serialize and isinstance(dict_to_serialize,dict):
54
- for key, value in dict_to_serialize.items():
55
- if value is not None:
56
- dict_to_serialize[key] = _serialize(value)
57
-
58
- return {
59
- k: v
60
- for k, v in dict_to_serialize.items()
61
- if v is not None and not (isinstance(v, Sized) and len(v) == 0)
62
- }
63
- return {}
64
-
65
- @staticmethod
66
- def _coerce_value(value: Any, typ: Any) -> Any:
67
- """Coerce `value` to `typ`:
68
- - primitives: pass through
69
- - containers: recurse into elements
70
- - objects: call typ._from_json_(dict) if available and value is dict
71
- - already-instantiated objects of typ: pass through
72
- - otherwise: return value unchanged
73
- """
74
- def is_enum_type(T) -> bool:
75
- """Return True if T (possibly a typing construct) is or contains an Enum type."""
76
- origin = get_origin(T)
77
-
78
- # Unwrap Union/Optional/PEP 604 (A | B)
79
- if origin in (Union, types.UnionType):
80
- return any(is_enum_type(a) for a in get_args(T))
81
-
82
- # Unwrap Annotated[T, ...]
83
- if origin is Annotated:
84
- return is_enum_type(get_args(T)[0])
85
-
86
- # Resolve forward refs / strings if you use them
87
- if isinstance(T, ForwardRef):
88
- T = globals().get(T.__forward_arg__, T)
89
- if isinstance(T, str):
90
- T = globals().get(T, T)
91
-
92
- # Finally check enum-ness
93
- try:
94
- return issubclass(T, enum.Enum)
95
- except TypeError:
96
- return False # not a class (e.g., typing.List[int], etc.)
97
- log.debug(f"Coercing value '{value}' of type '{type(value).__name__}' to '{typ}'")
98
-
99
- def _resolve(t):
100
- # resolve ForwardRef('Resource') -> actual object if already in globals()
101
- if isinstance(t, ForwardRef):
102
- return globals().get(t.__forward_arg__, t)
103
- return t
104
-
105
- if is_enum_type(typ):
106
- log.debug(f"Enum type detected: {typ}")
107
- return typ(value) # cast to enum
108
-
109
- origin = get_origin(typ)
110
- if origin in (Union, types.UnionType):
111
- args = tuple(_resolve(a) for a in get_args(typ))
112
- else:
113
- args = (_resolve(typ),)
114
- log.debug(f"Origin: {origin}, args: {args}")
115
-
116
- if Resource in args and isinstance(value, dict):
117
- if Resource in args:
118
- log.info(f"Deserializing Resource from value: {value}")
119
- return Resource(uri=value.get('resource'), id=value.get('resourceId', None))
120
-
121
- if isinstance(value, _PRIMITIVES):
122
- if Resource in args:
123
- log.info(f"Deserializing Resource from value: {value}")
124
- return Resource(uri=value)
125
- if URI in args:
126
- log.info(f"Deserializing URI from value: {value}")
127
- return URI.from_url(value)
128
- return value
129
-
130
- if IdentifierList in args:
131
- log.error(f"Deserializing IdentifierList from value: {value}")
132
- return IdentifierList._from_json_(value)
133
-
134
- if origin in (list, List):
135
- elem_args = get_args(typ) # NOT get_args(args)
136
- elem_t = elem_args[0] if elem_args else Any
137
- log.debug(f"List: {typ}, elem={elem_t}")
138
- return [Serialization._coerce_value(v, elem_t) for v in (value or [])]
139
-
140
- if origin in (set, Set):
141
- (elem_t,) = args or (Any,)
142
- return { Serialization._coerce_value(v, elem_t) for v in (value or []) }
143
-
144
- if origin in (tuple, Tuple):
145
- if not args:
146
- return tuple(value)
147
- if len(args) == 2 and args[1] is Ellipsis: # Tuple[T, ...]
148
- elem_t = args[0]
149
- return tuple(Serialization._coerce_value(v, elem_t) for v in (value or []))
150
- return tuple(Serialization._coerce_value(v, t) for v, t in zip(value, args))
151
-
152
- if origin in (dict, Dict):
153
- k_t, v_t = args or (Any, Any)
154
- return {
155
- Serialization._coerce_value(k, k_t): Serialization._coerce_value(v, v_t)
156
- for k, v in (value or {}).items()
157
- }
158
-
159
- # If `typ` has _from_json_ and value is a dict, use it
160
- if hasattr(typ, "_from_json_") and isinstance(value, dict):
161
- log.info(f"Deserializing {typ} from json method with value: {value}")
162
- return typ._from_json_(value)
163
-
164
- # If already the right type, keep it
165
- try:
166
- if isinstance(value, typ):
167
- return value
168
- except TypeError:
169
- log.debug(f"Could not coerce value '{value}' to type '{typ}'")
170
- pass # `typ` may be a typing construct not valid for isinstance
171
-
172
- # Fallback: leave as-is
173
- log.debug(f"Returning '{type(value)}' type")
174
- return value
175
-
176
- @staticmethod
177
- def get_class_fields(cls_name) -> Dict:
178
- from typing import List, Optional
179
- from gedcomx.Attribution import Attribution
180
- from gedcomx.Document import Document , DocumentType, TextType
181
- from gedcomx.Note import Note
182
- from gedcomx.Resource import Resource
183
- from gedcomx.SourceReference import SourceReference
184
- from gedcomx.extensions.rs10.rsLink import _rsLinkList
185
- from gedcomx.Conclusion import ConfidenceLevel
186
- from gedcomx.EvidenceReference import EvidenceReference
187
- from gedcomx.Identifier import IdentifierList
188
- from gedcomx.Gender import Gender, GenderType
189
- from gedcomx.Fact import Fact
190
- from gedcomx.Name import Name
191
- from gedcomx.URI import URI
192
- from gedcomx.Qualifier import Qualifier
193
- from gedcomx.PlaceDescription import PlaceDescription
194
- from gedcomx.PlaceReference import PlaceReference
195
- from gedcomx.Person import Person
196
- from gedcomx.Relationship import Relationship, RelationshipType
197
- from gedcomx.Identifier import Identifier
198
- from gedcomx.Date import Date
199
- from gedcomx.TextValue import TextValue
200
- from gedcomx.Address import Address
201
- from gedcomx.OnlineAccount import OnlineAccount
202
- from gedcomx.Event import Event, EventType, EventRole
203
- from .SourceDescription import SourceDescription
204
-
205
- fields = { 'Conclusion' : {
206
- "id": str,
207
- "lang": str,
208
- "sources": List["SourceReference"],
209
- "analysis": Document | Resource,
210
- "notes": List[Note],
211
- "confidence": ConfidenceLevel,
212
- "attribution": Attribution,
213
- "uri": "Resource",
214
- "max_note_count": int,
215
- "links": _rsLinkList
216
- },
217
- 'Subject' : {
218
- "id": str,
219
- "lang": str,
220
- "sources": List["SourceReference"],
221
- "analysis": Resource,
222
- "notes": List["Note"],
223
- "confidence": ConfidenceLevel,
224
- "attribution": Attribution,
225
- "extracted": bool,
226
- "evidence": List[EvidenceReference],
227
- "media": List[SourceReference],
228
- "identifiers": IdentifierList,
229
- "uri": Resource,
230
- "links": _rsLinkList
231
- },
232
- 'Person' : {
233
- "id": str,
234
- "lang": str,
235
- "sources": List[SourceReference],
236
- "analysis": Resource,
237
- "notes": List[Note],
238
- "confidence": ConfidenceLevel,
239
- "attribution": Attribution,
240
- "extracted": bool,
241
- "evidence": List[EvidenceReference],
242
- "media": List[SourceReference],
243
- "identifiers": IdentifierList,
244
- "private": bool,
245
- "gender": Gender,
246
- "names": List[Name],
247
- "facts": List[Fact],
248
- "living": bool,
249
- "links": _rsLinkList,
250
- 'uri': Resource
251
- },
252
- 'SourceReference' : {
253
- "description": SourceDescription | URI | Resource,
254
- "descriptionId": str,
255
- "attribution": Attribution,
256
- "qualifiers": List[Qualifier],
257
- },
258
- 'Attribution' : {
259
- "contributor": Resource | Attribution,
260
- "modified": str,
261
- "changeMessage": str,
262
- "creator": Resource | Attribution,
263
- "created": str
264
- },
265
- 'Gender' : {
266
- "id": str,
267
- "lang": str,
268
- "sources": List[SourceReference],
269
- "analysis": Resource,
270
- "notes": List[Note],
271
- "confidence": ConfidenceLevel,
272
- "attribution": Attribution,
273
- "type": GenderType,
274
- },
275
- 'PlaceReference' : {
276
- "original": str,
277
- "description": PlaceDescription | URI,
278
- },
279
- 'Relationship' : {
280
- "id": str,
281
- "lang": str,
282
- "sources": List[SourceReference],
283
- "analysis": Document | Resource,
284
- "notes": List[Note],
285
- "confidence": ConfidenceLevel,
286
- "attribution": Attribution,
287
- "extracted": bool,
288
- "evidence": List[EvidenceReference],
289
- "media": List[SourceReference],
290
- "identifiers": IdentifierList,
291
- "type": RelationshipType,
292
- "person1": Person | Resource,
293
- "person2": Person | Resource,
294
- "facts": List[Fact],
295
- },
296
- 'Document' : {
297
- "id": str,
298
- "lang": str,
299
- "sources": List[SourceReference],
300
- "analysis": Resource,
301
- "notes": List[Note],
302
- "confidence": ConfidenceLevel,
303
- "attribution": Attribution,
304
- "type": DocumentType,
305
- "extracted": bool,
306
- "textType": TextType,
307
- "text": str,
308
- },
309
- 'PlaceDescription' : {
310
- "id": str,
311
- "lang": str,
312
- "sources": List[SourceReference],
313
- "analysis": Resource,
314
- "notes": List[Note],
315
- "confidence": ConfidenceLevel,
316
- "attribution": Attribution,
317
- "extracted": bool,
318
- "evidence": List[EvidenceReference],
319
- "media": List[SourceReference],
320
- "identifiers": List[IdentifierList],
321
- "names": List[TextValue],
322
- "type": str,
323
- "place": URI,
324
- "jurisdiction": Resource | PlaceDescription,
325
- "latitude": float,
326
- "longitude": float,
327
- "temporalDescription": Date,
328
- "spatialDescription": Resource,
329
- },
330
- "Agent" : {
331
- "id": str,
332
- "identifiers": IdentifierList,
333
- "names": List[TextValue],
334
- "homepage": URI,
335
- "openid": URI,
336
- "accounts": List[OnlineAccount],
337
- "emails": List[URI],
338
- "phones": List[URI],
339
- "addresses": List[Address],
340
- "person": object | Resource, # intended to be Person | Resource
341
- # "xnotes": List[Note], # commented out in your __init__
342
- "attribution": object, # for GEDCOM5/7 compatibility
343
- "uri": URI | Resource,
344
- },
345
- 'Event' : {
346
- "id": str,
347
- "lang": str,
348
- "sources": List[SourceReference],
349
- "analysis": Resource,
350
- "notes": List[Note],
351
- "confidence": ConfidenceLevel,
352
- "attribution": Attribution,
353
- "extracted": bool,
354
- "evidence": List[EvidenceReference],
355
- "media": List[SourceReference],
356
- "identifiers": List[Identifier],
357
- "type": EventType,
358
- "date": Date,
359
- "place": PlaceReference,
360
- "roles": List[EventRole],
361
- }
362
-
363
- }
364
-
365
-
366
- return fields[cls_name] if cls_name in fields else {}
367
-
368
- @staticmethod
369
- def deserialize(data: dict[str, Any], class_type) -> Any:
370
- """
371
- Deserialize `data` according to `fields` (field -> type).
372
- - Primitives are assigned directly.
373
- - Objects use `type._from_json_(dict)` when present.
374
- - Lists/Sets/Tuples/Dicts are recursively processed.
375
- Returns (result, unknown_keys).
376
- """
377
- log.debug(f"Deserializing '{data}' into '{class_type.__name__}'")
378
- class_fields = Serialization.get_class_fields(str(class_type.__name__))
379
- if class_fields == {}:
380
- log.warning(f"No class fields found for '{class_type.__name__}'")
381
- log.debug(f"class fields: {class_fields}")
382
- result: dict[str, Any] = {}
383
- known = set(class_fields.keys())
384
- log.debug(f"keys found in JSON: {data.keys()}")
385
- #log.debug(f"known fields: {known}")
386
- for name, typ in class_fields.items():
387
- if name in data:
388
- log.debug(f"Field '{name}' of {class_type.__name__} found in data")
389
- result[name] = Serialization._coerce_value(data[name], typ)
390
- #if type(result[name]) != class_fields[name]:# TODO Write better type checking
391
- # log.error(f"Field '{name}' of {class_type.__name__} was expected to be of type '{class_fields[name]}', but got '{type(result[name])}' with value '{result[name]}'")
392
- # raise TypeError(f"Field '{name}' expected type '{class_fields[name]}', got '{type(result[name])}'")
393
- log.debug(f"Field '{name}' of '{class_type.__name__}' resulted in a '{type(result[name]).__name__}' with value '{result[name]}'")
394
- else:
395
- log.debug(f"Field '{name}' of '{class_type.__name__}' not found in JSON data")
396
-
397
- unknown_keys = [k for k in data.keys() if k not in known]
398
- log.info(f"Creating instance of {class_type.__name__} with fields: {result.keys()}")
399
- new_cls = class_type(**result)
400
- log.debug(f"Deserialized {class_type.__name__} with unknown keys: {unknown_keys}")
401
- return new_cls # type: ignore, unknown_keys