XPath 1.0 trace ONLY element names at top nodes along path - select

I edited this for clarity with a much clearer example.
interesting XPath problem I have not found an answer for.
"I would just like to trace the path from the top of the tree to a leaf without including any of the sub-branches at any node...just the node along the way without its contents...just its element name."
given:
|tree doc|
tree := '
<bookstore>
<book category="COOKING">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
<book category="CHILDREN">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book category="WEB">
<title lang="en">XQuery Kick Start</title>
<author>James McGovern</author>
<author>Per Bothner</author>
<author>Kurt Cagle</author>
<author>James Linn</author>
<author>Vaidyanathan Nagarajan</author>
<year>2003</year>
<price>49.99</price>
</book>
<book category="WEB">
<title lang="en">Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
</bookstore>'.
doc := (XMLDOMParser on: tree) parseDocument.
doc explore.
each ancestor going up the tree in reverse document order is giving me all of its contents, I just want its QName .
The intent is for didactic purposes in documentation I am writing for it.
Say I want the ancestors of <author>Erik T. Ray</author>, I just want to see <bookstore><book><author>.
What I end up with is The bookstore node and its children, the book node and its children and the author node and its child.
These are the correct nodes, but it is not the output I am looking for.
The intent is didactic, I would like to show that localName of the ancestor nodes without any other clutter
Thank you for your time

For all nodes that have children:
//*[*]
In [4]: root.xpath('//*[*]')
Out[4]:
[<Element I at 0x10bd40d00>,
<Element w at 0x10bdb4e40>,
<Element j at 0x10bca5f40>]
For all nodes with children that are not below a specific node in the document:
//*[*][not(./preceding::<node>) and not(./<node>)]
In [13]: root.xpath('//*[*][not(./preceding::ould) and not(./ould)]')
Out[13]: [<Element I at 0x10bd40d00>]
In [14]: root.xpath('//*[*][not(./preceding::ust) and not(./ust)]')
Out[14]: [<Element I at 0x10bd40d00>, <Element w at 0x10bdb4e40>]
However, a 1.0 XPath cannot return a set of strings, such as the local names: Get a nodeset of all local-names with xpath

Related

Handling forward 1:n relationships with drools

I'm trying to write a rule that applies on a set of facts based on the content of another fact. I have simplified the problem to a House with Rooms. Let's say we have something like:
House(id);
Room(id, houseId, floor, side, paint);
Now, if I want to trigger a rule on all the Houses with all Rooms in left side painted on green I would write something like:
rule "Left side 1st floor green"
when
$h: House()
forall($r: Room(houseId=$h.id, floor==1, side=="left")
Room(id == $r.id, paint == "green"))
then
//Do whatever on rule triggering
end
But what if the objects in the working memory are organized in this way:
House(id, List<> roomIds);
Room(id, floor, side, paint);
How can I write a foreach condition (or any other approach) to make the same consideration on the rooms for a given house? Does it make sense or should I better try to reorganize my objects in advance to have the relationship expressed the other way around?
Thanks
Assuming in House the List<> roomIds is a List of Room.id(s), then you can do something like:
rule "Left side 1st floor green"
when
$h: House(/* .. conditions for specific house? .. */)
$r : Room($h.roomIds contains id, floor==1, side=="left", paint == "green")
then
//Do whatever on rule triggering
end
However this is a bit unefficient, and I do agree as others replied, changing a bit the business/data model would make writing this kind of rule more idiomatic and more efficient. For example if the House did have the list of Rooms, you can also use OOPath to navigate as desired the structure.
According to your rule, you do not have houses with rooms. According to what you have defined you have houses in your working memory and you have rooms in your working memory and you try to match these.
Why don't you have a List of Rooms in your House? That would make much more sense:
House(houseId, List<Room> rooms)
Room(roomId, floor, side, paint)
Then your rule would be:
rule "Left side 1st floor green"
when
$houses : House ($rooms : rooms, $houseId : houseId)
$room : Room ($roomId : roomId, floor==1 && side=="left" && paint == "green") from $rooms
then
//Rule would trigger for each room left side 1st floor green rooms
System.out.println("House "+$houseId+" has following left side 1st floor green room: "+$roomId);
end

How do I visualize points in Paraview 5.4.1?

To whom it may concern,
I write a Fortran program to track particles. It creates the following output in .vtk format for Paraview:
<?xml version="1.0"?>
<VTKFile type="UnstructuredGrid" version="0.1" byte_order="LittleEndian">
<UnstructuredGrid>
<Piece NumberOfPoints="16" NumberOfCells="0">
<Points>
<DataArray type="Float64" NumberOfComponents="3" format="ascii">
-3.743016E-0003 5.787635E-0002 -1.104483E-0010
-3.244210E-0003 5.700748E-0002 5.074001E-0011
-2.747819E-0003 5.623541E-0002 9.991296E-0011
-2.246957E-0003 5.556635E-0002 -5.163316E-0011
-1.749140E-0003 5.501747E-0002 1.470107E-0010
-1.248574E-0003 5.460318E-0002 -1.527216E-0011
-7.487991E-0004 5.432458E-0002 -9.874857E-0012
-2.504589E-0004 5.418813E-0002 8.798235E-0012
2.504575E-0004 5.418813E-0002 -2.789069E-0011
7.487986E-0004 5.432458E-0002 1.118293E-0011
1.248530E-0003 5.460317E-0002 -1.385613E-0011
1.749141E-0003 5.501748E-0002 1.227365E-0011
2.246955E-0003 5.556635E-0002 -4.099211E-0011
2.747817E-0003 5.623541E-0002 8.857913E-0012
3.244206E-0003 5.700748E-0002 1.460764E-0010
3.743038E-0003 5.787647E-0002 3.815671E-0011
</DataArray>
</Points>
<Cells>
<DataArray type="Int64" Name="connectivity" format="ascii">
</DataArray>
<DataArray type="Int64" Name="offsets" format="ascii">
</DataArray>
<DataArray type="Int64" Name="types" format="ascii">
</DataArray>
</Cells>
</Piece>
</UnstructuredGrid>
</VTKFile>
Sixteen points are defined in the file, with their coordinates, no cells, and no point data too. When I read this file with Paraview (I use version 5.4.1) I just don't see the points. I tried the 3D Glyph and then Sphere, but that doesn't help.
Is something missing in the file I create?
Cheers
I would suggest using the "Point Gaussian" representation.
What you do is correct, but you are facing a problem of camera. All you need to do is use the "Reset" or the "Zoom To Data" button in the toolbar .
I hope it helps.

Unicode Character for Funnel to Signify Filtering

Is there a unicode character that signifies filtering (for example, a funnel) that is widely available on common computer operating systems?
Some of the most similar chars I've found so far:
∀, ∨, ∇, ▼, Y, Ⴤ, V, ᗊ, ⑂,
ツ
You can use search engines that allow you to draw like
http://shapecatcher.com/
http://www.mausr.com/
http://detexify.kirelabs.org/classify.html
I'm not able to find anything similar to the funnel but here are some possible results:
Turned shogi piece: ⛉ ⛊
Sector: ⌔
Down-pointing triangle with right half black: ⧩
Alchemical symbol for water: 🜄
Alchemical symbol for horse dung: 🝖
Canadian syllabics carrier hee: ᐶ
Rightwards arrow through superset ⭄
Subset above rightwards arrow ⥹
Rightwards arrow through greater-than ⭃ (probably should be rotated when display)
Greater-than above rightwards arrow ⥸
Rightwards arrow with tail ↣
Z notation range antirestriction ⩥
Excel does have a funnel shape when filtering data (see the icon in the c column above "7" in the below table) but I'm not sure whether they use an image or character for that since window inspection tools can't work out that symbol
In some cases the scissors ✀ can be used to signify "cut out unnecessary parts"
This is not really an answer, but possibly useful for anyone finding this page looking for a filter funnel icon. Here's a hack to make something look like a funnel - stack a triangle and a bar!
.filter-triangle,
.filter-bar {
position: absolute;
top: 0;
left: 0;
width: 1em;
text-align: center;
}
.filter-bar {
top: 0.1em;
}
<div class=filter-bar>❘</div>
<div class=filter-triangle>▼</div>
Alternatively this is an SVG icon I made:
<svg viewBox="0 0 80 90" focusable=false><path d="m 0,0 30,45 0,30 10,15 0,-45 30,-45 Z"></path></svg>
Both need aria attributes for accessability, amongst other problems! Both snippets are WTFPL-licenced!
Or you can use the MIT licenced filter icon from Feather.
I usually use the following:
y filter
Y active filter
¥ cancel or disable filter
Late here, but I like this ⫧
Found it by using shapecatcher.com which someone here suggested.
It works particularly well as a small placeholder in the inputs for my column filters.
(image)
https://unicode-table.com/en/2AE7/
I needed the same, and as far as I can tell there is no FUNNEL, FILTER or REDUCE symbol in Unicode.
However there is this:
⊆ U+2286 SUBSET OF OR EQUAL TO
You can use the character "X" with the Webdings Font, and it will give you a Speaker icon. Rotate it 90° and it'll be like a Funnel.
There is a proposal for a funnel (filter):
https://www.unicode.org/wg2/docs/n5181-repertoire-postAmd1.pdf
1CE08
Until it is released, the best character is the one provided by #phuclv (https://stackoverflow.com/a/51728429/5390321)
🝖 (1F756)
This is the best character I could find for myself ⊕
Unicode Character 'CIRCLED PLUS' (U+2295)
Which is by no means a funnel, but a kind of like a cross-hair insinuating "target more specific results". There are literally thousands of characters though...
In my case, I am going to use IcoMoon to replace the icon for this character, check out the IcoMoon app here
If you dont have a character map tool, you can use this quick PHP snippet to print out a range of unicode characters:
<?php
for ($i=hexdec("25ff");$i<=hexdec("26ff");$i++) echo sprintf("&#%u; ",$i);
Prints
◿ ☀ ☁ ☂ ☃ ☄ ★ ☆ ☇ ☈ ☉ ☊ ☋ ☌ ☍ ☎ ☏ ☐ ☑ ☒ ☓ ☔ ☕ ☖ ☗ ☘ ☙ ☚ ☛ ☜
☝ ☞ ☟ ☠ ☡ ☢ ☣ ☤ ☥ ☦ ☧ ☨ ☩ ☪ ☫ ☬ ☭ ☮ ☯ ☰ ☱ ☲ ☳ ☴ ☵ ☶ ☷ ☸ ☹ ☺ ☻
☼ ☽ ☾ ☿ ♀ ♁ ♂ ♃ ♄ ♅ ♆ ♇ ♈ ♉ ♊ ♋ ♌ ♍ ♎ ♏ ♐ ♑ ♒ ♓ ♔ ♕ ♖ ♗ ♘ ♙
♚ ♛ ♜ ♝ ♞ ♟ ♠ ♡ ♢ ♣ ♤ ♥ ♦ ♧ ♨ ♩ ♪ ♫ ♬ ♭ ♮ ♯ ♰ ♱ ♲ ♳ ♴ ♵ ♶ ♷ ♸ ♹
♺ ♻ ♼ ♽ ♾ ♿ ⚀ ⚁ ⚂ ⚃ ⚄ ⚅ ⚆ ⚇ ⚈ ⚉ ⚊ ⚋ ⚌ ⚍ ⚎ ⚏ ⚐ ⚑ ⚒ ⚓ ⚔ ⚕ ⚖ ⚗ ⚘
⚙ ⚚ ⚛ ⚜ ⚝ ⚞ ⚟ ⚠ ⚡ ⚢ ⚣ ⚤ ⚥ ⚦ ⚧ ⚨ ⚩ ⚪ ⚫ ⚬ ⚭ ⚮ ⚯ ⚰ ⚱ ⚲ ⚳ ⚴ ⚵ ⚶ ⚷ ⚸
⚹ ⚺ ⚻ ⚼ ⚽ ⚾ ⚿ ⛀ ⛁ ⛂ ⛃ ⛄ ⛅ ⛆ ⛇ ⛈ ⛉ ⛊ ⛋ ⛌ ⛍ ⛎ ⛏ ⛐ ⛑ ⛒ ⛓ ⛔ ⛕
⛖ ⛗ ⛘ ⛙ ⛚ ⛛ ⛜ ⛝ ⛞ ⛟ ⛠ ⛡ ⛢ ⛣ ⛤ ⛥ ⛦ ⛧ ⛨ ⛩ ⛪ ⛫ ⛬ ⛭ ⛮ ⛯ ⛰ ⛱
⛲ ⛳ ⛴ ⛵ ⛶ ⛷ ⛸ ⛹ ⛺ ⛻ ⛼ ⛽ ⛾ ⛿
Good luck
While it won't be a funnel, I would suggest to use the web symbol: 🕸
After all, a web allows to catch the resource after which its user is looking for while letting much of the rest going to some ignored places.
Ψ 03A8
ψ 03C8
¥ 00A5
⁝ 205D
⁞ 205E
⥺ 297A (Rotated to point down)
⦀ 2980
⧨ 29E8
⧩ 29E9
⧪ 29EA
⏚ 23DA
🔍 128269
🔎 1F50E
There are a lot pictured here https://www.vertex42.com/ExcelTips/unicode-symbols.html
This may help. While looking for the same thing I found that I could print a funnel using this JavaScript line:
String.fromCharCode(57710); // Prints: 
But it doesn't work all the time. Most of the time I end up with a box, like: "". I'm still trying to figure out why that is.

Search for points from multiple polygons

I am using ClusterPoint database to access Open Street Map data (https://github.com/clusterpoint/osm), but I'd like to find POI contained within multiple separate polygons.
Is there any example available how to define and use multiple polygons within query?
To use multiple polygons in one query, you need to define them under <shapes> tag. Each polygon should have individual name. If you want to search within multiple polygons, than use OR operator "{}" in query.
Example with two polygons and one circle could look like:
<query>
{><polygon1 ><polygon2 ><circle1}
</query>
<shapes>
<polygon1>lat1 lon1; lat2 lon2; lat3 lon3; lat4 lon4; lat5 lon5; ...
<coord1_tag_name>lat</coord1_tag_name>
<coord2_tag_name>lon</coord2_tag_name>
</polygon1>
<polygon2>lat1 lon1; lat2 lon2; lat3 lon3; lat4 lon4; lat5 lon5; ...
<coord1_tag_name>lat</coord1_tag_name>
<coord2_tag_name>lon</coord2_tag_name>
</polygon2>
<circle1>
<center>lat lon</center>
<radius>10 km</radius> <!-- here you can define distance in "km" or in "mi" -->
<coord1_tag_name>lat</coord1_tag_name>
<coord2_tag_name>lon</coord2_tag_name>
</circle1>
</shapes>
If polygons are overlapped, then matching points within this area will not "duplicate" in result set (will be displayed once).

Google Charts offsetting the horizontal axis marker labels

Does anyone know if its possible to offset the markers so they appear between the column of a google chart?
So that it appears like this design mockup...
Instead of the markers being directly inline with the columns like below which is the default behaviour of the google.visualization.ColumnChart api.
I have search through the documention, however cannot find any references to options that would allow for this kind of customisation. Does anyone know if perhaps there is a way of manipulating the layout after it has been rendered? Or if in fact there is an option to do this but I've just overlooked it?
Thanks
The chart is rendered in a <svg> structure containing <g>, <rect>, <text> (and other) elements. The structure differs a lot form chart to chart, and the internal ordering can change if basic chart elements are left out. The horizontal axis elements is rendered as something like
<text text-anchor="middle" x="468.46875" y="343.05" font-family="Arial" font-size="13" stroke="none" stroke-width="0" fill="#222222">12</text>
To get an idea of where to look for those <text> elements in the <svg> structure you can copy the rendered code of the chart to a editor capable of styling code, or use a online code beautifier.
Then simply iterate through the <svg> by using DOM methods such as querySelector, querySelectorAll, getElementsByTagName etc.
See this google.visualization.ColumnChart :
By changing the x attribute of each <text> element that belongs to the horizontal axis we can get the labels to appear between the columns :
google.visualization.events.addListener(chart, 'ready', updateAxis);
function updateAxis() {
var x,
svg = document.getElementById('chart').querySelector('svg'),
g = svg.querySelectorAll('g'),
chartArea = g[3].querySelectorAll('g'),
hAxisTexts = chartArea[5].querySelectorAll('text');
//0-15 labels, the rest belongs to the yAxis
for (var i=0;i<16;i++) {
x = parseFloat(hAxisTexts[i].getAttribute('x'));
if (x>9) {
x = x-15;
} else {
x = x-18;
}
hAxisTexts[i].setAttribute('x', x);
}
}
demo -> http://jsfiddle.net/hrrL45oq/
This is only an example. You will perhaps need to target a different <g> element holding the <text>'s, and how you manipulate x or other attributes of <text> depends of the layout of the chart.