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

Data types are not being written on serialization #381

Open
tcmitchell opened this issue Aug 12, 2020 · 4 comments
Open

Data types are not being written on serialization #381

tcmitchell opened this issue Aug 12, 2020 · 4 comments
Assignees

Comments

@tcmitchell
Copy link
Collaborator

When dateTime types are written to RDF/XML the data type is not included. This probably happens on other types besides dateTime but I don't have specific examples.

We need to modify SBOL2Serialize.py to include the data type of Literals when it is present.

This is one of those issues that is going to pop up because SBOL 2 requires a special serialization and we cannot use the default provided by RDFLib. SBOL 3 fixes this issue.

@bbartley
Copy link
Collaborator

Hi,
I'm not sure that data types are supposed to be serialized. There are a couple of serialization examples of XML DateTimes in the 2.3.0 spec that show datetime serialization without the rdf:DataType. See secs. 12.7 and 13.1.1

@tcmitchell
Copy link
Collaborator Author

SBOL 2.3.0 section 13.1.1 is pretty convincing that data types should NOT be included. It says:

The serialization of an Activity MUST have the following form

And then gives the following example, which does not have data type specified:

<prov:Activity rdf:about="...">
    ... properties inherited from identified ...
    zero or more <prov:qualifiedAssociation>
                    <prov:Association rdf:about="...">...</prov:Association>
                 </prov:qualifiedAssociation> elements
    zero or more <prov:qualifiedUsage>
                    <prov:Usage rdf:about="...">...</prov:Usage>
                </prov:qualifiedUsage> elements
    zero or more <sbol:type rdf:resource="... "/> elements
    zero or one <prov:startedAtTime>...</prov:startedAtTime> element
    zero or one <prov:endedAtTime>...</prov:startedAtTime> element
    zero or more <prov:wasInformedBy rdf:resource="..."/> element
</prov:Activity>

It sounds like the behavior we have now, which is not including the datatype, is the specified syntax, and including it may be a bug.

Additionally, all examples of endedAtTime in SBOLTestSuite/SBOL2* do not include a datatype attribute.

@tcmitchell
Copy link
Collaborator Author

Here is a candidate fix in case we want it in the future:

diff --git a/sbol2/SBOL2Serialize.py b/sbol2/SBOL2Serialize.py
index c012d7d..2300f3d 100644
--- a/sbol2/SBOL2Serialize.py
+++ b/sbol2/SBOL2Serialize.py
@@ -111,7 +111,11 @@ def serialize_sboll2(g):
                 QName(rdfNS, 'resource'): obj.toPython()
             })
         elif isinstance(obj, Literal):
-            elem = etree.SubElement(element, prefixify(predicate, prefixes, True))
+            attrib = None
+            if obj.datatype:
+                attrib = {QName(rdfNS, 'datatype'): obj.datatype.toPython()}
+            elem = etree.SubElement(element, prefixify(predicate, prefixes, True),
+                                    attrib=attrib)
             elem.text = obj
         else:
             raise Exception()

@tcmitchell tcmitchell removed this from the 1.2 milestone Aug 12, 2020
@cjmyers
Copy link

cjmyers commented Aug 13, 2020

I would not infer from the lack of datatype in the serialization that it is not allowed. This is indeed one of the problems with including serialization examples in the document, which we no longer do in SBOL3. I would interpret the lack of mention is not that is disallowed, but that it does not say if is or is not required. Namely, it is optional. I think though it is good to include as it is more precise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants