Anonymous user
Inverted index: Difference between revisions
m
→{{header|REXX}}: added/changed whitespace and comments, removed OVERFLOW from PRE html STYLE tag.
m (→{{header|Perl 6}}: Updating deprecated 'uniq' to 'unique') |
m (→{{header|REXX}}: added/changed whitespace and comments, removed OVERFLOW from PRE html STYLE tag.) |
||
Line 2,065:
=={{header|REXX}}==
Note: In this algorithm, word indices start at 1.
Note: the Burma Shave signs were created from 1930 ──► 1951 and were common among the rural byways of America.
<lang rexx>/*REXX program illustrates building a simple inverted index & word find.*/
@.='' /*dictionary of words (so far).*/
!='' /*a list of found words (so far).*/
call invertI
call invertI
call invertI
call invertI
call invertI
call invertI
call invertI
call invertI
call invertI
▲call invertI 9, 'BURMA9.TXT' /* " " 9 ... */
call findAword 'does' /*find a word. */
call findAword '60' /*find another word. */
Line 2,087 ⟶ 2,086:
exit /*stick a fork in it, we're done.*/
/*──────────────────────────────────FINDAWORD subroutine────────────────*/
findAword: procedure expose @.; arg
parse arg ox
_=@.x; oxo='───'ox"───"▼
▲oxo='───'ox"───"
if _=='' then do
say 'word' oxo "not found."
return 0
end
_@=_ /*save _, pass it back to invoker*/
say 'word' oxo "found in:"
do until _=='';
say ' file='f ' word='w
end /*until
return _@
/*─────────────────────────────────────INVERTI subroutine───────────────*/
invertI: procedure expose @. !; parse arg #,fn /*file#, filename*/
call lineout fn /*close the file, just in case. */
w=0 /*number of words found (so far).
do while lines(fn)\==0 /* [↓] process the entire file.*/
_=space(linein(fn)) /*read a line, elide extra blanks*/
say 'file' #", record:" _ /*echo a record (to be verbose).*/
do
▲ if xxx='' then iterate /*is the word now blank (null) ? */
▲ end /*until ... */
▲ end /*while lines(fn)¬==0*/
return w /*return the index of the word. */
/*─────────────────────────────────────STRIPPER subroutine──────────────*/
stripper: procedure; parse arg q /*remove punctuation at word-end.*/
@punctuation='.,:;?¿!¡∙·'; do j=1 for
▲ end /*j*/
return q</lang>
'''output'''
<pre style="height:
file 0, record
file 0, record
file 0, record
file 0, record
file 0, record
file 1, record
file 1, record
file 1, record
file 1,
file 1, record
file 1, record
file 2, record
file 2, record
file 2, record
file 2, record
file 2, record
file 2, record
file 3, record
file 3, record
file 3, record
file 3, record
file 3, record
file 4, record
file 4, record
file 4, record
file 4, record
file 4, record
file 4, record
file 5, record
file 5, record
file 5, record
file 5, record
file 5, record
file 5, record
file 6, record
file 6, record
file 6, record
file 6, record
file 6, record
file 7, record
file 7, record
file 7, record
file 7, record
file 7, record
file 7, record
file 8, record
file 8, record
file 8, record
file 8, record
file 8, record
file 8, record
file 9, record
file 9,
file 9, record
file 9, record
file 9, record
file 9, record
word ───does─── found in:
file=2 word=1
file=8 word=13
word ───60─── found in:
file=3 word=6
word ───don't─── found in:
file=3 word=1
file=7 word=12
word ───burma-shave─── found in:
file=0 word=14
file=1 word=
file=2 word=15
file=3 word=14
file=4 word=13
file=5 word=17
file=6 word=14
file=7 word=15
file=8 word=14
file=9 word=11
</pre>
|