Anonymous user
Inverted index: Difference between revisions
m
→{{header|REXX}}: changed/added comments and whitespace, changed indentations, changed a word (for finding).
m (added whitespace before the TOC (table of contents), added a ;Task: (bold) header.) |
m (→{{header|REXX}}: changed/added comments and whitespace, changed indentations, changed a word (for finding).) |
||
Line 2,325:
To see more about Burma Shave signs, see the Wikipedia entry: [http://en.wikipedia.org/wiki/Burma-Shave Burma Shave signs.]
<lang rexx>/*REXX program illustrates building a simple inverted index
@.=
!=
call invertI 0, 'BURMA0.TXT' /*read the file: BURMA0.TXT
call invertI 1, 'BURMA1.TXT' /* " "
call invertI 2, 'BURMA2.TXT' /* " "
call invertI 3, 'BURMA3.TXT' /* " "
call invertI 4, 'BURMA4.TXT' /* " "
call invertI 5, 'BURMA5.TXT' /* " "
call invertI 6, 'BURMA6.TXT' /* " "
call invertI 7, 'BURMA7.TXT' /* " "
call invertI 8, 'BURMA8.TXT' /* " "
call invertI 9, 'BURMA9.TXT' /* " "
call findAword
call findAword
call findAword "don't" /*and find another word. */
call findAword "burma-shave" /*and find yet another word. */
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
findAword:
parse arg ox
_=@.x; oxo='───'ox"───"
if _=='' then do
say 'word' oxo "not found."
return 0
end
_@=_
say 'word' oxo "found in:"
return _@
/*──────────────────────────────────────────────────────────────────────────────────────*/
invertI: procedure expose @. !;
call lineout fn
w=0
do while lines(fn)\==0
_=space( linein(fn
if _=='' then iterate
say 'file' #", record:" _
do until _==''
parse upper var _ ? _
?=stripper(?)
if ?='' then iterate
w=w+1
@.?=@.? # w
if wordpos(?,!)==0 then !=! ?
end /*until ··· */
end /*while ··· */
return w
/*──────────────────────────────────────────────────────────────────────────────────────*/
stripper: procedure; parse arg q /*remove punctuation at
@punctuation= '.,:;?¿!¡∙·'; do j=1 for length(@punctuation)
q=strip(q, 'T', substr(@punctuation, j, 1) )
end /*j*/
return q</lang>
'''output'''
<pre style="height:50ex">
Line 2,452:
file 9, record: Burma-Shave
word
file=
word ───60─── found in:
file=3 word=6
|