/**
  * Return an array of ternary arrays (subject predicate object) of
  * SMWExpElements that represents the flattened version of this data.
  *
  * @return array of array of SMWExpElement
  */
 public function getTripleList(Element $subject = null)
 {
     global $smwgBnodeCount;
     if (!isset($smwgBnodeCount)) {
         $smwgBnodeCount = 0;
     }
     if ($subject == null) {
         $subject = $this->m_subject;
     }
     $result = array();
     foreach ($this->m_edges as $key => $edge) {
         foreach ($this->m_children[$key] as $childElement) {
             if ($childElement instanceof SMWExpData) {
                 $childSubject = $childElement->getSubject();
             } else {
                 $childSubject = $childElement;
             }
             if ($childSubject instanceof SMWExpResource && $childSubject->isBlankNode()) {
                 // bnode, rename ID to avoid unifying bnodes of different contexts
                 // TODO: should we really rename bnodes of the form "_id" here?
                 $childSubject = new SMWExpResource('_' . $smwgBnodeCount++, $childSubject->getDataItem());
             }
             $result[] = array($subject, $edge, $childSubject);
             if ($childElement instanceof SMWExpData) {
                 // recursively add child's triples
                 $result = array_merge($result, $childElement->getTripleList($childSubject));
             }
         }
     }
     return $result;
 }