3
$\begingroup$

By default, no matter

ElementData["Hydrogen", "DiscoveryCountries"]

or

EntityValue[Entity["Element", "Hydrogen"], "DiscoveryCountries"]

gives

enter image description here

However, preparing and rendering Entity object is quite slow as said in Speed of curated data calls in Version 10, a solution we can use is

SetSystemOptions[SystemOptions["DataOptions"] /. True -> False]

which results

{"DataOptions" -> {"ReturnEntities" -> False, "ReturnQuantities" -> False, 
"UseDataWrappers" -> False}}

to prevent output of entity object.

However, I found this only works for *Data function, not working for EntityValue query.

SetSystemOptions[SystemOptions["DataOptions"] /. True -> False]
ElementData["Hydrogen", "DiscoveryCountries"]
EntityValue[Entity["Element", "Hydrogen"], "DiscoveryCountries"]

gives

enter image description here

How to prevent output of Entity object of EntityValue? And combine with my previous post, it seems that EntityValue and *Data are unexpectedly inconsistent.

$\endgroup$

1 Answer 1

4
$\begingroup$

You can use $PrePrint and Replace with either ToString or CanonicalName.

Before setting $PrePrint

SessionTime[];
ConstantArray[Entity["Country", "Bermuda"], 10000]
SessionTime[] - Out[-2]

takes 1.0735404 seconds to render the 10,000 entity objects.

I use Interpretation to ensure the reformatted entities can still used. Pane provides formatting and spacing when reformatted entities are used in input.

With ToString

$PrePrint =
 Replace[#
   , e_Entity :> 
    Interpretation[Pane[ToString[e], ContentPadding -> False], e]
   , Infinity
   ] & ;

Now

SessionTime[];
ConstantArray[Entity["Country", "Canada"], 10000]
SessionTime[] - Out[-2]

takes 0.1586101 seconds to render the 10,000 reformatted entity objects.

These objects can still be used as entities and even copied and pasted as input.

enter image description here

With CanonicalName it is slightly faster that ToString.

$PrePrint =
  Replace[#
    , e_Entity :> 
     Interpretation[Pane[CanonicalName[e], ContentPadding -> False], e]
    , Infinity
    ] &;

then

SessionTime[];
ConstantArray[Entity["Country", "Nigeria"], 10000]
SessionTime[] - Out[-2]

takes 0.1426487 seconds to render the 10,000 reformatted entity objects.

Still can be used for input

enter image description here

$PrePrint can be cleared with

$PrePrint =.

Hope this helps.

$\endgroup$
5
  • $\begingroup$ Thank you so much! Great trick! I never used Interpretation before, a good lesson for me. But it seems that Interpretation[ToString[e]], e] is already enough and even faster. Am I right? $\endgroup$
    – matheorem
    Commented Mar 18, 2022 at 3:21
  • $\begingroup$ Yes. However, I did not like the fact that copying and pasting that output into an input cell gives a string. It looks better to me to have the entity statement in a pane without string quotes. $\endgroup$
    – Edmund
    Commented Mar 18, 2022 at 3:24
  • $\begingroup$ Ok, I understand the necessity of Pane now, thank you so much. $\endgroup$
    – matheorem
    Commented Mar 18, 2022 at 4:26
  • $\begingroup$ @matheorem Forgot to mention that you can use CanonicalName instead of ToString for a shorter descriptive string. $\endgroup$
    – Edmund
    Commented Mar 18, 2022 at 11:39
  • $\begingroup$ Thank you for mention, it seems that CanonicalName is what *Data function use after SetSystemOptions. $\endgroup$
    – matheorem
    Commented Mar 18, 2022 at 13:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.