This question about Topic Markup Language and applications: Answered
Find sequence over mutliple lines
Hi,
My Topic has several tables like this:
---++ ThisTable1
<!---SOT=ThisTable1--->
| foo | foo | foo | done |
| foo | foo | foo | todo |
| foo | foo | foo | done |
<!---EOT=ThisTable1--->
---++ ThisTable2
<!---SOT=ThisTable2--->
| foo | foo | foo | todo |
| foo | foo | foo | todo |
| foo | foo | foo | done |
<!---EOT=ThisTable2--->
<!---SOT=ThisTable3--->
| foo | foo | foo | done |
| foo | foo | foo | done |
| foo | foo | foo | done |
<!---EOT=ThisTable3--->
...(and so on)
I would like to use a query search to find out a certain table (e.g.
ThisTable1) has the entry "todo".
I started with
%SEARCH{ "$text ~ ' *SOT=ThisTable1*| todo |*EOT=ThisTable1* "
topic = "%TOPIC%
Scope = "text"
nonoise="on"
format=""
footer="$ntopics"
}%
But there is no result.
Any idea?
I want to use this information to either show
or
in the headline.
Thank you for you help.
--
MartenLucas - 19 Dec 2016
I tried to solve this question and wasn't successful and it bugs me. There are some things I'll suggest and see if someone else can come up with an answer.
First, I'll point out a few basic issues in your SEARCH macro:
- In the search string
$text
should just be text
. Also, there needs to be a closing single quote delineating the string to match.
- The parameters
topic
and scope
shouldn't be capitalized and should not have the spaces before and after equal sign.
- The topic parameter is lacking a closing double quote.
- If the search returns no results, nothing is displayed (including no footer). To display an icon for no results, I'd use the
zeroresults
parameter.
Making these corrections, I was able to get a positive result and was all pleased, but then I realized that this was because I was
finding my own search string since it was in the same topic as being searched. To avoid this, I would recommend using a
regex
search and add square brackets about some letters to avoid the search finding itself.
Putting this all together (plus some code to display the icons you mentioned), this is what I come up with:
%SEARCH{"[T]hisTable1.*?todo.*?ThisTable1"
type="regex"
topic="%TOPIC%"
scope="text"
nonoise="on"
limit="1"
format="$percntICON{choice-yes}$percnt"
zeroresults="$percntICON{choice-no}$percnt"
}%
...but alas it doesn't work and I don't know why. Perhaps it's because the regex search string has to span multiple lines?
I'd love to hear some more comments on this little puzzle.
--
LynnwoodBrown - 21 Dec 2016
I think you've identified the issue. The SEARCH code internally first splits the topic into lines and applies the pattern to each line. So a multi-line match isn't going to work. At least that's how I read the code in Search.pm.
--
GeorgeClark - 22 Dec 2016
I could not come up with a way to put it into the table title, but you can get a conditional checkbox in the table by using the
SpreadSheetPlugin. (Be sure to set the ALLOWHTML switch so that the CALC macro can emit HTML.)
I also used a $SET / $GET variable to put the flag below the table. But the
SpreadSheetPlugin can't move backwards in the page.
For ex;
- Set SPREADSHEETPLUGIN_ALLOWHTML = 1
| | | | %CALC{"$SET(T1,$IF($COUNTSTR($ABOVE(),todo), %ICON{choice-no}%, %ICON{choice-yes}% ))"}% |
Table 1
foo |
foo |
foo |
done |
foo |
foo |
foo |
todo |
|
|
|
|
Status of Table 1
foo |
foo |
foo |
done |
foo |
foo |
foo |
done |
|
|
|
|
Status of Table 2
--
GeorgeClark - 22 Dec 2016
Goes like this using
FilterPlugin:
%STARTSECTION{"extractTable"}%%EXTRACT{
topic="%from%"
pattern="<!\-\-+\s*SOT=%id%.*?\n(.*?)\n<!\-\-+\s*EOT=%id%"
format="$1"
limit="1"
}%%ENDSECTION{"extractTable"}%
Test:
foo |
foo |
foo |
done |
foo |
foo |
foo |
todo |
foo |
foo |
foo |
done |
--
Main.MichaelDaum - 22 Dec 2016
Curious mixture of search techniques being used above. Simplest is to correct OP's search, thus:
%SEARCH{ "text ~ '*SOT=ThisTable1*| todo |*EOT=ThisTable1*'" type="query" topic="%TOPIC%"}%
which gets you:
Question1844
Hi, My Topic has several tables like this: ThisTable1 foo foo foo done foo foo foo todo foo foo foo done ThisTable2 foo ...
Number of topics: 1
--
Main.CrawfordCurrie - 22 Dec 2016 - 09:00
Sorry Crawford - the reason why your search works is that it's finding it's own search string, not the table. To demonstrate, here's the same search but targeting a
separate topic containing only the tables:
Number of topics: 0
I like Michaels approach but it doesn't exactly answer Marten's question. He's not asking to extract the table, he's asking to determine whether the table has a row that contains "todo". Here's a variation that achieves what Marten ask for, including displaying the icons:
%STARTSECTION{"extractTable1"}%%EXTRACT{
topic="%from%"
pattern="<!\-\-+\s*SOT=%id%.*?todo.*?<!\-\-+\s*EOT=%id%"
format="$percntICON{choice-yes}$percnt"
null="$percntICON{choice-no}$percnt"
limit="1"
}%%ENDSECTION{"extractTable1"}%
Tests:
- Table 1 (containing 1 todo):
- Table 2 (containing 2 todos):
- Table 3 (containing no todos):
Thanks George for confirming that searches (either regex or query) can only search over single lines of text at one time. What's odd is that I don't remember it always working like that but perhaps I'm wrong. It's good to know that
FilterPlugin 's
EXTRACT
macro
can do this as I would think the need to search over multiple lines would come up with some regularity.
--
Main.LynnwoodBrown - 22 Dec 2016