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
I want to change parts of a ggplot2 object made by a function and returned as a result, to remove the Y-axis label. No, the function does not allow that to be specified in the first place so I want to change it after the fact.
str(theObject) ## shows the nested structure with parts shortened to ".." and I want to be able to type something like:
theObject$A$B$C$myLabel <- ""
So how can I either make an str -like listing with full paths like that or perhaps draw a tree structure showing the inner working of the object?
Yes, I can figure things out using names(theObject) and finding which branch leads to what I am looking for, then switching to that branch and repeating but it looks like there could be a better automated way to find a leaf node such as:
leaf_str(obj=theObject, leaf="myLabel")
might return zero or more lines like:
theObject$A$B$C$myLabel
theObject$A$X$Y$Z$myLabel
Or, the entire structure could be put out as a series of such lines.
I have searched and found nothing quite like this. I can see lots of uses especially in teaching what an object is. Yes, S4 objects might also use # as well as $.
The
tree
function in the xfun package may be useful.
See here for more details
https://yihui.org/xfun/
I have a list of roots and I want to plot the real/imaginary parts. If s=allroots(), r=realpart() and i=imagpart(), all with makelist(). Since length(s) can get ...lengthy, is there a way to plot point by point and have them numbered? Actually, the numbering part is what concerns me most. I can simply use points(r,i) and get the job done, but I'd like to know their occurence before and after some sorting algorithms. It's not always necessary to plot all the points, I can plot up until some number, but I do have to be able to see their order of having been sorted out.
I have tried multiplot_mode but it doesn't work:
multiplot_mode(wxt)$
for i:1 thru length(s) do draw2d(points([r[i]],[i[i]]))$
multiplot_mode(none)$
All I get is a single point. Now, if this should work, using draw2d's label(["label",posx,posy]) is very handy, but can I somehow evaluate i in the for loop inside the ""?
Or, is there any other way to do it? With Octave? or Scilab? I'm on Linux, btw.
Just to be clear, here's what I currently do: (I can't post images, here's the link: i.stack.imgur.com/hNYZF.png )
...and here is the wxMaxima code:
ptest:sortd(pp2); length(ptest);
draw2d(proportional_axes=xy,xrange=[sort(realpart(s))[1]-0.1,sort(realpart(s))[length(s)]+0.1],
yrange=[sort(imagpart(s))[1]-0.1,sort(imagpart(s))[length(s)]+0.1],point_type=0,
label(["1",realpart(ptest[1]),imagpart(ptest[1])]),points([realpart(ptest[1])],[imagpart(ptest[1])]),
label(["2",realpart(ptest[2]),imagpart(ptest[2])]),points([realpart(ptest[2])],[imagpart(ptest[2])]),
label(["3",realpart(ptest[3]),imagpart(ptest[3])]),points([realpart(ptest[3])],[imagpart(ptest[3])]),
label(["4",realpart(ptest[4]),imagpart(ptest[4])]),points([realpart(ptest[4])],[imagpart(ptest[4])]),
label(["5",realpart(ptest[5]),imagpart(ptest[5])]),points([realpart(ptest[5])],[imagpart(ptest[5])]),
label(["6",realpart(ptest[6]),imagpart(ptest[6])]),points([realpart(ptest[6])],[imagpart(ptest[6])]),
label(["7",realpart(ptest[7]),imagpart(ptest[7])]),points([realpart(ptest[7])],[imagpart(ptest[7])]),
label(["8",realpart(ptest[8]),imagpart(ptest[8])]),points([realpart(ptest[8])],[imagpart(ptest[8])]),
label(["9",realpart(ptest[9]),imagpart(ptest[9])]),points([realpart(ptest[9])],[imagpart(ptest[9])]),
label(["10",realpart(ptest[10]),imagpart(ptest[10])]),points([realpart(ptest[10])],[imagpart(ptest[10])]),
label(["11",realpart(ptest[11]),imagpart(ptest[11])]),points([realpart(ptest[11])],[imagpart(ptest[11])]),
label(["12",realpart(ptest[12]),imagpart(ptest[12])]),points([realpart(ptest[12])],[imagpart(ptest[12])]),/*
label(["13",realpart(ptest[13]),imagpart(ptest[13])]),points([realpart(ptest[13])],[imagpart(ptest[13])]),
label(["14",realpart(ptest[14]),imagpart(ptest[14])]),points([realpart(ptest[14])],[imagpart(ptest[14])]),*/
color=red,point_type=circle,point_size=3,points_joined=false,points(realpart(pp2),imagpart(pp2)),points_joined=false,
color=black,key="",line_type=dots,nticks=50,polar(1,t,0,2*%pi) )$
This is for 14 zeroes, only. For higher orders it would be very painful.
I gather that the problem is that you want to automatically construct all the points([realpart(...), imagpart(...)]). My advice is to construct the list of points expressions via makelist, then append that list to any other plotting arguments, then apply the plotting function to the appended list. Something like:
my_labels_and_points :
apply (append,
makelist ([label ([sconcat (i), realpart (ptest[i]), imagpart (ptest[i])]),
points ([realpart (ptest[i])], [imagpart (ptest[i])])],
i, 1, length (ptest)));
all_plot_args : append ([proptional_axes=..., ...], my_labels_and_points, [color=..., key=..., ...]);
apply (draw2d, all_plot_args);
The general idea is to build up the list of plotting arguments and then apply the plotting function to that.
I need to represent a recursive function on a flow chart.
My problem is that I don't know how to indicate that the function may call itself over multiple elements at a time (think for example to a function which scans graphs).
Someone has any suggestion?
In a flow chart, you don't normally add multiple invocations for things like loops, you would just indicate that the code may be repetitively called until a condition is met. So, for a recursive function, it would be similar - the base case is a regular step and the recursive step is the same as loop. See this for an example.
I'd like to find patterns and sort them by number of occurrences on an HEX file I have.
I am not looking for some specific pattern, just to make some statistics of the occurrences happening there and sort them.
DB0DDAEEDAF7DAF5DB1FDB1DDB20DB1BDAFCDAFBDB1FDB18DB23DB06DB21DB15DB25DB1DDB2EDB36DB43DB59DB32DB28DB2ADB46DB6FDB32DB44DB40DB50DB87DBB0DBA1DBABDBA0DB9ADBA6DBACDBA0DB96DB95DBB7DBCFDBCBDBD6DB9CDBB5DB9DDB9FDBA3DB88DB89DB93DBA5DB9CDBC1DBC1DBC6DBC3DBC9DBB3DBB8DBB6DBC8DBA8DBB6DBA2DB98DBA9DBB9DBDBDBD5DBD9DBC3DB9BDBA2DB84DB83DB7DDB6BDB58DB4EDB42DB16DB0DDB01DB02DAFCDAE9DAE5DAD9DAE2DAB7DA9BDAA6DA9EDAAADAC9DACADAC4DA92DA90DA84DA89DA93DAA9DA8CDA7FDA62DA53DA6EDA
That's an excerpt of the HEX file, and as an example I'd like to get:
XX occurrences of BDBDBD
XX occurrences of B93D
Is there a way to mine the file to generate that output?
Sure. Use a sliding window to create the counts (The link is for Perl, but it seems general enough to understand the algorithm). Your patterns are named N-grams. You will have to limit the maximal pattern, though.
This is a pretty classic CS problem. The code in general is non-trivial to implement as it will require at least one full parse of the sequence, and depending on your efficiency and memory/processor constraints might require several. See here.
You will need to partition your input string in some way to ensure that you get a good subsequence across it.
If there is a specific problem we might be able to help more, but the general strategy is in the Wikipedia article above.
You can use Regular Expressions to make a pattern to search for.
The regex needed would be very simple. Just use the exact phrase you're searching for. Then there should be a regular expression function in the language you're using (you didn't specify) that can count the number of matches.
Use that to create a simple counter.