Batch File for SpinText system

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
vmackey
Posts: 1
Joined: 25 May 2024 08:42

Batch File for SpinText system

#1 Post by vmackey » 25 May 2024 09:01

Hello,

I just started using batch files, and I have a little question. I am trying to create a simple spintext system for which the script will replace all the strings in text files, like with a spintext system.
Basically, I have 3 TXT files which contains my libraries of synonyms, and the content looks like that for example:

computer [PC|computer system]
laptop [portable computer]
mobile phone [cellphone|mobile|portable phone]
etc...

And I would like the script to use these 3 libraries to replace the text in the TXT Files contained in a folder.

The reason I have 3 libraries is because there is several degrees of priorities of replacement. If for example, the script replace a string based on a expression found on the library considered as the most important, it replace the string and continue with the rest of text. The string must not be replaced a second time by the libraries of lower priorities. So there is a HIGH, MEDIUM and LOW priority library.
(I hope my explanation aren't confusing as my technical language is limited.)

Note: That I would like the script to batch process several Text files at once that are in the same folder.

I hope you can help with that. Thank you very much.

shodan
Posts: 87
Joined: 01 May 2023 01:49

Re: Batch File for SpinText system

#2 Post by shodan » 26 May 2024 15:12

I would copy all matches position to a temp file, writing line, index, length of the word and from which library it is
As you go through your input text the subsequent times, for each matches check the temp file to see if that match already exists and only add a new match if it doesn't

Once all your library files are done, execute all substitution from the temp file one at a time

If your text is under 64 megs and contains no lines longer than 8191 characters.

Somewhere I have a FileToArray function
You can put your entire file in memory
do your matching from memory
save your substitution instruction to memory and run them from there

This is very old but I think it still works

Code: Select all

::Usage Call :SimpleFileToArray Filename OutputArray
:SimpleFileToArray
set "_SimpleFileToArray_prefix=_SFTA"
set /a "%~2.lbound=1"
for /f delims^=^ eol^= %%a in ('%SystemRoot%\System32\findstr.exe /N "^" "%~1"') do ( 
	for /f "tokens=1,2* delims=:" %%f in ("%%a") do set /a "%~2.ubound=%%f" & set %~2[%%f]=%%a
	)
set /a "_SFTA_index=1"
call set /a "_SFTA_ubound=%%%~2.ubound%%"
:SimpleFileToArray-loop
Setlocal enabledelayedexpansion
set _SFTA_localscope=true
set %~2[%_SFTA_index%]=!%~2[%_SFTA_index%]:*:=!
for /f "delims=" %%a in ('set %~2[%_SFTA_index%] 2^>nul') do (
		endlocal
		set %%a
	)
if defined _SFTA_localscope endlocal & set %~2[%_SFTA_index%]=
set /a "_SFTA_index+=1"
if %_SFTA_index% LEQ %_SFTA_ubound% GoTo :SimpleFileToArray-loop
Call :ClearVariablesByPrefix %_SimpleFileToArray_prefix% _SimpleFileToArray
GoTo :EOF

Post Reply