# How do I perform complex queries on Entity data?

I'd like to query, for example, the Entity["MusicWork"] data for something like "all music works whose names contain the word 'Funk'". Or even "plot a date histogram by year of the number of works whose name contains the word 'Funk', as a fraction of the total number of works".

I can easily get all the works with some exact name:

EntityList[
Entity["MusicWork", {"Name" -> "Jump"}]]


I can query for works released within some time interval:

EntityList[
Entity["MusicWork", {"FirstRecordingDate" -> DateObject[{2006}]}]]


But I'd like to query for a pattern in the "Name" property, but I'm unable to glean from the documentation what type of expression I can use here.

• I you want to edit your question a lot, please do it in a separate paragraph. We don't want to end up with a question and a bunch of unrelated answers. – paw Oct 28 '15 at 17:13
• I edited the question because it got two answers about date intervals. While that's helpful, it's not really what the question is about. – Apocalisp Oct 28 '15 at 17:16

Interval needs { and }:

In[1]:= EntityList[
EntityClass[
"MusicWork", {"FirstRecordingDate" ->
Interval[{DateObject[{2006, 1}],
DateObject[{2006, 12}]}]}]] // Length

Out[1]= 3951


Implicitly defined entity classes do not support string matching inside property values.

You don't need to use Interval here, DateObject[{2006}] is a much better option here.

music2006 =
EntityList[
Entity["MusicWork", {"FirstRecordingDate" -> DateObject[{2006}]}]];


You can filter this list of entities for works that contain the word "funk" using

Select[music2006, StringMatchQ[EntityValue[#, "Name"], ___ ~~ "funk" ~~ ___] &]

• One might want to add IgnoreCase -> True as a StringMatchQ[] setting. – J. M.'s technical difficulties Oct 28 '15 at 16:35
• But doesn't EntityValue call out to the internet for each element? – Apocalisp Oct 28 '15 at 16:35
• @Apocalisp, it would be a good idea to cache the names (i.e. map EntityValue[] in one go) and do any subsequent searches on the cache afterwards. – J. M.'s technical difficulties Oct 28 '15 at 16:42