cancel
Showing results for 
Search instead for 
Did you mean: 

Accessing elements of WD Context node randomly

Former Member
0 Kudos

Hi All

I have context node structure like

Question (node)

|--- qid (attribute under Question)

|--- qtext (attribute under Question)

|--- Answer (node)

|--- aid (attribute under Answer)

|--- avalue (attribute under Answer)

Is there any way to access DIRECTLY the value of avalue if i know the value of qid and aid?

Please help

Regards

Sonal Mangla

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

Looks like you have multiple Questions with multiple choice answers.

If you know the qid & aid, you have to iterate through the question node elements to find the particular question whose id is qid (for loop with size of QuestionNode). After finding that que node element, in that you will have multiple answers i.e multiple answernode elements will exist. So you have to again iterate through the Answer node (for loop with size of answerNode) to check for the element with given aid value. When you get that, get the corresponding avalue.

I am not sure how it could be done in a more direct way. In case you are able to implement, do share the same.

Regards,

Anagha

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Sonal,

I suppose that you want to the implement the logic as you mentioned to reduced the iteration through the entire questions nodes which would be of course 1..n cardinality node.

If that was my requirement I would have implemented it in following way.

- The question node structure with cardinality 1..n

- Answer node is declared as SINGLETON - true.

- Assigning supply functions for the answer node/attributes

- Adjusting the lead selection based on the qid

The above solution will not only fulfill your requirement but it would also prevent your context memory size from blowing up if your answer choices are huge set of text string in multiple.

Please let me know if this helps you.

regards,

Prasanna

Former Member
0 Kudos

Making Answer node as singleton and using supply function is fine, but it still needs traversing through both the nodes to reach avalue.

Former Member
0 Kudos

Hello Anagha,

Yes you are right. Traversing is needed but only if the qid(question id) is a random number. We can very well use the lead selection if the question numbers are serial ones.

REgards,

Prasanna

Former Member
0 Kudos

Hi All

Thanks a ton for your inputs. This means there is no way we can avoid looping to get a particular element in the nodes.

Regards

Sonal

Former Member
0 Kudos

I am not sure if I understand your question completely but if you want to avoid looping through the "Question" node to find the question with the given ID then you could for example store the (question, answers)-pairs using a map and access the list of answers for a given question ID directly.

Armin

Former Member
0 Kudos

Hi,

I think you need to have Parent and Child nodes relationship for your purpose. That is you need to have qid attribute in your Answer node also mapped to Question node, which behaves as primary key and foreign key references.

Regards

Raghu