Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 5 message thread #38

Merged
merged 5 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 104 additions & 27 deletions case.jsonld
Original file line number Diff line number Diff line change
Expand Up @@ -610,70 +610,147 @@
]
},
{
"@id": "kb:bb9cd337-eb51-50dd-9cee-00f9e9acbf94",
"@type": "uco-observable:Message",
"uco-observable:state": "some state",
"uco-observable:hasChanged": {
"@type": "xsd:boolean",
"@value": true
},
"olo:length": null,
"olo:slot": null,
"@id": "kb:562c20c5-bef7-5919-a969-6c820a80e0d3",
"@type": "uco-observable:ObservableObject",
ajnelson-nist marked this conversation as resolved.
Show resolved Hide resolved
"uco-core:hasFacet": [
{
"@id": "kb:73af707b-f00e-5327-8fd4-83467b4441c4",
"@type": "uco-observable:MessageFacet"
"@id": "kb:bb9cd337-eb51-50dd-9cee-00f9e9acbf94",
"@type": "uco-observable:ApplicationFacet",
"uco-core:name": "Discord"
}
]
},
{
"@id": "kb:7c4d5cff-deb0-5031-b881-c572d6ef2fd7",
"@id": "kb:73af707b-f00e-5327-8fd4-83467b4441c4",
"@type": "uco-observable:ObservableObject",
"uco-core:hasFacet": [
{
"@id": "kb:7c4d5cff-deb0-5031-b881-c572d6ef2fd7",
"@type": "uco-observable:AccountFacet",
"uco-observable:isActive": {
"@type": "xsd:boolean",
"@value": true
},
"uco-observable:accountIdentifier": "11111007"
},
{
"@id": "kb:551338f3-0bb6-5325-a63a-f164f8750a17",
"@type": "uco-observable:ApplicationAccountFacet",
"uco-observable:application": {
"@id": "kb:562c20c5-bef7-5919-a969-6c820a80e0d3"
}
}
]
},
{
"@id": "kb:09b10c04-d04b-5808-a1b6-0392dd3a00e8",
"@type": "uco-observable:ObservableObject",
"uco-core:hasFacet": [
{
"@id": "kb:a19e1e1f-3953-5fb9-92b6-2b46f85752b2",
"@type": "uco-observable:AccountFacet",
"uco-observable:isActive": {
"@type": "xsd:boolean",
"@value": true
},
"uco-observable:accountIdentifier": "22222007"
},
{
"@id": "kb:6f79d4ae-d92c-5cad-bbe5-a0afde6f475a",
"@type": "uco-observable:ApplicationAccountFacet",
"uco-observable:application": {
"@id": "kb:562c20c5-bef7-5919-a969-6c820a80e0d3"
}
}
]
},
{
"@id": "kb:56f74818-1d3d-51f9-8cb1-d6bdc8ecee60",
"@type": "uco-observable:Message",
"uco-observable:hasChanged": {
"@type": "xsd:boolean",
"@value": true
},
"olo:length": null,
"olo:slot": null,
"uco-core:hasFacet": [
{
"@id": "kb:551338f3-0bb6-5325-a63a-f164f8750a17",
"@type": "uco-observable:MessageFacet"
"@id": "kb:90068d94-5aa6-5f18-8227-c3df1afe5486",
"@type": "uco-observable:MessageFacet",
"uco-observable:messageText": "Send me the instructions!",
"uco-observable:sentTime": {
"@type": "xsd:dateTime",
"@value": "2024-01-02T16:55:01+00:00"
},
"uco-observable:from": {
"@id": "kb:09b10c04-d04b-5808-a1b6-0392dd3a00e8"
},
"uco-observable:to": {
"@id": "kb:73af707b-f00e-5327-8fd4-83467b4441c4"
}
}
]
},
{
"@id": "kb:09b10c04-d04b-5808-a1b6-0392dd3a00e8",
"@id": "kb:f5cb2a76-a0b7-57b3-ae47-3c25c854326c",
"@type": "uco-observable:Message",
"uco-observable:hasChanged": {
"@type": "xsd:boolean",
"@value": true
},
"olo:length": null,
"olo:slot": null,
"uco-core:hasFacet": [
{
"@id": "kb:a19e1e1f-3953-5fb9-92b6-2b46f85752b2",
"@type": "uco-observable:MessageFacet"
"@id": "kb:ce971304-c510-54e8-937a-29b7bb15bb88",
"@type": "uco-observable:MessageFacet",
"uco-observable:messageText": "Sure, in a couple of hours you'lll receive them",
"uco-observable:sentTime": {
"@type": "xsd:dateTime",
"@value": "2024-01-02T17:28:42+00:00"
},
"uco-observable:from": {
"@id": "kb:73af707b-f00e-5327-8fd4-83467b4441c4"
},
"uco-observable:to": {
"@id": "kb:09b10c04-d04b-5808-a1b6-0392dd3a00e8"
}
}
]
},
{
"@id": "kb:562c20c5-bef7-5919-a969-6c820a80e0d3",
"@id": "kb:5c1c9e5f-e23c-5906-aa3e-d6257f984f77",
"@type": "uco-observable:MessageThread",
"uco-core:name": "Jenny D.",
"uco-core:hasFacet": [
{
"@id": "kb:6f79d4ae-d92c-5cad-bbe5-a0afde6f475a",
"@id": "kb:63032af7-e54e-5c72-af8f-7f078ad468fb",
"@type": "uco-observable:MessageThreadFacet",
"uco-observable:displayName": "some name",
"uco-observable:visibility": {
"@type": "xsd:boolean",
"@value": true
},
"uco-observable:participant": [
{
"@id": "kb:73af707b-f00e-5327-8fd4-83467b4441c4"
},
{
"@id": "kb:09b10c04-d04b-5808-a1b6-0392dd3a00e8"
}
],
"uco-observable:messageThread": {
"@id": "kb:56f74818-1d3d-51f9-8cb1-d6bdc8ecee60",
"@id": "kb:935d87a1-0980-5cb7-8d99-b4001652ddbd",
"@type": "uco-types:Thread",
"co:size": {
"@type": "xsd:nonNegativeInteger",
"@value": "3"
"@value": "2"
},
"co:element": [
{
"@id": "kb:09b10c04-d04b-5808-a1b6-0392dd3a00e8"
},
{
"@id": "kb:7c4d5cff-deb0-5031-b881-c572d6ef2fd7"
"@id": "kb:56f74818-1d3d-51f9-8cb1-d6bdc8ecee60"
},
{
"@id": "kb:bb9cd337-eb51-50dd-9cee-00f9e9acbf94"
"@id": "kb:f5cb2a76-a0b7-57b3-ae47-3c25c854326c"
}
]
}
Expand Down
43 changes: 11 additions & 32 deletions case_mapping/uco/observable.py
Original file line number Diff line number Diff line change
Expand Up @@ -1342,56 +1342,35 @@ def __init__(
class FacetMessagethread(FacetEntity):
def __init__(
self,
display_name=None,
visibility=None,
participants=None,
messages=None,
):
"""
A message thread facet is a grouping of characteristics unique to a running commentary of electronic messages
pertaining to one topic or question.
:param messages: Adjacency matrix, encoded as a dictionary. Key: IRI of Message ObservableObject. Value: Set of IRIs of Message ObservableObjects.
A message thread facet is a grouping of characteristics unique to a running
commentary of electronic messages pertaining to one topic or question.
:param visibility: A boolean value to indicate if the theead is private (False) or
public (True).
:param participants: Array of Account ObservableObject,
:param messages: Array of Message ObservableObjects.
"""
super().__init__()
self["@type"] = "uco-observable:MessageThreadFacet"
self._str_vars(**{"uco-observable:displayName": display_name})
self._bool_vars(**{"uco-observable:visibility": visibility})
ajnelson-nist marked this conversation as resolved.
Show resolved Hide resolved
self._node_reference_vars(**{"uco-observable:participant": participants})

self["uco-observable:messageThread"] = {
"@id": self.prefix_label + ":" + local_uuid(),
"@type": "uco-types:Thread",
}

# How many messages are there?
_message_ids = set()
if messages is not None:
for message_id in messages:
_message_ids.add(message_id)
for next_message_id in messages[message_id]:
_message_ids.add(next_message_id)
self["uco-observable:messageThread"]["co:size"] = {
"@type": "xsd:nonNegativeInteger",
"@value": str(len(_message_ids)),
"@value": str(len(messages)),
}
if len(_message_ids) > 0:
_element_list = []
# TODO - Need to implement checker for thread having only one terminus.
# _item_list = []
for message_id in sorted(_message_ids):
_element = {"@id": message_id}
_element_list.append(_element)
_item = {
"@id": message_id,
"@type": "uco-types:ThreadItem",
"co:itemContent": {"@id": message_id},
}
if message_id in messages and len(messages[message_id]) > 0:
_next_items = []
for next_message_id in sorted(messages[message_id]):
_next_items.append({"@id": next_message_id})
_item["uco-types:threadNextItem"] = _next_items
self["uco-observable:messageThread"]["co:element"] = _element_list
list_id_messages = list()
for m in messages:
list_id_messages.append({"@id": m.get_id()})
self["uco-observable:messageThread"]["co:element"] = list_id_messages

def append_messages(self, messages):
raise NotImplementedError(
Expand Down
86 changes: 52 additions & 34 deletions example.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,50 +285,68 @@ def _next_timestamp() -> datetime:
# A message thread to be added to the case #
###########################################

message_thread_object = uco.observable.MessageThread()
# Application Object
app_object = uco.observable.ObservableObject()
app_facet = uco.observable.FacetApplication(app_name="Discord")
app_object.append_facets(app_facet)
bundle.append_to_uco_object(app_object)

# Account 1
id_account_object_1 = uco.observable.ObservableObject()
id_account_facet_1 = uco.observable.FacetAccount(identifier="11111007")
app_account_facet_1 = uco.observable.FacetApplicationAccount(application=app_object)
id_account_object_1.append_facets(id_account_facet_1, app_account_facet_1)
bundle.append_to_uco_object(id_account_object_1)

# Account 2
id_account_object_2 = uco.observable.ObservableObject()
id_account_facet_2 = uco.observable.FacetAccount(identifier="22222007")
app_account_facet_2 = uco.observable.FacetApplicationAccount(application=app_object)
id_account_object_2.append_facets(id_account_facet_2, app_account_facet_2)
bundle.append_to_uco_object(id_account_object_2)


# 1st message
message_1 = uco.observable.Message(
message_object_1 = uco.observable.Message(
has_changed=True,
state="some state",
)
facet_message_1 = uco.observable.FacetMessage()
message_1.append_facets(facet_message_1)
sent_datetime = datetime.strptime("2024-01-02T16:55:01", "%Y-%m-%dT%H:%M:%S")
facet_message_1 = uco.observable.FacetMessage(
msg_to=id_account_object_1,
msg_from=id_account_object_2,
message_text="Send me the instructions!",
sent_time=sent_datetime,
)

message_object_1.append_facets(facet_message_1)
bundle.append_to_uco_object(message_object_1)

# 2nd message
message_2 = uco.observable.Message()
facet_message_2 = uco.observable.FacetMessage()
message_2.append_facets(facet_message_2)
# 3rd message
message_3 = uco.observable.Message()
facet_message_3 = uco.observable.FacetMessage()
message_3.append_facets(facet_message_3)

# 1st message is followed by 2nd and 3rd message.
# Create MessageThread
message_thread_facet = uco.observable.FacetMessagethread(
display_name="some name",
messages={
message_1["@id"]: {
message_2["@id"],
message_3["@id"],
}
},
message_object_2 = uco.observable.Message(
has_changed=True,
)

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

# TODO Restore from list-style demo.
# Append more messages to MessageThread
# message_thread_facet.append_messages(messages=message_3)
message_object_2.append_facets(facet_message_2)
bundle.append_to_uco_object(message_object_2)

# Add all objects to bundle
objs = (
message_1,
message_2,
message_3,
message_thread_object,
# Create MessageThread
message_thread_object = uco.observable.MessageThread(name="Jenny D.")
message_thread_facet = uco.observable.FacetMessagethread(
visibility=True,
participants=[id_account_object_1, id_account_object_2],
messages=[message_object_1, message_object_2],
)
bundle.append_to_uco_object(objs)

message_thread_object.append_facets(message_thread_facet)
bundle.append_to_uco_object(message_thread_object)

##################
# Print the case #
Expand Down
Loading