Skip to content

Commit

Permalink
Merge pull request #265 from sbmlteam/relax_annot
Browse files Browse the repository at this point in the history
Relax annot
  • Loading branch information
fbergmann committed Aug 12, 2022
2 parents f5788b4 + bc15bea commit 326a82a
Show file tree
Hide file tree
Showing 11 changed files with 103 additions and 35 deletions.
2 changes: 1 addition & 1 deletion src/sbml/Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4578,7 +4578,7 @@ Model::readOtherXML (XMLInputStream& stream)
if (RDFAnnotationParser::hasHistoryRDFAnnotation(mAnnotation))
{
mHistory = RDFAnnotationParser::parseRDFAnnotation(mAnnotation,
getMetaId().c_str(), &(stream));
getMetaId().c_str(), &(stream), this);

if (mHistory != NULL && mHistory->hasRequiredAttributes() == false)
{
Expand Down
2 changes: 1 addition & 1 deletion src/sbml/SBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4712,7 +4712,7 @@ SBase::readAnnotation (XMLInputStream& stream)
if (RDFAnnotationParser::hasHistoryRDFAnnotation(mAnnotation))
{
mHistory = RDFAnnotationParser::parseRDFAnnotation(mAnnotation,
getMetaId().c_str(), &(stream));
getMetaId().c_str(), &(stream), this);
if (mHistory != NULL && mHistory->hasRequiredAttributes() == false)
{
logError(RDFNotCompleteModelHistory, getLevel(), getVersion(),
Expand Down
2 changes: 1 addition & 1 deletion src/sbml/SpeciesReference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1213,7 +1213,7 @@ SpeciesReference::readOtherXML (XMLInputStream& stream)
if (RDFAnnotationParser::hasHistoryRDFAnnotation(mAnnotation))
{
mHistory = RDFAnnotationParser::parseRDFAnnotation(mAnnotation,
getMetaId().c_str(), &(stream));
getMetaId().c_str(), &(stream), this);

if (mHistory != NULL && mHistory->hasRequiredAttributes() == false)
{
Expand Down
72 changes: 62 additions & 10 deletions src/sbml/annotation/ModelHistory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ LIBSBML_CPP_NAMESPACE_BEGIN
* Creates a new ModelHistory.
*/
ModelHistory::ModelHistory ():
mHasBeenModified (false)
mHasBeenModified (false),
mParentSBMLObject (NULL)
{
mCreatedDate = NULL;
// mModifiedDate = NULL;
Expand Down Expand Up @@ -112,6 +113,7 @@ ModelHistory::ModelHistory(const ModelHistory& orig)
mCreatedDate = NULL;
}
mHasBeenModified = orig.mHasBeenModified;
mParentSBMLObject = orig.mParentSBMLObject;

}

Expand Down Expand Up @@ -164,6 +166,7 @@ ModelHistory::operator=(const ModelHistory& rhs)
mCreatedDate = NULL;

mHasBeenModified = rhs.mHasBeenModified;
mParentSBMLObject = rhs.mParentSBMLObject;
}

return *this;
Expand Down Expand Up @@ -373,12 +376,25 @@ bool
ModelHistory::hasRequiredAttributes()
{
bool valid = true;

const SBase * parent = getParentSBMLObject();

if ( getNumCreators() < 1 ||
!isSetCreatedDate() ||
!isSetModifiedDate() )
if (parent == NULL || parent->getLevel() < 3)
{
if (getNumCreators() < 1 ||
!isSetCreatedDate() ||
!isSetModifiedDate())
{
return false;
}
}
else
{
valid = false;
// remove restriction that dates be present in L3
if (getNumCreators() < 1)
{
return false;
}
}

unsigned int i = 0;
Expand All @@ -394,15 +410,19 @@ ModelHistory::hasRequiredAttributes()
return valid;
}

valid = getCreatedDate()->representsValidDate();

if (!valid)
if (isSetCreatedDate())
{
return valid;
valid = getCreatedDate()->representsValidDate();
if (!valid)
{
return valid;
}
}
for (i = 0; i < getNumModifiedDates(); ++i)
i = 0;
while (valid && i < getNumModifiedDates())
{
valid = getModifiedDate(i)->representsValidDate();
i++;
}

return valid;
Expand Down Expand Up @@ -466,6 +486,38 @@ ModelHistory::resetModifiedFlags()
}
/** @endcond */

/** @cond doxygenLibsbmlInternal */

const SBase *
ModelHistory::getParentSBMLObject() const
{
return mParentSBMLObject;
}


bool
ModelHistory::isSetParentSBMLObject() const
{
return (mParentSBMLObject != NULL);
}


void
ModelHistory::setParentSBMLObject(const SBase * sb)
{
mParentSBMLObject = sb;
}


int
ModelHistory::unsetParentSBMLObject()
{
mParentSBMLObject = NULL;
return LIBSBML_OPERATION_SUCCESS;
}

/** @endcond */


#endif /* __cplusplus */

Expand Down
12 changes: 12 additions & 0 deletions src/sbml/annotation/ModelHistory.h
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,16 @@ class LIBSBML_EXTERN ModelHistory

protected:
/** @cond doxygenLibsbmlInternal */

// record the SBML Object on which this ModelHistory is set

const SBase * getParentSBMLObject() const;
bool isSetParentSBMLObject() const;
void setParentSBMLObject(const SBase * sb);
int unsetParentSBMLObject();

friend class RDFAnnotationParser;

/* Can have more than one creator. */

List * mCreators;
Expand All @@ -400,6 +410,8 @@ class LIBSBML_EXTERN ModelHistory
List * mModifiedDates;

bool mHasBeenModified;
const SBase *mParentSBMLObject;



/** @endcond */
Expand Down
10 changes: 8 additions & 2 deletions src/sbml/annotation/RDFAnnotationParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ ModelHistory*
RDFAnnotationParser::parseRDFAnnotation(
const XMLNode * annotation,
const char* metaId,
XMLInputStream* stream /*= NULL*/)
XMLInputStream* stream /*= NULL*/,
const SBase* parent)
{
ModelHistory * history = NULL;

Expand Down Expand Up @@ -310,7 +311,11 @@ RDFAnnotationParser::parseRDFAnnotation(
{
history = deriveHistoryFromAnnotation(annotation);
}

// add a parent SBase object with level and version
if (history != NULL && parent != NULL)
{
history->setParentSBMLObject(parent);
}
return history;
}

Expand Down Expand Up @@ -710,6 +715,7 @@ RDFAnnotationParser::parseModelHistory(const SBase *object)
{
return NULL;
}
history->setParentSBMLObject(object);

XMLNode *description = createRDFDescriptionWithHistory(object);

Expand Down
2 changes: 1 addition & 1 deletion src/sbml/annotation/RDFAnnotationParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class LIBSBML_EXTERN RDFAnnotationParser
* @return a pointer to the ModelHistory created.
*/
static ModelHistory* parseRDFAnnotation(const XMLNode *annotation,
const char* metaId = NULL, XMLInputStream* stream = NULL);
const char* metaId = NULL, XMLInputStream* stream = NULL, const SBase* parent = NULL);


/**
Expand Down
2 changes: 2 additions & 0 deletions src/sbml/annotation/test/TestRDFAnnotation2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ START_TEST (test_RDFAnnotation2_getModelHistory)
fail_unless(Date_getHoursOffset(date) == 0);
fail_unless(Date_getMinutesOffset(date) == 0);
fail_unless(!strcmp(Date_getDateAsString(date), "2007-01-16T15:31:52Z"));

fail_unless(ModelHistory_hasRequiredAttributes(history) == 1);
}
END_TEST

Expand Down
28 changes: 14 additions & 14 deletions src/sbml/annotation/test/TestRDFAnnotationNestedCVTerms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,9 @@ END_TEST

START_TEST (test_RDFAnnotationNestedCVTerm_dcterms_31)
{
ModelHistory * mh = m31->getModelHistory();
fail_unless(mh->hasRequiredAttributes() == true);

XMLNode* node = RDFAnnotationParser::parseModelHistory(m31);

fail_unless(node->getNumChildren() == 1);
Expand All @@ -600,7 +603,7 @@ START_TEST (test_RDFAnnotationNestedCVTerm_dcterms_31)
fail_unless(!strcmp(XMLNode_getName(desc), "Description"));
fail_unless(!strcmp(XMLNode_getPrefix(desc), "rdf"));
fail_unless(!strcmp(XMLNode_getURI(desc), "http://www.w3.org/1999/02/22-rdf-syntax-ns#"));
fail_unless(XMLNode_getNumChildren(desc) == 3);
fail_unless(XMLNode_getNumChildren(desc) == 2);

const XMLNode_t * creator = XMLNode_getChild(desc, 0);
fail_unless(!strcmp(XMLNode_getName(creator), "creator"));
Expand Down Expand Up @@ -671,17 +674,17 @@ START_TEST (test_RDFAnnotationNestedCVTerm_dcterms_31)
fail_unless(!strcmp(XMLNode_getURI(cr_date), "http://purl.org/dc/terms/"));
fail_unless(XMLNode_getNumChildren(cr_date) == 1);

const XMLNode_t * modified = XMLNode_getChild(desc, 2);
fail_unless(!strcmp(XMLNode_getName(modified), "modified"));
fail_unless(!strcmp(XMLNode_getPrefix(modified), "dcterms"));
fail_unless(!strcmp(XMLNode_getURI(modified), "http://purl.org/dc/terms/"));
fail_unless(XMLNode_getNumChildren(modified) == 1);
//const XMLNode_t * modified = XMLNode_getChild(desc, 2);
//fail_unless(!strcmp(XMLNode_getName(modified), "modified"));
//fail_unless(!strcmp(XMLNode_getPrefix(modified), "dcterms"));
//fail_unless(!strcmp(XMLNode_getURI(modified), "http://purl.org/dc/terms/"));
//fail_unless(XMLNode_getNumChildren(modified) == 1);

const XMLNode_t * mo_date = XMLNode_getChild(created, 0);
fail_unless(!strcmp(XMLNode_getName(mo_date), "W3CDTF"));
fail_unless(!strcmp(XMLNode_getPrefix(mo_date), "dcterms"));
fail_unless(!strcmp(XMLNode_getURI(mo_date), "http://purl.org/dc/terms/"));
fail_unless(XMLNode_getNumChildren(mo_date) == 1);
//const XMLNode_t * mo_date = XMLNode_getChild(created, 0);
//fail_unless(!strcmp(XMLNode_getName(mo_date), "W3CDTF"));
//fail_unless(!strcmp(XMLNode_getPrefix(mo_date), "dcterms"));
//fail_unless(!strcmp(XMLNode_getURI(mo_date), "http://purl.org/dc/terms/"));
//fail_unless(XMLNode_getNumChildren(mo_date) == 1);


delete node;
Expand Down Expand Up @@ -714,9 +717,6 @@ START_TEST(test_RDFAnnotationNestedCVTerm_writeDC_creator_31)
" <dcterms:created rdf:parseType=\"Resource\">\n"
" <dcterms:W3CDTF>2005-02-02T14:56:11</dcterms:W3CDTF>\n"
" </dcterms:created>\n"
" <dcterms:modified rdf:parseType=\"Resource\">\n"
" <dcterms:W3CDTF>2006-05-30T10:46:02</dcterms:W3CDTF>\n"
" </dcterms:modified>\n"
" </rdf:Description>\n"
" </rdf:RDF>\n"
" </annotation>\n"
Expand Down
3 changes: 1 addition & 2 deletions src/sbml/annotation/test/TestValidation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ END_TEST

START_TEST (test_Validation_ModelHistory1)
{

ModelHistory * mh = new ModelHistory();
fail_unless(mh != NULL);

Expand All @@ -157,7 +158,6 @@ START_TEST (test_Validation_ModelHistory1)

delete mh;
delete mc;
delete date;
}
END_TEST

Expand Down Expand Up @@ -222,7 +222,6 @@ START_TEST (test_Validation_ModelHistory3)
}
END_TEST


START_TEST (test_Validation_CVTerm1)
{
CVTerm * cv = new CVTerm();
Expand Down
3 changes: 0 additions & 3 deletions src/sbml/annotation/test/test-data/annotationNested-l3v1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
<dcterms:created rdf:parseType="Resource">
<dcterms:W3CDTF>2005-02-02T14:56:11</dcterms:W3CDTF>
</dcterms:created>
<dcterms:modified rdf:parseType="Resource">
<dcterms:W3CDTF>2006-05-30T10:46:02</dcterms:W3CDTF>
</dcterms:modified>
</rdf:Description>
</rdf:RDF>
</annotation>
Expand Down

0 comments on commit 326a82a

Please sign in to comment.