Message Boards Message Boards

How put a DataResource into persistent local storage?

GROUPS:

I've downloaded a DataResource EntityStore from the Wolfram Data Depository, specifically, the ResourceObject["General Topology EntityStore"], in the form of the packageGeneral-Topology-EntityStore.wl`.

I know how to use $EntityStores to use this EntityStore within a given Mathematica session.

But exactly how do I use the Wolfram Language, within Mathematica, to make this EntityStore into a local persistent object?

POSTED BY: Murray Eisenberg
Answer
13 days ago

If you've already downloaded the file "General-Topology-EntityStore.wl" linked to from here, then all you need to do in your notebook is run this command

store = << "~/Downloads/General-Topology-EntityStore.wl"; (* or wherever you downloaded the data to *)
AppendTo[$EntityStores, << store]

and then you can access all the data via EntityValue

POSTED BY: Jason Biggs
Answer
13 days ago

That is precisely the location to which the .wl file was downloaded and (temporarily) resides. But...

  • evaluating << "~/Downloads/General-Topology-EntityStore.wl" gives a $Failed message; and
  • $EntityStoresseems to be localized to the particular session rather than persisting across sessions.
POSTED BY: Murray Eisenberg
Answer
13 days ago

@Murray Eisenberg First you need to figure out why you get $Failed when trying to Get the file (<<).

Do you get True from FileExistsQ["~/Downloads/General-Topology-EntityStore.wl"]? What happens when you try to use Import instead of Get?

As to the persistence - I think that is just the way $EntityStores was designed. If you solve the problem above and are able to read in the store using Get, then you could add the line AppendTo code above to your "~/Library/Mathematica/Kernel/init.m" file and it would be available via EntityValue every time you start a kernel

POSTED BY: Jason Biggs
Answer
12 days ago

OK, I can do the Get for the .wl now — have no idea why it didn't work yesterday! — and then successfully evaluating AppendTo[$EntityStores, store].

But after quitting the Mathematica session and starting a new session, once again $EntityStores is empty.

Is there some Option I need to set in order make the objects persistent?

POSTED BY: Murray Eisenberg
Answer
12 days ago

I don't believe there is a way to make the new store permanent, I think at startup the $EntityStores is empty by design.

But you can add the relevant code to your .init file, where you can keep any code you want executed when the kernel starts. I have tons of stuff in my init file, little helper functions I find to be useful.

To find the init file, run

SystemOpen@Echo @ FileNameJoin[{$UserBaseDirectory, "Kernel", "init.m"}]

add the lines

store = Get[ "~/Downloads/General-Topology-EntityStore.wl" ]; 
AppendTo[ $EntityStores , store]; 

And then when you restart your kernel you should be able to run

EntityValue["GeneralTopologyTheorem", "Activate"] // Activate;
Entity["GeneralTopologyTheorem", "ClassicalAscolisTheorem"]["QualifyingObjects"]

and get the result. There isn't a way to have the "Activate" code run beforehand, since the EntityValue framework is loaded after the init.m file is read.

POSTED BY: Jason Biggs
Answer
12 days ago

Yes, I do understand how to add code to init.m so as to load files automatically.

What I obviously do not understand, and the Documentation Center has been of very little help on this, is how to utilize the new(er) LocalObject, LocalObjects, LocalCache, etc. I note that $LocalBase points to my folder:

~/Library/Wolfram/Objects

My expectation is that there must be some way to make "General-Topology-EntityStore" available there, for call on demand, without my having to modify init.m.

POSTED BY: Murray Eisenberg
Answer
12 days ago

@Murray Eisenberg I would like to know how was the dataset downloaded to the local system. Could you please help me with this? Thank you

Answer
12 days ago

The .wl file was downloaded directly from https://datarepository.wolframcloud.com.

POSTED BY: Murray Eisenberg
Answer
12 days ago

Is something like the following on the right track?

ro = ResourceObject["General Topology EntityStore"];
store = ResourceData[ro, "EntityStore"];
PersistentValue["GeneralTopologyEntityStore"] = store;

Then

Quit[]

in a new session:

AppendTo[$EntityStores, PersistentValue["GeneralTopologyEntityStore"]];

RandomEntity["GeneralTopologyConcept"]
(* Entity["GeneralTopologyConcept", "SpaceWithTopologyOfPointwiseConvergence"]*)
POSTED BY: Jesus Hernandez
Answer
10 days ago

Yes, that's exactly what I was looking for! Thank you.

POSTED BY: Murray Eisenberg
Answer
10 days ago

Group Abstract Group Abstract