Note : This answer uses internal functions so it might not work in the future.
Code
entityQ[entity_] :=
Internal`PossibleEntityQ[entity] &&
EntityFramework`EntityExistsQ[entity];
I wrote a function that searches all functions and variables in Mathematica including those that are internal:
all…names[name_]:= Information[{___~~"`"~~___~~name~~___ ,___~~name~~___~~"`"~~___}]//Sort;
Using :
all…names["Entity*Q"]
one finds a list with multiple matching names. The three considered in the following are :
One may check the definitions of these functions using, for example :
<< GeneralUtilities`
PrintDefinitions@EntityFramework`EntityTypeExistsQ
Consider some examples to see what these functions do.
EntityFramework`Predicates`Private`iEntityExistsQ[
Entity["randrand", "rand"]]
(* False *)
and
EntityFramework`EntityExistsQ[
Entity["randrand", "rand"]]
(* False *)
But
EntityFramework`Predicates`Private`iEntityExistsQ[
Entity["Company", "StackExchange::n59g4"]]
(* True *)
EntityFramework`EntityExistsQ[
Entity["Company", "StackExchange::n59g4"]]
(* True *)
If the object does not have the expected structure of an Entity
for example "word"
or Entity["english"]
instead of Entity["Language", "English::385w8"]
then
EntityFramework`Predicates`Private`iEntityExistsQ
throws an error while
EntityFramework`EntityExistsQ
does not evaluate.
One can use the following internal function first that seems to just test whether the structure is correct:
Internal`PossibleEntityQ[Entity["randrand", "rand"]]
(* True *)
Internal`PossibleEntityQ[Entity["rand"]]
(* False *)
Internal`PossibleEntityQ[42]
(* False *)
So one can combine those two functions to make an entityQ :
entityQ[entity_] :=
Internal`PossibleEntityQ[entity] &&
EntityFramework`EntityExistsQ[entity];
Verify that the code works:
entityQ[42]
(* False *)
entityQ[Entity["randrand", "rand"]]
(* False *)
entityQ[Entity["Company", "StackExchange::n59g4"]]
(* True *)
SymbolQ
here. If the list elements contain either entities or strings you could also useNot@*StringQ
. $\endgroup$