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$
2
  • $\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
    Commented Oct 28, 2015 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
    Commented Oct 28, 2015 at 17:16

2 Answers 2

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.

$\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" ~~ ___] &]
$\endgroup$
3
  • $\begingroup$ One might want to add IgnoreCase -> True as a StringMatchQ[] setting. $\endgroup$ Commented Oct 28, 2015 at 16:35
  • $\begingroup$ But doesn't EntityValue call out to the internet for each element? $\endgroup$
    – Apocalisp
    Commented Oct 28, 2015 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$ Commented Oct 28, 2015 at 16:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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