Using XPATH to get child nodes having index divisible by n - xpath

My XML is some how like this:
<a>
<b></b> <!-- 1 -->
<b></b> <!-- 2 -->
<b></b> <!-- 3 -->
<b></b> <!-- 4 -->
<b></b> <!-- 5 -->
<b></b> <!-- 6 -->
<b></b> <!-- 7 -->
<b></b> <!-- 8 -->
<b></b> <!-- 9 -->
<b></b> <!-- 10 -->
<b></b> <!-- 11 -->
</a>
Is the a way to write XPATH that get child nodes of a having index divisible by n? For example, with n = 3, it will get b nodes with index 3, 6, 9.

get child nodes of a having index divisible by n
Like this:
/a/*[position() mod 3 = 0]
Note that position() returns a 1-based index.

Related

LogQL Group dynamic request in one line

sum (count_over_time({filename=“/var/log/nginx/access.log”}[1m] | pattern <_> <_> "<_> <request> <_>" <_> <_> "<_>" "<_>" "<_>" <_> <_> |~ “/json//users/*********” )) by(request)
I need to merge into one line. Otherwise it's overloaded.

Decision tree training for Multi-View face detection

I am working for multi-view face detection and following the Jones's multiple-view face detection algorithm.
In the paper "Fast Multi-view Face Detection", Jones trained C4.5 decision tree with images of different face poses. In Section 3.3 of Decision Tree Training, it is mentioned as "the training algorithm is almost identical to the boosting algorithm. The two main differences are the criteria for feature selection and the splitting of the training set at each node"
I learned and understood C4.5 algorithm here.
I can't figure out how to train images of different face poses for C4.5 decision tree.
EDIT 1:
Stage 0 and Stage 1 features of training the ADABOOST algorithm for cascade classifier is shown below.
<!-- stage 0 -->
<_>
<maxWeakCount>3</maxWeakCount>
<stageThreshold>-0.7520892024040222</stageThreshold>
<weakClassifiers>
<!-- tree 0 -->
<_>
<internalNodes>
0 -1 46 -67130709 -21569 -1426120013 -1275125205 -21585
-16385 587145899 -24005</internalNodes>
<leafValues>
-0.6543210148811340 0.8888888955116272</leafValues></_>
<!-- tree 1 -->
<_>
<internalNodes>
0 -1 13 -163512766 -769593758 -10027009 -262145 -514457854
-193593353 -524289 -1</internalNodes>
<leafValues>
-0.7739216089248657 0.7278633713722229</leafValues></_>
<!-- tree 2 -->
<_>
<internalNodes>
0 -1 2 -363936790 -893203669 -1337948010 -136907894
1088782736 -134217726 -741544961 -1590337</internalNodes>
<leafValues>
-0.7068563103675842 0.6761534214019775</leafValues></_></weakClassifiers></_>
<!-- stage 1 -->
<_>
<maxWeakCount>4</maxWeakCount>
<stageThreshold>-0.4872078299522400</stageThreshold>
<weakClassifiers>
<!-- tree 0 -->
<_>
<internalNodes>
0 -1 84 2147483647 1946124287 -536870913 2147450879
738132490 1061101567 243204619 2147446655</internalNodes>
<leafValues>
-0.8083735704421997 0.7685696482658386</leafValues></_>
<!-- tree 1 -->
<_>
<internalNodes>
0 -1 21 2147483647 263176079 1879048191 254749487 1879048191
-134252545 -268435457 801111999</internalNodes>
<leafValues>
-0.7698410153388977 0.6592915654182434</leafValues></_>
<!-- tree 2 -->
<_>
<internalNodes>
0 -1 106 -98110272 1610939566 -285484400 -850010381
-189334372 -1671954433 -571026695 -262145</internalNodes>
<leafValues>
-0.7506558895111084 0.5444605946540833</leafValues></_>
<!-- tree 3 -->
<_>
<internalNodes>
0 -1 48 -798690576 -131075 1095771153 -237144073 -65569 -1
-216727745 -69206049</internalNodes>
<leafValues>
-0.7775990366935730 0.5465461611747742</leafValues></_></weakClassifiers></_>
EDIT2:
My consideration for how to train the decision is described in the following picture
I am still figuring out what are the features to use, but I think the training should be as shown in the attached image.
Thanks
Did not read the paper but frm what I know from early face recognition experiments, the attributes you are looking for are probably just the grey level inputs of the face images. Usually, images are rescaled, say to 32x32 pixels, so you have a 1024 dimensionnal vector to train your decision tree. Have a closer look at the article if they use other features, they will be written, or at least given a reference to?

Suggest Data Structure which implement this

Can any one suggest any data structure/code such that if we map 1 to a, 2 to b, 3 to c i.e.
1 --> a
2 --> b
3 --> c
then we can also reverse lookup such as if i query 'a' then it should output 1 and similarly 2 and 3 for 'b' and 'c' respectively.
Also if i change the mapping afterwards from above mapping to :
1 --> a
2 --> a
3 --> c
then after reverse lookup i should get (1,2) for 'a' and (3) for 'c'.
The number to letter direction: a hash.
For the letter to number direction: multimap (or a hash where each value is a list)

Freemarker Pagination - or just general algorithm for clicking through pages

p - is request parameter where the page number is given by user
<#assign totalPages =searchResult.getTotalPages()>
<#assign lastPage = 0>
<#list totalPages as curPage>
<#if p=curPage>
${p}
<#assign lastPage = curPage?number>
<#else>
${curPage}
</#if>
</#list>
This will print links like this
1 2 3 4 5 6 7 8 9 10 11 - and the list keeps going to the last page lets say 100
What I would like to accomplish is these cases (number in <x> is the p - page selected by user):
Case A:
1 <2> 3 4 5 ... 100
Case B:
1 ... 11 12 <13> 14 15 ... 100
Case C:
1 ... <96> 97 98 99 100
Any ideas on how to do this in the above freemarker code? Pseudo code is fine too.
Here are two helper functions max and min and a macro I called pages:
<#function max x y>
<#if (x<y)><#return y><#else><#return x></#if>
</#function>
<#function min x y>
<#if (x<y)><#return x><#else><#return y></#if>
</#function>
<#macro pages totalPages p>
<#assign size = totalPages?size>
<#if (p<=5)> <#-- p among first 5 pages -->
<#assign interval = 1..(min(5,size))>
<#elseif ((size-p)<5)> <#-- p among last 5 pages -->
<#assign interval = (max(1,(size-4)))..size >
<#else>
<#assign interval = (p-2)..(p+2)>
</#if>
<#if !(interval?seq_contains(1))>
1 ... <#rt>
</#if>
<#list interval as page>
<#if page=p>
<${page}> <#t>
<#else>
${page} <#t>
</#if>
</#list>
<#if !(interval?seq_contains(size))>
... ${size}<#lt>
</#if>
</#macro>
This macro produces, when invoked with a sequence of page numbers and the current page, e.g.
<#pages 1..100 2 />
<#pages 1..100 13 />
<#pages 1..100 96 />
<#pages 1..3 2 />
the following output (removed some whitespaces):
1 <2> 3 4 5 ... 100
1 ... 11 12 <13> 14 15 ... 100
1 ... <96> 97 98 99 100
1 <2> 3
I think it would be better correct
<#if (p<=5)> <#-- p among first 5 pages -->
<#assign interval = 1..(min(5,size))>
<#elseif ((size-p)<5)> <#-- p among last 5 pages -->
<#assign interval = (max(1,(size-4)))..size >
to
<#if (p<=4)> <#-- p among first 5 pages -->
<#assign interval = 1..(min(5,size))>
<#elseif ((size-p)<4)> <#-- p among last 5 pages -->
<#assign interval = (max(1,(size-4)))..size >
(just correct 5 -> 4)
Because first code shows weird result in some situation like
<#pages 1...12 5>
My expectation was 1 ... 3 4 <5> 6 7 ... 12 but it showed
1 2 3 4 <5> ... 12 which means if current page is 5, can't get to next page.
Second one works correctly as I expected.

Selecting every other node uing XPATH

Given an arbitrary amount nodes to select:
<root>
<foo>1</foo>
<foo>2</foo>
<foo>3</foo>
<foo>4</foo>
<!-- ... -->
<root>
How do I select every other foo so that I get foo[1], foo[3], ... ?
Try
/root/foo[position() mod 2 = 1]
No idea if it will work right, might need 0. I forget if position starts at 0 or 1
position() returns a number that indicates the position of an element relative to other child elements.
The mod function returns the „rest“ of a division:
5 mod 2 = 1; 6 mod 2 = 0; 9 mod 2 = 1; 10 mod 2 = 0;
also see: https://en.wiktionary.org/wiki/modulo

Resources