Calculate the difference between two nodes - orbeon

Is it possible to find the difference two nodes and use the that difference as a constraint for a particular control.
<xforms:bind id="DebitRebate1"
nodeset="instance('charge-options-setup')/Pattern_Setup1/Pattern1/DebitRebate1"
type="xforms:double"
constraint=". < instance('charge-options-setup')/Pattern_Setup1/Pattern1/DebitPrice1
and instance('charge-options-setup')/Pattern_Setup1/Pattern1/DebitPrice1-. >
instance('charge-options-setup')/Locations_Patterns/Debit_Minimum_Margin"/>

Yes, you can use the difference between two nodes as a constraint on another node, and the code you quote seems about right. Just a couple of comments:
In your XPath, instead of < and > you can use just lt and gt. This performs a value comparison, and makes the expression easier to read.
Also make sure you have spaces around node named: instead of DebitPrice1-. use DebitPrice1 - .. This is necessary, as - can be used as part of an element or attribute name, so foo-bar point to <foo-bar> not what's in <foo> minus what's in <bar>.

Related

Lua: Sort table of numbers with multiple dots

I have a table of strings like this:
{
"1",
"1.5",
"3.13",
"1.2.5.7",
"2.5",
"1.3.5",
"2.2.5.7.10",
"1.17",
"1.10.5",
"2.3.14.9",
"3.5.21.9.3",
"4"
}
And would like to sort that like this:
{
"1",
"1.2.5.7",
"1.3.5",
"1.5",
"1.10.5",
"1.17",
"2.2.5.7.10",
"2.3.14.9",
"2.5",
"3.5.21.9.3",
"3.13",
"4"
}
How do I sort this in Lua? I know that table.sort() will be used, I just don't know the function (second parameter) to use for comparison.
Given your requirements, you probably want something like natural sort order. I described several possible solution as well as their impact on the results in a blog post.
The simplest solution may look like this (below), but there are 5 different solutions listed with different complexity and the results:
function alphanumsort(o)
local function padnum(d) return ("%03d%s"):format(#d, d) end
table.sort(o, function(a,b)
return tostring(a):gsub("%d+",padnum) < tostring(b):gsub("%d+",padnum) end)
return o
end
table.sort sorts ascending by default. You don't have to provide a second parameter then. As you're sorting strings Lua will compare the strings character by character. Hence you must implement a sorting function that tells Lua which comes first.
I just don't know the function (second parameter) to use for
comparison.
That's why people wrote the Lua Reference Manual
table.sort (list [, comp])
Sorts the list elements in a given order, in-place, from list1 to
list[#list]. If comp is given, then it must be a function that
receives two list elements and returns true when the first element
must come before the second in the final order, so that, after the
sort, i <= j implies not comp(list[j],list[i]). If comp is not given,
then the standard Lua operator < is used instead.
The comp function must define a consistent order; more formally, the
function must define a strict weak order. (A weak order is similar to
a total order, but it can equate different elements for comparison
purposes.)
The sort algorithm is not stable: Different elements considered equal
by the given order may have their relative positions changed by the
sort.
Think about how you would do it with pen an paper. You would compare each number segment. As soon as a segment is smaller than the other you know this number comes first.
So a solution would probably require you to get those segments for the strings, convert them to numbers so you can compare their values...

How do I repeat a capturing group?

I have an input string that looks something like this:
HLI6Ch60000Ch500C0Ch46400Ch30000Ch21888Ch10E79CS07LCU3Ch37880Ch27800Ch16480CS8CA00000000000000000000
Now I don't care about the part that follows the last letter A, it'll always be A and exactly 20 numbers that are of no use to me. I do, however, need the part before the last letter A, and ideally, I'd need it to be separated into two different captures, just like this:
1: HLI6Ch60000Ch500C0Ch46400Ch30000Ch21888Ch10E79CS07
2: LCU3Ch37880Ch27800Ch16480CS8C
The only way to identify these matches is that they end with characters CS followed by two hexadecimal characters. I thought that a regular expression like (.+?CS.{2})+ (or (.+?CS[[:xdigit:]]{2})+) would do the job but when tried on www.regex101.com, it only captures the last group and gives the following warning:
Note: A repeated capturing group will only capture the last iteration. Put a capturing group around the repeated group to capture all iterations or use a non-capturing group instead if you're not interested in the data
Which I thought suggests that I should use regular expression like ((.+?CS.{2})+) instead and I mean – sure, now I get two captures, but they look like this:
1: HLI6Ch60000Ch500C0Ch46400Ch30000Ch21888Ch10E79CS07LCU3Ch37880Ch27800Ch16480CS8C
2: LCU3Ch37880Ch27800Ch16480CS8C
Meaning the first one is… slightly longer than I'd like it to be. If it helps in any way, I should point out that the final regular expression will be part of an iOS application so an instance of NSRegularExpression class will be used – not sure if that's a helpful information at all, it's just that I know that NSRegularExpression doesn't support every part of the world of regular expressions.
(.+?CS.{2})
You can direclty use this.See demo.Grab the group or capture.
https://regex101.com/r/vD5iH9/68
It doesn't seem like you need a capturing group at all:
(?:(?!CS[0-9A-F]{2}).)+CS[0-9A-F]{2}
will match all strings that end in CS + 2 hex digits.
Test it live on regex101.com.
Explanation:
(?: # Start a group.
(?!CS[0-9A-F]{2}) # Make sure we can't match CSff here,
. # if so, match any character.
)+ # Do this at least once.
CS[0-9A-F]{2} # Then match CSff.
Change your regex to,
(.+?CS[[:xdigit:]]{2})
DEMO
You don't need to put the regex inside another capturing group and make it to repeat one or more times. Just print the group index 1 to get your desired output.

Create Relationship in nodes and Using quotes and back tick in Cypher - Neo4J

I am a newbie to Neo4j, I have created two nodes with the below Cypher , how can I create a relationship between them ?
CREATE (Someone { name:'Abhilash',from :'Kerala',knows:'java' }) return someone;
CREATE (Someone { name:'Theo',worked :'WALMART',from:'kUNOOR' });return someone;
The relationship is 'Team: QualityControl'.
Second Question
Also I have seen in some create node queries that are using back tick (`) symbols in code.
e.g.
CREATE (_1:`Someone` { `name`:"Abhilash",`from`:"Kerala":,`knows`:"java" })
Whats the difference between the first create statement and the above create statement ?
Can we create properties of nodes as
{key:'Values'} or {<back tick> key <back tick>:"Values"}
where < back tick > is `
Am much confused with the different ways of using tick(`) , double Quote ("") ans single quote (') inside the query . Can any one help me to understand the right scenarios of using these characters ?
Update
thanks for the clarification . i used the below query to create the relationship , but its not returning any result or creating a relationship between my nodes . this is my statement,
MATCH (a:someone),(b:someone)
WHERE a.name = 'Abhilash' AND b.name = 'Theo'
CREATE a-[r:RELTYPE]->b
RETURN r
Backtick is only used if you have a character in a property name or reltype that isn't valid to cypher, such as spaces or hyphens. I recommend avoiding the need to use backticks.
Double quotes and single quotes are interchangeable to represent strings, similar to JavaScript. I usually go the route of using double quotes and escaping internal double quotes with backslash: {dialog:"Joe said, \"Hello World.\""}...
As an aside, you probably don't want to use "Team: Quality Control" as a relationship. That should probably be a node with relationships to each team member.

xpath parent attribute of selection

Syntax of the xml document:
<x name="GET-THIS">
<y>
<z>Z</z>
<z>Z__2</z>
<z>Z__3</z>
</y>
</x>
I'm able to get all z elements using:
xpath("//z")
But after that I got stuck, I'm not sure what to do next. I don't really understand the syntax of the .. parent method
So, how do I get the attribute of the parent of the parent of the element?
Instead of traversing back to the parent, just find the right parent to begin with:
//x will select all x elements.
//x[//z] will select all x elements which have z elements as descendants.
//x[//z]/#name will get the name attribute of each of those elements.
You already have a good accepted answer, but here are some other helpful expressions:
//z/ancestor::x/#name - Find <z> elements anywhere, then find all the ancestor <x> elements, and then the name="…" attributes of them.
//z/../../#name - Find the <z> elements, and then find the parent node(s) of those, and then the parent node(s) of those, and then the name attribute(s) of the final set.
This is the same as: //z/parent::*/parent::*/#name, where the * means "an element with any name".
The // is useful, but inefficient. If you know that the hierarchy is x/y/z, then it is more efficient to do something like //x[y/z]/#name
I dont have a reputation, so I cannot add comment to accepted answer by Blender. But his answer will not work in general.
Correct version is
//x[.//z]/#name
Explanation is simple - when you use filter like [//z] it will search for 'z' in global context, i.e. it returns true if xml contains at least one node z anywhere in xml. For example, it will select both names from xml below:
<root>
<x name="NOT-THIS">
</x>
<x name="GET-THIS">
<y>
<z>Z</z>
<z>Z__2</z>
<z>Z__3</z>
</y>
</x>
</root>
Filter [.//z] use context of current node (.) which is xand return only 2nd name.

How to sort a list of 1million records by the first letter of the title

I have a table with 1 million+ records that contain names. I would like to be able to sort the list by the first letter in the name.
.. ABCDEFGHIJKLMNOPQRSTUVWXYZ
What is the most efficient way to setup the db table to allow for searching by the first character in the table.name field?
The best idea right now is to add an extra field which stores the first character of the name as an observer, index that field and then sort by that field. Problem is it's no longer necessarily alphabetical.
Any suggestions?
You said in a comment:
so lets ignore the first letter part. How can I all records that start with A? All A's no B...z ? Thanks – AnApprentice Feb 21 at 15:30
I issume you meant How can I RETURN all records...
This is the answer:
select * from t
where substr(name, 1, 1) = 'A'
I agree with the questions above as to why you would want to do this -- a regular index on the whole field is functionally equivalent. PostgreSQL (with some new ones in v. 9) has some rather powerful indexing capabilities for special cases which you might want to read about here http://www.postgresql.org/docs/9.1/interactive/sql-createindex.html

Resources