gedcom-x 0.5__tar.gz → 0.5.2__tar.gz
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.
- {gedcom_x-0.5 → gedcom_x-0.5.2}/PKG-INFO +1 -1
- {gedcom_x-0.5 → gedcom_x-0.5.2}/gedcom_x.egg-info/PKG-INFO +1 -1
- {gedcom_x-0.5 → gedcom_x-0.5.2}/gedcom_x.egg-info/SOURCES.txt +7 -2
- {gedcom_x-0.5 → gedcom_x-0.5.2}/gedcomx/Address.py +40 -11
- gedcom_x-0.5.2/gedcomx/Agent.py +189 -0
- gedcom_x-0.5.2/gedcomx/Attribution.py +100 -0
- {gedcom_x-0.5 → gedcom_x-0.5.2}/gedcomx/Conclusion.py +60 -45
- gedcom_x-0.5.2/gedcomx/Date.py +70 -0
- {gedcom_x-0.5 → gedcom_x-0.5.2}/gedcomx/Document.py +19 -9
- {gedcom_x-0.5 → gedcom_x-0.5.2}/gedcomx/Event.py +4 -4
- {gedcom_x-0.5 → gedcom_x-0.5.2}/gedcomx/EvidenceReference.py +2 -2
- gedcom_x-0.5.2/gedcomx/Exceptions.py +10 -0
- {gedcom_x-0.5 → gedcom_x-0.5.2}/gedcomx/Fact.py +70 -46
- {gedcom_x-0.5 → gedcom_x-0.5.2}/gedcomx/Gedcom.py +111 -37
- {gedcom_x-0.5 → gedcom_x-0.5.2}/gedcomx/GedcomX.py +405 -175
- gedcom_x-0.5.2/gedcomx/Gender.py +101 -0
- {gedcom_x-0.5 → gedcom_x-0.5.2}/gedcomx/Group.py +3 -3
- gedcom_x-0.5.2/gedcomx/Identifier.py +172 -0
- gedcom_x-0.5.2/gedcomx/Logging.py +19 -0
- {gedcom_x-0.5 → gedcom_x-0.5.2}/gedcomx/Name.py +67 -38
- {gedcom_x-0.5 → gedcom_x-0.5.2}/gedcomx/Note.py +5 -4
- {gedcom_x-0.5 → gedcom_x-0.5.2}/gedcomx/OnlineAccount.py +2 -2
- {gedcom_x-0.5 → gedcom_x-0.5.2}/gedcomx/Person.py +88 -33
- {gedcom_x-0.5 → gedcom_x-0.5.2}/gedcomx/PlaceDescription.py +22 -8
- {gedcom_x-0.5 → gedcom_x-0.5.2}/gedcomx/PlaceReference.py +7 -5
- {gedcom_x-0.5 → gedcom_x-0.5.2}/gedcomx/Relationship.py +19 -9
- gedcom_x-0.5.2/gedcomx/Resource.py +61 -0
- gedcom_x-0.5.2/gedcomx/Serialization.py +80 -0
- {gedcom_x-0.5 → gedcom_x-0.5.2}/gedcomx/SourceCitation.py +6 -1
- {gedcom_x-0.5 → gedcom_x-0.5.2}/gedcomx/SourceDescription.py +89 -72
- {gedcom_x-0.5 → gedcom_x-0.5.2}/gedcomx/SourceReference.py +25 -14
- {gedcom_x-0.5 → gedcom_x-0.5.2}/gedcomx/Subject.py +10 -8
- {gedcom_x-0.5 → gedcom_x-0.5.2}/gedcomx/TextValue.py +2 -1
- gedcom_x-0.5.2/gedcomx/URI.py +104 -0
- gedcom_x-0.5.2/gedcomx/Zip.py +1 -0
- gedcom_x-0.5.2/gedcomx/_Links.py +37 -0
- {gedcom_x-0.5 → gedcom_x-0.5.2}/gedcomx/__init__.py +4 -2
- gedcom_x-0.5.2/gedcomx/g7interop.py +205 -0
- {gedcom_x-0.5 → gedcom_x-0.5.2}/pyproject.toml +1 -1
- {gedcom_x-0.5 → gedcom_x-0.5.2}/setup.py +1 -1
- gedcom_x-0.5/gedcomx/Agent.py +0 -83
- gedcom_x-0.5/gedcomx/Attribution.py +0 -116
- gedcom_x-0.5/gedcomx/Date.py +0 -29
- gedcom_x-0.5/gedcomx/Gender.py +0 -48
- gedcom_x-0.5/gedcomx/Identifier.py +0 -89
- gedcom_x-0.5/gedcomx/Serialization.py +0 -37
- gedcom_x-0.5/gedcomx/URI.py +0 -70
- gedcom_x-0.5/gedcomx/_Resource.py +0 -11
- {gedcom_x-0.5 → gedcom_x-0.5.2}/gedcom_x.egg-info/dependency_links.txt +0 -0
- {gedcom_x-0.5 → gedcom_x-0.5.2}/gedcom_x.egg-info/top_level.txt +0 -0
- {gedcom_x-0.5 → gedcom_x-0.5.2}/gedcomx/Coverage.py +0 -0
- {gedcom_x-0.5 → gedcom_x-0.5.2}/gedcomx/Qualifier.py +0 -0
- {gedcom_x-0.5 → gedcom_x-0.5.2}/gedcomx/TopLevelTypeCollection.py +0 -0
- {gedcom_x-0.5 → gedcom_x-0.5.2}/setup.cfg +0 -0
@@ -13,12 +13,14 @@ gedcomx/Date.py
|
|
13
13
|
gedcomx/Document.py
|
14
14
|
gedcomx/Event.py
|
15
15
|
gedcomx/EvidenceReference.py
|
16
|
+
gedcomx/Exceptions.py
|
16
17
|
gedcomx/Fact.py
|
17
18
|
gedcomx/Gedcom.py
|
18
19
|
gedcomx/GedcomX.py
|
19
20
|
gedcomx/Gender.py
|
20
21
|
gedcomx/Group.py
|
21
22
|
gedcomx/Identifier.py
|
23
|
+
gedcomx/Logging.py
|
22
24
|
gedcomx/Name.py
|
23
25
|
gedcomx/Note.py
|
24
26
|
gedcomx/OnlineAccount.py
|
@@ -27,6 +29,7 @@ gedcomx/PlaceDescription.py
|
|
27
29
|
gedcomx/PlaceReference.py
|
28
30
|
gedcomx/Qualifier.py
|
29
31
|
gedcomx/Relationship.py
|
32
|
+
gedcomx/Resource.py
|
30
33
|
gedcomx/Serialization.py
|
31
34
|
gedcomx/SourceCitation.py
|
32
35
|
gedcomx/SourceDescription.py
|
@@ -35,5 +38,7 @@ gedcomx/Subject.py
|
|
35
38
|
gedcomx/TextValue.py
|
36
39
|
gedcomx/TopLevelTypeCollection.py
|
37
40
|
gedcomx/URI.py
|
38
|
-
gedcomx/
|
39
|
-
gedcomx/
|
41
|
+
gedcomx/Zip.py
|
42
|
+
gedcomx/_Links.py
|
43
|
+
gedcomx/__init__.py
|
44
|
+
gedcomx/g7interop.py
|
@@ -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) ->
|
34
|
-
if self._value:
|
35
|
-
return self._value
|
54
|
+
def value(self) -> str:
|
36
55
|
return ', '.join(filter(None, [
|
37
|
-
self.
|
38
|
-
self.
|
39
|
-
self.
|
40
|
-
self.
|
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
|
86
|
-
|
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
|
|
@@ -0,0 +1,189 @@
|
|
1
|
+
import base64
|
2
|
+
import uuid
|
3
|
+
|
4
|
+
from typing import List, Optional
|
5
|
+
|
6
|
+
from .Address import Address
|
7
|
+
#from .Attribution import Attribution
|
8
|
+
from .Identifier import Identifier, IdentifierList
|
9
|
+
|
10
|
+
from .OnlineAccount import OnlineAccount
|
11
|
+
from .TextValue import TextValue
|
12
|
+
from .Resource import Resource
|
13
|
+
from .URI import URI
|
14
|
+
from .Serialization import Serialization
|
15
|
+
|
16
|
+
|
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
|
+
|
50
|
+
@staticmethod
|
51
|
+
def default_id_generator():
|
52
|
+
# Generate a standard UUID
|
53
|
+
standard_uuid = uuid.uuid4()
|
54
|
+
# Convert UUID to bytes
|
55
|
+
uuid_bytes = standard_uuid.bytes
|
56
|
+
# Encode bytes to a Base64 string
|
57
|
+
short_uuid = base64.urlsafe_b64encode(uuid_bytes).rstrip(b'=').decode('utf-8')
|
58
|
+
return short_uuid
|
59
|
+
|
60
|
+
def __init__(self, id: Optional[str] = None,
|
61
|
+
identifiers: Optional[IdentifierList] = None,
|
62
|
+
names: Optional[List[TextValue]] = [],
|
63
|
+
homepage: Optional[URI] = None,
|
64
|
+
openid: Optional[URI] = None,
|
65
|
+
accounts: Optional[List[OnlineAccount]] = [],
|
66
|
+
emails: Optional[List[URI]] = [],
|
67
|
+
phones: Optional[List[URI]] = [],
|
68
|
+
addresses: Optional[List[Address]] = [],
|
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):
|
73
|
+
|
74
|
+
self._id_generator = Agent.default_id_generator
|
75
|
+
|
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
|
+
|
89
|
+
def _append_to_name(self, text_to_append: str):
|
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
|
96
|
+
|
97
|
+
def add_address(self, address_to_add: Address):
|
98
|
+
if address_to_add and isinstance(address_to_add, Address):
|
99
|
+
for current_address in self.addresses:
|
100
|
+
if address_to_add == current_address:
|
101
|
+
return False
|
102
|
+
self.addresses.append(address_to_add)
|
103
|
+
else:
|
104
|
+
raise ValueError(f"address must be of type Address, not {type(address_to_add)}")
|
105
|
+
|
106
|
+
def add_name(self, name_to_add: TextValue):
|
107
|
+
if isinstance(name_to_add,str): name_to_add = TextValue(value=name_to_add)
|
108
|
+
if name_to_add and isinstance(name_to_add,TextValue):
|
109
|
+
for current_name in self.names:
|
110
|
+
if name_to_add == current_name:
|
111
|
+
return
|
112
|
+
self.names.append(name_to_add)
|
113
|
+
else:
|
114
|
+
raise ValueError(f'name must be of type str or TextValue, recived {type(name_to_add)}')
|
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
|
+
|
126
|
+
@property
|
127
|
+
def _as_dict_(self):
|
128
|
+
type_as_dict = {
|
129
|
+
"id": self.id if self.id else None,
|
130
|
+
"identifiers": self.identifiers._as_dict_ if self.identifiers else None,
|
131
|
+
"names": [name._as_dict_ for name in self.names],
|
132
|
+
"homepage": self.homepage if self.homepage else None,
|
133
|
+
"openid": self.openid if self.openid else None,
|
134
|
+
"accounts": self.accounts if self.accounts else None,
|
135
|
+
"emails": self.emails if self.emails else None,
|
136
|
+
"phones": self.phones if self.phones else None,
|
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
|
@@ -0,0 +1,100 @@
|
|
1
|
+
|
2
|
+
from datetime import datetime
|
3
|
+
from typing import Optional, Dict, Any
|
4
|
+
|
5
|
+
from .Agent import Agent
|
6
|
+
from .Resource import Resource, get_resource_as_dict
|
7
|
+
from .Serialization import Serialization
|
8
|
+
|
9
|
+
class Attribution:
|
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
|
18
|
+
|
19
|
+
Raises:
|
20
|
+
|
21
|
+
"""
|
22
|
+
identifier = 'http://gedcomx.org/v1/Attribution'
|
23
|
+
version = 'http://gedcomx.org/conceptual-model/v1'
|
24
|
+
|
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
|
32
|
+
self.modified = modified
|
33
|
+
self.changeMessage = changeMessage
|
34
|
+
self.creator = creator
|
35
|
+
self.created = created
|
36
|
+
|
37
|
+
@property
|
38
|
+
def _as_dict_(self) -> Dict[str, Any]:
|
39
|
+
"""
|
40
|
+
Serialize Attribution to a JSON-ready dict, skipping None values.
|
41
|
+
"""
|
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)
|
50
|
+
|
51
|
+
@classmethod
|
52
|
+
def _from_json_(cls, data: Dict[str, Any]) -> 'Attribution':
|
53
|
+
"""
|
54
|
+
Construct Attribution from a dict (as parsed from JSON).
|
55
|
+
Handles 'created' and 'modified' as ISO strings or epoch ms ints.
|
56
|
+
"""
|
57
|
+
# contributor
|
58
|
+
|
59
|
+
contrib = None
|
60
|
+
if 'contributor' in data:
|
61
|
+
contrib_data = data['contributor']
|
62
|
+
|
63
|
+
contrib = Resource(contrib_data['resource'],contrib_data['resourceId'])
|
64
|
+
|
65
|
+
# creator
|
66
|
+
creat = None
|
67
|
+
if 'creator' in data:
|
68
|
+
raw = data['creator']
|
69
|
+
if isinstance(raw, dict):
|
70
|
+
creat = Resource._from_json_(raw)
|
71
|
+
elif isinstance(raw, str):
|
72
|
+
creat = Resource(uri=raw)
|
73
|
+
|
74
|
+
# parse created date
|
75
|
+
raw_created = data.get('created')
|
76
|
+
if isinstance(raw_created, (int, float)):
|
77
|
+
created_dt = datetime.fromtimestamp(raw_created / 1000.0)
|
78
|
+
elif isinstance(raw_created, str):
|
79
|
+
created_dt = datetime.fromisoformat(raw_created)
|
80
|
+
else:
|
81
|
+
created_dt = None
|
82
|
+
|
83
|
+
# parse modified date
|
84
|
+
raw_modified = data.get('modified')
|
85
|
+
if isinstance(raw_modified, (int, float)):
|
86
|
+
modified_dt = datetime.fromtimestamp(raw_modified / 1000.0)
|
87
|
+
elif isinstance(raw_modified, str):
|
88
|
+
modified_dt = datetime.fromisoformat(raw_modified)
|
89
|
+
else:
|
90
|
+
modified_dt = None
|
91
|
+
|
92
|
+
change_msg = data.get('changeMessage')
|
93
|
+
|
94
|
+
return cls(
|
95
|
+
contributor=contrib,
|
96
|
+
created=created_dt,
|
97
|
+
creator=creat,
|
98
|
+
modified=modified_dt,
|
99
|
+
changeMessage=change_msg
|
100
|
+
)
|
@@ -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 .
|
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[
|
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[
|
50
|
-
|
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 =
|
62
|
-
self.
|
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
|
-
|
85
|
-
|
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
|
-
|
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
|
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
|
-
|
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__):
|
@@ -0,0 +1,70 @@
|
|
1
|
+
from typing import Optional
|
2
|
+
from datetime import datetime, timezone
|
3
|
+
from dateutil import parser
|
4
|
+
import time
|
5
|
+
|
6
|
+
|
7
|
+
class DateFormat:
|
8
|
+
def __init__(self) -> None:
|
9
|
+
pass
|
10
|
+
|
11
|
+
class DateNormalization():
|
12
|
+
pass
|
13
|
+
|
14
|
+
class Date:
|
15
|
+
identifier = 'http://gedcomx.org/v1/Date'
|
16
|
+
version = 'http://gedcomx.org/conceptual-model/v1'
|
17
|
+
|
18
|
+
def __init__(self, original: Optional[str],normalized: Optional[DateNormalization] = None ,formal: Optional[str | DateFormat] = None) -> None:
|
19
|
+
self.orginal = original
|
20
|
+
self.formal = formal
|
21
|
+
|
22
|
+
self.normalized: DateNormalization | None = normalized if normalized else None
|
23
|
+
|
24
|
+
def _prop_dict(self):
|
25
|
+
return {'original': self.orginal,
|
26
|
+
'formal': self.formal}
|
27
|
+
|
28
|
+
@classmethod
|
29
|
+
def _from_json_(obj,data):
|
30
|
+
original = data.get('original',None)
|
31
|
+
formal = data.get('formal',None)
|
32
|
+
|
33
|
+
return Date(original=original,formal=formal)
|
34
|
+
|
35
|
+
|
36
|
+
Date._to_dict_ = lambda self: {
|
37
|
+
'original': self.orginal,
|
38
|
+
'formal': self.formal}
|
39
|
+
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
def date_to_timestamp(date_str: str, assume_utc_if_naive: bool = True, print_definition: bool = True):
|
44
|
+
"""
|
45
|
+
Convert a date string of various formats into a Unix timestamp.
|
46
|
+
|
47
|
+
A "timestamp" refers to an instance of time, including values for year,
|
48
|
+
month, date, hour, minute, second, and timezone.
|
49
|
+
"""
|
50
|
+
# Handle year ranges like "1894-1912" → pick first year
|
51
|
+
if "-" in date_str and date_str.count("-") == 1 and all(part.isdigit() for part in date_str.split("-")):
|
52
|
+
date_str = date_str.split("-")[0].strip()
|
53
|
+
|
54
|
+
# Parse date
|
55
|
+
dt = parser.parse(date_str)
|
56
|
+
|
57
|
+
# Ensure timezone awareness
|
58
|
+
if dt.tzinfo is None:
|
59
|
+
dt = dt.replace(tzinfo=timezone.utc if assume_utc_if_naive else datetime.now().astimezone().tzinfo)
|
60
|
+
|
61
|
+
# Normalize to UTC and compute timestamp
|
62
|
+
dt_utc = dt.astimezone(timezone.utc)
|
63
|
+
epoch = datetime(1970, 1, 1, tzinfo=timezone.utc)
|
64
|
+
ts = (dt_utc - epoch).total_seconds()
|
65
|
+
|
66
|
+
# Create ISO 8601 string with full date/time/timezone
|
67
|
+
full_timestamp_str = dt_utc.replace(microsecond=0).isoformat()
|
68
|
+
|
69
|
+
|
70
|
+
return ts, full_timestamp_str
|