Function Repository Resource:

SameResourceQ

Source Notebook

Determine if resource objects are the same

Contributed by: Bob Sandheinrich

ResourceFunction["SameResourceQ"][r1,r2,]

returns True if the resources ri represent the same ResourceObject and returns False otherwise.

ResourceFunction["SameResourceQ"][r]

represents an operator form of ResourceFunction["SameResourceQ"] that can be applied to resources.

Details and Options

Resources can be specified by ResourceObject or ResourceFunction.
Resources are considered the same if they have matching UUIDs. Differing versions are ignored.
Two resource objects with the same name can be different if they are not both published in the same resource system.
ResourceFunction["SameResourceQ"][r1][r2,] is equivalent to ResourceFunction["SameResourceQ"][r1,r2,].

Examples

Basic Examples (3) 

Specify a resource by its name and UUID and see if it is the same resource:

In[1]:=
ResourceFunction["SameResourceQ"][ResourceObject["WoodFramed"], ResourceObject["29dcc1d8-437f-4eb4-9d10-a54bff5f83ae"]]
Out[1]=

See if a ResourceFunction is the same as its underlying ResourceObject:

In[2]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/48e063cc-9f07-4299-ae99-3dd8f07454e5"]
Out[2]=

A custom resource is not the same as one from the repository, even with the same name:

In[3]:=
ResourceFunction["SameResourceQ"][
 ResourceObject["Gettysburg Address"], ResourceObject[<|"Name" -> "Gettysburg Address", "ResourceType" -> "Data", "Content" -> "Four Score, something, something"|>]]
Out[3]=

Scope (2) 

Compare more than two resources:

In[4]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/e627f774-a548-44a9-97f2-74be37dfb9ce"]
Out[4]=

Create a matching operator:

In[5]:=
chirptest = ResourceFunction["SameResourceQ"][ResourceFunction["BirdSay"]]
Out[5]=
In[6]:=
fakebird = DefineResourceFunction["A Bird Said: " <> # &, "BadBirdSay"]
Out[6]=
In[7]:=
chirptest[fakebird]
Out[7]=
In[8]:=
chirptest[ResourceFunction@"BirdSay"]
Out[8]=

Applications (4) 

After creating a resource function, the developer can end up with many saved copies:

In[9]:=
ResourceSearch["Name" -> "Wiggled"]
Out[9]=

Create a function to remove all but one of the deployments of a resource:

In[10]:=
deleteOtherResources[ro_] := DeleteObject /@ Select[ResourceSearch["Name" -> ro["Name"], "Objects"], ! ResourceFunction["SameResourceQ"][ro, #] &]

Clean up all but the published resource:

In[11]:=
deleteOtherResources[ResourceObject@ResourceFunction[
ResourceObject[<|{"Name" -> "Wiggled", "ShortName" -> "Wiggled", "UUID" -> "f69fec42-e835-4760-a345-a538d835a8e3", "ResourceType" -> "Function", "Version" -> "1.0.0", "Description" -> "Give your expression a wiggly jiggly attitude", "RepositoryLocation" -> URL[
       "https://www.wolframcloud.com/objects/resourcesystem/api/1.0"],
       "SymbolName" -> "FunctionRepository`$01148c3f7bd04b8c85e269689655cb14`Wiggled", "FunctionLocation" -> CloudObject[
       "https://www.wolframcloud.com/obj/65255922-e149-4d1f-adc9-9010f8db6b11"]}|>, ResourceSystemBase -> "https://www.wolframcloud.com/objects/resourcesystem/api/1.0"]]]
Out[11]=

Only the published version remains:

In[12]:=
ResourceSearch["Name" -> "Wiggled"]
Out[12]=

Properties and Relations (5) 

SameQ often fails for ResourceObject expressions because the metadata changes when content is downloaded. Get a new resource:

In[13]:=
resource = ResourceObject["State of the Union Addresses"]
Out[13]=

The content is in the cloud:

In[14]:=
resource["ContentElementLocations"]
Out[14]=

After retrieving the data, the resource metadata has changed:

In[15]:=
ResourceData[resource] // Length
Out[15]=
In[16]:=
resource["ContentElementLocations"]
Out[16]=

SameQ gives False for the output ResourceObject compared with recreating the same object:

In[17]:=
SameQ[ResourceObject[<|"Name" -> "State of the Union Addresses", "UUID" -> "ad08960b-f43e-4e8f-92bf-04fd17234703", "ResourceType" -> "DataResource", "Version" -> "1.5.0", "Description" -> "Complete text of State of the Union addresses from 1790 to 2019", "RepositoryLocation" -> URL[
    "https://www.wolframcloud.com/objects/resourcesystem/api/1.0"], "ContentSize" -> Quantity[71.13824, "Megabytes"], "ContentElements" -> {"Dataset", "RawData", "RawData"}|>, {ResourceSystemBase -> Automatic}], ResourceObject["State of the Union Addresses"]]
Out[17]=

SameResourceQ correctly matches the two:

In[18]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/f725b387-e0d9-4d17-b814-758ac900d45a"]
Out[18]=

Possible Issues (2) 

Resource names outside of an object are not supported:

In[19]:=
ResourceFunction["SameResourceQ"]["BirdSay", "WolfieSay"]
Out[19]=

Use objects instead:

In[20]:=
ResourceFunction["SameResourceQ"][ResourceFunction@"BirdSay", ResourceFunction@"WolfieSay"]
Out[20]=
In[21]:=
ResourceFunction[
  "BirdSay"]["How could you confuse me with that guy?!?!"]
Out[21]=

Version History

  • 1.0.0 – 20 November 2019

Related Resources

License Information