Skip to main content
Add CanonicalName method.
Source Link
Edmund
  • 43.2k
  • 3
  • 53
  • 148

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.

You can use $PrePrint and Replace.

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.

$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

$PrePrint can be cleared with

$PrePrint =.

Hope this helps.

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.

Source Link
Edmund
  • 43.2k
  • 3
  • 53
  • 148

You can use $PrePrint and Replace.

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.

$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

$PrePrint can be cleared with

$PrePrint =.

Hope this helps.