COPASI API  4.16.103
Public Member Functions | Private Member Functions | Private Attributes | List of all members
CRDFNode Class Reference

#include <CRDFNode.h>

Collaboration diagram for CRDFNode:
Collaboration graph
[legend]

Public Member Functions

CRDFTriplet addEdge (const CRDFPredicate &predicate, CRDFNode *pObject)
 
bool addTripletToGraph (const CRDFTriplet &triplet) const
 
 CRDFNode (CRDFGraph &graph)
 
std::set< CRDFTripletgetDescendantsWithPredicate (const CRDFPredicate &predicate) const
 
const std::string & getFieldValue (const CRDFPredicate::ePredicateType &predicate) const
 
const std::string & getId () const
 
CRDFObjectgetObject ()
 
const CRDFObjectgetObject () const
 
CRDFPredicate::Path getPath () const
 
const CRDFSubjectgetSubject () const
 
bool hasAncestor (const CRDFNode *pNode) const
 
bool isBagNode () const
 
bool isBlankNode () const
 
bool isObjectNode () const
 
bool isReadOnly () const
 
bool isSubjectNode () const
 
void removeEdge (const CRDFPredicate &predicate, CRDFNode *pObject)
 
void removeTripletFromGraph (const CRDFTriplet &triplet) const
 
bool setFieldValue (const CMIRIAMResourceObject &value, const CRDFPredicate::ePredicateType &predicate, const CRDFPredicate::Path &nodePath)
 
bool setFieldValue (const std::string &value, const CRDFPredicate::ePredicateType &predicate, const CRDFPredicate::Path &nodePath)
 
void setId (const std::string &id)
 
void setObject (const CRDFObject &object)
 
void setSubject (const CRDFSubject &subject)
 
 ~CRDFNode ()
 

Private Member Functions

 CRDFNode ()
 
 CRDFNode (const CRDFNode &CRDFNode)
 
CRDFNodecreateMissingAncestors (const CRDFPredicate::Path &nodePath, const CRDFPredicate::ePredicateType &predicate, CRDFPredicate::sAllowedLocation const *&pLocation)
 
CRDFNodecreateMissingAncestors (const CRDFPredicate::Path &predicatePath, const size_t &level)
 
CRDFNodeoperator= (const CRDFNode &rhs)
 

Private Attributes

CRDFGraphmGraph
 
std::string mId
 
bool mIsBlankNode
 
CRDFObjectmpObject
 
CRDFSubjectmpSubject
 

Detailed Description

Definition at line 38 of file CRDFNode.h.

Constructor & Destructor Documentation

CRDFNode::CRDFNode ( )
private

Default Constructor

CRDFNode::CRDFNode ( const CRDFNode CRDFNode)
private
CRDFNode::CRDFNode ( CRDFGraph graph)

Specific Constructor

Parameters
CRDFGraph& graph

Definition at line 32 of file CRDFNode.cpp.

32  :
33  mGraph(graph),
34  mId(""),
35  mpSubject(NULL),
36  mpObject(NULL),
37  mIsBlankNode(false)
38 {}
CRDFSubject * mpSubject
Definition: CRDFNode.h:241
CRDFObject * mpObject
Definition: CRDFNode.h:246
CRDFGraph & mGraph
Definition: CRDFNode.h:231
bool mIsBlankNode
Definition: CRDFNode.h:251
std::string mId
Definition: CRDFNode.h:236
CRDFNode::~CRDFNode ( )

Destructor

Definition at line 40 of file CRDFNode.cpp.

References mpObject, mpSubject, and pdelete.

41 {
44 }
#define pdelete(p)
Definition: copasi.h:215
CRDFSubject * mpSubject
Definition: CRDFNode.h:241
CRDFObject * mpObject
Definition: CRDFNode.h:246

Member Function Documentation

CRDFTriplet CRDFNode::addEdge ( const CRDFPredicate predicate,
CRDFNode pObject 
)

Add a property edge to the node.

Parameters
constCRDFPredicate & edge
CRDFNode* pObject
Returns
CRDFTriplet triplet

Definition at line 321 of file CRDFNode.cpp.

References CRDFGraph::addTriplet(), addTripletToGraph(), CRDFGraph::getTriplets(), isBagNode(), mGraph, CRDFPredicate::rdf_li, CRDFPredicate::rdf_type, CRDFObject::RESOURCE, CRDFObject::setResource(), and CRDFObject::setType().

Referenced by CRDFGraphConverter::convert(), CRDFGraph::moveTriplet(), and CBiologicalDescription::setPredicate().

322 {
323  CRDFTriplet Failed;
324  CRDFTriplet Triplet(this, predicate, pObject);
325 
326  // We do not want any duplicate triplets;
327  if (mGraph.getTriplets().count(Triplet) > 0)
328  return Failed;
329 
330  // If this is a bag node the only predicate allowed is rdf_li.
331  if (isBagNode() && predicate != CRDFPredicate::rdf_li)
332  return Failed;
333 
334  // If the predicate is rdf:li and this is not a bag node we bagify it.
335  if (!isBagNode() && predicate == CRDFPredicate::rdf_li)
336  {
337  // Bagify the node.
338  CRDFObject Object;
340  Object.setResource("http://www.w3.org/1999/02/22-rdf-syntax-ns#Bag", false);
341 
342  if (!mGraph.addTriplet(this->getSubject(), CRDFPredicate(CRDFPredicate::rdf_type), Object))
343  return Failed;
344  }
345 
346  // We now can safely insert any edge with the predicate rdf_li
347  if (predicate == CRDFPredicate::rdf_li)
348  {
349  if (!addTripletToGraph(Triplet))
350  return Failed;
351 
352  return Triplet;
353  }
354 
355  if (!addTripletToGraph(Triplet))
356  return Failed;
357 
358  return Triplet;
359 }
CRDFGraph & mGraph
Definition: CRDFNode.h:231
bool isBagNode() const
Definition: CRDFNode.cpp:423
void setType(const eObjectType &type)
Definition: CRDFObject.cpp:82
CRDFTriplet addTriplet(const CRDFSubject &subject, const CRDFPredicate &predicate, const CRDFObject &object)
Definition: CRDFGraph.cpp:141
const std::set< CRDFTriplet > & getTriplets() const
Definition: CRDFGraph.cpp:434
void setResource(const std::string &resource, const bool &isLocal)
Definition: CRDFObject.cpp:88
bool addTripletToGraph(const CRDFTriplet &triplet) const
Definition: CRDFGraph.cpp:678
bool CRDFNode::addTripletToGraph ( const CRDFTriplet triplet) const

This method is for internal use only. The method is declared public since friend declarations may not refer to public methods.

Parameters
constCRDFTriplet & triplet
Returns
bool success.

Definition at line 678 of file CRDFGraph.cpp.

References CRDFGraph::addTriplet(), and mGraph.

Referenced by addEdge().

679 {
680  return mGraph.addTriplet(triplet);
681 }
CRDFGraph & mGraph
Definition: CRDFNode.h:231
CRDFTriplet addTriplet(const CRDFSubject &subject, const CRDFPredicate &predicate, const CRDFObject &object)
Definition: CRDFGraph.cpp:141
CRDFNode * CRDFNode::createMissingAncestors ( const CRDFPredicate::Path nodePath,
const CRDFPredicate::ePredicateType predicate,
CRDFPredicate::sAllowedLocation const *&  pLocation 
)
private

Definition at line 246 of file CRDFNode.cpp.

References C_INVALID_INDEX, CRDFPredicate::getAllowedLocationList(), CRDFPredicate::getSubPathIndex(), and isSubjectNode().

Referenced by setFieldValue().

249 {
250  pLocation = NULL;
251 
252  // If this is not a subject node we are not able to do anything.
253  if (!isSubjectNode()) return NULL;
254 
255  // Determine the path leading to the field
257  size_t i, imax = Locations.size();
258  size_t SubPathIndex = C_INVALID_INDEX;
259 
260  for (i = 0; i < imax; i++)
261  {
262  // We ignore read only locations.
263  if (Locations[i].ReadOnly)
264  continue;
265 
266  SubPathIndex = CRDFPredicate::getSubPathIndex(Locations[i].Location, nodePath);
267 
268  if (SubPathIndex != C_INVALID_INDEX)
269  break;
270  }
271 
272  // The value can not be inserted
273  if (SubPathIndex == C_INVALID_INDEX)
274  return NULL;
275 
276  // Now we build each missing ancestor as a blank node.
277  CRDFNode * pParent = createMissingAncestors(Locations[i].Location, SubPathIndex);
278 
279  if (pParent != NULL)
280  pLocation = &Locations[i];
281 
282  return pParent;
283 }
std::vector< sAllowedLocation > AllowedLocationList
#define C_INVALID_INDEX
Definition: copasi.h:222
bool isSubjectNode() const
Definition: CRDFNode.cpp:414
static size_t getSubPathIndex(const Path &fullPath, const Path &currentPath)
static const AllowedLocationList & getAllowedLocationList(const ePredicateType &predicate)
CRDFNode * createMissingAncestors(const CRDFPredicate::Path &nodePath, const CRDFPredicate::ePredicateType &predicate, CRDFPredicate::sAllowedLocation const *&pLocation)
Definition: CRDFNode.cpp:246
CRDFNode * CRDFNode::createMissingAncestors ( const CRDFPredicate::Path predicatePath,
const size_t &  level 
)
private

Definition at line 285 of file CRDFNode.cpp.

References CRDFGraph::addTriplet(), CRDFObject::BLANK_NODE, CRDFGraph::generatedNodeId(), getDescendantsWithPredicate(), getSubject(), CRDFPredicate::getURI(), mGraph, CRDFTriplet::pObject, and CRDFObject::setType().

287 {
288  CRDFNode * pNode = this;
289 
290  size_t i, imax = predicatePath.size() - 1; // We only create the ancestors
291 
292  for (i = level; i < imax; i++)
293  {
294  std::set< CRDFTriplet > Triplets =
295  getDescendantsWithPredicate(predicatePath[i]);
296 
297  // Check whether the predicate exists.
298  if (Triplets.size() > 0)
299  {
300  pNode = Triplets.begin()->pObject;
301  }
302  else
303  {
304  CRDFObject object;
306  object.setBlankNodeId(mGraph.generatedNodeId());
307 
308  CRDFTriplet Triplet =
309  mGraph.addTriplet(pNode->getSubject(), CRDFPredicate::getURI(predicatePath[i]), object);
310 
311  if (!Triplet)
312  return NULL;
313  else
314  pNode = Triplet.pObject;
315  }
316  }
317 
318  return pNode;
319 }
std::set< CRDFTriplet > getDescendantsWithPredicate(const CRDFPredicate &predicate) const
Definition: CRDFNode.cpp:398
const CRDFSubject & getSubject() const
Definition: CRDFNode.cpp:69
CRDFGraph & mGraph
Definition: CRDFNode.h:231
void setType(const eObjectType &type)
Definition: CRDFObject.cpp:82
CRDFTriplet addTriplet(const CRDFSubject &subject, const CRDFPredicate &predicate, const CRDFObject &object)
Definition: CRDFGraph.cpp:141
const std::string & getURI() const
std::string generatedNodeId(const std::string &existingId="")
Definition: CRDFGraph.cpp:380
CRDFNode * pObject
Definition: CRDFTriplet.h:42
std::set< CRDFTriplet > CRDFNode::getDescendantsWithPredicate ( const CRDFPredicate predicate) const

Definition at line 398 of file CRDFNode.cpp.

References CRDFGraph::getPredicatePath(), CRDFGraph::getTriplets(), and mGraph.

Referenced by CRDFGraphConverter::convert(), createMissingAncestors(), CReference::CReference(), getFieldValue(), CMIRIAMInfo::load(), CMIRIAMInfo::loadBiologicalDescriptions(), CMIRIAMInfo::loadCreators(), CMIRIAMInfo::loadModifications(), CMIRIAMInfo::loadReferences(), setFieldValue(), CReference::setId(), CReference::setResource(), and CSBMLExporter::updateMIRIAMAnnotation().

399 {
400  std::set< CRDFTriplet > Triplets;
402 
403  std::set< CRDFTriplet > Predicates = mGraph.getTriplets(predicate);
404  std::set< CRDFTriplet >::const_iterator it = Predicates.begin();
405  std::set< CRDFTriplet >::const_iterator end = Predicates.end();
406 
407  for (; it != end; ++it)
408  if (it->pObject->hasAncestor(this))
409  Triplets.insert(*it);
410 
411  return Triplets;
412 }
CRDFGraph & mGraph
Definition: CRDFNode.h:231
const std::set< CRDFTriplet > & getTriplets() const
Definition: CRDFGraph.cpp:434
CRDFPredicate::Path getPredicatePath(const CRDFNode *pNode)
Definition: CRDFGraph.cpp:349
std::vector< ePredicateType > Path
Definition: CRDFPredicate.h:91
const std::string & CRDFNode::getFieldValue ( const CRDFPredicate::ePredicateType predicate) const

Retrieve the string representation of the property predicate

Parameters
constCRDFPredicate::ePredicateType & predicate
Returns
const std::string & fieldValue

Definition at line 113 of file CRDFNode.cpp.

References CRDFObject::BLANK_NODE, CRDFObject::getBlankNodeID(), getDescendantsWithPredicate(), CRDFLiteral::getLexicalData(), CRDFObject::getLiteral(), CRDFObject::getResource(), CRDFObject::getType(), CRDFObject::LITERAL, and CRDFObject::RESOURCE.

Referenced by CMIRIAMInfo::getCreatedDT(), CModification::getDate(), CReference::getDescription(), CCreator::getEmail(), CCreator::getFamilyName(), CCreator::getGivenName(), and CCreator::getORG().

114 {
115  static std::string Empty = "";
116 
117  const std::set< CRDFTriplet > Triplets = getDescendantsWithPredicate(predicate);
118 
119  if (Triplets.size() > 0)
120  {
121  const CRDFObject & Object = Triplets.begin()->pObject->getObject();
122 
123  switch (Object.getType())
124  {
125  case CRDFObject::LITERAL:
126  return Object.getLiteral().getLexicalData();
127  break;
128 
130  return Object.getResource();
131  break;
132 
134  return Object.getBlankNodeID();
135  break;
136  }
137  }
138 
139  return Empty;
140 }
const eObjectType & getType() const
Definition: CRDFObject.cpp:85
std::set< CRDFTriplet > getDescendantsWithPredicate(const CRDFPredicate &predicate) const
Definition: CRDFNode.cpp:398
const std::string & getBlankNodeID() const
Definition: CRDFObject.cpp:103
const std::string & getLexicalData() const
Definition: CRDFLiteral.cpp:60
const std::string & getResource() const
Definition: CRDFObject.cpp:94
CRDFLiteral & getLiteral()
Definition: CRDFObject.cpp:112
const std::string & CRDFNode::getId ( ) const

Retrieve the Id of the node

Returns
const std::string & id

Definition at line 49 of file CRDFNode.cpp.

References mId.

50 {return mId;}
std::string mId
Definition: CRDFNode.h:236
CRDFObject & CRDFNode::getObject ( )

Retrieve the object data of the node. It is recommended to call isObjectNode before retrieving the object.

Returns
CRDFObject & object

Definition at line 94 of file CRDFNode.cpp.

References mpObject.

Referenced by CMIRIAMResourceObject::CMIRIAMResourceObject(), CRDFGraph::destroyUnreferencedNode(), operator<<(), setFieldValue(), CBiologicalDescription::setId(), CReference::setId(), CMIRIAMResourceObject::setNode(), CBiologicalDescription::setResource(), CReference::setResource(), and CQRDFTreeViewItem::setTriplet().

95 {
96  if (mpObject == NULL)
97  mpObject = new CRDFObject;
98 
99  return *mpObject;
100 }
CRDFObject * mpObject
Definition: CRDFNode.h:246
const CRDFObject & CRDFNode::getObject ( ) const

Retrieve the object data of the node. It is recommended to call isObjectNode before retrieving the object.

Returns
const CRDFObject & object

Definition at line 102 of file CRDFNode.cpp.

References mpObject.

103 {
104  if (mpObject == NULL)
105  mpObject = new CRDFObject;
106 
107  return *mpObject;
108 }
CRDFObject * mpObject
Definition: CRDFNode.h:246
CRDFPredicate::Path CRDFNode::getPath ( ) const
const CRDFSubject & CRDFNode::getSubject ( ) const

Retrieve the subject data of the node. It is recommended to call isSubjectNode before retrieving the subject.

Returns
const CRDFSubject & subject

Definition at line 69 of file CRDFNode.cpp.

References mpSubject.

Referenced by CRDFGraphConverter::convert(), CMIRIAMInfo::createBiologicalDescription(), CMIRIAMInfo::createCreator(), createMissingAncestors(), CMIRIAMInfo::createModification(), CMIRIAMInfo::createReference(), CRDFGraph::guessGraphRoot(), operator<<(), CMIRIAMInfo::setCreatedDT(), and setFieldValue().

70 {
71  if (mpSubject == NULL)
72  mpSubject = new CRDFSubject;
73 
74  return *mpSubject;
75 }
CRDFSubject * mpSubject
Definition: CRDFNode.h:241
bool CRDFNode::hasAncestor ( const CRDFNode pNode) const

Check whether the given node is in the path, i.e., has the given node as an ancestor

Parameters
constCRDFNode * pNode
Returns
bool hasAncestor

Definition at line 442 of file CRDFNode.cpp.

References CRDFGraph::getParentSubjects(), and mGraph.

443 {
444  // We consider each node to be its own ancestor.
445  if (pNode == this)
446  return true;
447 
448  bool hasAncestor = false;
449 
450  std::set< const CRDFNode * > Parents = mGraph.getParentSubjects(this);
451  std::set< const CRDFNode * >::const_iterator it = Parents.begin();
452  std::set< const CRDFNode * >::const_iterator end = Parents.end();
453 
454  for (; it != end && !hasAncestor; ++it)
455  hasAncestor = (*it)->hasAncestor(pNode);
456 
457  return hasAncestor;
458 }
std::set< const CRDFNode * > getParentSubjects(const CRDFNode *pObject) const
Definition: CRDFGraph.cpp:499
CRDFGraph & mGraph
Definition: CRDFNode.h:231
bool hasAncestor(const CRDFNode *pNode) const
Definition: CRDFNode.cpp:442
bool CRDFNode::isBagNode ( ) const

Check whether this is a bag node

Returns
isBagNode

Definition at line 423 of file CRDFNode.cpp.

References CRDFGraph::getTriplets(), mGraph, and CRDFPredicate::rdf_type.

Referenced by addEdge(), CRDFGraphConverter::convert(), and CRDFGraph::removeEmptyNodes().

424 {
425  std::set< CRDFTriplet > Triplets = mGraph.getTriplets(this, CRDFPredicate::rdf_type);
426  std::set< CRDFTriplet >::const_iterator it = Triplets.begin();
427  std::set< CRDFTriplet >::const_iterator end = Triplets.end();
428 
429  for (; it != end; ++it)
430  if (Triplets.begin()->pObject->getObject().getResource() == "http://www.w3.org/1999/02/22-rdf-syntax-ns#Bag")
431  return true;
432 
433  return false;
434 }
CRDFGraph & mGraph
Definition: CRDFNode.h:231
const std::set< CRDFTriplet > & getTriplets() const
Definition: CRDFGraph.cpp:434
bool CRDFNode::isBlankNode ( ) const

Check whether this is a blank node

Returns
bool isBlankNode

Definition at line 420 of file CRDFNode.cpp.

References mIsBlankNode.

421 {return mIsBlankNode;}
bool mIsBlankNode
Definition: CRDFNode.h:251
bool CRDFNode::isObjectNode ( ) const

Check whether this is a object node

Returns
bool isObjectNode

Definition at line 417 of file CRDFNode.cpp.

References mpObject.

418 {return mpObject != NULL;}
CRDFObject * mpObject
Definition: CRDFNode.h:246
bool CRDFNode::isReadOnly ( ) const

Check whether the node is read only

Returns
bool isReadOnly

Definition at line 436 of file CRDFNode.cpp.

References CRDFGraph::getPredicatePath(), CRDFPredicate::isReadOnly(), and mGraph.

437 {
439  return CRDFPredicate::isReadOnly(NodePath);
440 }
static bool isReadOnly(const Path &currentPath)
CRDFGraph & mGraph
Definition: CRDFNode.h:231
CRDFPredicate::Path getPredicatePath(const CRDFNode *pNode)
Definition: CRDFGraph.cpp:349
std::vector< ePredicateType > Path
Definition: CRDFPredicate.h:91
bool CRDFNode::isSubjectNode ( ) const

Check whether this is a subject node

Returns
bool isSubjectNode

Definition at line 414 of file CRDFNode.cpp.

References mpSubject.

Referenced by CRDFGraph::addTriplet(), createMissingAncestors(), and CRDFGraph::guessGraphRoot().

415 {return mpSubject != NULL;}
CRDFSubject * mpSubject
Definition: CRDFNode.h:241
CRDFNode& CRDFNode::operator= ( const CRDFNode rhs)
private
void CRDFNode::removeEdge ( const CRDFPredicate predicate,
CRDFNode pObject 
)

Remove a property edge from the node.

Parameters
constCRDFPredicate & edge
CRDFNode* pObject
Returns
bool success

Definition at line 361 of file CRDFNode.cpp.

References CRDFGraph::getTriplets(), mGraph, CRDFPredicate::rdf_li, and removeTripletFromGraph().

Referenced by CBiologicalDescription::clearInvalidEntries(), CRDFGraphConverter::convert(), CRDFGraph::moveTriplet(), CRDFGraph::removeTriplet(), and CBiologicalDescription::setPredicate().

362 {
363  // Determine whether the predicate points to a bag node
364  std::set< CRDFTriplet > Triplets = mGraph.getTriplets(this, predicate);
365 
366  // Debugging
367  assert(Triplets.size() > 0);
368 
369  CRDFNode * pTarget = Triplets.begin()->pObject;
370 
371  if (pTarget->isBagNode() && pTarget != pObject)
372  {
373  pTarget->removeEdge(CRDFPredicate::rdf_li, pObject);
374 
375  Triplets = mGraph.getTriplets(pTarget, CRDFPredicate::rdf_li);
376 
377  switch (Triplets.size())
378  {
379  case 0:
380  // If pTarget is an empty bag node we remove it.
381  // Note, this will destroy pTarget, i.e., no need to unbag
382  removeEdge(predicate, pTarget);
383  break;
384 
385  default:
386  // We have more than 1 rdf_li element left.
387  break;
388  }
389 
390  return;
391  }
392 
393  removeTripletFromGraph(CRDFTriplet(this, predicate, pObject));
394 
395  return;
396 }
CRDFGraph & mGraph
Definition: CRDFNode.h:231
const std::set< CRDFTriplet > & getTriplets() const
Definition: CRDFGraph.cpp:434
void removeEdge(const CRDFPredicate &predicate, CRDFNode *pObject)
Definition: CRDFNode.cpp:361
void removeTripletFromGraph(const CRDFTriplet &triplet) const
Definition: CRDFGraph.cpp:683
void CRDFNode::removeTripletFromGraph ( const CRDFTriplet triplet) const

This method is for internal use only. The method is declared public since friend declarations may not refer to public methods.

Parameters
constCRDFTriplet & triplet

Definition at line 683 of file CRDFGraph.cpp.

References mGraph, and CRDFGraph::removeTriplet().

Referenced by removeEdge(), and setFieldValue().

684 {
685  mGraph.removeTriplet(triplet);
686 }
void removeTriplet(CRDFNode *pSubject, const CRDFPredicate &predicate, CRDFNode *pObject)
Definition: CRDFGraph.cpp:277
CRDFGraph & mGraph
Definition: CRDFNode.h:231
bool CRDFNode::setFieldValue ( const CMIRIAMResourceObject value,
const CRDFPredicate::ePredicateType predicate,
const CRDFPredicate::Path nodePath 
)

Set the field value for the property predicate

Parameters
constCMIRIAMResource & value
constCRDFPredicate::ePredicateType & predicate
constCRDFPredicate::Path & nodePath
Returns
bool success

Definition at line 142 of file CRDFNode.cpp.

References CRDFGraph::addTriplet(), createMissingAncestors(), CMIRIAMResourceObject::getNode(), getSubject(), CMIRIAMResourceObject::getURI(), CRDFPredicate::getURI(), CMIRIAMResourceObject::isValid(), mGraph, CRDFObject::RESOURCE, setFieldValue(), and CRDFObject::setType().

Referenced by CReference::clearInvalidEntries(), CMIRIAMInfo::setCreatedDT(), CModification::setDate(), CReference::setDescription(), CCreator::setEmail(), CCreator::setFamilyName(), setFieldValue(), CCreator::setGivenName(), CReference::setId(), CCreator::setORG(), and CReference::setResource().

145 {
146  // If a node is associated with the resource we can just set the field value
147  if (value.getNode() != NULL)
148  return value.getNode()->setFieldValue(value.getURI(), predicate, nodePath);
149 
150  // We have no node and the value is invalid, i.e., nothing to do.
151  if (!value.isValid())
152  return true;
153 
154  // We need to create a node
155 
156  // We build each missing ancestor as a blank node.
157  CRDFPredicate::sAllowedLocation const * pLocation = NULL;
158  CRDFNode * pParent = createMissingAncestors(nodePath, predicate, pLocation);
159 
160  if (pParent == NULL) return false;
161 
162  // Create the missing object
163  CRDFObject object;
165  object.setResource(value.getURI(), false);
166 
167  bool success = true;
168 
169  if (!mGraph.addTriplet(pParent->getSubject(), CRDFPredicate::getURI(predicate), object))
170  success = false;
171 
172  return success;
173 }
bool isValid() const
Definition: CConstants.cpp:182
std::string getURI() const
Definition: CConstants.cpp:133
const CRDFSubject & getSubject() const
Definition: CRDFNode.cpp:69
CRDFGraph & mGraph
Definition: CRDFNode.h:231
CRDFNode * getNode() const
Definition: CConstants.cpp:160
void setType(const eObjectType &type)
Definition: CRDFObject.cpp:82
bool setFieldValue(const CMIRIAMResourceObject &value, const CRDFPredicate::ePredicateType &predicate, const CRDFPredicate::Path &nodePath)
Definition: CRDFNode.cpp:142
CRDFTriplet addTriplet(const CRDFSubject &subject, const CRDFPredicate &predicate, const CRDFObject &object)
Definition: CRDFGraph.cpp:141
const std::string & getURI() const
CRDFNode * createMissingAncestors(const CRDFPredicate::Path &nodePath, const CRDFPredicate::ePredicateType &predicate, CRDFPredicate::sAllowedLocation const *&pLocation)
Definition: CRDFNode.cpp:246
bool CRDFNode::setFieldValue ( const std::string &  value,
const CRDFPredicate::ePredicateType predicate,
const CRDFPredicate::Path nodePath 
)

Set the field value for the property predicate

Parameters
conststd::string & value
constCRDFPredicate::ePredicateType & predicate
constCRDFPredicate::Path & nodePath
Returns
bool success

Definition at line 175 of file CRDFNode.cpp.

References CRDFGraph::addTriplet(), CRDFObject::BLANK_NODE, createMissingAncestors(), fatalError, CRDFGraph::generatedNodeId(), getDescendantsWithPredicate(), CRDFObject::getLiteral(), getObject(), getSubject(), CRDFObject::getType(), CRDFPredicate::getURI(), CRDFObject::LITERAL, mGraph, CRDFLiteral::PLAIN, CRDFTriplet::pObject, removeTripletFromGraph(), CRDFObject::RESOURCE, CRDFLiteral::setLexicalData(), CRDFObject::setResource(), CRDFLiteral::setType(), CRDFObject::setType(), and CRDFPredicate::sAllowedLocation::Type.

178 {
179  std::set< CRDFTriplet > Triplets =
180  getDescendantsWithPredicate(predicate);
181 
182  CRDFNode * pObject = NULL;
183 
184  if (Triplets.size() > 0)
185  pObject = Triplets.begin()->pObject;
186 
187  // Check whether the value is not empty.
188  if (value != "")
189  {
190  // We do not have an object
191  if (pObject == NULL)
192  {
193  // We build each missing ancestor as a blank node.
194  CRDFPredicate::sAllowedLocation const * pLocation = NULL;
195  CRDFNode * pParent = createMissingAncestors(nodePath, predicate, pLocation);
196 
197  if (pParent == NULL) return false;
198 
199  // Create the missing object
200  CRDFObject object;
201  object.setType(pLocation->Type);
202 
203  if (object.getType() == CRDFObject::BLANK_NODE)
204  object.setBlankNodeId(mGraph.generatedNodeId());
205 
206  CRDFTriplet Triplet =
207  mGraph.addTriplet(pParent->getSubject(), CRDFPredicate::getURI(predicate), object);
208 
209  if (!Triplet)
210  return false;
211 
212  pObject = Triplet.pObject;
213 
214  // Debugging
215  assert(pObject != NULL);
216  }
217 
218  // Now we finally can save the information.
219  CRDFObject & Object = pObject->getObject();
220 
221  switch (Object.getType())
222  {
223  case CRDFObject::LITERAL:
224  {
225  CRDFLiteral & Literal = Object.getLiteral();
226  Literal.setType(CRDFLiteral::PLAIN);
227  Literal.setLexicalData(value);
228  }
229  break;
230 
232  Object.setResource(value, false);
233  break;
234 
236  fatalError();
237  break;
238  }
239  }
240  else if (pObject != NULL)
241  removeTripletFromGraph(*Triplets.begin());
242 
243  return true;
244 }
const eObjectType & getType() const
Definition: CRDFObject.cpp:85
std::set< CRDFTriplet > getDescendantsWithPredicate(const CRDFPredicate &predicate) const
Definition: CRDFNode.cpp:398
const CRDFSubject & getSubject() const
Definition: CRDFNode.cpp:69
#define fatalError()
CRDFGraph & mGraph
Definition: CRDFNode.h:231
CRDFObject::eObjectType Type
Definition: CRDFPredicate.h:98
void setType(const eObjectType &type)
Definition: CRDFObject.cpp:82
CRDFObject & getObject()
Definition: CRDFNode.cpp:94
CRDFTriplet addTriplet(const CRDFSubject &subject, const CRDFPredicate &predicate, const CRDFObject &object)
Definition: CRDFGraph.cpp:141
void setType(const eLiteralType &type)
Definition: CRDFLiteral.cpp:39
void setLexicalData(const std::string &lexicalData)
Definition: CRDFLiteral.cpp:57
void setResource(const std::string &resource, const bool &isLocal)
Definition: CRDFObject.cpp:88
const std::string & getURI() const
CRDFNode * createMissingAncestors(const CRDFPredicate::Path &nodePath, const CRDFPredicate::ePredicateType &predicate, CRDFPredicate::sAllowedLocation const *&pLocation)
Definition: CRDFNode.cpp:246
std::string generatedNodeId(const std::string &existingId="")
Definition: CRDFGraph.cpp:380
CRDFNode * pObject
Definition: CRDFTriplet.h:42
CRDFLiteral & getLiteral()
Definition: CRDFObject.cpp:112
void removeTripletFromGraph(const CRDFTriplet &triplet) const
Definition: CRDFGraph.cpp:683
void CRDFNode::setId ( const std::string &  id)

Set the Id of the node

Parameters
conststd::string & id

Definition at line 46 of file CRDFNode.cpp.

References mId.

47 {mId = id;}
std::string mId
Definition: CRDFNode.h:236
void CRDFNode::setObject ( const CRDFObject object)

Set the object data of the node

Parameters
constCRDFObject & object

Definition at line 77 of file CRDFNode.cpp.

References CRDFSubject::BLANK_NODE, CRDFObject::BLANK_NODE, CRDFObject::getBlankNodeID(), CRDFObject::getType(), mId, mIsBlankNode, mpObject, mpSubject, pdelete, CRDFSubject::setBlankNodeId(), and CRDFSubject::setType().

78 {
80  mpObject = new CRDFObject(object);
81 
83  {
84  mIsBlankNode = true;
86 
88  mpSubject = new CRDFSubject;
91  }
92 }
#define pdelete(p)
Definition: copasi.h:215
CRDFSubject * mpSubject
Definition: CRDFNode.h:241
const eObjectType & getType() const
Definition: CRDFObject.cpp:85
CRDFObject * mpObject
Definition: CRDFNode.h:246
const std::string & getBlankNodeID() const
Definition: CRDFObject.cpp:103
void setBlankNodeId(const std::string &blankNodeId)
Definition: CRDFSubject.cpp:88
bool mIsBlankNode
Definition: CRDFNode.h:251
std::string mId
Definition: CRDFNode.h:236
void setType(const eSubjectType &type)
Definition: CRDFSubject.cpp:70
void CRDFNode::setSubject ( const CRDFSubject subject)

Set the subject data of the node

Parameters
constCRDFSubject & subject

Definition at line 52 of file CRDFNode.cpp.

References CRDFSubject::BLANK_NODE, CRDFObject::BLANK_NODE, CRDFSubject::getBlankNodeID(), CRDFSubject::getType(), mId, mIsBlankNode, mpObject, mpSubject, pdelete, CRDFObject::setBlankNodeId(), and CRDFObject::setType().

Referenced by CRDFGraph::addTriplet(), and CRDFGraph::createAboutNode().

53 {
55  mpSubject = new CRDFSubject(subject);
56 
58  {
59  mIsBlankNode = true;
61 
63  mpObject = new CRDFObject;
66  }
67 }
#define pdelete(p)
Definition: copasi.h:215
CRDFSubject * mpSubject
Definition: CRDFNode.h:241
CRDFObject * mpObject
Definition: CRDFNode.h:246
const std::string & getBlankNodeID() const
Definition: CRDFSubject.cpp:91
void setType(const eObjectType &type)
Definition: CRDFObject.cpp:82
bool mIsBlankNode
Definition: CRDFNode.h:251
std::string mId
Definition: CRDFNode.h:236
void setBlankNodeId(const std::string &blankNodeId)
Definition: CRDFObject.cpp:100
const eSubjectType & getType() const
Definition: CRDFSubject.cpp:73

Member Data Documentation

CRDFGraph& CRDFNode::mGraph
private
std::string CRDFNode::mId
private

The Id of the node

Definition at line 236 of file CRDFNode.h.

Referenced by getId(), setId(), setObject(), and setSubject().

bool CRDFNode::mIsBlankNode
private

Stores whether this is a blank node

Definition at line 251 of file CRDFNode.h.

Referenced by isBlankNode(), setObject(), and setSubject().

CRDFObject* CRDFNode::mpObject
mutableprivate

A pointer to the object if of type OBJECT or BOTH

Definition at line 246 of file CRDFNode.h.

Referenced by getObject(), isObjectNode(), setObject(), setSubject(), and ~CRDFNode().

CRDFSubject* CRDFNode::mpSubject
mutableprivate

A pointer to the subject if of type SUBJECT or BOTH

Definition at line 241 of file CRDFNode.h.

Referenced by getSubject(), isSubjectNode(), setObject(), setSubject(), and ~CRDFNode().


The documentation for this class was generated from the following files: