5

I tried to create my own entity type in which entities have dated properties.

But I can't find any helpful documentation on that matter. And every try failed.

I tried

store = EntityStore[
  "t" -> <|

    "Entities" -> <|

      "e1" -> <|Dated["p1", 2019] -> 17, "p2" -> 59|>,
      "e2" -> <|"p1" -> 27, "p2" -> 288|>
      |>
    |>]

And

store = EntityStore[
  "t" -> <|

    "Entities" -> <|

      "e1" -> <|"p1" -> <|"Value" -> 17, "Date"->DateObject@2019|>, "p2" -> 59|>,
      "e2" -> <|"p1" -> 27, "p2" -> 288|>
      |>
    |>]

Do you have any suggestions?

Y. Kwon
  • 565
  • 2
  • 8

1 Answers1

2

I was wrong. I found that dated properties are related to qualifiers and there're some posts about qualifiers of entity framework.

Here's my modified example.

EntityUnregister["beehive"];
EntityRegister[
 EntityStore[
  "beehive" -> <|
    "Entities" -> <|
      "lisa" -> <|{"Population", "Date" -> All} -> 
         TimeSeries[{{{2013}, 100000}, {{2014}, 200000}, {{2015}, 
            150000}}]|>, 
      "tom" -> <|{"Population", "Date" -> All} -> 
         TimeSeries[{{{2013}, 300000}, {{2014}, 200000}, {{2015}, 
            200000}}]|>|>, 
    "Properties" -> <|
      "Population" -> <|
        "DefaultFunction" -> 
         Function[ent, 
          ent[Dated["Population", All]][
           "LastValue"]]|>, {"Population", 
        "Date" -> _?DateObjectQ} -> <|
        "DefaultFunction" -> 
         Function[{ent, quals}, 
          Round[ent[Dated["Population", All]][quals["Date"]]]]|>,
      {"Population", "Date" -> _Interval} -> <|

        "DefaultFunction" -> 
         Function[{ent, quals}, 
          TimeSeriesWindow[ent[Dated["Population", All]], 
            quals["Date"][[1]]]["Values"]]|>
      |>|>]];

So, if you want Lisa's population in 2014,

Entity["beehive", "lisa"][Dated["Population", 2014]]

Or, to get the whole time series,

Entity["beehive", "lisa"][Dated["Population", All]]

You can also use DateObject

EntityValue[Entity["beehive", "lisa"], 
 EntityProperty["beehive", 
  "Population", {"Date" -> DateObject[{2013}]}]]

And Interval.

EntityValue[Entity["beehive", "lisa"], 
 EntityProperty["beehive", 
  "Population", {"Date" -> 
    Interval[{DateObject[{2013}], DateObject[{2014}]}]}]]

I hope this is useful for someone. I'm not fluent in Mathematica. So, please help me improve this example.

Y. Kwon
  • 565
  • 2
  • 8
  • Any chance you can point to exactly where the Dated comes in here? I know a reader can figure it out, but it's nice to make it easy on them. – b3m2a1 May 15 '19 at 05:43