Jump to content

2DArray --> Neo4j


iamtheky
 Share

Recommended Posts

Hopefully this expands as I get to play more with Neo4j.  Starting simple here is an example of mapping artists to the bands they are in (a not quite complete Puscifer visualization).

 

Puscifer_completish.thumb.PNG.01da87dc05

 

 

;2DArray TO Neo4j
#include<array.au3>

Local $aBandMaster[0]           ;  declare this array fo later
Local $aArray[1][2]             ; declare this array for right....now

$aArray[0][0] = "name"          ;Title of column 1, will also be the Property of the NODEs established by the elements in this column
$aArray[0][1] = "is_member_of"  ;Title of column 2, will also be the Relationship of the items in column 1 to those in column 2

$Property = $aArray[0][0]                ; Using 0,0 as property
$Relationship = $aArray[0][1]            ; using 0,1 as relationship


                                        ;creating a 2D array with semicolon as the delimiter between the NAME (The Property) ; IS_MEMBER_OF (The Relationship)
                                        ;(The Relationship) for this example, is a comma delimited list of the bands that the person IS_MEMBER_OF

_ArrayAdd($aArray , "Jeff;Puscifer,APC,EODM,TBM,CarinaRound,Filter" , 0 , ";")
_ArrayAdd($aArray , "MJK;Puscifer,APC,Tool" , 0 , ";")
_ArrayAdd($aArray , "MattMc;Puscifer,EODM,TBM" , 0 , ";")
_ArrayAdd($aArray , "Carina;Puscifer,CarinaRound" , 0 , ";")
_ArrayAdd($aArray , "MatMit;Puscifer" , 0 , ";")
_ArrayAdd($aArray , "Paul;Puscifer,Ministry" , 0 , ";")
_ArrayAdd($aArray , "Mahsa;Puscifer,Omniflux" , 0 , ";")

;~ _ArrayDisplay($aArray)                   ; Mira! it is the array we just created



$sOutStr = "Create" & @LF                   ;sOutStr will be the running catchall for the command we eventually want to run in Neo4j

For $i = 1 to ubound($aArray) - 1

    $sOutStr &= "(" & $aArray[$i][0] & ":Person {" & $Property & ": '" & $aArray[$i][0] & "'})," & @LF     ; as we are looping through, use column one to create NODES that are PERSONS (this is assumed unique, if not you should get on that)

    _ArrayAdd($aBandMaster , stringsplit($aArray[$i][1] , "," , 2))                                         ; also while looping split all the comma delimited strings in column 2 and make one big list of bands stored in $aBandMaster

;~     _ArrayDisplay($aBandMaster , "BandMaster")
Next

$aBands = _ArrayUnique($aBandMaster)        ; unique that master list and now we have a nice list of all of the bands from everyones list

;~ _ArrayDisplay($aBands , "unique bands")

For $k = 1 to $aBands[0]

    $sOutStr &= "(" & $aBands[$k] & ":Band {" & $Property & ": '" & $aBands[$k] & "'})," & @LF              ;roll through that list once creating NODES, one for each BAND

Next

For $i = 1 to ubound($aArray) - 1

    $aPersonalBands = stringsplit($aArray[$i][1] , "," , 2)                     ; second loop, only this time we are building relationships, so we are working only off of the comma separated list for each individual

        For $k = 0 to ubound($aPersonalBands) - 1

            $sOutStr &= "(" & $aArray[$i][0] & ")-[:" & $Relationship & "]->(" & $aPersonalBands[$k] & ")," & @LF                   ;Since those NODES were created above, we know their names and can build RELATIONSHIPS

        Next

Next


consolewrite(stringtrimright($sOutstr , 2) & @LF)                                   ; This should be able to copy/paste directly into Neo4j



;  match n optional match (n)-[r]-() return n, r;                                   ; you need to run this afterward in Neo4j for the visualization

 

 

Edited by iamtheky
updated visual and code

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

i went the docker route for installing neo4j.  I believe the latest docker installer comes with Kitematic, which essentially gives you a storefront to just spin up and down environments way easy.

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

Cool @iamtheky. It's strange because for 10 years now I have been saying that I can connect any band or musician back to Tool, so funny you should create this example.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

*update to give the visual a little more substance, and to make sure it was handling single entries ok (it was!)

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

  • 4 months later...

* I get to see EODM tonight - would have been more fitting in the locked Paris thread, but I am so glad these guys are finishing their tour.  It's the biggest ..i., that can be given.

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...