Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
43
Task/Inverted-index/PowerShell/inverted-index-1.psh
Normal file
43
Task/Inverted-index/PowerShell/inverted-index-1.psh
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
function Index-File ( [string[]]$FileList )
|
||||
{
|
||||
# Create index hashtable, as needed
|
||||
If ( -not $Script:WordIndex ) { $Script:WordIndex = @{} }
|
||||
|
||||
# For each file to be indexed...
|
||||
ForEach ( $File in $FileList )
|
||||
{
|
||||
# Find any previously existing entries for this file
|
||||
$ExistingEntries = $Script:WordIndex.Keys | Where { $Script:WordIndex[$_] -contains $File }
|
||||
|
||||
# For any previously existing entries
|
||||
# Delete them (prior to reindexing the file)
|
||||
ForEach ( $Key in $ExistingEntries )
|
||||
{
|
||||
$Script:WordIndex[$Key] = @( $Script:WordIndex[$Key] | Where { $_ -ne $File } )
|
||||
}
|
||||
|
||||
# Get the contents of the file, split on non-alphanumeric characters, and remove duplicates
|
||||
$Words = ( Get-Content $File ) -split '[^a-zA-Z\d]' | Sort -Unique
|
||||
|
||||
# For each word in the file...
|
||||
ForEach ( $Word in $Words )
|
||||
{
|
||||
# If the entry for the word already exists...
|
||||
If ( $Script:WordIndex[$Word] )
|
||||
{
|
||||
# Add the file name to the entry
|
||||
$Script:WordIndex[$Word] += $File
|
||||
}
|
||||
Else
|
||||
{
|
||||
# Create a new entry
|
||||
$Script:WordIndex[$Word] = @( $File )
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function Find-Word ( [string]$Word )
|
||||
{
|
||||
return $WordIndex[$Word]
|
||||
}
|
||||
15
Task/Inverted-index/PowerShell/inverted-index-2.psh
Normal file
15
Task/Inverted-index/PowerShell/inverted-index-2.psh
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
# Populate test files
|
||||
@'
|
||||
Files full of
|
||||
various words.
|
||||
'@ | Out-File -FilePath C:\Test\File1.txt
|
||||
|
||||
@'
|
||||
Create an index
|
||||
of words.
|
||||
'@ | Out-File -FilePath C:\Test\File2.txt
|
||||
|
||||
@'
|
||||
Use the index
|
||||
to find the files.
|
||||
'@ | Out-File -FilePath C:\Test\File3.txt
|
||||
2
Task/Inverted-index/PowerShell/inverted-index-3.psh
Normal file
2
Task/Inverted-index/PowerShell/inverted-index-3.psh
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
# Index files
|
||||
Index-File C:\Test\File1.txt, C:\Test\File2.txt, C:\Test\File3.txt
|
||||
2
Task/Inverted-index/PowerShell/inverted-index-4.psh
Normal file
2
Task/Inverted-index/PowerShell/inverted-index-4.psh
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
# Query index
|
||||
Find-Word files
|
||||
Loading…
Add table
Add a link
Reference in a new issue