I'm afraid there's nothing (existing at least) that will do that, the URI function is provided by the module implementing the entity (in hook_entity_info()
) and the method within that function is completely transparent to Drupal...the core entity module doesn't give modules the chance to implement a function that reverses the process, nor does it store how the conversion was made.
Because of this I don't think a fully generic function is possible, however you could do it on a type-by-type basis:
$uri = entity_uri('node', $entity);
if (preg_match('/node\/([0-9+])/', $uri, $matches)) {
$entity2 = entity_load('node', array($matches[1]));
}
You could then extract that logic to build a slightly more generic function based on the known attributes of your Drupal installation...it's not a pretty way to do it though, I'd love to hear a different solution to this.