Skip to content

Commit 89edf1a

Browse files
Merge pull request #38 from fabrizio-turchi/issue_5_message_thread
Issue 5 message thread
2 parents edfeea1 + e93506c commit 89edf1a

File tree

3 files changed

+169
-95
lines changed

3 files changed

+169
-95
lines changed

case.jsonld

Lines changed: 104 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -610,70 +610,147 @@
610610
]
611611
},
612612
{
613-
"@id": "kb:bb9cd337-eb51-50dd-9cee-00f9e9acbf94",
614-
"@type": "uco-observable:Message",
615-
"uco-observable:state": "some state",
616-
"uco-observable:hasChanged": {
617-
"@type": "xsd:boolean",
618-
"@value": true
619-
},
620-
"olo:length": null,
621-
"olo:slot": null,
613+
"@id": "kb:562c20c5-bef7-5919-a969-6c820a80e0d3",
614+
"@type": "uco-observable:ObservableObject",
622615
"uco-core:hasFacet": [
623616
{
624-
"@id": "kb:73af707b-f00e-5327-8fd4-83467b4441c4",
625-
"@type": "uco-observable:MessageFacet"
617+
"@id": "kb:bb9cd337-eb51-50dd-9cee-00f9e9acbf94",
618+
"@type": "uco-observable:ApplicationFacet",
619+
"uco-core:name": "Discord"
626620
}
627621
]
628622
},
629623
{
630-
"@id": "kb:7c4d5cff-deb0-5031-b881-c572d6ef2fd7",
624+
"@id": "kb:73af707b-f00e-5327-8fd4-83467b4441c4",
625+
"@type": "uco-observable:ObservableObject",
626+
"uco-core:hasFacet": [
627+
{
628+
"@id": "kb:7c4d5cff-deb0-5031-b881-c572d6ef2fd7",
629+
"@type": "uco-observable:AccountFacet",
630+
"uco-observable:isActive": {
631+
"@type": "xsd:boolean",
632+
"@value": true
633+
},
634+
"uco-observable:accountIdentifier": "11111007"
635+
},
636+
{
637+
"@id": "kb:551338f3-0bb6-5325-a63a-f164f8750a17",
638+
"@type": "uco-observable:ApplicationAccountFacet",
639+
"uco-observable:application": {
640+
"@id": "kb:562c20c5-bef7-5919-a969-6c820a80e0d3"
641+
}
642+
}
643+
]
644+
},
645+
{
646+
"@id": "kb:09b10c04-d04b-5808-a1b6-0392dd3a00e8",
647+
"@type": "uco-observable:ObservableObject",
648+
"uco-core:hasFacet": [
649+
{
650+
"@id": "kb:a19e1e1f-3953-5fb9-92b6-2b46f85752b2",
651+
"@type": "uco-observable:AccountFacet",
652+
"uco-observable:isActive": {
653+
"@type": "xsd:boolean",
654+
"@value": true
655+
},
656+
"uco-observable:accountIdentifier": "22222007"
657+
},
658+
{
659+
"@id": "kb:6f79d4ae-d92c-5cad-bbe5-a0afde6f475a",
660+
"@type": "uco-observable:ApplicationAccountFacet",
661+
"uco-observable:application": {
662+
"@id": "kb:562c20c5-bef7-5919-a969-6c820a80e0d3"
663+
}
664+
}
665+
]
666+
},
667+
{
668+
"@id": "kb:56f74818-1d3d-51f9-8cb1-d6bdc8ecee60",
631669
"@type": "uco-observable:Message",
670+
"uco-observable:hasChanged": {
671+
"@type": "xsd:boolean",
672+
"@value": true
673+
},
632674
"olo:length": null,
633675
"olo:slot": null,
634676
"uco-core:hasFacet": [
635677
{
636-
"@id": "kb:551338f3-0bb6-5325-a63a-f164f8750a17",
637-
"@type": "uco-observable:MessageFacet"
678+
"@id": "kb:90068d94-5aa6-5f18-8227-c3df1afe5486",
679+
"@type": "uco-observable:MessageFacet",
680+
"uco-observable:messageText": "Send me the instructions!",
681+
"uco-observable:sentTime": {
682+
"@type": "xsd:dateTime",
683+
"@value": "2024-01-02T16:55:01+00:00"
684+
},
685+
"uco-observable:from": {
686+
"@id": "kb:09b10c04-d04b-5808-a1b6-0392dd3a00e8"
687+
},
688+
"uco-observable:to": {
689+
"@id": "kb:73af707b-f00e-5327-8fd4-83467b4441c4"
690+
}
638691
}
639692
]
640693
},
641694
{
642-
"@id": "kb:09b10c04-d04b-5808-a1b6-0392dd3a00e8",
695+
"@id": "kb:f5cb2a76-a0b7-57b3-ae47-3c25c854326c",
643696
"@type": "uco-observable:Message",
697+
"uco-observable:hasChanged": {
698+
"@type": "xsd:boolean",
699+
"@value": true
700+
},
644701
"olo:length": null,
645702
"olo:slot": null,
646703
"uco-core:hasFacet": [
647704
{
648-
"@id": "kb:a19e1e1f-3953-5fb9-92b6-2b46f85752b2",
649-
"@type": "uco-observable:MessageFacet"
705+
"@id": "kb:ce971304-c510-54e8-937a-29b7bb15bb88",
706+
"@type": "uco-observable:MessageFacet",
707+
"uco-observable:messageText": "Sure, in a couple of hours you'lll receive them",
708+
"uco-observable:sentTime": {
709+
"@type": "xsd:dateTime",
710+
"@value": "2024-01-02T17:28:42+00:00"
711+
},
712+
"uco-observable:from": {
713+
"@id": "kb:73af707b-f00e-5327-8fd4-83467b4441c4"
714+
},
715+
"uco-observable:to": {
716+
"@id": "kb:09b10c04-d04b-5808-a1b6-0392dd3a00e8"
717+
}
650718
}
651719
]
652720
},
653721
{
654-
"@id": "kb:562c20c5-bef7-5919-a969-6c820a80e0d3",
722+
"@id": "kb:5c1c9e5f-e23c-5906-aa3e-d6257f984f77",
655723
"@type": "uco-observable:MessageThread",
724+
"uco-core:name": "Jenny D.",
656725
"uco-core:hasFacet": [
657726
{
658-
"@id": "kb:6f79d4ae-d92c-5cad-bbe5-a0afde6f475a",
727+
"@id": "kb:63032af7-e54e-5c72-af8f-7f078ad468fb",
659728
"@type": "uco-observable:MessageThreadFacet",
660-
"uco-observable:displayName": "some name",
729+
"uco-observable:visibility": {
730+
"@type": "xsd:boolean",
731+
"@value": true
732+
},
733+
"uco-observable:participant": [
734+
{
735+
"@id": "kb:73af707b-f00e-5327-8fd4-83467b4441c4"
736+
},
737+
{
738+
"@id": "kb:09b10c04-d04b-5808-a1b6-0392dd3a00e8"
739+
}
740+
],
661741
"uco-observable:messageThread": {
662-
"@id": "kb:56f74818-1d3d-51f9-8cb1-d6bdc8ecee60",
742+
"@id": "kb:935d87a1-0980-5cb7-8d99-b4001652ddbd",
663743
"@type": "uco-types:Thread",
664744
"co:size": {
665745
"@type": "xsd:nonNegativeInteger",
666-
"@value": "3"
746+
"@value": "2"
667747
},
668748
"co:element": [
669749
{
670-
"@id": "kb:09b10c04-d04b-5808-a1b6-0392dd3a00e8"
671-
},
672-
{
673-
"@id": "kb:7c4d5cff-deb0-5031-b881-c572d6ef2fd7"
750+
"@id": "kb:56f74818-1d3d-51f9-8cb1-d6bdc8ecee60"
674751
},
675752
{
676-
"@id": "kb:bb9cd337-eb51-50dd-9cee-00f9e9acbf94"
753+
"@id": "kb:f5cb2a76-a0b7-57b3-ae47-3c25c854326c"
677754
}
678755
]
679756
}

case_mapping/uco/observable.py

Lines changed: 13 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from datetime import datetime
2-
from typing import Dict
2+
from typing import Dict, Optional
33

44
from cdo_local_uuid import local_uuid
55
from pytz import timezone
@@ -1342,56 +1342,35 @@ def __init__(
13421342
class FacetMessagethread(FacetEntity):
13431343
def __init__(
13441344
self,
1345-
display_name=None,
1346-
visibility=None,
1345+
visibility: Optional[bool] = None,
13471346
participants=None,
13481347
messages=None,
13491348
):
13501349
"""
1351-
A message thread facet is a grouping of characteristics unique to a running commentary of electronic messages
1352-
pertaining to one topic or question.
1353-
:param messages: Adjacency matrix, encoded as a dictionary. Key: IRI of Message ObservableObject. Value: Set of IRIs of Message ObservableObjects.
1350+
A message thread facet is a grouping of characteristics unique to a running
1351+
commentary of electronic messages pertaining to one topic or question.
1352+
:param visibility: A boolean value to indicate if the thread is private (False) or
1353+
public (True).
1354+
:param participants: Array of Account ObservableObject,
1355+
:param messages: Array of Message ObservableObjects.
13541356
"""
13551357
super().__init__()
13561358
self["@type"] = "uco-observable:MessageThreadFacet"
1357-
self._str_vars(**{"uco-observable:displayName": display_name})
13581359
self._bool_vars(**{"uco-observable:visibility": visibility})
13591360
self._node_reference_vars(**{"uco-observable:participant": participants})
13601361

13611362
self["uco-observable:messageThread"] = {
13621363
"@id": self.prefix_label + ":" + local_uuid(),
13631364
"@type": "uco-types:Thread",
13641365
}
1365-
1366-
# How many messages are there?
1367-
_message_ids = set()
1368-
if messages is not None:
1369-
for message_id in messages:
1370-
_message_ids.add(message_id)
1371-
for next_message_id in messages[message_id]:
1372-
_message_ids.add(next_message_id)
13731366
self["uco-observable:messageThread"]["co:size"] = {
13741367
"@type": "xsd:nonNegativeInteger",
1375-
"@value": str(len(_message_ids)),
1368+
"@value": str(len(messages)),
13761369
}
1377-
if len(_message_ids) > 0:
1378-
_element_list = []
1379-
# TODO - Need to implement checker for thread having only one terminus.
1380-
# _item_list = []
1381-
for message_id in sorted(_message_ids):
1382-
_element = {"@id": message_id}
1383-
_element_list.append(_element)
1384-
_item = {
1385-
"@id": message_id,
1386-
"@type": "uco-types:ThreadItem",
1387-
"co:itemContent": {"@id": message_id},
1388-
}
1389-
if message_id in messages and len(messages[message_id]) > 0:
1390-
_next_items = []
1391-
for next_message_id in sorted(messages[message_id]):
1392-
_next_items.append({"@id": next_message_id})
1393-
_item["uco-types:threadNextItem"] = _next_items
1394-
self["uco-observable:messageThread"]["co:element"] = _element_list
1370+
list_id_messages = list()
1371+
for m in messages:
1372+
list_id_messages.append({"@id": m.get_id()})
1373+
self["uco-observable:messageThread"]["co:element"] = list_id_messages
13951374

13961375
def append_messages(self, messages):
13971376
raise NotImplementedError(

example.py

Lines changed: 52 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -285,50 +285,68 @@ def _next_timestamp() -> datetime:
285285
# A message thread to be added to the case #
286286
###########################################
287287

288-
message_thread_object = uco.observable.MessageThread()
288+
# Application Object
289+
app_object = uco.observable.ObservableObject()
290+
app_facet = uco.observable.FacetApplication(app_name="Discord")
291+
app_object.append_facets(app_facet)
292+
bundle.append_to_uco_object(app_object)
293+
294+
# Account 1
295+
id_account_object_1 = uco.observable.ObservableObject()
296+
id_account_facet_1 = uco.observable.FacetAccount(identifier="11111007")
297+
app_account_facet_1 = uco.observable.FacetApplicationAccount(application=app_object)
298+
id_account_object_1.append_facets(id_account_facet_1, app_account_facet_1)
299+
bundle.append_to_uco_object(id_account_object_1)
300+
301+
# Account 2
302+
id_account_object_2 = uco.observable.ObservableObject()
303+
id_account_facet_2 = uco.observable.FacetAccount(identifier="22222007")
304+
app_account_facet_2 = uco.observable.FacetApplicationAccount(application=app_object)
305+
id_account_object_2.append_facets(id_account_facet_2, app_account_facet_2)
306+
bundle.append_to_uco_object(id_account_object_2)
307+
289308

290309
# 1st message
291-
message_1 = uco.observable.Message(
310+
message_object_1 = uco.observable.Message(
292311
has_changed=True,
293-
state="some state",
294312
)
295-
facet_message_1 = uco.observable.FacetMessage()
296-
message_1.append_facets(facet_message_1)
313+
sent_datetime = datetime.strptime("2024-01-02T16:55:01", "%Y-%m-%dT%H:%M:%S")
314+
facet_message_1 = uco.observable.FacetMessage(
315+
msg_to=id_account_object_1,
316+
msg_from=id_account_object_2,
317+
message_text="Send me the instructions!",
318+
sent_time=sent_datetime,
319+
)
320+
321+
message_object_1.append_facets(facet_message_1)
322+
bundle.append_to_uco_object(message_object_1)
323+
297324
# 2nd message
298-
message_2 = uco.observable.Message()
299-
facet_message_2 = uco.observable.FacetMessage()
300-
message_2.append_facets(facet_message_2)
301-
# 3rd message
302-
message_3 = uco.observable.Message()
303-
facet_message_3 = uco.observable.FacetMessage()
304-
message_3.append_facets(facet_message_3)
305-
306-
# 1st message is followed by 2nd and 3rd message.
307-
# Create MessageThread
308-
message_thread_facet = uco.observable.FacetMessagethread(
309-
display_name="some name",
310-
messages={
311-
message_1["@id"]: {
312-
message_2["@id"],
313-
message_3["@id"],
314-
}
315-
},
325+
message_object_2 = uco.observable.Message(
326+
has_changed=True,
316327
)
317328

318-
message_thread_object.append_facets(message_thread_facet)
329+
sent_datetime = datetime.strptime("2024-01-02T17:28:42", "%Y-%m-%dT%H:%M:%S")
330+
facet_message_2 = uco.observable.FacetMessage(
331+
msg_to=id_account_object_2,
332+
msg_from=id_account_object_1,
333+
message_text="Sure, in a couple of hours you'lll receive them",
334+
sent_time=sent_datetime,
335+
)
319336

320-
# TODO Restore from list-style demo.
321-
# Append more messages to MessageThread
322-
# message_thread_facet.append_messages(messages=message_3)
337+
message_object_2.append_facets(facet_message_2)
338+
bundle.append_to_uco_object(message_object_2)
323339

324-
# Add all objects to bundle
325-
objs = (
326-
message_1,
327-
message_2,
328-
message_3,
329-
message_thread_object,
340+
# Create MessageThread
341+
message_thread_object = uco.observable.MessageThread(name="Jenny D.")
342+
message_thread_facet = uco.observable.FacetMessagethread(
343+
visibility=True,
344+
participants=[id_account_object_1, id_account_object_2],
345+
messages=[message_object_1, message_object_2],
330346
)
331-
bundle.append_to_uco_object(objs)
347+
348+
message_thread_object.append_facets(message_thread_facet)
349+
bundle.append_to_uco_object(message_thread_object)
332350

333351
##################
334352
# Print the case #

0 commit comments

Comments
 (0)