5

When extracting the "name" of an Entity one has CommonName. Good. Before I discovered this, I simply applied a rule like:

en = Entity["Language", "English"];
en /. Entity[a_, b_] :> b (* out: "English"*) 

Maybe I´m missing something stupid, but why does the following not work?

Cases[en, Entity[a_, b_] :> b] (* out: {} *) 
J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
mgamer
  • 5,593
  • 18
  • 26

1 Answers1

6

You need to specify the levelspec as {0} using the third argument of Cases:

Cases[en, Entity[a_, b_] :> b, {0}]
(* or Cases[en, x_Entity:> Last[x], {0}] *)

{"English"}

Notes: from Cases >> Details and Options

enter image description here

enter image description here

enter image description here

The last one explains why Cases[{en}, Entity[a_, b_] :> b] and, more generally, Cases[foo[en], Entity[a_, b_] :> b] gives {"English"}.

kglr
  • 394,356
  • 18
  • 477
  • 896