4
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ 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. $\endgroup$ – paw Oct 28 '15 at 17:13
  • $\begingroup$ 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. $\endgroup$ – Apocalisp Oct 28 '15 at 17:16
1
$\begingroup$

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.

|improve this answer|||||
$\endgroup$
0
$\begingroup$

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" ~~ ___] &]
|improve this answer|||||
$\endgroup$
  • $\begingroup$ One might want to add IgnoreCase -> True as a StringMatchQ[] setting. $\endgroup$ – J. M.'s technical difficulties Oct 28 '15 at 16:35
  • $\begingroup$ But doesn't EntityValue call out to the internet for each element? $\endgroup$ – Apocalisp Oct 28 '15 at 16:35
  • $\begingroup$ @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. $\endgroup$ – J. M.'s technical difficulties Oct 28 '15 at 16:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.