Sample Data
A knows B
A knows C
A knows D
B knows E
C knows F
Desired Output
B
C
D
E
F
I tried the following query, but it's not working,
g.V('A').
out('knows').
as('x').
out('knows').
as('x').
project('Employee').
by(select('x'))
If you just want to get all the vertices in the path you can do:
g.V('A').repeat(out("knows")).emit().label()
example: https://gremlify.com/c533ij58a98z8
Related
Is it possible in Isabelle to access the individual elements of a data type? Let's say I have the following data type:
datatype foo = mat int int int int
and (e.g. in a lemma)
fixes A :: foo
Is it possible to access the single elements of A? Or alternatively, fix the single elements (fix a b c d :: int) and then define A as mat a b c d?
Alternatively it is possible to define custom extractor functions when specifying a data type. In your case, for example
datatype foo = Mat (mat_a : int) (mat_b : int) (mat_c : int) (mat_d : int)
would work.
Then you can access the first element of a foo value x by mat_a x, the second by mat_b x, and so on.
Example:
value "mat_a (Mat 1 2 3 4)"
"1" :: "int"
On a logical level, you can use the case syntax to deconstruct the datatype (i.e. case A of mat a b c d ⇒ …). You can also define your own projection functions using fun or primrec, e.g.
primrec foo1 where "foo1 (mat a b c d) = a"
In a proof, you can access the values using obtain and the cases command, e.g.
obtain a b c d where "A = mat a b c d" by (cases A) auto
As for your questions about definitions, you can make local definitions in Isar proofs like this:
define A where "A = mat a b c d"
and you can then unfold that definition using the theorem A_def.
If you want to use your definition in the premises or goal already (and have it unfolded in the theorem after proving it), you can use defines:
lemma
defines "A ≡ mat a b c d"
shows …
Again, this gives you a fact A_def that you can use to unfold the definition.
You can also use let ?A = mat a b c d or pattern matching with is to introduce abbreviations. In contrast to the definitions from before, these are only on the syntactic level, i.e. you type ?A, but after parsing, you have mat a b c d, and you will also see mat a b c d in the output. is works like this:
lemma
shows "P (mat a b c d)" (is "P ?A")
proof -
term ?A
It also works after "assumes".
I have been given a problem to solve that I am fairly certain its insoluble.
For a system I am working in I need to take piece of branching logic (graph) and translate it to a linear path(flatten it), without node repeats. Given a tree I know that I can do this.
The rules are that the path must be traversed in order, but can 'skip' any panel if some condition is met.
Given the tree:
A > B > C
&&
A > D > E
Our tree can be flattened to:
A > B > C > D > E
So in this case B and C share the same conditional, and D, and E have the inverse of that condition. Thus if B is met so is C, but D and E will be skipped. Conversely, if B is not met, B and C are skipped, but D and E aren't.
So far, so simple. I am fairly convinced this is true for any tree. The problem I have is that the objects I have been given to flatten are graphs, and contain simple cycles, and closed walks.
After that huge preamble my questions are:
Am I right in stating that it is impossible to guarantee that such a graph can be flattened?
I know that closed walks cannot follow my rules (by virtue of returning to a node), but are there any other rules that describe a 'flatten-able' graph versus a 'non-flatten-able' one?
Cheers
If it is a directed graph, then the graph can be flattened if there are no directed cycles.
There is a handy library available JGraphT which will provide the necessary methods to determine if there is a cycle presnet as well a TopologicalOrderIterator which will perform the flattening as well.
Using the graph library and the example above this code will show an exmaple of how to do it.
DirectedGraph<String, DefaultEdge> graph = new DefaultDirectedGraph<String, DefaultEdge>(DefaultEdge.class);
graph.addVertex("A");
graph.addVertex("B");
graph.addVertex("C");
graph.addVertex("D");
graph.addVertex("E");
// A > B
graph.addEdge("A", "B");
// B > C
graph.addEdge("B", "C");
// A > D
graph.addEdge("A", "D");
// D > E
graph.addEdge("D", "E");
// Uncomment the following line to create a cyclic graph.
//graph.addEdge("E", "D");
CycleDetector<String, DefaultEdge> cycleDector = new CycleDetector<String, DefaultEdge>(graph);
if (cycleDector.detectCycles()) {
System.err.println("Cyclic graph");
} else {
StringBuilder sb = new StringBuilder();
// Create topological order iterator
for (TopologicalOrderIterator<String, DefaultEdge> iter = new TopologicalOrderIterator<String, DefaultEdge>(
graph); iter.hasNext();) {
String vertex = iter.next();
if (sb.length() > 0) {
sb.append(" > ");
}
sb.append(vertex);
}
System.out.println(sb.toString());
}
Sample output with the cycle disabled.
A > B > D > C > E
the data i am having is like, i am trying this from week am not able to find any solution.
I need to do this using either pivot using c# or using lists. Kindly provide the answers. immediate.
Key Value
A e
B f
C i
D j
A k
B l
C m
D n
i need something like this
A B C D
-------
e f i j
k l m n
where the first line is a column header.
Any better link of any stackoverflow question also appreciable.
By following code am able to get distinct columns, now problem is with assigning values in rows.
please provide any better way of doing this.
foreach (DataRow row in dtBackupData.Rows)
{
keyname = row["KeyName"].ToString();
if (!keyNameList.Contains(keyname))
{
keyNameList.Add(keyname);
dtDynamic.Columns.Add(keyname, typeof(string));
}
}
I can add my shapes to the stage and get them to do fades and such, but I can't get them to morph - do I need to separate out into lines and curves somehow?
var shape = new Path('M 321.051,510.078 c 0,0-10.126-23.854-19.438-45.792 c -7.927-18.675-15.265-35.961-15.265-35.961 s -17.977-41.111-19.036-77.643 c -1.05-36.243,14.817-67.908,14.817-67.908 s -36.176,73.71-49.086,137.219 c -9.327,45.879,3.426,87.39,3.426,87.39 L 321.051,510.078 z').attr({fillColor: 'red'});
stage.addChild(shape);
var targetPath = new Path('M 321.75,515.816 c 0,0,8.678-42.28,0.604-77.096 c -8.102-34.936-32.956-62.408-32.956-62.408 l -76.102-96.41c0,0-39.866-41.142-45.55-84.785 c -4.992-38.332,24.108-79.856,24.108-79.856 s -55.379,72.451-63.818,141.683 c -6.186,50.745,33.857,104.106,33.857,104.106 s 36.746,38.732,51.061,75.346 c 13.283,33.975,4.212,66.029,4.212,66.029L326.75,515.816 z').attr({fillColor: 'blue'});
shape.addTo(stage);
shape.morphTo(targetPath, '3s');
Bonsai 0.4.1 doesn't support smooth curves (s, S) SVG commands. See related ticket: https://github.com/uxebu/bonsai/issues/191
I guess you get it to work by removing those commands.
I have a question.
How can do an alphabetical index with links without plugin ?
Example : A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
If a character contains posts, it will be a link.
Else it will text.
Anyone can help me ?
Update : Or something like this http://dribbble.com/tags
You could write a few lines of code to query the database and do a like search on the post titles. The below is not formatted for a WP query, but it should give you a good idea:
SELECT count(*)
FROM wp_posts
WHERE post_title LIKE 'a%';
If the count is greater than 0, you know there are posts and you can add a hyperlink to the letter.