0
votes

I have a following Cypher Pattern Comprehension:

[ (parentD)<-[:DEFINED_BY]-(ch1:Characteristic)<-[v1:HAS_VALUE_ON]-(childD)  
WHERE NOT ((ch1)<-[:DEPENDS_ON]-()) AND ch1.type = 'CHILD'
| {characteristicId: toInt(ch1.id),  value: v1.value, available: v1.available, totalHistoryValues: v1.totalHistoryValues, description: v1.description, valueType: ch1.valueType, visualMode: ch1.visualMode} ] AS valuedCharacteristics

where parentD and childD are the variables from outer query scope.

Right now I need to improve this Pattern Comprehension with additional nodes:

(childD)<-[:DEFINED_BY]-(ch2:Characteristic)<-[v2:HAS_VALUE_ON]-(childD)
WHERE NOT ((ch2)<-[:DEPENDS_ON]-()) AND ch2.type = 'OWN'

in order to be able also return Characteristics(ch2) from this query and their values(v2).

Please help to extend the mentioned query in order to return this information under the same valuedCharacteristics

UPDATED

I have updated comprehension to the following:

[ (parentD)<-[:DEFINED_BY]-(ch1:Characteristic)<-[v1:HAS_VALUE_ON]-(childD)<-[:DEFINED_BY]-(ch2:Characteristic)<-[v2:HAS_VALUE_ON]-(childD)  
  WHERE 
    NOT ((ch1)<-[:DEPENDS_ON]-()) AND ch1.type = 'CHILD' AND 
    NOT ((ch2)<-[:DEPENDS_ON]-()) AND ch2.type = 'OWN' | 
  { characteristicId: toInt(ch1.id), value: v1.value, available: v1.available, totalHistoryValues: v1.totalHistoryValues, description: v1.description, valueType: ch1.valueType, visualMode: ch1.visualMode, 
    childCharacteristicId: toInt(ch2.id), childValue: v2.value, childAvailable: v2.available, childTotalHistoryValues: v2.totalHistoryValues, childDescription: v2.description, childValueType: ch2.valueType, childVisualMode: ch2.visualMode 
  } 
] AS valuedCharacteristics

but right now it always returns empty collection.

I may be wrong but I think the reason is that the following query:

[ (parentD)<-[:DEFINED_BY]-(ch1:Characteristic)<-[v1:HAS_VALUE_ON]-(childD)<-[:DEFINED_BY]-(ch2:Characteristic)<-[v2:HAS_VALUE_ON]-(childD)  

can't return the result in some cases.. for example when ch2 is present and ch1 is absent.

1
In the second pattern comprehension, you have (childD) on both sides of the pattern. Is that intended?InverseFalcon
yes, it means that Decision defines Characteristic and then place a value for itself on this Characteristic (in this case type = 'OWN')alexanoid

1 Answers

0
votes

This pattern comprehension should work (but it will generate an empty collection unless the entire pattern is matched):

[(parentD)<-[:DEFINED_BY]-(ch1:Characteristic)<-[v1:HAS_VALUE_ON]-(childD)<-[:DEFINED_BY]-(ch2:Characteristic)<-[v2:HAS_VALUE_ON]-(childD)
  WHERE
    NOT ((ch1)<-[:DEPENDS_ON]-()) AND ch1.type = 'CHILD' AND
    NOT ((ch2)<-[:DEPENDS_ON]-()) AND ch2.type = 'OWN' |
  {
    characteristicId: toInt(ch1.id), value: v1.value, available: v1.available, totalHistoryValues: v1.totalHistoryValues, description: v1.description, valueType: ch1.valueType, visualMode: ch1.visualMode,
    childCharacteristicId: toInt(ch2.id), childValue: v2.value, childAvailable: v2.available, childTotalHistoryValues: v2.totalHistoryValues, childDescription: v2.description, childValueType: ch2.valueType, childVisualMode: ch2.visualMode
  }
] AS valuedCharacteristics

[UPDATED]

However, if you want to always get the "parent" data, but optionally get the "child" data (if it exists), then you could switch to using MATCH and OPTIONAL MATCH. For example:

MATCH (parentD)<-[:DEFINED_BY]-(ch1:Characteristic)<-[v1:HAS_VALUE_ON]-(childD)
WHERE NOT ((ch1)<-[:DEPENDS_ON]-()) AND ch1.type = 'CHILD'
OPTIONAL MATCH (childD)<-[:DEFINED_BY]-(ch2:Characteristic)<-[v2:HAS_VALUE_ON]-(childD)
WHERE NOT ((ch2)<-[:DEPENDS_ON]-()) AND ch2.type = 'OWN'
RETURN COLLECT({
  parent: {characteristicId: toInt(ch1.id), value: v1.value, available: v1.available, totalHistoryValues: v1.totalHistoryValues, description: v1.description, valueType: ch1.valueType, visualMode: ch1.visualMode},
  child: {characteristicId: toInt(ch2.id), value: v2.value, available: v2.available, totalHistoryValues: v2.totalHistoryValues, description: v2.description, valueType: ch2.valueType, visualMode: ch2.visualMode}
}) AS valuedCharacteristics