EntityValue मूल्यांकन व्यवहार

Sep 29 2020

मैं एक व्यवहार से हैरान हूँ EntityValue, जहाँ मुझे यह पता नहीं चल रहा है। यहाँ एक न्यूनतम उदाहरण है। निम्नलिखित रिवाज पर विचार करें EntityStore:

store = EntityStore[{
   "Group" -> <|
     "Entities" -> <|
       "GroupA" -> <|
         "name" -> "Group A",
         "size" -> 2,
         "members" -> {
           Entity["Individual", "Claus"],
           Entity["Individual", "Andrea"]
           }
         |>,
       "GroupB" -> <|
         "name" -> "Group B",
         "size" -> 2,
         "members" -> {
           Entity["Individual", "John"],
           Entity["Individual", "Claudia"]
           }
         |>
       |>
     |>,
   "Individual" -> <|
     "Entities" -> <|
       "Claus" -> <|"name" -> "Claus Smith", "age" -> 25|>,
       "Andrea" -> <|"name" -> "Andrea Fisher", "age" -> 35|>,
       "John" -> <|"name" -> "John Allen", "age" -> 45|>,
       "Claudia" -> <|"name" -> "Claudia Wilson", "age" -> 60|>
       |>
     |>
   }
  ]

आइए इसे पंजीकृत करें:

EntityRegister[store]

और फिर इसे क्वेरी करें:

assoc = EntityValue["Group", "PropertyAssociation"]

जो अपेक्षित है:

{<|
  EntityProperty["Group", "members"] -> {Entity["Individual", "Claus"], Entity["Individual", "Andrea"]}, 
  EntityProperty["Group", "name"] -> "Group A", 
  EntityProperty["Group", "size"] -> 2
|>, 
<|
  EntityProperty["Group", "members"] -> {Entity["Individual", "John"], Entity["Individual", "Claudia"]}, 
  EntityProperty["Group", "name"] -> "Group B", 
  EntityProperty["Group", "size"] -> 2
|>}

अब कहते हैं कि हम इस संपत्ति को अपनी संपत्ति संघों द्वारा अलग-अलग संपत्तियों की जगह देकर इस श्रेणी को पदानुक्रमित बनाना चाहेंगे:

ds = assoc /. {Entity["Individual", n_] :> EntityValue[Entity["Individual", n], "PropertyAssociation"]}

यह - मेरे लिए अप्रत्याशित रूप से - आंतरिक इकाई भावों का निर्विवाद रूप से:

{<|
  EntityProperty["Group", "members"] -> {EntityValue[Entity["Individual", "Claus"], "PropertyAssociation"], EntityValue[Entity["Individual", "Andrea"], "PropertyAssociation"]}, 
  EntityProperty["Group", "name"] -> "Group A", 
  EntityProperty["Group", "size"] -> 2|>,
 <|EntityProperty["Group", "members"] -> {EntityValue[Entity["Individual", "John"],  "PropertyAssociation"], EntityValue[Entity["Individual", "Claudia"], "PropertyAssociation"]}, 
  EntityProperty["Group", "name"] -> "Group B", 
  EntityProperty["Group", "size"] -> 2
|>
}

क्या चल रहा है? अजीब बात है, आंतरिक EntityValueभावों का मूल्यांकन तब होता है जब हम किसी तरह से सीधे उनसे प्रश्न करते हैं:

Lookup[ds, EntityProperty["Group", "members"]]

सही ढंग से पैदावार

{{<|EntityProperty["Individual", "age"] -> 25, 
   EntityProperty["Individual", "name"] -> "Claus Smith"|>,
  <|EntityProperty["Individual", "age"] -> 35, 
   EntityProperty["Individual", "name"] -> "Andrea Fisher"|>},
 {<|EntityProperty["Individual", "age"] -> 45, 
   EntityProperty["Individual", "name"] -> "John Allen"|>,
  <|EntityProperty["Individual", "age"] -> 60, 
   EntityProperty["Individual", "name"] -> "Claudia Wilson"
|>}}

यह मुझे क्यों परेशान कर रहा है? मैं एक पदानुक्रमित इकाई स्टोर से एक पदानुक्रमित एसोसिएशन अभिव्यक्ति बनाने के लिए इस तरह के प्रतिस्थापित तंत्र का उपयोग करना चाहूंगा। एक-से-कई रिश्तों के एक झरने की कल्पना करें, जैसे कि कॉन्टिनेंट -> देश -> क्षेत्र -> शहर -> पड़ोस "या कुछ इसी तरह। मैं बाल-संस्थाओं की सूची की पुनरावृति की जगह संघों के पदानुक्रम का निर्माण करना चाहूंगा। उनकी संपत्ति संघों द्वारा।

तो मैं किस प्रकार मूल्यांकन को नियंत्रित कर सकता हूं EntityValue?

धन्यवाद।

जवाब

2 Jean-Pierre Sep 29 2020 at 04:53
ds = Replace[
  assoc, {Entity["Individual", n_] :> 
    EntityValue[Entity["Individual", n], "PropertyAssociation"]}, 
  Infinity]

या उपयोग Normalकरने के लिए एसोसिएशन से नियमों (उपयोग ) की एक सूची बनाएं ReplaceAll।

ds = Normal[assoc] /. 
 Entity["Individual", n_] :> 
  EntityValue[Entity["Individual", n], "PropertyAssociation"]