Module:Str find word/links/doc

This template looks for a word in a comma-separated list of words. It returns a True (found) or False (not found) value.

By default, the True-value returned is the found word itself; the False-value is a blank string.

T: {{Str find word |source=alpha, foo, bar |word=foo}}Script error: No such module "Str find word".
F: {{Str find word |source=alpha, foo, bar |word=nov}}Script error: No such module "Str find word".

The True and False return values can be set through |yes=, |no=:

T: {{Str find word |source=alpha, foo, bar |word=foo |yes=Yesss |no=Nooo}}Script error: No such module "Str find word".
F: {{Str find word |source=alpha, foo, bar |word=nov |yes=Yesss |no=Nooo}}Script error: No such module "Str find word".

Using this template, the editor does not have to apply patterns ('%f[^,][^,]+%f[,]'). No return value interpretation is required (like when 1 then do x), though is optionally possible. There is no inbetween-result: the logic says it is either T or F. The logic can not result in an error.

Specifics தொகு

Words
A 'word' is the character string between commas. This can be all characters and inner spaces:
T: {{Str find word |source=alpha, foo bar sunday, bar |word=foo bar sunday}}Script error: No such module "Str find word".
T: {{Str find word |source=alpha, bar(22) [take care]!, foo |word=bar(22) [take care]!}}Script error: No such module "Str find word".
Return value
True- and False-value can be set through |yes=, |no=:
T: {{Str find word |source=alpha, foo, bar |word=foo |yes=Yesss |no=Nooo}}Script error: No such module "Str find word".
F: {{Str find word |source=alpha, foo, bar |word=nov |yes=Yesss |no=Nooo}}Script error: No such module "Str find word".
Partial fit
Partial word matching are not considered a hit:
F: {{Str find word |source=alpha, foobar, bar |word=foo}}Script error: No such module "Str find word".
Case-sensitive
By default, the comparison is not case-sensitive (Foo = foo); all text is turned into lowercase. One can make the check case-sensitive by |case=true
T: {{Str find word |source=alpha, Foo, bar |word=foo |case=false}}Script error: No such module "Str find word".
F: {{Str find word |source=alpha, Foo, bar |word=foo |case=true}}Script error: No such module "Str find word".
Boolean value read
Setting |booleans=true will read common bolean words as boolean (true, false).
Boolean words for true: 'True', 'T', 'Yes', '1'. False: 'False', 'F', 'No', '0'. Boolean words are always case-insensistive (True=true).
T: {{Str find word |source=alpha, yes, bar |word=true |booleans=true}}Script error: No such module "Str find word".
T: {{Str find word |source=alpha, false, bar |word=0 |booleans=true}}Script error: No such module "Str find word".
F: {{Str find word |source=alpha, false, bar |word=0 |booleans=false}}(default) → Script error: No such module "Str find word".

Word lists தொகு

The word list |source= is comma-separated. Prefixed and suffixed spaces are discarded (trimmed).

வார்ப்புரு:Hair spacealpha, foo, barவார்ப்புரு:Hair space
Inner spaces are kept, and are part of the 'word':
வார்ப்புரு:Hair spacealpha, foo, hello world, barவார்ப்புரு:Hair space
Any character apart from வார்ப்புரு:Angle bracket comma can be part of the word:
வார்ப்புரு:Hair spaceα(12) [mind the gap]!, foo, hello world, barவார்ப்புரு:Hair space
Multiple spaces (whitespace) inside a string is reduced to a single space:
வார்ப்புரு:Hair spacealpha,  foo    bar, வார்ப்புரு:Hair space
equals வார்ப்புரு:Hair spacealpha, foo bar,வார்ப்புரு:Hair space
Spaces வார்ப்புரு:Angle bracket, Comma வார்ப்புரு:Angle bracket, quote வார்ப்புரு:Angle bracket, pipe வார்ப்புரு:Angle bracket
Trimmed spaces
All words are trimmed before checking (leading and trailing whitespace is removed; repeated inner whitespaces are reduced to one space):
T: {{Str find word |source=alpha , hello   world, foo |word=hello world}}Script error: No such module "Str find word".
...but the remaining in-word space does matter:
F: {{Str find word |source=alpha, hello   world, foo |word=helloworld}}Script error: No such module "Str find word".


Comma வார்ப்புரு:Angle bracket
When a comma வார்ப்புரு:Angle bracket is part of the word to check. Word strings that contain a comma can be made literal (escape the comma):
T: Red XN TODO check this doc claim {{Str find word |source=alpha, "hello, world", foo |word="hello, world"}}Script error: No such module "Str find word".
??chk: {{Str find word |source=alpha, "hello, world", foo |word="hello, world"|literals=false}}Script error: No such module "Str find word".
??chk: {{Str find word |source=alpha, "hello, world", foo |word="hello, world"|literals=true}}Script error: No such module "Str find word".
Quote character வார்ப்புரு:Angle bracket
Conversely, quote characters வார்ப்புரு:Angle bracket that are part of the word are escaped by setting |literals=false:
T: {{Str find word |source=alpha, she said "hello world", "foo" |word=she said "hello world" |literals=false}}Script error: No such module "Str find word".
Pipe வார்ப்புரு:Angle bracket
The pipe character can be entered as {{!}}
T: {{Str find word |source=alpha, hello{{!}}world, foo |word=hello{{!}}world }}Script error: No such module "Str find word".

Checking multiple words தொகு

It is possible to check multiple words against the source wordlist.

AND-words to check
|andwords=: can have a wordlist (comma-separated as |source= is). Each word will be checked against the source. When all and-words are found, the return value is True.
T: {{Str find word |source=alpha, beta, gamma, foo, bar |andwords=alpha, foo}}Script error: No such module "Str find word".
T: {{Str find word |source=alpha, beta, gamma, foo, bar |andwords=bar, foo, beta, alpha}}Script error: No such module "Str find word".
F: {{Str find word |source=alpha, beta, gamma, foo, bar |andwords=alpha, nov}}Script error: No such module "Str find word".
OR-words to check
|orwords=: can have a wordlist (comma-separated as |source= is). Each word will be checked against the source. When a single or-words is found, the return value is True. Default True return value is the list with all words found.
T: {{Str find word |source=alpha, beta, gamma, foo, bar |orwords=alpha, foo}}Script error: No such module "Str find word".
T: {{Str find word |source=alpha, happy, gamma, nice, foo, bar |orwords=april, sad, happy, ugly, nice}}Script error: No such module "Str find word".
F: {{Str find word |source=alpha, happy, gamma, nice, foo, bar |orwords=sad, ugly, november}}Script error: No such module "Str find word".
Both AND-words, OR-words to check
|andwords=, :|orwords= can be used together. Each wordlist will get its own logical checks (AND-words must all be present; OR-words at least one)
T: {{Str find word |source=alpha, beta, april, gamma, foo, happy |andwords=alpha, beta |orwords=april, november, sad, ugly}}Script error: No such module "Str find word".
F: {{Str find word |source=alpha, beta, april, gamma, foo, happy |andwords=alpha, november |orwords=april, november, sad, ugly}}Script error: No such module "Str find word".

todo தொகு

word order in return string
resove synonyms eg |_monday=Monday, Mon, monday
Note 1. The True return value is a list of all words found
T: {{Str find word |source=alpha, beta, gamma, foo, bar |andwords=alpha, foo}}Script error: No such module "Str find word".
return-text: add space after comma வார்ப்புரு:Angbr.
later
Note 2. Parameter |word= is equal to |andwords=
|andwords=alpha, foo
T: {{Str find word |source=alpha, beta, gamma, foo, bar |andwords=alpha, foo}}Script error: No such module "Str find word".
|orwords= wordlist with OR-check
The wordlist |orwords= requires that at least one word of the list is found.
T: {{Str find word |source=alpha, beta, gamma, foo, bar |orwords=nov, drop, foo}}Script error: No such module "Str find word".
Here too, all found words are returned in the True-value
T: {{Str find word |source=alpha, beta, gamma, foo, bar |orwords=gamma, nov, drop, foo}}Script error: No such module "Str find word".
Checking AND-wordlists, OR-wordlists
|andwords= and |orwords= can be used together.
Words in the AND-list must all be present, the OR-list requires one or more words to be found.
When True, all hitwords are returned (once).
T: {{Str find word |source=alpha, beta, gamma, foo, bar |andwords=foo, bar |orwords=gamma, nov, drop}}Script error: No such module "Str find word".
option "count hits"
(unique, no aka's)
handle blanks
in {str find word|source={format|}|orwords=default, monotype, foo, <blank>} - detect & separate blank
option notwords
notwords -- reversed logic? what to output?
multiple AND-lists
"AND-1=(workday, 0700) OR AND-2=(weekend, 0900)"
basically works by adding twice: {IF:{sfw|andw|workday, 0700}{sfw|andw=weekend, 0900}|THEN...|ELSE}

27 February 2023 (UTC)

Examples தொகு

|source= |word= result note
|source=alpha, foo, lima |word=foo Script error: No such module "Str find word". Green tickY
|source=alpha, foo, lima |word=nov Script error: No such module "Str find word". Red XN
|source=alpha, uc-all |word=uc-all Script error: No such module "Str find word". Green tickY
|source=alpha, hello world_, bar |word=hello world_ Script error: No such module "Str find word". Green tickY The comma is the word-delimiter
|source=alpha,foo   bar , lima |word=  foo   bar Script error: No such module "Str find word". Green tickY Spaces are trimmed, multi-space into one space
|source=alpha, foo bar, lima |word=foobar Script error: No such module "Str find word". Red XN An inner space is a character too
|source=alpha, FOO, bAr, lima |word=bar, foo Script error: No such module "Str find word". Green tickY Not case-sensistive by default
|source=alpha, FOO, bAr, lima |word=bar, foo Script error: No such module "Str find word". Red XN |case=true: case-sensistive

note தொகு

The editor does not have to apply Lua patterns like [%a%d]*
The editor does not have to interpret the return value (as in: "when ='blue' then ..."). They can prescribe the value even (yes-value, no-value).

Usage தொகு

Basic தொகு

Core function:

{{Str find word
|source =
|word  =
|yes  =
|no   =
}}
When the word is found in the source (True), the function returns the word itself (by default), or |yes= value (when entered non-empty).
When not found (False), the function returns an empty string (''), or the |no= value when entered.
|source= |word= result note
|source=alpha, foo, lima |word=foo Script error: No such module "Str find word". Green tickY
|source=alpha, uc-all |word=uc-all Script error: No such module "Str find word". Green tickY "-" (hyphen) is part of the word
|source=alpha, do_something, white |word=do_something Script error: No such module "Str find word". Green tickY "_" (underscore) is part of the word
|source=alpha, foo, lima |word=november Script error: No such module "Str find word". Red XN
|source=alpha, foobar, lima |word=foo Script error: No such module "Str find word". Red XN 'foo' is not the complete word
|source=alpha, foo, lima |word= Script error: No such module "Str find word". Red XN no |word= entered
|source=alpha, foo, lima |word=foobar Script error: No such module "Str find word". Red XN full word foo-bar not in the source
|source=alpha, foo, lima |word=foobar Script error: No such module "Str find word". Red XN word foo not in the source as full word
... |yes=Yes, hit |no=Not found
|source=alpha, foo, lima |word=foo Script error: No such module "Str find word". Green tickY
|source=alpha, foo, lima |word=foobar Script error: No such module "Str find word". Red XN

All parameters தொகு

All parameters, in three options
{{Str find word
|string = 
|word  =
|allwords =
|orwords = 
|case=
|yes =
|no =
|explain =
}}
{{Str find word
|s  = 
|w  =
|allw=
|orw =
|case=
|yes =
|no =
|explain =
}}
{{Str find word |s= |w= |allw= |orw= |case= |yes= |no= |explain=}}

More options தொகு

|source=
|s= |1=
|word=
|w= |2=
|case= result note
|s=alpha, foo, lima |w=foo Script error: No such module "Str find word".
|s=alpha, foo, lima |w=foobar Script error: No such module "Str find word".
|s=alpha, foobar, lima |w=foo Script error: No such module "Str find word". 'foo' is not the complete word
|s=alpha, FOO, lima |w=foo Script error: No such module "Str find word". |case=false: a=A (default)
|s=alpha, FOO, lima |w=foo Script error: No such module "Str find word". |case=true: a=/=A

word list தொகு

Instead of a single word to check, a list of target words can be entered: |word=alpha, foo, bingo. This |word=-list will be treated with AND-logic: each and all of the words must be present. See:

AND-, OR-wordlist checks தொகு

|word= as noted, can be a list of words. all will be checked with the AND-requirement (each word must be present).
|andwords= accepts a list of words that all will be checked with the AND-requirement (each word must be present).
When both |word=, |andwords= are present, they are combined into one single AND-wordlist.
|orwords= accepts a list of words that all will be checked with the OR-requirement (at least one of the words must be present).

Errors and analysis தொகு

  • The logic itself does not produce errors. There is always a True of False result.
There are no logical errors foreseen: any flaw in the input will return a False result (for example, no input strings to check were entered).
  • |explain=true: when in Preview, display a report on input, output and the logical steps (debug).
  • |explain=testcases: When set in ns Template or User on subpage /testcases, the Preview report is static (shown permanently).


"https://ta.wikipedia.org/w/index.php?title=வார்ப்புரு:Str_find_word/doc&oldid=3672073" இலிருந்து மீள்விக்கப்பட்டது