How do i check if a node is a child of another node? - xslt-2.0

I want to get all "generateId" values of the text nodes which are a child of a specific node whose attribute "id" value is known. I can i test for this condition using XSL?

Use an XPath 2.0 expression like this:
//specificNode[#id=$knownValue]/text()/generate-id(.)
You may also use keys (<xsl:key> and the key() function) for more efficient selection of all specificNode-s that have an id attribute with a knownValue.

Related

ActiveRecord: Querying for parent record where child records have certain values in an AND query

Normally I understand that if you pass an array of values to an ActiveRecord query it executes it like an OR statement. That is to say:
Parent.joins(:kiddos).where(kiddos: {rando_attr:[1,2]})
This query looks for Parent objects where the parent object has a kiddo object that has rando_attr of EITHER 1 OR 2.
In my case however, I want to look for Parent object where the parent object has a kiddo object with rando_attr of 1, AND ALSO has a kiddo object with rando_attr of 2.
How would I write this query?
Parent.joins(:kiddos)
.where(kiddos: {rando_attr:[1,2]})
.group(:id).having('COUNT(DISTINCT(kiddos.rando_attr)) = 2')
Indeed the array syntax makes an IN query (which is like a logical or), an alternative to grouping (#Lam's answer) can be using 2 wheres
Parent.joins(:kiddos).where(kiddos: {rando_attr: 1}).where(kiddos: {rando_attr: 2})

Add Integer Number to existing Values - Neo4j

Using Neo4j.
I would like to add a integer number to values already existing in properties of several relationships that I call this way:
MATCH x=(()-[y]->(s:SOL{PRB:"Taking time"})) SET y.points=+2
But it doesn't add anything, just replace by 2 the value I want to incremente.
To achieve this use
SET y.points = y.points + 2
From your original question it looks like you were trying to use the Addition Assignment operator which exists in lots of languages (e.g. python, type/javascript, C#, etc.). However, in cypher += is a little different and is designed to do this in a way which allows you to add or update properties to or on entire nodes or relationships based on a mapping.
If you had a parameter like the below (copy this into the neo4j browser to create a param).
:param someMapping: {a:1, b:2}
The query below would create a property b on the node with value 2, and set the value of property a on that node to 1.
MATCH (n:SomeLabel) WHERE n.a = 0
SET n+= $someMapping
RETURN n

How to refine the mandatory property of nodes from a grouping in YANG language?

I defined a grouping which has a leaf with mandatory property set to false.
But in some cases, I would like to use this grouping and specify that the leaf should be mandatory. How do I achieve this in YANG?
You would use the refine statement when specifying a use of your grouping.
module mandatory-and-grouping {
namespace "org:example:mandatory-and-grouping";
prefix "mag";
grouping my-grouping {
leaf my-leaf {
type string;
}
}
container top {
uses my-grouping {
refine my-leaf {
mandatory true;
}
}
}
}
7.13.2. The "refine" Statement
Some of the properties of each node in the grouping can be refined
with the "refine" statement. The argument is a string that
identifies a node in the grouping. This node is called the refine's
target node. If a node in the grouping is not present as a target
node of a "refine" statement, it is not refined and thus is used
exactly as it was defined in the grouping.
The argument string is a descendant schema node identifier (see
Section 6.5).
The following refinements can be done:
A leaf or choice node may get a default value, or a new default
value if it already had one.
A leaf-list node may get a set of default values, or a new set of
default values if it already had defaults; i.e., the set of
refined default values replaces the defaults already given.
Any node may get a specialized "description" string.
Any node may get a specialized "reference" string.
Any node may get a different "config" statement.
A leaf, anydata, anyxml, or choice node may get a different
"mandatory" statement.
A container node may get a "presence" statement.
A leaf, leaf-list, list, container, anydata, or anyxml node may
get additional "must" expressions.
A leaf-list or list node may get a different "min-elements" or
"max-elements" statement.
A leaf, leaf-list, list, container, choice, case, anydata, or
anyxml node may get additional "if-feature" expressions.
Any node can get refined extensions, if the extension allows
refinement. See Section 7.19 for details.
RFC7950, Section 7.13.2

Querying array element in node property

I have nodes within a the graph with property pathway storing an array of of values ranging from
path:ko00030
path:ko00010
.
.
path:koXXXXX
As an example, (i'm going to post in the batch import format:https://github.com/jexp/batch-import/tree/20)
ko:string:koid name definition l:label pathway:string_array pathway.name:string_array
ko:K00001 E1.1.1.1, adh alcohol dehydrogenase [EC:1.1.1.1] ko path:ko00010|path:ko00071|path:ko00350|path:ko00625|path:ko00626|path:ko00641|path:ko00830
the subsequent nodes might have a different combination of pathway values.
How do i query using CYPHER to retrieve all nodes with path:ko00010 in pathway
the closest i've gotten is using the solution provided for a different problem:
How to check array property in neo4j?
match (n:ko)--cpd
Where has(n.pathway) and all ( m in n.pathway where m in ["path:ko00010"])
return n,cpd;
but here only nodes with pathways matching exactly to the list provided are returned.
ie. if i were to query path:ko00010 like in the example above, I'll only be able to retrieve nodes holding path:ko00010 as the only element in the pathway property and not nodes containing path:ko00010 as well as other path:koXXXXX
In your query the extension of the predicate ALL is all the values in the property array, meaning that your query will only return those cases where every value in the pathway property array are found in the literal array ["path:ko00010"]. If I understand you right you want the opposite, you want to test that all values in the literal array ["path:ko00010"] are found in the property array pathway. If that's indeed what you want you can just switch their places, your WHERE clause will then be
WHERE HAS(n.pathway) AND ALL (m IN ["path:ko00010"] WHERE m IN n.pathway)
It is not strictly correct to say that your query only matches cases where the array you ask for and the property array are exactly the same. You could have had more than one value in the literal array, something like ["path:ko00010","path:ko00020"], and nodes with only one one of those values in their pathway array would also have matched–as long as all values in the property array could be found in the literal array. Conversely, with the altered WHERE filter that I've suggested, the query will match any node that has all of the values of the literal array in their pathway property.
If you want to filter the matched patterns with an array of values where all of them have to be present, this is good. In your example you only use one value, however, and for those queries there is no reason to use an array and the ALL predicate. You can simply do
WHERE HAS(n.pathway) and "path:ko00010" IN n.pathway
If in some context you want to include results where any of a set of values are found in the pathway property array you can just switch from ALL to ANY
WHERE HAS(n.pathway) AND ANY (m IN ["path:ko00010","path:ko00020"] WHERE m IN n.pathway)
Also, you probably don't need to check for the presence of the pathway property, unless you have some special use for it you should be fine without the HAS(n.pathway).
And once you've got the queries working right, try to switch out literal strings and arrays for parameters!
WHERE {value} IN n.pathway
// or
WHERE ALL (m IN {value_array} WHERE m IN n.pathway)
// or
WHERE ANY (m IN {value_array} WHERE m IN n.pathway)

How to match ets:match against a record in Erlang?

I have heard that specifying records through tuples in the code is a bad practice: I should always use record fields (#record_name{record_field = something}) instead of plain tuples {record_name, value1, value2, something}.
But how do I match the record against an ETS table? If I have a table with records, I can only match with the following:
ets:match(Table, {$1,$2,$3,something}
It is obvious that once I add some new fields to the record definition this pattern match will stop working.
Instead, I would like to use something like this:
ets:match(Table, #record_name{record_field=something})
Unfortunately, it returns an empty list.
The cause of your problem is what the unspecified fields are set to when you do a #record_name{record_field=something}. This is the syntax for creating a record, here you are creating a record/tuple which ETS will interpret as a pattern. When you create a record then all the unspecified fields will get their default values, either ones defined in the record definition or the default default value undefined.
So if you want to give fields specific values then you must explicitly do this in the record, for example #record_name{f1='$1',f2='$2',record_field=something}. Often when using records and ets you want to set all the unspecified fields to '_', the "don't care variable" for ets matching. There is a special syntax for this using the special, and otherwise illegal, field name _. For example #record_name{record_field=something,_='_'}.
Note that in your example you have set the the record name element in the tuple to '$1'. The tuple representing a record always has the record name as the first element. This means that when you create the ets table you should set the key position with {keypos,Pos} to something other than the default 1 otherwise there won't be any indexing and worse if you have a table of type 'set' or 'ordered_set' you will only get 1 element in the table. To get the index of a record field you can use the syntax #Record.Field, in your example #record_name.record_field.
Try using
ets:match(Table, #record_name{record_field=something, _='_'})
See this for explanation.
Format you are looking for is #record_name{record_field=something, _ = '_'}
http://www.erlang.org/doc/man/ets.html#match-2
http://www.erlang.org/doc/programming_examples/records.html (see 1.3 Creating a record)

Resources