#!/bin/sh
#] 
#] *********************
#] $ bash "$d_web"'Neural nets/TrNNs_ART/webWork/bash script: thematic [search, collect]s.sh'
# www.BillHowell.ca  20Jun2023 initial taken from "$d_bin"'fileops run.sh'
# view in text editor, using constant-width font (eg courier), tabWidth = 3

# NOTE: Before you run any function of this script you must download numerous files : 
#		"$d_bin"'standard header.sh'  
#		"$d_bin"'fileops header.sh'  
#		"$d_bin""fileops.sh"
#		ptxtFileL - all of the files listed
#	define environmental symbols as per Setup section below
#		(mostly [path, dir] where you put files on your computer network for this webSite) 
#	read the instructions near the end of this file
#24************************24




#24************************24
# List of operators, generated with :
# $ grep  "^#] "  "$d_web"'Neural nets/TrNNs_ART/webWork/bash script: thematic [search, collect]s.sh' |  sed "s/^#\]/#  /" 
#   *********************
#   $ bash "$d_web"'Neural nets/TrNNs_ART/webWork/bash script: thematic [search, collect]s.sh'
#   TrNNs_ART_pStrPL() -  replace strPL in d_TrNN_ART
#   TrNNs_ART_grep() -  very simple grep for themes in 'Grossbergs TableOfContents.html'
#   +-----+
#   [simple multi-file, multi-keyword] extraction of 
#      [[chapter, section, headings, list of figures, reader notes] 
#   TrNNs_ART_grepL_bag() -  keep on-hand already-run themes in [chapter, section] headings
#   TrNNs_ART_grepL() -  current run of themes in [chapter, section] headings


#08********08
# Setup 

#	source  "$d_bin""standard header.sh"	# not here - done by fileops.sh
source  "$d_bin""fileops.sh"

	d_TrNN_ART="$d_web"'Neural nets/TrNNs_ART/'  
	# ptxtFileL contains all paths to be grepped
	ptxtFileL="$d_web"'Neural nets/TrNNs_ART/webWork/bash script: thematic, list of txt files to search.txt'
	# [current, archive] files (current = output), final combined output file with header etc
	pThm_527="$d_TrNN_ART"'Grossbergs [core, fun, strange] concepts.html'
	pArc_527="$d_TrNN_ART"'z_Archive/Grossbergs [core, fun, strange] concepts archive.html'
	# temporary grep results file for one theme (each use of TrNNs_ART_grep)
	pTmp_527="$d_temp"'TrNNs_ART_grep tmp1.html'
	# [header, diff, TblOfCntt, result]s paths for ALL themes in TrNNs_ART_grepL_bag
	pBag_527="$d_temp"'TrNNs_ART_grep bag.html'
	pHdr_527="$d_TrNN_ART"'webWork/Grossbergs [core, fun, strange] concepts header file.html'
	pTOC_527="$d_temp"'TrNNs_ART_grepL_bag TableOfContents.txt'
	pDif_527="$d_TrNN_ART"'webWork/Grossbergs [core, fun, strange] concepts diff.txt'


#08********08
# code


#] TrNNs_ART_pStrPL() -  replace strPL in d_TrNN_ART
# 01May2023 later need script to change each file for upload      

	TrNNs_ART_pStrPL()  
{  
	pStrPL="$d_TrNN_ART"'pStrPL - list of strP replacements.txt'
	povrL="$d_TrNN_ART"'5_povrL html file list for TrNN_ART subDir.txt'
	find "$d_TrNN_ART"  -maxdepth 1  -type f  -name "*.html"  |  sort  >"$povrL"

	povrL_pStrPL_replace  1  "$povrL"  "$pStrPL"  
}  

# echo 'TrNN-ART'  |  grep -w  'ART' 
# >> TrNN-ART
# echo 'TrNN_ART'  |  grep -w  'ART' 
# >> null! OK - change dirName!


#] TrNNs_ART_grep() -  very simple grep for one theme, using inputs [title, grepStr]
# 08May023 initial version (very simple - just a bash command)     
# global random code = 527 to reduce chances of symbolName overlap between functions
# grepOp=["$1", "$2", "$3"] defined in TrNNs_ART_grepL() which calls this function
# this is a far cry from "Support Vector Machine" (SVM), Deep Learning, etc!!
# 17Jul2023 must augment to : 
#     [backup "$d_TrNN_ART" , cat "pThm_527 file header" "$pBag_527" >"$pThm_527"]

	TrNNs_ART_grep()  
{  
	echo  >"$pTmp_527"  '<A id="'"$title"'"> </a>'
	echo >>"$pTmp_527"  '   <H4>'"$title"'</h4>'
	echo >>"$pTmp_527"  ''
	echo >>"$pTmp_527"  "grepStr = $grepStr <BR>"
	echo >>"$pTmp_527"  ''
	echo >>"$pTmp_527"  '<UL>'

	while IFS='' read -r ptxtFile; do
		cmdStr='grep '"$grepOp"' "'"$grepStr"'"  "'"$ptxtFile"'"  >>"'"$pTmp_527"'" ' 
		#	echo  "$cmdStr"
			eval  "$cmdStr"
	done < "$ptxtFileL"

	echo >>"$pTmp_527"  '</ul>'
	echo >>"$pTmp_527"  '<BR>'
	echo >>"$pTmp_527"  ''

	grep  --invert-match  "URL :\|pInsert] "  "$pTmp_527"  >>"$pBag_527"  
}  


# olde code
#	grep  --invert-match  "URL :\|pInsert] \|<LI><A HREF="  "$pTmp2_527"  >>"$pTmp3_527"  




#08********08
#] +-----+
#] [simple multi-file, multi-keyword] extraction of 
#]    [[chapter, section, headings, list of figures, reader notes] 


#] TrNNs_ART_grepL() -  grep specified themes
# 01May2023 later need script to change each file for upload      

	TrNNs_ART_grepL()  
{  
	if [ -f "$pBag_527" ]; then 
		rm "$pBag_527" 
	fi

	grepOp=' -i '
	title='conscious vs non-conscious'
	grepStr='nonconscious\|non-conscious\|subconscious\|sub-conscious\|unconscious'
	TrNNs_ART_grep  

}  

#] TrNNs_ART_grepL_bag() -  [z_Archive, run] themes in [chapter, section] headings
#]    iterate at least once to manually fix up TblOfCont 
# 01May2023 later need script to change each file for upload      

	TrNNs_ART_grepL_bag()  
{  
	date_ymdhms=$(date +"%0y%0m%0d %0kh%0Mm%0Ss")
	echo  >>"$p_log" "$date_ymdhms TrNNs_ART_grepL_bag"

	if [ -f "$pBag_527" ]; then 
		rm "$pBag_527" 
	fi

	# principles, architecture, function, process
	echo  >>"$pBag_527"  '<HR>'  
	echo  >>"$pBag_527"  '<A id="principles, architecture, function, process"> </a>'  
	echo  >>"$pBag_527"  '   <H3>principles, architecture, function, process</h3>'  
	echo  >>"$pBag_527"  ''  

	grepOp=' -i '
	title='Principles, Principia'
	grepStr='Principles-Principia\|behavior-mind-brain link\|cycle of model evolution'
	TrNNs_ART_grep  

	grepOp=' -i '
	title='equations of the [brain, mind]'
	grepStr='equation'
	TrNNs_ART_grep  

	grepOp=' -i '
	title='modules & modal architectures ([micro, macro]-circuits)'
	grepStr='modules\|microcircuit\|modal architecture\|macrocircuit'
	TrNNs_ART_grep  

	grepOp=' -i '
	title='CogEM Cognitive-Emotional-Motor model'
	grepStr='CogEM\|Cognitive-Emotional-Motor'
	TrNNs_ART_grep  

	grepOp=' -i '
	title='[intra, inter]-cellular process'
	grepStr='intracellular\|extracellular'
	TrNNs_ART_grep  

	grepOp=' -i '
	title='informational noise suppression'
	grepStr='noise suppression\|rate spectra'
	TrNNs_ART_grep  


	# [stable, robust, adaptive] learning
	echo  >>"$pBag_527"  '<HR>'  
	echo  >>"$pBag_527"  '<A id="[stable, robust, adaptive] learning"> </a>'  
	echo  >>"$pBag_527"  '   <H3>[stable, robust, adaptive] learning</h3>'  
	echo  >>"$pBag_527"  ''  

	grepOp=' -i '
	title='on-center off-surround'
	grepStr='on-center\|off-surround\|on center\|off surround'
	TrNNs_ART_grep  

	grepOp=' -i '
	title='top-down bottom-up'
	grepStr='top-down\|bottom-up\|top down\|bottom up'
	TrNNs_ART_grep  

	grepOp=' -i '
	title='cooperative-competitive'
	grepStr='cooperative\|competitive'
	TrNNs_ART_grep  

	grepOp=' -i '
	title='complementary computing'
	grepStr='complementary'
	TrNNs_ART_grep  

	grepOp=' -i '
	title='laminar computing'
	grepStr='laminar'
	TrNNs_ART_grep  

	grepOp=' -i '
	title='computing with cellular patterns'
	grepStr='cellular pattern'
	TrNNs_ART_grep  


	# family of ART .....base, linguistic
	echo  >>"$pBag_527"  '<HR>'  
	echo  >>"$pBag_527"  '<A id="family of ART.....base, linguistic"> </a>'  
	echo  >>"$pBag_527"  '   <H3>family of ART.....base, linguistic</h3>'  
	echo  >>"$pBag_527"  ''  

	grepOp=' -w '
	title='ART - Adaptive Resonance Theory'
	grepStr='ART'
	TrNNs_ART_grep  

	grepOp=' -w '
	title='LAMINART vison, speech, cognition'
	grepStr='LAMINART'
	TrNNs_ART_grep  

	grepOp=' -w '
	title='[, n]START learning & memory consolidation'
	grepStr='START\|nSTART'
	TrNNs_ART_grep  

	grepOp=' -w '
	title='ARTMAP learn maps of natural terrain '
	grepStr='ARTMAP'
	TrNNs_ART_grep  

	grepOp=' -w '
	title='[, c]ARTWORD word perception cycle'
	grepStr='ARTWORD\|cARTWORD'
	TrNNs_ART_grep  

	grepOp=' -w '
	title='LIST PARSE [linguistic, spatial, motor] working memory'
	grepStr='LIST PARSE'
	TrNNs_ART_grep  


	# family of ART ....visual, auditory
	echo  >>"$pBag_527"  '<HR>'  
	echo  >>"$pBag_527"  '<A id="family of ART ....visual, auditory"> </a>'  
	echo  >>"$pBag_527"  '   <H3>family of ART ....visual, auditory</h3>'  
	echo  >>"$pBag_527"  ''  

	grepOp=' -w '
	title='[, d, p]ARTSCAN attentional shroud, binocular rivalry'
	grepStr='ARTSCAN\|dARTSCAN\|pARTSCAN'
	TrNNs_ART_grep  

	grepOp=' -w '
	title='ARTSCENE classification of scenic properties'
	grepStr='ARTSCENE'
	TrNNs_ART_grep  

	grepOp=' -i '
	title='SMART synchronous matching ART, mismatch triggering'
	grepStr='SMART\|synchronous match\|mismatch trigger'
	TrNNs_ART_grep  

	grepOp=' -w '
	title='ARTPHONE [gain control, working] memory'
	grepStr='ARTPHONE'
	TrNNs_ART_grep  

	grepOp=' -w '
	title='ARTSTREAM auditory streaming, SPINET sound spectra'
	grepStr='ARTSTREAM\|SPINET'
	TrNNs_ART_grep  


	# conciousness
	echo  >>"$pBag_527"  '<HR>'  
	echo  >>"$pBag_527"  '<A id="conciousness"> </a>'  
	echo  >>"$pBag_527"  '   <H3>conciousness</h3>'  
	echo  >>"$pBag_527"  ''  

	grepOp=' -i '
	title='What is consciousness?'
	grepStr='conscious'
	TrNNs_ART_grep  

	grepOp=' -w '
	title='conscious vs non-conscious'
	grepStr='non-conscious\|nonconscious\|unconscious'
	TrNNs_ART_grep  

	grepOp=' -i '
	title='behavior-mind-brain link'
	grepStr='behavior-mind-brain link'
	TrNNs_ART_grep  

	grepOp=' -i '
	title='classical mind-brain problem'
	grepStr='mind-body -classical- problem'
	TrNNs_ART_grep  

	grepOp=' -i '
	title='Grossberg: other consciousness theories'
	grepStr='Baars\|Dehaene\|Tononi\|Edelman\|Dennett\|Damasio\|Crick\|Koch\|Marcus\|Pinker\|Chomsky'
	TrNNs_ART_grep  



	# random fun themes
	echo  >>"$pBag_527"  '<HR>'  
	echo  >>"$pBag_527"  '<A id="random fun themes"> </a>'  
	echo  >>"$pBag_527"  '   <H3>random fun themes</h3>'  
	echo  >>"$pBag_527"  ''  

	grepOp=' -i '
	title='art (painting etc)'
	grepStr='DaVinci\|Monet\|Matisse\|Seurat'
	TrNNs_ART_grep  

	grepOp=' -i '
	title='biology, evolution, paleontology'
	grepStr='biology\|evolution\|paleontology\|brain evolution'
	TrNNs_ART_grep  

	grepOp=' -i '
	title='brain disorders and disease'
	grepStr='brain disorder\|autism\|amnesia\|Alzheimer\|sleep\|Agnosia\|schizophrenia\|ADHD\|Theory of Mind\|HeLa cancer cells\|Xenopus oocytes\|cardiac myocytes\|helplessness\|self-punitive\|fetish\|hallucinate'
	TrNNs_ART_grep  

	grepOp=' -i '
	title='hippocampus IS a cognitive map!'
	grepStr='hippocampus\|hippocampal\|cognitive map'
	TrNNs_ART_grep  

	grepOp=' -i '
	title='auditory continuity illusion'
	grepStr='auditory continuity'
	TrNNs_ART_grep  

	grepOp=' -i '
	title='see-reach to hear-speak'
	grepStr='reach\|speak\|see-reach to hear-speak '
	TrNNs_ART_grep  

	grepOp=' -i '
	title='neurotransmitter'
	grepStr='neurotransmitter\|dopamine\|serotonin\|noradrenaline\|acetocholine\|gaba'
	TrNNs_ART_grep  

	grepOp=' -i '
	title='learning and development'
	grepStr='infant development\|adult learning\|cortical development'
	TrNNs_ART_grep  

	grepOp=' -i '
	title='Why are there hexagonal grid cell receptive fields?'
	grepStr='hexagonal'
	TrNNs_ART_grep  



	# Strange themes
	echo  >>"$pBag_527"  '<HR>'  
	echo  >>"$pBag_527"  '<A id="Strange themes"> </a>'  
	echo  >>"$pBag_527"  '   <H3>Strange themes</h3>'  
	echo  >>"$pBag_527"  ''  

	grepOp=' -i '
	title='AI, machine intelligence, etc'
	grepStr='artificial intelligence\|autonomous adaptive mobile intelligence\|machine intelligence'
	TrNNs_ART_grep  

	grepOp=' -i '
	title='Brain is NOT Bayesian?'
	grepStr='Bayesian'
	TrNNs_ART_grep  

	grepOp=' -wi '
	title='brain rythms & Schuman resonances'
	grepStr='theta\|gamma\|beta\|delta\|Schuman'
	TrNNs_ART_grep  

	grepOp=' -i '
	title='Explainable AI'
	grepStr='Explainable AI'
	TrNNs_ART_grep  

	grepOp=' -wi '
	title='logic vs connectionist'
	grepStr='logic\|connectionist'
	TrNNs_ART_grep  


	# Successful [datamodelling, applications] showing effectiveness
	echo   >>"$pBag_527"  '<HR>'  
	echo   >>"$pBag_527"  '<A id="Successful [datamodelling, applications] showing effectiveness of cART etc"> </a>'  
	echo   >>"$pBag_527"  '   <H3>Successful [datamodelling, applications] showing effectiveness of cART etc</h3>'  
	echo   >>"$pBag_527"  ''  

	grepOp=' -i '
	title='[bio, neuro, psycho]logy data'
	grepStr='data\|monkey\|sea urchin\|slime mold\|slug\|tree shrew\|biology\|Psychological\|neurobiological\|neurophysiological\|perceptual\|mudpuppy\hydra\|aplysia'
	TrNNs_ART_grep  

	# this list was retyped manually from a paragraph in the book
	# there are no section headings for this, too diverse!
	grepOp=' -i '
	title='[software, engineering, other] applications'
	grepStr='software\|science\|engineering\|applications'
	TrNNs_ART_grep  



	# generate RAW TableOfContents 
	pHtml_extract_pTOC  "$pBag_527"  "$pTOC_527"  
	# backup original "$pThm_527"
	if		[ -f "$pThm_527" ]; then
		pInn_archiveLocal_pDateMod  "$pThm_527"
	fi
	cat  "$pHdr_527"  "$pBag_527"  >"$pThm_527"
}  



#] pThm_pArc_diff_pDif(pThm pArc)  - extract diffs [old, new]

	pThm_pArc_diff_pDif()
{
	diff "$pArc_527"  "$pThm_527"  --suppress-common-lines  >"$pDif_527"
} 



#08********08
# Descriptions of functions (copy of TableOfContents near top of this file) :
#   TrNNs_ART_pStrPL()		-  replace strPL in d_TrNN_ART
#   TrNNs_ART_grep()			-  grep one theme 
#   TrNNs_ART_grepL_bag()	-  ALL themes 
#   TrNNs_ART_grepL()		-  grep just one theme 
#      results file : pTmp3_527="$d_temp"'TrNNs_ART_grep tmp3.html' 


# Instructions to run : 
#	uncomment ONE line below to select a function call
#	, save this file,  
#    copy-paste to command line : bash "$d_web"'Neural nets/TrNNs_ART/webWork/bash script: thematic [search, collect]s.sh' 

# not normally used : ? 
	#htmlHeadings_to_TblOfContents  "$d_web"'Neural nets/TrNNs_ART/What is consciousness: from historical to Grossberg.html'

	#TrNNs_ART_pStrPL				# replace strPL in d_TrNN_ART
	#TrNNs_ART_grepL				# grep several themes
	TrNNs_ART_grepL_bag			# [z_Archive, run] themes in [chapter, section] headings
	# manual - reconstruct NEW TblOfCont in pHdr, NOT IN pThm!!!!
#	pThm_pArc_diff_pDif			# extract diffs [old, new]




# $ bash  "$d_web"'Neural nets/TrNNs_ART/webWork/bash script: thematic [search, collect]s.sh'  

# enddoc

