/** * Copies the mappings and other properties into new field/predicate map. * Any URIs that are prefixed by the source field/predicate map's URI will be converted to * be prefixed with this field/predicate map's URI * * For example<br/> * http://example.org/source/fpmaps/1#name<br/> * Would become<br/> * http://example.org/destination/fpmaps/1#name<br/> * * @return FieldPredicateMap * @author Ian Davis **/ function copy_to($new_uri) { $res = new FieldPredicateMap($new_uri, $this->credentials); $index = $this->get_index(); foreach ($index as $uri => $uri_info) { $subject_uri = preg_replace('/^' . preg_quote($this->uri, '/') . '(.*)$/', $res->uri . '$1', $uri); foreach ($uri_info as $res_property_uri => $res_property_values) { foreach ($res_property_values as $res_property_info) { if ($res_property_info['type'] == 'uri') { $value_uri = preg_replace('/^' . preg_quote($this->uri, '/') . '(.+)$/', $res->uri . '$1', $res_property_info['value']); $res->add_resource_triple($subject_uri, $res_property_uri, $value_uri); } elseif ($res_property_info['type'] == 'bnode') { $res->add_resource_triple($subject_uri, $res_property_uri, $res_property_info['value']); } else { $res->add_literal_triple($subject_uri, $res_property_uri, $res_property_info['value']); } } } } return $res; }
function test_copy_to() { $fpmap = new FieldPredicateMap("http://example.org/store/fpmaps/1"); $fpmap->add_mapping("http://example.org/pred", "pred"); $fpmap2 = $fpmap->copy_to("http://example.org/store2/fpmaps/1"); $index2 = $fpmap2->get_index(); $this->assertEquals(1, count($index2["http://example.org/store2/fpmaps/1"][FRM_MAPPEDDATATYPEPROPERTY])); $this->assertEquals("http://example.org/store2/fpmaps/1#pred", $index2["http://example.org/store2/fpmaps/1"][FRM_MAPPEDDATATYPEPROPERTY][0]['value']); $this->assertEquals(1, count($index2[$index2["http://example.org/store2/fpmaps/1"][FRM_MAPPEDDATATYPEPROPERTY][0]['value']][FRM_NAME])); $this->assertEquals("pred", $index2[$index2["http://example.org/store2/fpmaps/1"][FRM_MAPPEDDATATYPEPROPERTY][0]['value']][FRM_NAME][0]['value']); }