gedcom-x 0.5.1__py3-none-any.whl → 0.5.2__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: gedcom-x
3
- Version: 0.5.1
3
+ Version: 0.5.2
4
4
  Summary: Python implimentation of gedcom-x standard
5
5
  Author-email: "David J. Cartwright" <davidcartwright@hotmail.com>
6
6
  License: MIT
@@ -0,0 +1,42 @@
1
+ gedcomx/Address.py,sha256=b_4X1w_FX6vPwpo4dVez7QlI5jn8w3dC0bWUlv_0IjM,4810
2
+ gedcomx/Agent.py,sha256=4o1Gi_l_QsEgLLZzvFZ4SNUvla0O01jzUBXPniNcQ1g,8304
3
+ gedcomx/Attribution.py,sha256=FVEjOiJorne1gxbL6CBwThC4CUfynVklpOsfVSO-pCg,3800
4
+ gedcomx/Conclusion.py,sha256=lpMGr_S-KdVAB5L0h9L1d0qZOMJZGeCy90YplB1F3i8,6490
5
+ gedcomx/Coverage.py,sha256=FuVsLDAhzS4HjNHKOHCjwQcvnxd4Uf_EeF3QcDEbems,912
6
+ gedcomx/Date.py,sha256=N6-gDOLLCT_3_5bhS_4REP25LzEnOJpE6hNlMaYqxMA,2216
7
+ gedcomx/Document.py,sha256=uSTEgtu1s8V_2IJaCxVS6A20Ho06FOUUZ7GWLeOmV8w,2231
8
+ gedcomx/Event.py,sha256=x2jpWu27WCaksvNAGzsJ499rsugcbJ1DVELc-rBnFXo,9563
9
+ gedcomx/EvidenceReference.py,sha256=WXZpmcKzwb3lYQmGVf-TY2IsbNG3fIInPY1khRjtOSg,348
10
+ gedcomx/Exceptions.py,sha256=fzYtJ8d9C3oN-NMl0VMBc3U6ED41yu23dN885-_9brI,383
11
+ gedcomx/Fact.py,sha256=emh3WsN-4mzSFXHt-3DffRLK9JPctG-PzRcrJkIcuao,24396
12
+ gedcomx/Gedcom.py,sha256=v7XM0x8VX77uPPe5T3vB8AIxDhV65evXXW_kvH_HtXo,14954
13
+ gedcomx/GedcomX.py,sha256=jaLLYA4J6k9jFOKfLeus0g0RWyKtmqycKkDrrp6iZLs,62456
14
+ gedcomx/Gender.py,sha256=SH7ZyjSQ2Vi9PEQKN0uTZrKOma79QO7a_dJ-2lpMp0c,3925
15
+ gedcomx/Group.py,sha256=VNI_cI_-YnJ9cHzwMmHD8qwDNMe89kEocPuQ67rwStA,1606
16
+ gedcomx/Identifier.py,sha256=PIk2NedDm9a3XHJiX_hHv17xYqVpR2OVEIrxPM7jV88,6617
17
+ gedcomx/Logging.py,sha256=vBDOjawVXc4tCge1laYjy6_2Ves-fnGzG0m6NnLZejE,624
18
+ gedcomx/Name.py,sha256=xQWdvtSjd6jr-OnG73oMqqz0zaCcy-R3ChJ5KYnNECc,12733
19
+ gedcomx/Note.py,sha256=cvV4-fCZ0oh2zXfzD-YYoIM_WTox-fk2_bfl3i4CoNc,2251
20
+ gedcomx/OnlineAccount.py,sha256=P24o98IXo_8XQoICYZPgALjdzS0q8t2l4DU3Od9KxyI,291
21
+ gedcomx/Person.py,sha256=IwCyxcbqdKxo0uN8O6R3FznES27ZSvM_kAIPcZwLoTg,9298
22
+ gedcomx/PlaceDescription.py,sha256=doU2sAMZQIpfTi-sKAeo_mCitUfOOgy_G5OrRJ8YjBk,2934
23
+ gedcomx/PlaceReference.py,sha256=ti7cFxKTd-1sTB5tGmPyTnYIxLZ7CF7_YCHbF9m-4K0,1137
24
+ gedcomx/Qualifier.py,sha256=mZ_GWT3gca8g9nWidlXIRTN5dEtf_rmnLHYl1jJkQYs,728
25
+ gedcomx/Relationship.py,sha256=2Ng6eNYHisusWUE-ufHfgGjU99dDBMx6ySRRsp3prnk,4959
26
+ gedcomx/Resource.py,sha256=iBymUXv1-2u6qVVKsS16NaU6I_pYFZpN9mDz2vVUzLY,1650
27
+ gedcomx/Serialization.py,sha256=wy-XRSM7Q9MyQ_dVP8gv8mwZ8a-bS7znSS-2DV6XOLU,2819
28
+ gedcomx/SourceCitation.py,sha256=aW-lEb7bT9QU49GiBjJppFMBvtisR6fhVVuXjr5y4vQ,742
29
+ gedcomx/SourceDescription.py,sha256=LBYp2s5WfH0jENYIog53OnnuzTPXwqjOy4CxsMT6Ud0,11883
30
+ gedcomx/SourceReference.py,sha256=rHq0aD8wkNFj1hlm2cwd-RQe1C5GosDLDwg6-8fl9VU,7571
31
+ gedcomx/Subject.py,sha256=1EqvKvudtZ8ky9QYFqQqAeaPzSsdWpAeeorvW05vxCM,3223
32
+ gedcomx/TextValue.py,sha256=6B0wMxL0nigFNzhXZDhbTONvFGbnM2t2NcDZiZuu4Zw,1112
33
+ gedcomx/TopLevelTypeCollection.py,sha256=nvTO6GwFwEZk9jX4fVqhy75ygsshomNb20tnlExKqyY,1495
34
+ gedcomx/URI.py,sha256=SSxp8QWdxgEmD4sOgfjBFWG3kqoDtWg0IHSTQXbfhU8,4230
35
+ gedcomx/Zip.py,sha256=lBxcv-Vip45884EHj56wZJJ5I36Q38UuHUidDxQBoS8,14
36
+ gedcomx/_Links.py,sha256=--7d7PA80EeKCLtDOGOMp8QjLB679qnmVmHHakucEoo,972
37
+ gedcomx/__init__.py,sha256=Bv5g_0UT2dHfzpD4k-AuVDfUgbJHqj5ee16ExFvQxXs,1439
38
+ gedcomx/g7interop.py,sha256=KO4EQrvoGBSEPzLkWtO7E8-oZHmzL-q-_QRLQjhUNo4,9944
39
+ gedcom_x-0.5.2.dist-info/METADATA,sha256=4GZGTw_sws2qevHyOPaFE6WuPmz8C-PWWNIXg42DCLY,633
40
+ gedcom_x-0.5.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
41
+ gedcom_x-0.5.2.dist-info/top_level.txt,sha256=smVBF4nxSU-mzCd6idtRYTbYjPICMMi8pTqewEmqF8Y,8
42
+ gedcom_x-0.5.2.dist-info/RECORD,,
gedcomx/Address.py CHANGED
@@ -1,7 +1,28 @@
1
1
  from typing import Optional
2
2
  import json
3
3
 
4
+ from .Serialization import Serialization
5
+
4
6
  class Address:
7
+ """A GedcomX Address Data Type
8
+ A GedcomX Address Data Type.
9
+
10
+ Represents a postal address according to the GedcomX conceptual model.
11
+
12
+ Args:
13
+ value (str, optional): A complete address as a single string.
14
+ city (str, optional): Name of the city or town.
15
+ country (str, optional): Name of the country.
16
+ postalCode (str, optional): Postal or ZIP code.
17
+ stateOrProvince (str, optional): Name of the state, province, or region.
18
+ street (str, optional): First street address line.
19
+ street2 (str, optional): Second street address line.
20
+ street3 (str, optional): Third street address line.
21
+ street4 (str, optional): Fourth street address line.
22
+ street5 (str, optional): Fifth street address line.
23
+ street6 (str, optional): Sixth street address line.
24
+ """
25
+
5
26
  identifier = "http://gedcomx.org/v1/Address"
6
27
  version = 'http://gedcomx.org/conceptual-model/v1'
7
28
 
@@ -30,17 +51,24 @@ class Address:
30
51
  self.street6 = street6
31
52
 
32
53
  @property
33
- def value(self) -> Optional[str]:
34
- if self._value:
35
- return self._value
54
+ def value(self) -> str:
36
55
  return ', '.join(filter(None, [
37
- self._street, self._street2, self._street3,
38
- self._street4, self._street5, self._street6,
39
- self._city, self._stateOrProvince,
40
- self._postalCode, self._country
56
+ self.street, self.street2, self.street3,
57
+ self.street4, self.street5, self.street6,
58
+ self.city, self.stateOrProvince,
59
+ self.postalCode, self.country
41
60
  ]))
42
61
 
43
-
62
+ @value.setter
63
+ def value(self,value: str):
64
+ raise NotImplementedError("Parsing of a full address is not implimented.")
65
+
66
+ def _append(self,value):
67
+ if self._value:
68
+ self._value = self._value + ' ' + value
69
+ else:
70
+ self._value = value
71
+
44
72
  def __eq__(self, other):
45
73
  if not isinstance(other, self.__class__):
46
74
  return False
@@ -82,9 +110,8 @@ class Address:
82
110
  return ', '.join(filtered_parts)
83
111
 
84
112
  @property
85
- def __as_dict__(self):
86
- return {
87
- #"value": self._value if self._value else None,
113
+ def _as_dict_(self):
114
+ type_as_dict = {
88
115
  "city": self.city if self.city else None,
89
116
  "country": self.country if self.country else None,
90
117
  "postalCode": self.postalCode if self.postalCode else None,
@@ -97,4 +124,6 @@ class Address:
97
124
  "street6": self.street6 if self.street6 else None
98
125
  }
99
126
 
127
+ return Serialization.serialize_dict(type_as_dict)
128
+
100
129
 
gedcomx/Agent.py CHANGED
@@ -4,12 +4,49 @@ import uuid
4
4
  from typing import List, Optional
5
5
 
6
6
  from .Address import Address
7
- from .Identifier import Identifier
7
+ #from .Attribution import Attribution
8
+ from .Identifier import Identifier, IdentifierList
9
+
8
10
  from .OnlineAccount import OnlineAccount
9
11
  from .TextValue import TextValue
12
+ from .Resource import Resource
10
13
  from .URI import URI
14
+ from .Serialization import Serialization
15
+
11
16
 
12
17
  class Agent:
18
+ """A GedcomX Agent Data Type.
19
+
20
+ Represents an agent entity such as a person, organization, or software
21
+ responsible for creating or modifying genealogical data, as defined in
22
+ the GedcomX conceptual model.
23
+
24
+ Static Methods:
25
+ default_id_generator(): Generates a short, URL-safe Base64-encoded UUID
26
+ for use as a default agent identifier.
27
+
28
+ Args:
29
+ id (str, optional): A unique identifier for this agent. If not provided,
30
+ one may be generated automatically using `default_id_generator()`.
31
+ identifiers (IdentifierList, optional): A list of alternate identifiers for this agent.
32
+ names (List[TextValue], optional): Names associated with the agent. Defaults to an empty list.
33
+ homepage (URI, optional): A link to the agent's homepage or primary website.
34
+ openid (URI, optional): The OpenID identifier for the agent.
35
+ accounts (List[OnlineAccount], optional): Online accounts associated with the agent.
36
+ Defaults to an empty list.
37
+ emails (List[URI], optional): Email addresses associated with the agent.
38
+ Defaults to an empty list.
39
+ phones (List[Resource], optional): Phone numbers associated with the agent.
40
+ Defaults to an empty list.
41
+ addresses (List[Address], optional): Postal addresses associated with the agent.
42
+ Defaults to an empty list.
43
+ person (Person, optional): A reference to the person represented
44
+ by the agent. Accepts a `Person` object or a `Resource` reference.
45
+ Declared as `object` to avoid circular imports.
46
+ attribution (Attribution, optional): Attribution information related to the agent.
47
+ uri (Resource, optional): A URI reference for this agent.
48
+ """
49
+
13
50
  @staticmethod
14
51
  def default_id_generator():
15
52
  # Generate a standard UUID
@@ -21,7 +58,7 @@ class Agent:
21
58
  return short_uuid
22
59
 
23
60
  def __init__(self, id: Optional[str] = None,
24
- identifiers: Optional[List[Identifier]] = [],
61
+ identifiers: Optional[IdentifierList] = None,
25
62
  names: Optional[List[TextValue]] = [],
26
63
  homepage: Optional[URI] = None,
27
64
  openid: Optional[URI] = None,
@@ -29,25 +66,33 @@ class Agent:
29
66
  emails: Optional[List[URI]] = [],
30
67
  phones: Optional[List[URI]] = [],
31
68
  addresses: Optional[List[Address]] = [],
32
- person: Optional[object] | Optional[URI] = None, # should be of Type 'Person', 'object' to avoid circular imports
33
- uri: URI = None):
69
+ person: Optional[object] | Optional[Resource] = None, # should be of Type 'Person', 'object' to avoid circular imports
70
+ #xnotes: Optional[List[Note]] = None,
71
+ attribution: Optional[object] = None, # Added for compatibility with GEDCOM5/7 Imports
72
+ uri: Optional[URI | Resource] = None):
34
73
 
35
74
  self._id_generator = Agent.default_id_generator
36
75
 
37
- self.id = id if id else self._id_generator()
38
- self.identifiers = identifiers
39
- self.names = names
40
- self.homepage = homepage
41
- self.openid = openid
42
- self.accounts = accounts
43
- self.emails = emails
44
- self.phones = phones
45
- self.addresses = addresses
46
-
47
- self._uri = URI(fragment="agent:"+ self.id)
48
-
76
+ self.id = id if id else None #TODO self._id_generator()
77
+ self.identifiers = identifiers or IdentifierList()
78
+ self.names = names if names else []
79
+ self.homepage = homepage or None
80
+ self.openid = openid or None
81
+ self.accounts = accounts or []
82
+ self.emails = emails or []
83
+ self.phones = phones or []
84
+ self.addresses = addresses if addresses else []
85
+ self.xnotes = []
86
+ self.attribution = attribution or None
87
+ self.uri = URI(fragment=self.id)
88
+
49
89
  def _append_to_name(self, text_to_append: str):
50
- self.names[0].value = self.names[0].value + text_to_append
90
+ if self.names and self.names[0] and self.names[0].value:
91
+ self.names[0].value = self.names[0].value + text_to_append
92
+ elif self.names and self.names[0]:
93
+ self.names[0].value = text_to_append
94
+ else:
95
+ raise ValueError() #TODO
51
96
 
52
97
  def add_address(self, address_to_add: Address):
53
98
  if address_to_add and isinstance(address_to_add, Address):
@@ -68,16 +113,77 @@ class Agent:
68
113
  else:
69
114
  raise ValueError(f'name must be of type str or TextValue, recived {type(name_to_add)}')
70
115
 
116
+ def add_note(self, note_to_add: 'Note'):
117
+ from .Note import Note
118
+ if note_to_add and isinstance(note_to_add,Note):
119
+ self.xnotes.append(note_to_add)
120
+ else:
121
+ raise ValueError(f'note must be of type Note, recived {type(note_to_add)}')
122
+
123
+ def add_identifier(self, identifier_to_add: Identifier):
124
+ self.identifiers.append(identifier_to_add)
125
+
71
126
  @property
72
- def __as_dict__(self):
73
- return {
127
+ def _as_dict_(self):
128
+ type_as_dict = {
74
129
  "id": self.id if self.id else None,
75
- "identifiers": [identifier.__as_dict__() for identifier in self.identifiers],
76
- "names": [name._prop_dict() for name in self.names],
130
+ "identifiers": self.identifiers._as_dict_ if self.identifiers else None,
131
+ "names": [name._as_dict_ for name in self.names],
77
132
  "homepage": self.homepage if self.homepage else None,
78
133
  "openid": self.openid if self.openid else None,
79
134
  "accounts": self.accounts if self.accounts else None,
80
135
  "emails": self.emails if self.emails else None,
81
136
  "phones": self.phones if self.phones else None,
82
- "addresses": [address.__as_dict__ for address in self.addresses]
83
- }
137
+ "addresses": [address._as_dict_ for address in self.addresses],
138
+ "notes": [note._as_dict_ for note in self.xnotes]
139
+ }
140
+ return Serialization.serialize_dict(type_as_dict)
141
+
142
+ def __str__(self):
143
+ """
144
+ Return a human-readable string representation of the Agent.
145
+
146
+ Returns:
147
+ str: A concise description including ID, primary name (if any), and type of agent.
148
+ """
149
+ primary_name = self.names[0].value if self.names else "Unnamed Agent"
150
+ homepage_str = f", homepage={self.homepage}" if self.homepage else ""
151
+ return f"Agent(id={self.id}, name='{primary_name}'{homepage_str})"
152
+
153
+ def __eq__(self, other):
154
+ """
155
+ Determine equality between two Agent instances.
156
+
157
+ Args:
158
+ other (Agent): The other object to compare against.
159
+
160
+ Returns:
161
+ bool: True if both objects represent the same agent, False otherwise.
162
+ """
163
+ '''
164
+ if not isinstance(other, Agent):
165
+ return NotImplemented
166
+
167
+ return (
168
+ self.id == other.id and
169
+ self.identifiers == other.identifiers and
170
+ self.names == other.names and
171
+ self.homepage == other.homepage and
172
+ self.openid == other.openid and
173
+ self.accounts == other.accounts and
174
+ self.emails == other.emails and
175
+ self.phones == other.phones and
176
+ self.addresses == other.addresses and
177
+ self.person == other.person and
178
+ self.attribution == other.attribution and
179
+ self.uri == other.uri
180
+ )
181
+ '''
182
+ print(other)
183
+ print(self)
184
+ self_names = {n.value for n in self.names if hasattr(n, "value")}
185
+ other_names = {n.value for n in other.names if hasattr(n, "value")}
186
+ if self_names & other_names: # intersection not empty
187
+ return True
188
+
189
+ return False
gedcomx/Attribution.py CHANGED
@@ -1,67 +1,52 @@
1
+
1
2
  from datetime import datetime
2
3
  from typing import Optional, Dict, Any
3
4
 
4
- from .URI import URI
5
+ from .Agent import Agent
6
+ from .Resource import Resource, get_resource_as_dict
7
+ from .Serialization import Serialization
5
8
 
6
9
  class Attribution:
7
- identifier = 'http://gedcomx.org/v1/Attribution'
8
- version = 'http://gedcomx.org/conceptual-model/v1'
10
+ """Attribution Information for a Genealogy, Conclusion, Subject and child classes
11
+
12
+ Args:
13
+ contributor (Agent): Contributor to object being attributed.
14
+ modified (timestamp): timestamp for when this record was modified.
15
+ changeMessage (str): Birth date (YYYY-MM-DD).
16
+ creator (Agent, optional): Creator of object being attributed.
17
+ created (timestamp): timestamp for when this record was created
9
18
 
10
- def __init__(self,contributor: Optional[URI],
11
- modified: Optional[datetime],
12
- changeMessage: Optional[str],
13
- creator: Optional[URI],
14
- created: Optional[datetime]) -> None:
19
+ Raises:
15
20
 
21
+ """
22
+ identifier = 'http://gedcomx.org/v1/Attribution'
23
+ version = 'http://gedcomx.org/conceptual-model/v1'
16
24
 
17
- from .Agent import Agent
18
- self._contributor_object = None
25
+ def __init__(self,contributor: Optional[Agent | Resource] = None,
26
+ modified: Optional[datetime] = None,
27
+ changeMessage: Optional[str] = None,
28
+ creator: Optional[Agent | Resource] = None,
29
+ created: Optional[datetime] = None) -> None:
30
+
31
+ self.contributor = contributor
19
32
  self.modified = modified
20
33
  self.changeMessage = changeMessage
21
34
  self.creator = creator
22
35
  self.created = created
23
-
24
-
25
- if isinstance(contributor,URI):
26
- # TODO DEAL WITH URI <------------------------------------------------------------------------------------------------------------------
27
- self._contributor_object = contributor
28
- elif isinstance(contributor,Agent):
29
- self._contributor_object = contributor
30
- if hasattr(contributor,'_uri'):
31
- self.contributor = contributor._uri
32
- else:
33
- assert False
34
- self.description = URI(object=description)
35
- description._uri = self.description
36
- description._object = description
37
- else:
38
- raise ValueError(f"'description' must be of type 'SourceDescription' or 'URI', type: {type(contributor)} was provided, with value: {contributor}")
39
-
36
+
40
37
  @property
41
38
  def _as_dict_(self) -> Dict[str, Any]:
42
39
  """
43
40
  Serialize Attribution to a JSON-ready dict, skipping None values.
44
41
  """
45
- def _fmt_dt(dt: datetime) -> str:
46
- # ISO 8601 format
47
- return dt.isoformat()
48
-
49
- data: Dict[str, Any] = {}
50
- if self._contributor_object:
51
- data['contributor'] = (self._contributor_object._as_dict_
52
- if hasattr(self._contributor_object, '_as_dict_') else
53
- None)
54
- if self.created:
55
- data['created'] = _fmt_dt(self.created)
56
- if self.creator:
57
- data['creator'] = (self.creator._prop_dict()
58
- if hasattr(self.creator, '_prop_dict') else
59
- self.creator._prop_dict())
60
- if self.modified:
61
- data['modified'] = _fmt_dt(self.modified)
62
- if self.changeMessage is not None:
63
- data['changeMessage'] = self.changeMessage
64
- return data
42
+ type_as_dict: Dict[str, Any] = {}
43
+ type_as_dict['contributor'] = get_resource_as_dict(self.contributor)
44
+ type_as_dict['modified'] = self.modified if self.modified else None
45
+ type_as_dict['changeMessage'] = self.changeMessage if self.changeMessage else None
46
+ type_as_dict['creator'] = get_resource_as_dict(self.creator)
47
+ type_as_dict['created'] = self.created if self.created else None
48
+
49
+ return Serialization.serialize_dict(type_as_dict)
65
50
 
66
51
  @classmethod
67
52
  def _from_json_(cls, data: Dict[str, Any]) -> 'Attribution':
@@ -70,22 +55,21 @@ class Attribution:
70
55
  Handles 'created' and 'modified' as ISO strings or epoch ms ints.
71
56
  """
72
57
  # contributor
58
+
73
59
  contrib = None
74
60
  if 'contributor' in data:
75
- raw = data['contributor']
76
- if isinstance(raw, dict):
77
- contrib = URI._from_json_(raw)
78
- elif isinstance(raw, str):
79
- contrib = URI(uri=raw)
61
+ contrib_data = data['contributor']
62
+
63
+ contrib = Resource(contrib_data['resource'],contrib_data['resourceId'])
80
64
 
81
65
  # creator
82
66
  creat = None
83
67
  if 'creator' in data:
84
68
  raw = data['creator']
85
69
  if isinstance(raw, dict):
86
- creat = URI._from_json_(raw)
70
+ creat = Resource._from_json_(raw)
87
71
  elif isinstance(raw, str):
88
- creat = URI(uri=raw)
72
+ creat = Resource(uri=raw)
89
73
 
90
74
  # parse created date
91
75
  raw_created = data.get('created')
gedcomx/Conclusion.py CHANGED
@@ -5,10 +5,15 @@ import warnings
5
5
  from typing import List, Optional
6
6
 
7
7
  from .Attribution import Attribution
8
+ #from .Document import Document
8
9
  from .Note import Note
9
10
  from .Qualifier import Qualifier
11
+ from .Serialization import Serialization
10
12
  from .SourceReference import SourceReference
11
- from .URI import URI
13
+ from .Resource import Resource, URI
14
+ from ._Links import _LinkList, _Link
15
+
16
+ from collections.abc import Sized
12
17
 
13
18
  class ConfidenceLevel(Qualifier):
14
19
  High = "http://gedcomx.org/High"
@@ -25,6 +30,37 @@ class ConfidenceLevel(Qualifier):
25
30
  return descriptions.get(self, "No description available.")
26
31
 
27
32
  class Conclusion:
33
+ """
34
+ Represents a conclusion in the GEDCOM X conceptual model. A conclusion is a
35
+ genealogical assertion about a person, relationship, or event, derived from
36
+ one or more sources, with optional supporting metadata such as confidence,
37
+ attribution, and notes.
38
+
39
+ Args:
40
+ id (str, optional): A unique identifier for the conclusion. If not provided,
41
+ a UUID-based identifier will be automatically generated.
42
+ lang (str, optional): The language code of the conclusion. Defaults to 'en'.
43
+ sources (list[SourceReference], optional): A list of source references that
44
+ support the conclusion.
45
+ analysis (Document | Resource, optional): A reference to an analysis document
46
+ or resource that supports the conclusion.
47
+ notes (list[Note], optional): A list of notes providing additional context.
48
+ Defaults to an empty list.
49
+ confidence (ConfidenceLevel, optional): The contributor's confidence in the
50
+ conclusion (High, Medium, or Low).
51
+ attribution (Attribution, optional): Information about who contributed the
52
+ conclusion and when.
53
+ uri (Resource, optional): A URI reference for the conclusion. Defaults to a
54
+ URI with the fragment set to the `id`.
55
+ links (_LinkList, optional): A list of links associated with the conclusion.
56
+ Defaults to an empty `_LinkList`.
57
+
58
+ Methods:
59
+ add_note(note_to_add): Adds a note if it is not a duplicate and does not
60
+ exceed the maximum allowed notes.
61
+ add_source(source_to_add): Adds a source reference if it is not already present.
62
+ add_link(link): Adds a link to the `_LinkList`.
63
+ """
28
64
  identifier = 'http://gedcomx.org/v1/Conclusion'
29
65
  version = 'http://gedcomx.org/conceptual-model/v1'
30
66
 
@@ -41,28 +77,30 @@ class Conclusion:
41
77
  def __init__(self,
42
78
  id: Optional[str],
43
79
  lang: Optional[str] = 'en',
44
- sources: Optional[List[SourceReference]] = [],
45
- analysis: Optional[URI] = None,
80
+ sources: Optional[List[SourceReference]] = None,
81
+ analysis: Optional[object | Resource] = None,
46
82
  notes: Optional[List[Note]] = [],
47
83
  confidence: Optional[ConfidenceLevel] = None,
48
84
  attribution: Optional[Attribution] = None,
49
- uri: Optional[URI] = None,
50
- max_note_count: int = 20) -> None:
85
+ uri: Optional[Resource] = None,
86
+ _max_note_count: int = 20,
87
+ links: Optional[_LinkList] = None) -> None:
51
88
 
52
89
  self._id_generator = Conclusion.default_id_generator
53
90
 
54
91
  self.id = id if id else self._id_generator()
55
92
  self.lang = lang
56
- self.sources = sources
93
+ self.sources = sources if sources else []
57
94
  self.analysis = analysis
58
- self.notes = notes
95
+ self.notes = notes if notes else []
59
96
  self.confidence = confidence
60
97
  self.attribution = attribution
61
- self.max_note_count = max_note_count
62
- self._uri = uri if uri else URI(fragment=id)
98
+ self.max_note_count = _max_note_count
99
+ self.uri = uri if uri else URI(fragment=id)
100
+ self.links = links if links else _LinkList() #NOTE This is not in specification, following FS format
63
101
 
64
102
  def add_note(self,note_to_add: Note):
65
- if len(self.notes) >= self.max_note_count:
103
+ if self.notes and len(self.notes) >= self.max_note_count:
66
104
  warnings.warn(f"Max not count of {self.max_note_count} reached for id: {self.id}")
67
105
  return False
68
106
  if note_to_add and isinstance(note_to_add,Note):
@@ -79,48 +117,25 @@ class Conclusion:
79
117
  self.sources.append(source_to_add)
80
118
  else:
81
119
  raise ValueError()
82
-
83
- '''
84
- def _as_dict_(self):
85
- return {
86
- 'id':self.id,
87
- 'lang':self.lang,
88
- 'sources': [source._prop_dict() for source in self.sources] if self.sources else None,
89
- 'analysis': self.analysis._uri if self.analysis else None,
90
- 'notes':"Add notes here",
91
- 'confidence':self.confidence
92
- }
93
- '''
120
+
121
+ def add_link(self,link: _Link):
122
+ if link and isinstance(link,_Link):
123
+ self.links.add(link)
94
124
 
95
125
  @property
96
126
  def _as_dict_(self):
97
- def _serialize(value):
98
- if isinstance(value, (str, int, float, bool, type(None))):
99
- return value
100
- elif isinstance(value, dict):
101
- return {k: _serialize(v) for k, v in value.items()}
102
- elif isinstance(value, (list, tuple, set)):
103
- return [_serialize(v) for v in value]
104
- elif hasattr(value, "_as_dict_"):
105
- return value._as_dict_
106
- else:
107
- return str(value) # fallback for unknown objects
108
-
109
- # Only add Relationship-specific fields
110
- conclusion_fields = {
127
+ type_as_dict = {
111
128
  'id':self.id,
112
129
  'lang':self.lang,
113
- 'sources': [source for source in self.sources] if self.sources else None,
114
- 'analysis': self.analysis._uri if self.analysis else None,
130
+ 'sources': [source._as_dict_ for source in self.sources] if self.sources else None,
131
+ 'analysis': self.analysis if self.analysis else None,
115
132
  'notes': [note for note in self.notes] if self.notes else None,
116
- 'confidence':self.confidence
133
+ 'confidence':self.confidence,
134
+ 'attribution':self.attribution,
135
+ 'links':self.links._as_dict_ if self.links else None
117
136
  }
118
-
119
- # Serialize and exclude None values
120
- for key, value in conclusion_fields.items():
121
- if value is not None:
122
- conclusion_fields[key] = _serialize(value)
123
- return conclusion_fields
137
+
138
+ return Serialization.serialize_dict(type_as_dict)
124
139
 
125
140
  def __eq__(self, other):
126
141
  if not isinstance(other, self.__class__):