Jump to content

indexing idea


fraizor
 Share

Recommended Posts

HI im new here

 

i am making a script that endex some file by letter

the main idea is that it should make an index of some words then write in that index the lines that the words appeared in

 

untill now i did all of the work of finding the words and there lines

 

my problem is with saving the data i have.

i tried multi dimentional arrays but no luck , i cant find a way to add a string at the last non accoupied coulumn in a spesific row ?

 

for example:

 

i want to add the number "9" to all of the array rows

but each row have a diffrent occupied coulumns

here what the array looks like currently

A  1  2  3  4  5

B  1  2  3 

C 1  2  3  4 

D 1  2  3  4  5

 

when i use _array_add or array_insert it will be like this

 

A  1  2  3  4  5  9

B  1  2  3           9

C 1  2  3  4        9

D 1  2  3  4  5  9

 

i want to make it like this (no empty fields)

A  1  2  3  4  5  9

B  1  2  3  9

C 1  2  3  4  9

D 1  2  3  4  5  9

 

 

any one can provide some easy multidimentions examples please

 

AutoFox, A Modern, Simple, No dependency, Noob friendly yet powerful Firefox UDF !

Link to comment
Share on other sites

hello @fraizor, welcome to AutoIt and to the forum.

you will undoubtedly end up using a database, so begin with studying the SQLite UDF that ships with AutoIt. i woud begin with a two-column table, where one column stores the word, and the other stores that word occurrences, in a format of this kind:

"file1.ext:1,5,9,18;file2.ext:2,3,8;"

so when a new file is indexed, you scan the file for for the list of words, and add a substring to the contents of the respective column.

and when you query for a word, you get all its occurrences instantly.

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

Link to comment
Share on other sites

This example appends a new value to the first occurring blank column of each row in an array.

#include <Array.au3>

Local $Array[4][6] = [ _
        ["A", 1, 2, 3, 4, 5], _
        ["B", 1, 2], _
        ["C", 1, 2, 3, 4], _
        ["D", 1, 2, 3, 4, 5]]

_ArrayDisplay($Array, "Before")
$aArr = _ArrayAppendToEachRow($Array, 9)
_ArrayDisplay($aArr, "After")


Func _ArrayAppendToEachRow(ByRef $Array, $Value)
    Local $s = _ArrayToString($Array)
    ;ConsoleWrite($s & @CRLF)
    $s = StringRegExpReplace($s, "(?m)([^\|\v]+)$|(\|+)$", "${1}|" & $Value)
    ;ConsoleWrite($s & @CRLF)
    Local $a[0][UBound($Array, 2) + 1]
    _ArrayAdd($a, $s)
    Return $a
EndFunc   ;==>_ArrayAppendToEachRow

 

Link to comment
Share on other sites

array of arrays

#include <Array.au3>
Local $a1[6] = ["A", 1, 2, 3, 4, 5]
Local $a2[3] = ["B", 1, 2]
Local $a3[5] = ["C", 1, 2, 3, 4]
Local $a4[6] = ["D", 1, 2, 3, 4, 5]
Local $aHolder[4] = [$a1,$a2,$a3,$a4]

ArrayAdd($aHolder,9)

; just to display:
For $i = 0 To UBound($aHolder)-1
    _ArrayDisplay($aHolder[$i])
Next


Func ArrayAdd(ByRef $a, $iNum)
    For $i = 0 To UBound($a)-1
        Local $aTemp = $a[$i]
        _ArrayAdd($aTemp,$iNum)
        $a[$i] = $aTemp
    Next
EndFunc

 

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

15 hours ago, orbs said:

hello @fraizor, welcome to AutoIt and to the forum.

you will undoubtedly end up using a database, so begin with studying the SQLite UDF that ships with AutoIt. i woud begin with a two-column table, where one column stores the word, and the other stores that word occurrences, in a format of this kind:

"file1.ext:1,5,9,18;file2.ext:2,3,8;"

so when a new file is indexed, you scan the file for for the list of words, and add a substring to the contents of the respective column.

and when you query for a word, you get all its occurrences instantly.

thanks you for your participation

yes i belive it is the most handy soulution

 

but my problem is that i need to save the index result to a file each time then read the data from the file and add some indexes to it

 

i belive the sql file is unreadable by txt editor

 

i used arrayes because i can use write/ read array from/to file

AutoFox, A Modern, Simple, No dependency, Noob friendly yet powerful Firefox UDF !

Link to comment
Share on other sites

4 hours ago, Malkey said:

This example appends a new value to the first occurring blank column of each row in an array.

#include <Array.au3>

Local $Array[4][6] = [ _
        ["A", 1, 2, 3, 4, 5], _
        ["B", 1, 2], _
        ["C", 1, 2, 3, 4], _
        ["D", 1, 2, 3, 4, 5]]

_ArrayDisplay($Array, "Before")
$aArr = _ArrayAppendToEachRow($Array, 9)
_ArrayDisplay($aArr, "After")


Func _ArrayAppendToEachRow(ByRef $Array, $Value)
    Local $s = _ArrayToString($Array)
    ;ConsoleWrite($s & @CRLF)
    $s = StringRegExpReplace($s, "(?m)([^\|\v]+)$|(\|+)$", "${1}|" & $Value)
    ;ConsoleWrite($s & @CRLF)
    Local $a[0][UBound($Array, 2) + 1]
    _ArrayAdd($a, $s)
    Return $a
EndFunc   ;==>_ArrayAppendToEachRow

 

 

 

thnak you very much this is really brilliant

 

i had been trying to edit your example to make it add a value at the exd of a sepicified row , but i failed

i still cant understand how you did that without using "for loops" or "if then"

 

 

AutoFox, A Modern, Simple, No dependency, Noob friendly yet powerful Firefox UDF !

Link to comment
Share on other sites

1 hour ago, fraizor said:

i had been trying to edit your example to make it add a value at the exd of a sepicified row , but i failed

i still cant understand how you did that without using "for loops" or "if then"

Then In this case, It isn't exactly "_arrayadd" that is needed:

#include <Array.au3>

Local $Array[4][9] = [ _
        ["A", 1, 2, 3, 4, 5], _
        ["B", 1, 2], _
        ["C", 1, 2, 3, 4], _
        ["D", 1, 2, 3, 4, 5]]
_ArrayAddInsert($Array, 0, 9)

_ArrayDisplay($Array)

Func _ArrayAddInsert(ByRef $Array, $iRow, $Vadd)
    $Array[$iRow][ _
            UBound(StringRegExp(_ArrayToString($Array, "|", $iRow, $iRow), "([?|])+", 3)) _
            ] = $Vadd
EndFunc   ;==>_ArrayAddInsert

Deye

Link to comment
Share on other sites

Just slightly modified Deye's example so that it would append a value to the blank end column of the specified row.

#include <Array.au3>
; https://www.autoitscript.com/forum/topic/197474-indexing-idea/?do=findComment&comment=1416575

Local $Array[4][6] = [ _
        ["A", 1, 2, 3, 4, 5], _
        ["B", 1, 2], _
        ["C", 1, 2, 3, 4], _
        ["D", 1, 2, 3, 4, 5]]

_ArrayAddInsert($Array, 0, 9)
_ArrayAddInsert($Array, 1, 10)
_ArrayAddInsert($Array, 2, 11)
_ArrayAddInsert($Array, 3, 12)

_ArrayDisplay($Array)

Func _ArrayAddInsert(ByRef $Array, $iRow, $Vadd)
    ReDim $Array[UBound($Array)][UBound($Array, 2) + 1]
    $Array[$iRow][UBound(StringRegExp(_ArrayToString($Array, "|", $iRow, $iRow), "[^|]+", 3))] = $Vadd
    If $Array[$iRow][UBound($Array, 2) - 1] == "" Then ReDim $Array[UBound($Array)][UBound($Array, 2) - 1]
EndFunc   ;==>_ArrayAddInsert

 

Edited by Malkey
Changed R.E. Pattern from "([?|])+" to "[^|]+".
Link to comment
Share on other sites

Malkey,

Nice, I see the changed Pattern to work with col 0 when its a blank row ..

  • Here are small additions to the example for Adding from 1D Array or delimited strings 
    •  - fix to Redim in question
    •  New -  _ArrayShrink (Cols) Example ( Aided by the same formula ..)
#include <Array.au3>

Local $Array[4][11] = [ _
        [], _
        ["B", 1], _
        ["C", 1, 2], _
        ["D", 1, 2, 3]]

_ArrayDisplay($Array, "Original")
_ArrayShrink($Array)    ; shrink the Array to the first none blank Col
_ArrayDisplay($Array, "Original (shrinked)")

_ArrayAppendToRow($Array, 1, "|||||Append-Point")       ;Appended with blanks
_ArrayAppendToRow($Array, 1, "Another Append Point")    ;Appended to first blank Col
_ArrayAppendToRow($Array, 0, _ArrayExtract($Array, 0, Default, 0, 0))  ;1D (COl 0) ;Array
_ArrayAppendToRow($Array, 2, "Append-Point|11|12|13")
_ArrayAppendToRow($Array, 3, "Append-Point|11|12")

$iNew = _ArrayAdd($Array, "")
_ArrayAppendToRow($Array, $iNew, "^>>")

_ArrayDisplay($Array, "Original + Appends")

Func _ArrayAppendToRow(ByRef $Array, $iRow, $Vadd)
    Local $aAdd = (StringInStr($Vadd, "|") ? StringSplit($Vadd, "|", 3) : ($Vadd ? 1 : $Vadd))
    Local $i = UBound(StringRegExp(_ArrayToString($Array, "|", $iRow, $iRow), "[^|]+\|", 3))
    Local $iColAdd = ($aAdd ? $aAdd : UBound($aAdd))
    If UBound($Array, 2) - ($i + $iColAdd) < 0 Then ReDim $Array[UBound($Array)][$i + $iColAdd]
    If $iColAdd > 1 Then
        For $j = 0 To UBound($aAdd) - 1
            $Array[$iRow][$i + $j] = $aAdd[$j]
        Next
    Else
        $Array[$iRow][$i] = $Vadd
    EndIf
EndFunc   ;==>_ArrayAppendToRow

Func _ArrayShrink(ByRef $Array)
    Local $iCols = UBound($Array, 2), $aCol, $x = 0
    Do
        $x += 1
        $aCol = _ArrayExtract($Array, Default, Default, ($iCols - $x), ($iCols - $x))
    Until UBound(StringRegExp(_ArrayToString($aCol, "|"), "[^|]+", 3))
    If $x > 1 Then ReDim $Array[UBound($Array)][$iCols - $x + 1]
EndFunc   ;==>_ArrayShrink

Deye

Edited by Deye
Link to comment
Share on other sites

Deye

It is interesting how you focused on the $Vadd ($Value) parameter to manipulate the array. I hadn't considered that, nice.
In this example, I focused on the $iRow ($iRowRange - row range) parameter as a routine for future use.

#include <Array.au3>

Local $Array[7][6] = [ _
        ["A", 1, 2, 3, 4, 5], _
        ["B", 1, 2], _
        ["C", 1, 2, 3, 4], _
        ["D", 1, 2, 3, 4, 5], _
        ["E", 1, 2], _
        ["F", 1, 2], _
        ["G", 1, 2, 3, 4, 5]]

; ---------------- Examples of _ArrayAppendToRow() function ---------------
Local $Arr0 = $Array
_ArrayAppendToRow($Arr0, 9) ; Note: The default "$iRowRange" parameter, "" or Default, will append the "$Value" to
;                                 the first blank column in every row in the array.
_ArrayDisplay($Arr0, "Default (All Rows)")

Local $Arr1 = $Array
_ArrayAppendToRow($Arr1, 9, "0;2-4;6") ; <== This "$iRowRange" parameter means values will be appended to rows 0, 2, 3, 4, and 6.
_ArrayDisplay($Arr1, "Rows #0; 2-4; 6")

Local $Arr2 = $Array
_ArrayAppendToRow($Arr2, 9, "0 - 2; 4 - 2 ; 2") ; Note: There are three row 2's mentioned in "$iRowRange", so there are 3 "$Value"
;                                                  appended to row #2.  As well as, one "$Value" appended to rows #0, 1, 3, and 4.
_ArrayDisplay($Arr2, "Rows #0-2; 4-2; 2")
; ------------- End of Examples of _ArrayAppendToRow() function ------------


Func _ArrayAppendToRow(ByRef $Array, $Value, $iRowRange = "")
    If $iRowRange = Default Or $iRowRange = "" Then $iRowRange = "0-" & UBound($Array) - 1

    ;-------- Get index array from $iRowRange -----------------
    Local $aR = StringSplit(StringStripWS($iRowRange, 8), ";", 2) ; 8 = strip all spaces, and, the 2 = disable the
    ;                                                               return count in the first element of return array.
    Local $sStrIndex = "", $iIndex, $aTemp
    For $i = 0 To UBound($aR) - 1
        If StringInStr($aR[$i], "-") Then
            $aTemp = StringSplit($aR[$i], "-", 2)
            For $j = $aTemp[0] To $aTemp[1] Step ($aTemp[0] <= $aTemp[1] ? 1 : -1) ; The "stepval" parameter allows for either
                ;             the "start" parameter, or the "stop" parameter, being the bigger value in the For-Next function.
                $sStrIndex &= $j & "|"
            Next
        Else
            $sStrIndex &= $aR[$i] & "|"
        EndIf
    Next
    Local $aArrayIndex = StringSplit(StringTrimRight($sStrIndex, 1), "|", 2)
    ; _ArrayDisplay($aArrauIndex)
    ;-------- End of Get index array from $iRowRange -----------------

    For $iRow In $aArrayIndex
        $iIndex = UBound(StringRegExp(_ArrayToString($Array, "|", $iRow, $iRow), "[^|]+", 3))
        If $iIndex = UBound($Array, 2) Then ReDim $Array[UBound($Array)][UBound($Array, 2) + 1]
        $Array[$iRow][$iIndex] = $Value
    Next
EndFunc   ;==>_ArrayAppendToRow

 

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...