ARC2::getSimpleIndex PHP Method

getSimpleIndex() static public method

*
static public getSimpleIndex ( $triples, $flatten_objects = 1, $vals = '' )
    static function getSimpleIndex($triples, $flatten_objects = 1, $vals = '')
    {
        $r = array();
        foreach ($triples as $t) {
            $skip_t = 0;
            foreach (array('s', 'p', 'o') as $term) {
                ${$term} = $t[$term];
                /* template var */
                if (isset($t[$term . '_type']) && $t[$term . '_type'] == 'var') {
                    $val = isset($vals[${$term}]) ? $vals[${$term}] : '';
                    $skip_t = isset($vals[${$term}]) ? $skip_t : 1;
                    $type = '';
                    $type = !$type && isset($vals[${$term} . ' type']) ? $vals[${$term} . ' type'] : $type;
                    $type = !$type && preg_match('/^\\_\\:/', $val) ? 'bnode' : $type;
                    if ($term == 'o') {
                        $type = !$type && (preg_match('/\\s/s', $val) || !preg_match('/\\:/', $val)) ? 'literal' : $type;
                        $type = !$type && !preg_match('/[\\/]/', $val) ? 'literal' : $type;
                    }
                    $type = !$type ? 'uri' : $type;
                    $t[$term . '_type'] = $type;
                    ${$term} = $val;
                }
            }
            if ($skip_t) {
                continue;
            }
            if (!isset($r[$s])) {
                $r[$s] = array();
            }
            if (!isset($r[$s][$p])) {
                $r[$s][$p] = array();
            }
            if ($flatten_objects) {
                if (!in_array($o, $r[$s][$p])) {
                    $r[$s][$p][] = $o;
                }
            } else {
                $o = array('value' => $o);
                foreach (array('lang', 'type', 'datatype') as $suffix) {
                    if (isset($t['o_' . $suffix]) && $t['o_' . $suffix]) {
                        $o[$suffix] = $t['o_' . $suffix];
                    } elseif (isset($t['o ' . $suffix]) && $t['o ' . $suffix]) {
                        $o[$suffix] = $t['o ' . $suffix];
                    }
                }
                if (!in_array($o, $r[$s][$p])) {
                    $r[$s][$p][] = $o;
                }
            }
        }
        return $r;
    }

Usage Example

 function test_set_comment_add_rdfs_comment_triple()
 {
     $fpmap = new QueryProfile("http://example.org/store/queryprofiles/1");
     $fpmap->set_comment('my qp is kewl');
     $index = ARC2::getSimpleIndex($fpmap->get_triples(), true);
     $this->assertEquals("my qp is kewl", $index[$fpmap->uri]['http://www.w3.org/2000/01/rdf-schema#comment'][0]);
 }
All Usage Examples Of ARC2::getSimpleIndex