Consultas de propriedades de entidades de forma livre
Use Interpreter para construir uma função similar a EntityValue, mas permitindo especificações de linguagem natural EntityType, Entity, e EntityProperty.
In[1]:=
![Click for copyable input](assets.pt-br/free-form-entity-property-queries/In_327.png)
NLEntityValue[type_String, entity_String, property_String] :=
With[{res =
Map[{Replace[#, AmbiguityList[{a___}, ___] :> a]} &,
Interpreter[
CompoundElement[{"EntityType", "Entity", "EntityProperty"}],
AmbiguityFunction -> All][{type, entity, property}]]},
If[FreeQ[res, Failure],
EntityValue[FirstCase[res[[2]], Entity[res[[1, 1]], ___]],
FirstCase[res[[3]], EntityProperty[res[[1, 1]], ___]]],
Missing["Unknown"]]]
Aplique a função a vários tipos de entidades, entidades e propriedades.
In[2]:=
![Click for copyable input](assets.pt-br/free-form-entity-property-queries/In_328.png)
NLEntityValue["country", "GB", "oil imports"]
Out[2]=
![](assets.pt-br/free-form-entity-property-queries/O_208.png)
In[3]:=
![Click for copyable input](assets.pt-br/free-form-entity-property-queries/In_329.png)
NLEntityValue["city", "windy city", "elderly population"]
Out[3]=
![](assets.pt-br/free-form-entity-property-queries/O_209.png)
In[4]:=
![Click for copyable input](assets.pt-br/free-form-entity-property-queries/In_330.png)
NLEntityValue["celebrity", "the Boss", "birthday"]
Out[4]=
![](assets.pt-br/free-form-entity-property-queries/O_210.png)
In[5]:=
![Click for copyable input](assets.pt-br/free-form-entity-property-queries/In_331.png)
NLEntityValue["moon", "ganymede", "image"]
Out[5]=
![](assets.pt-br/free-form-entity-property-queries/O_211.png)
In[6]:=
![Click for copyable input](assets.pt-br/free-form-entity-property-queries/In_332.png)
Row[NLEntityValue["popular curve", #, "image"] & /@ {"trump",
"hillary clinton"}]
Out[6]=
![](assets.pt-br/free-form-entity-property-queries/O_212.png)