dot: dash in name - graphviz

Is it possible to have a dash in the node name? I tried escaping with backslash (searching the web didn't helped either).
Example:
digraph test {
some-name -> other-name;
}

Just include the node names in double quotes like this:
digraph test {
"some-name" -> "other-name";
}

Since I faced the problem, the same goes for subgraphes names:
digraph G {
{node "A-1"}
{node "B"}
subgraph "A-1B" {edge [dir=none]"A-1" -> "B"}
}

You can also use identifier-like names (i.e. without spaces, dashes, etc.), but also provide a better name as a label attribute, by declaring node explicitly first.
digraph D {
nodeA [label="Node A"];
nodeB [label="Node B"];
nodeA -> nodeB;
}

Related

Depth first search on Neo4j with filtering on node properties

I would like to perform a depth first search on my graph and so, get all the paths existing from a given node ('N1456' in my example), and all the nodes of theses path must have the same property "PROPERTY_TO_FILTER".
Typically, my graph is composed of two types of node, and two types of relations.
For now, I tested the following request :
WITH "
MATCH (my_node{name : 'N1456'})
CALL apoc.path.expandConfig(protein, {uniqueness:'NODE_GLOBAL', bfs : FALSE}) YIELD path
WITH path, my_node, last(nodes(path)) as subgraph
WHERE my_node<> subgraph and my_node.my_property CONTAINS 'PROPERTY_TO_FILTER'
RETURN nodes(path), length(path) AS len
ORDER BY len DESC" AS query
CALL apoc.export.json.query(query, "my_results.json", {})
YIELD properties, data
RETURN properties, data;
However, the results are not the ones attended. I get a list of paths but only the first node has the property "PROPERTY_TO_FILTER" ; this filter is not taken into account for the other nodes...
I guess I should put a filter at apoc.path.expandConfig level, but I see in the documentation that this is only possible to filter the node label, not the node properties.
Could someone help please ?
Maybe this can help:
MATCH(fromNode:LABEL{name : 'N1456'})-[r:REL_TO_TRAVERSE*1..2]->(toNode:LABEL)
WHERE toNode.my_property CONTAINS 'PROPERTY_TO_FILTER'
RETURN fromNode,r,toNode
It's called variable length pattern matching:
https://neo4j.com/docs/cypher-manual/current/syntax/patterns/#cypher-pattern-varlength

Jenkins - Put parameter in array

In a declarative pipeline I want user will choose list of machines and then some action will be executed on them in parallel.
I have an extendedChoice parameter with multiSelectDelimiter: ','
When I go over the list with this code below I get the characters of node and not entire node, how can I fix it ?
for (node in nodes) {
echo node
}
This should do it:
for (node in nodes.split(',')) {
echo node
}

Pattern matching with tregex in Stanzas Corenlp implementation doesn't seem to finde the right subtrees

I am relatively new to NLP and at the moment I'm trying to extract different phrase scructures in german texts. For that I'm using the Stanford corenlp implementation of stanza with the tregex feature for pattern machting in trees.
So far I didn't have any problem an I was able to match simple patterns like "NPs" or "S > CS".
No I'm trying to match S nodes that are immediately dominated either by ROOT or by a CS node that is immediately dominated by ROOT. For that im using the pattern "S > (CS > TOP) | > TOP". But it seems that it doesn't work properly. I'm using the following code:
text = "Peter kommt und Paul geht."
def linguistic_units(_client, _text, _pattern):
matches = _client.tregex(_text,_pattern)
list = matches['sentences']
print('+++++Tree++++')
print(list[0])
for sentence in matches['sentences']:
for match_id in sentence:
print(sentence[match_id]['spanString'])
return count_units
with CoreNLPClient(properties='./corenlp/StanfordCoreNLP-german.properties',
annotators=['tokenize', 'ssplit', 'pos', 'lemma', 'ner', 'parse', 'depparse', 'coref'],
timeout=300000,
be_quiet=True,
endpoint='http://localhost:9001',
memory='16G') as client:
result = linguistic_units(client, text, 'S > (CS > ROOT) | > ROOT'
print(result)
In the example with the text "Peter kommt und Paul geht" the pattern I'm using should match the two phrases "Peter kommt" and "Paul geht", but it doesn't work.
Afterwards I had a look at the tree itselfe and the output of the parser was the following:
constituency parse of first sentence
child {
child {
child {
child {
child {
value: "Peter"
}
value: "PROPN"
}
child {
child {
value: "kommt"
}
value: "VERB"
}
value: "S"
}
child {
child {
value: "und"
}
value: "CCONJ"
}
child {
child {
child {
value: "Paul"
}
value: "PROPN"
}
child {
child {
value: "geht"
}
value: "VERB"
}
value: "S"
}
value: "CS"
}
child {
child {
value: "."
}
value: "PUNCT"
}
value: "NUR"
}
value: "ROOT"
score: 5466.83349609375
I now suspect that this is due to the ROOT node, since it is the last node of the tree. Should the ROOT node not be at the beginning of the tree?
Does anyone know what I am doing wrong?
A few comments:
1.) Assuming you are using a recent version of CoreNLP (4.0.0+), you need to use the mwt annotator with German. So your annotators list should be tokenize,ssplit,mwt,pos,parse
2.) Here is your sentence in PTB for clarity:
(ROOT
(NUR
(CS
(S (PROPN Peter) (VERB kommt))
(CCONJ und)
(S (PROPN Paul) (VERB geht)))))
As you can see the ROOT is the root node of the tree, so your pattern would not match in this sentence. I personally find the PTB format easier to see the tree structure and for writing Tregex patterns off of. You can get that via the json or text output formats (instead of the serialized object). In the client request set output_format="text"
3.) Here is the latest documentation on using the Stanza client: https://stanfordnlp.github.io/stanza/client_properties.html

Graphviz: automatic variables?

Suppose I define a node:
"somenode" [xlabel="somenode"]
Is there an automatic variable, as in make such that I can write, for example (in pseudo code) something like:
"somenode" [xlabel=$#]
You can use graphviz-py to make a variable.
Code
digraph g {
{{ some_node_name = "somenode" }}
"{{= some_node_name }}" [xlabel="{{= some_node_name }}"]
}
Output
If attribute supports type escString (which label attribute does) you can use \N for node name and \G for graph name. On edge label you can use \T for tail node name and \H for head node name.
digraph {
Node1 [xlabel="\N"]
Node2 -> Node3 [xlabel="\T" label="\H"]
}
Result:

Fastest/shortest way to build unique tree in Ruby?

What is the fastest/shortest/one-liner (not possible :p) way to build a unique tree of elements from a tree where many of the elements are duplicated/missing in some nodes, given the tree has a defined set of nodes (which we'd use this algorithm to figure out so we don't have to manually do it).
It could be XML/JSON(hash), or whatever. So something like this:
root {
nodes {
nodeA {}
nodeB {
subNodeA {}
}
}
nodes {
nodeA {
subNodeA {}
}
nodeB {
subNodeX {}
}
}
}
...converted to this:
root {
nodes {
nodeA {
subNodeA {}
}
nodeB {
subNodeA {}
subNodeX {}
}
}
}
Same with xml:
<root>
<nodes>
<nodeA/>
<nodeB>
<subNodeA/>
</nodeB>
</nodes>
<nodes>
<nodeA>
<subNodeA/>
</nodeA>
<nodeB>
<subNodeX/>
</nodeB>
</nodes>
</root>
<root>
<nodes>
<nodeA>
<subNodeA/>
</nodeA>
<nodeB>
<subNodeA/>
<subNodeX/>
</nodeB>
</nodes>
</root>
The xml/json files could be decently large (1MB+), so having to iterate over every element depth-first or something seems like it would take a while. It could also be as small as the example above.
This'll get you a set of unique paths:
require 'nokogiri'
require 'set'
xml = Nokogirl::XML.parse(your_data)
paths = Set.new
xml.traverse {|node| next if node.text?; paths << node.path.gsub(/\[\d+\]/,"").sub(/\/$/,"")}
Does that get you started?
[response to question in comment]
Adding attibute-paths is also easy, but let's go at least a little bit multi-line:
xml.traverse do |node|
next if node.text?
paths << (npath = node.path.gsub(/\[\d+\]/,"").sub(/\/$/,""))
paths += node.attributes.map {|k,v| "#{npath}##{k}"}
end

Resources