I'm trying to wrap my head around how to work with Mathematica for building (computable) domain specific knowledge. One particular thing I didn't quite understand is how to create symbols for operations which are to be applied (computed) only for specific entity-types. I understand how I can restrict the pattern-matching to basic datatypes (i.e using x_Integer
as parameter to restrict input to only integers for example). But all entities share the exact same head (Entity
), so how do I make the pattern understand which specific entity-type I want to match on?
ex:
f[x_{Planet entity}]:=y
which I'd like to evaluate to y
if, for example, x="Entity["Planet", "Mercury"]"
, but not if Entity["Country", "Sweden"]
PatternTest
orCondition
to check if it's the 'correct' type of entity. Something likef[x_?MemberQ[EntityList["Planet"],#]&]
? $\endgroup$x : HoldPattern[Entity["Planet", __]]
? $\endgroup$