Checking last element in a boost::fusion::for_each loop - boost-fusion

I want to know if there is a way to check for the last element in a fusion for_each loop (in order to apply special code for this case)
Edit : Maybe a better question should be :
I have played with fusion::for_each, now I want to apply code on each element of a fusion sequence with special code (special code does not mean "extra code" but different code) for the last element. May be I should use iterators (an example please)?

Some ideas:
1) use boost::fusion::fold, count your way though, and on the last one, perform your edit
2) if all types in the tuple are heterogenous, match on type to determine last one
3) include some sort of marker for the last one on which you can match
4) use the 'prior(end(v))' operators to manipulate the last element when for_each processing is complete

Related

Marklogic: Find documents containing elements without a particular attribute (maybe many per document)

I have some data which looks something like this:
<wrapper>
<inner a="1"/>
<inner a="2" b="3"/>
</wrapper>
The attribute b may or may not be present on each inner element. My aim is to find all documents containing at least one inner element that doesn't have attribute b.*
This similar question proposes the answer:
cts:not-query(cts:element-attribute-value-query(xs:QName('inner'), xs:QName('b'), '*', ("wildcarded"))))
but that doesn't work, because some inner elements on the same document may have attribute b, and not-queries work on the entire fragment, so a mixed case like the example above would not be returned. Wrapping it in an element-query doesn't help, and cts:and-not-query seems to behave the same way.
I have also tried attacking the problem using co-occurrence/values functions to read the values of relevant attributes a, but that also seems to be impossible. It might have been possible with proximity settings on co-occurrences calls except there is no element text, so the attribute are indexed with the same word positions.
Are there any alternatives to the blunt xpath?
//inner[#a and not(#b)]
You can always make the xpath more complicated if simplicity isnt your goal.
How about this one: (it more accurately answers the exact question of 'return all documents that contain 'innner' elements that do not have an atribute #b'
doc()[exists(//inner[not(#b)])]
I do not know how well this is optimized -- some xpath expressions optimize down to the equivalent cts: query and some do not.
There is another 'trick' involving combining cts expressions represented as maps. Take the results of 2 searches, use the options that return the results as a map, then you can use the operations on this page https://developer.marklogic.com/blog/im-a-map to do extremely efficient set operations (union, intersection, difference etc). When properly constructed, this technique can be as fast as 'native' cts searches --- the cts searches use the same general technique internally for resolving results.
Make the XPath a path range index. //inner[#a and not(#b)], or if there's no element text, //inner[#a and not(#b)]/#a, then do
cts:path-range-query('//inner[#a and not(#b)]/#a','>','')
This happens to also allow us to efficiently answer the question of which #a values have a missing #b, using cts:values.
cts:not-in-query has the necessary behaviour to make this work where cts:and-not-query doesn’t. E.g.
cts:not-in-query(
cts:element-query(xs:QName('inner'), cts:true-query()),
cts:element-attribute-query(xs:QName('inner'), xs:QName('b'),'*','wildcarded')
)
Finds all ‘inner’ elements at positions that do not match the positions of ‘inner’ elements with attribute b.
Element position index must be enabled. Wildcard index must be enabled.
http://docs.marklogic.com/cts:not-in-query

Suppress/Filter a row

I am fairly new to using PeopleSoft BI Publisher plugin for MS Word and integrating it with PS Query Manager. My question is whether in the RTF file you can put logic to suppress or filter out data?
I have a for-each grouping that prints a line (row). I would like to add logic to NOT print the line if the Witholding amount field (M.WTHD_AMT) is equal to 0 (zero). My question is what would the syntax look like, and where should I place it (on the For Each grouping below, the Field level, or somewhere else?) I know I can alter the PS Query (data source) to do the filtering but I would like to leave that as-is and handle this in the template.
I see that there is another conditional IF statement ("rmt_") so I'm not sure if I can add this additional logic to that element or if I need a separate one. I appreciate any feedback!
EDIT:
I've added a new "Conditional Region" as suggested, and it works with just the WTHD_AMT criteria !0 to zero, however I tried added additional criteria where L.PYMNT_TYPE = 'R' and when I run the process it doesn't display data on the PDF output. Is there something wrong with the syntax? Do I need to have a separate Conditional Region for this 2nd criteria? I've seen another BI report where they have 2 or 3 criteria as part of one element.
<?if:number(M.WTHD_AMT)!=0.00?> and <?if:L.PYMNT_TYPE='R'?>
Option 1
You can nest <?if?> statements. Just add another <?end if?> at the end. Make sure there are no spaces between the all of the IF or END IF objects at the beginning or end of the content/row, else the row may still be displayed.
Option 2
You can add conditions in the repeating section. Below will repeat the region for every record where M.WTHD_AMT is not 0.00
<?for-each:record_path/record[M.WTHD_AMT!='0.00']?>
'Conditional Region' is the button you are looking for.
When using this button, make sure to double check where the if/endif or C/EC elements are added. It tends to ignore the selected element and join the elements to the start and end of the line. You will then need to cut and paste it into the right spot. For you this will probably be right after the F element and before the E element.

Regex in R match specified words when they all (two or more) occur in whatever order within certain distance in particular line

I have a double challenge.
First, I want to match lines that contain two (or eventually more) specified words within certain distance in whatever order.
Using lookaround I manage to select lines matching two or more words, regardless of the order within they occur. I can also easily add more words to be found in the same line, so it this can also be applied without much effort when more word must occur in order to be selected. The disadvantage is that can't detail the maximal distance between them.
^(?=.*\john)(?=.*\jack).*$
By using the pipe operator I can detail both orders in which the terms may occur as well as the accepted distance between them, but when more words should be matched the code becomes lengthy and errorsensitive.
jack.{0,100}john|john.{0,100}jack
Is there a way to combine the respective advantages of both approaches in one regular expression?
Second, ideally I would like that only 'jack' and 'john' (and are selected in the line but not the whole line.
Is there a possibility to do this all at once?
For this case, you have to use the second approach. But it can't be possible with regex alone.. You have to ask for language tools help like paste in-order to build a regex (given in the second format).
In python, I would do like below to create a long regex.
>>> def create_reg(lis):
out = []
for i in lis:
out.append(''.join(i) + '|' + ''.join([i[2],i[1], i[0]]))
return '(?:' + '|'.join(out) + ')'
>>> lst = [('john', '{0,100}', 'jack'), ('foo', '{0,100}', 'bar')]
>>> create_reg(lst)
'(?:john{0,100}jack|jack{0,100}john|foo{0,100}bar|bar{0,100}foo)'
>>>

How to remember which variables are in a list

I have a huge list in which I put different variables in order to apply the same function to all of them.
In a next step I want to apply specific functions to specific elements of the list, i.e. all functions used vary from element to element within the list.
How can I do this? My first idea was (see my other question, Reassign variables to elements of list) to split the list into the original variables again. This can be done.
But I was recommended to keep the items in the list instead. My questions is: How can I access each variable quickly by doing that? One idea would be to use the names attribute of the list in the beginning and fill it with a vector of the original variable names. However, by doing that it would be much longer later on to type list["name_x"] than just typing name_x assuming name_x is globally available.
What is the most efficient way to deal with my problem?

Replacing a symbol in a .txt file

Alright, I've been given a program that requires me to take a .txt file of varying symbols in rows and columns that would look like this.
..........00
...0....0000
...000000000
0000.....000
............
..#########.
..#...#####.
......#####.
...00000....
and using command arguments to specify row and column, requires me to select a symbol and replace that symbol with an asterisk. The problem i have with this is that it then requires me to recur up, down, left, and right any of the same symbol and change those into an asterisk.
As i understand it, if i were to enter "1 2" into my argument list it would change the above text into.
**********00
***0....0000
***000000000
0000.....000
............
..#########.
..#...#####.
......#####.
...00000....
While selecting the specified character itself isn't a problem, how do i have any similar, adjacent symbols change and then the ones next to those. I have looked around but can't find any information and as my teacher has had a different subs for the last 3 weeks, i havent had a chance to clarify my questions with them. I've been told that recursion can be used, but my actual experience using recursion is limited. Any suggestions or links i can follow to get a better idea on what to do? Would it make sense to add a recursive method that takes the coordinates given adds and subtracts from the row and column respectively to check if the symbol is the same and repeats?
Load in char by char, row by row, into a 2D array of characters. That'll make it a lot easier to move up and down and left and right, all you need to do is move one of the array indexes.
You can also take advantage of recursion. Make a function that changes all adjacent matching characters, and then call that same function on all adjacent matching characters.

Resources