创建节点路径

时间:2018-10-20 15:28:30

标签: neo4j cypher

如果我应该有一个数组,并且我想procedure TForm_Config.FormCreate(Sender: TObject); type tagWAVEOUTCAPS2A = packed record wMid: WORD; wPid: WORD; vDriverVersion: MMVERSION; szPname: array[0..MAXPNAMELEN-1] of AnsiChar; dwFormats: DWORD; wChannels: WORD; wReserved1: WORD; dwSupport: DWORD; ManufacturerGuid: System.TGUID; ProductGuid: System.TGUID; NameGuid: System.TGUID; end; var i,outdevs: Integer; woCaps: tagWAVEOUTCAPS2A; RegistryService: TRegistry; iClasses, iSubClasses, iNames: Integer; audioDeviceClasses, audioDeviceSubClasses, audioDeviceNames: TStringList; initialDeviceName, partialDeviceName, fullDeviceName: string; begin audioDeviceClasses := TStringList.Create; audioDeviceSubClasses := TStringList.Create; audioDeviceNames := TStringList.Create; try RegistryService := TRegistry.Create; try RegistryService.RootKey := HKEY_LOCAL_MACHINE; if RegistryService.OpenKeyReadOnly('\SYSTEM\CurrentControlSet\Enum\HDAUDIO\') then begin RegistryService.GetKeyNames(audioDeviceClasses); RegistryService.CloseKey(); for iClasses := 0 to audioDeviceClasses.Count - 1 do begin if RegistryService.OpenKeyReadOnly('\SYSTEM\CurrentControlSet\Enum\HDAUDIO\'+audioDeviceClasses[iClasses]) then begin RegistryService.GetKeyNames(audioDeviceSubClasses); RegistryService.CloseKey(); for iSubClasses := 0 to audioDeviceSubClasses.Count - 1 do begin if RegistryService.OpenKeyReadOnly('\SYSTEM\CurrentControlSet\Enum\HDAUDIO\'+audioDeviceClasses[iClasses]+'\'+audioDeviceSubClasses[iSubClasses]) then begin if RegistryService.ValueExists('DeviceDesc') then begin fullDeviceName := Trim(RegistryService.ReadString('DeviceDesc')); if AnsiPos(';',fullDeviceName) > 0 then begin fullDeviceName := Trim(AnsiMidStr(fullDeviceName, AnsiPos(';',fullDeviceName)+1, Length(fullDeviceName))); end; audioDeviceNames.Add(fullDeviceName); end; RegistryService.CloseKey(); end; end; end; end; end; finally FreeAndNil(RegistryService); end; // WaveOutDevComboBox is a selection box (combo) placed in the form and will receive the list of output audio devices WaveOutDevComboBox.Clear; try outdevs := waveOutGetNumDevs; for i := 0 to outdevs - 1 do begin ZeroMemory(@woCaps, sizeof(woCaps)); if waveOutGetDevCaps(i, @woCaps, sizeof(woCaps)) = MMSYSERR_NOERROR then begin RegistryService := TRegistry.Create; try RegistryService.RootKey := HKEY_LOCAL_MACHINE; if RegistryService.OpenKeyReadOnly('\System\CurrentControlSet\Control\MediaCategories\' + GUIDToString(woCaps.NameGuid)) then begin WaveOutDevComboBox.Items.Add(RegistryService.ReadString('Name')); RegistryService.CloseKey(); end else begin initialDeviceName := ''; partialDeviceName := Trim(woCaps.szPname); if AnsiPos('(',partialDeviceName) > 0 then begin initialDeviceName := Trim(AnsiLeftStr(partialDeviceName,AnsiPos('(',partialDeviceName)-1)); partialDeviceName := Trim(AnsiMidStr(partialDeviceName,AnsiPos('(',partialDeviceName)+1,Length(partialDeviceName))); if AnsiPos(')',partialDeviceName) > 0 then begin partialDeviceName := Trim(AnsiLeftStr(partialDeviceName,AnsiPos(')',partialDeviceName)-1)); end; end; for iNames := 0 to audioDeviceNames.Count - 1 do begin fullDeviceName := audioDeviceNames[iNames]; if AnsiStartsText(partialDeviceName,fullDeviceName) then begin break; end else begin fullDeviceName := partialDeviceName; end; end; WaveOutDevComboBox.Items.Add(initialDeviceName + IfThen(initialDeviceName<>EmptyStr,' (','') + fullDeviceName + IfThen(initialDeviceName<>EmptyStr,')','')); end; finally FreeAndNil(RegistryService); end; end; end; except WaveOutDevComboBox.Enabled := False; end; finally FreeAndNil(audioDeviceClasses); FreeAndNil(audioDeviceSubClasses); FreeAndNil(audioDeviceNames); end; end; 将数组中的所有元素放入节点的路径中,以便在给定关系名称时,将创建节点(如果它们尚不存在),并且然后彼此连接,数组中的最后一个元素将是叶子节点。我该如何在CYPHER中编写代码?

2 个答案:

答案 0 :(得分:1)

我不确定我是否理解正确,但是如果要将元素数组转换为节点的顺序路径,请使用以下查询:

WITH [1,2,3,4,5] as start
UNWIND start as a
MERGE (l:Label{id:a})
WITH collect(l) as array
    FOREACH(i in RANGE(0, length(array)-2) |
       FOREACH(element1 in [array[i]] |
           FOREACH(element2 in [array[i+1]] |
    MERGE (element1)-[:NEXT]->(element2))))

答案 1 :(得分:1)

Tomaž的答案是正确的,而且仅靠Cypher就能做到。

作为对此的补充,如果您安装了APOC Procedures,则可以使用以下过程为您执行此链接。

使用Tomaž的查询做了一些修改:

WITH [1,2,3,4,5] as start
UNWIND start as a
MERGE (l:Label{id:a})
WITH collect(l) as array
CALL apoc.nodes.link(array, 'NEXT')
RETURN true // since we can't end the query on a procedure call