Function for highlighting the path back to the root node - cytoscape.js

I want to find a function that highlights the path from the following nodes:
a > b > c > d > a
The importance is highlighting the path back to 'a'.
Or even a function where you can predefine the route for the path.

There are several algorithms that can be used for finding paths (e.g. BFS, A*, etc).
As for highlighting, you should define your style appropriately -- probably with a highlight class or similar.

Related

How to sort sections of markdown by heading?

Given a large markdown file with a structure like:
# Main
## Sub main Z
### Title Z
Content Z
### Title B
Content B
## Sub main A
### Title A
Content A
How would one sort its sections so that they are in alphabetical order by heading?
# Main
## Sub main A
### Title A
Content A
## Sub main Z
### Title B
Content B
### Title Z
Content Z
I don't think there is any solution that does not require you to write some code.
But the programmatic solution is pretty easy if you can code:
Parse the Markdown into an AST (abstract syntax tree).
Manipulate the AST, reordering nodes as you want.
Write the modified AST back to Markdown.
The trick is choosing a Markdown parser that supports the above steps, that lets you do it in the language of your choice, and that lets you do it most easily.
Here are the ones that I personally know that meet these requirements:
Pandoc
Probably the number one Markdown toolkit in the world. Pandoc's native language is Haskell, but it supports many languages. If you're going to do a lot of Markdown stuff down the road, it probably makes sense to become knowledgable in Pandoc anyway.
It has an option, --section-divs, that converts the document into a section hierarchy based on headings, which will make resorting sections at every nesting level almost trivial (if you can code).
It has (support for filters](https://pandoc.org/filters.html#), which are exactly the solution I am describing.
It has special support for Lua and Lua filters, which might be the easiest to code.
You can also write filters in other languages: Python, PHP, Perl, Javascript/Typescript, Groovy, Ruby.
A quick web search shows many example filters. With some more searching you might get lucky and find one that does what you want already written, though I doubt it as sorting sections alphabetically seems an uncommon thing to do.
CMark
The C reference implementation of CommonMark. Languages other than C are supported:
It provides a shared library (libcmark) with functions for parsing CommonMark documents to an abstract syntax tree (AST), manipulating the AST, and rendering the document to HTML, groff man, LaTeX, CommonMark, or an XML representation of the AST. It also provides a command-line program (cmark) for parsing and rendering CommonMark documents.
Flexible. CommonMark input is parsed to an AST which can be manipulated programmatically prior to rendering.
Multiple renderers. Output in HTML, groff man, LaTeX, CommonMark, and a custom XML format is supported. And it is easy to write new renderers to support other formats.
It is easy to use libcmark in python, lua, ruby, and other dynamic languages: see the wrappers/ subdirectory for some simple examples.
remark
A Javascript-based framework specifically designed around AST manipulation. I've never used it, but it possibly has tools to make AST manipulation easier, though I'm only guessing.
🍀🍀🍀🍀
Good luck!
I tried to use pandoc, but in step from AST to markdown was lost many formatting like new line and etc.
I found another way to do that. We need only MS Word.
Open markdown file thought Word
Create new macro with the next code. We find all headers (#) and apply style Title 1, Title 2 and so on. Change the name of style for you.
Sub insertStyleHeaders()
Dim hashCount As Integer
Dim styleStr As String
Set oRng = ActiveDocument.Range
With oRng.Find
.text = "#"
While .Execute
oRng.MoveEnd wdParagraph
If InStr(oRng.text, "# ") Then
hashCount = Len(oRng.text) - Len(Replace(oRng.text, "#", ""))
styleStr = "Title " + CStr(hashCount)
oRng.Select
oRng.Style = ActiveDocument.Styles(styleStr)
End If
oRng.Collapse wdCollapseEnd
Wend
End With
End Sub
After run macros, right mouse click to: Expand/Collapse -> Collapse All Headings
Now we have next doc. You need to select by mouse group of items and call sort by headings.
After end of sort, select all doc (Ctrl + A) and apply plain text/default style in order to remove header styles.
And last, use ruler to shift indents and save file.

Where can I find a complete list of keywords (of the form ${ ... } ) that can be used in netbeans "code template"

The complete list of keywords that are legal in creating code templates in Netbeans would be accompanied by some documentation, making the "list" a reference. A line from the reference might look like:
${cursor} says to put the cursor at this point in the generated line
Working examples might be included in the reference, such as:
User-defined word to invoke the template: edfold
The template as it would appear in the Netbeans 8.2 RC > Tools > Options > Editor > Code templates tab:
${no-indent}//
// <editor-fold desc="***** ${cursor} *****" >
//
How it works: When I type edfold and hit the Tab key, the template is pasted into my document at the cursor position and looks like the following:
//
// <editor-fold desc="***** # *****" >
//
The cursor is positioned between the 5th and 6th asterisks that follow desc, so that I can then type whatever brief documentation that I wish, if any.
So where is the list of such keywords and their syntax and meaning? Such as:
${cursor}
${selection}
${no-indent}
${arg}
${Type}
and who knows how many more
It just hit me that there are OTHER keywords, two of which I unwittingly used above (I noticed them in someone else's code template and figured out how to use them):
desc
editor-fold
Surely there are other such identifiers to include in the reference.
By the way, the code template above is cute (or not) but is useless without a companion code template:
keypress:
endfold
Code template in editor:
// </editor-fold> ---------------- ${cursor} -------------------
Wherever the first inserted code template is located in your code, the second template must be below it. There is a "collapse" symbol "-" at the left of the first template. Clicking it collapses the code between the two templates. The symbol then changes to "+" and will expand the collapsed code when clicked.
EDIT
I just found this equivalent code template to the edfold and endfold pair just completed. Easier to code, up to a point, and harder to learn to use, but worth it, in the long run. Just highlight text to "hide" by folding, look for the line with the "Light Bulb", click Alt+Enter, and click "Code Folding". (Ctrl+Z to undo!)
But please see my (much better) Answer than this (was a) Question below.
Egg on my face... Googled topic, scanned all hits WAY too fast. In particular, "netbeans 8.2 code templates" pointed to this page involving PHP (think Java), which contained a lot of invaluable info about PHP that applies directly to Code Templates in Netbeans 8.2.
So, that link is part of a manual of sorts for learning how to create Code Templates for Netbeans 8.2 (in particular, and PHP in general).
The reference that I asked for--complete list of keywords (of the form ${ … } )--implies a list of all keywords or reserved words, like ${cursor} and ${selection} that permeate the list of provided Code Templates. But in a sense, that is the list. It is exactly those two Reserved Names. There are no others. Short list.
In the list of provided Netbeans Code Templates, there are a LOT of words that share the same $(...) syntax, but most are placeholder names or parameters that you decide the name and (probably-simple) meaning of.
If a code template contains, for example, class ${className}, the word class is Java code and ${className} is a parameter or placeholder. When the IDE expands the template, class is entered and ${className} turns into class_name, which the IDE automatically selects for editing, suggesting for you to enter the name of the new Java class being defined.
This non-trivial, but understandable, code template and much of what follows it explains much of the process for creating Code Templates. The heading Inserting the code template with code completion ends the explanation, but here is a sort of note of summary from further down:
The syntax of a "code template parameter" is a dollar sign, $, followed by the
parameter's definition between curly brackets {...}. Within this syntax, template
parameters have one of four forms:
* A reserved name that gives processing instructions to IDE (cursor or selection, only)
* An arbitrary placeholder name, such as ${SomeName}
* A descriptive parameter name [that hints at its meaning]
* Pre-defined parameters (??)

Is it possible to preserve variable names when writing and reading term programatically?

I'm trying to write an SWI-Prolog predicate that applies numbervars/3 to a term's anonymous variables but preserves the user-supplied names of its non-anonymous variables. I eventually plan on adding some kind of hook to term_expansion (or something like that).
Example of desired output:
?- TestList=[X,Y,Z,_,_].
> TestList=[X,Y,Z,A,B].
This answer to the question Converting Terms to Atoms preserving variable names in YAP prolog shows how to use read_term to obtain as atoms the names of the variables used in a term. This list (in the form [X='X',Y='Y',...]) does not contain the anonymous variables, unlike the variable list obtained by term_variables, making isolation of the anonymous variables fairly straightforward.
However, the usefulness of this great feature is somewhat limited if it can only be applied to terms read directly from the terminal. I noticed that all of the examples in the answer involve direct user input of the term. Is it possible to get (as atoms) the variable names for terms that are not obtained through direct user input? That is, is there some way to 'write' a term (preserving variable names) to some invisible stream and then 'read' it as if it were input from the terminal?
Alternatively... Perhaps this is more of a LaTeX-ish line of thinking, but is there some way to "wrap" variables inside single quotes (thereby atom-ifying them) before Prolog expands/tries to unify them as variables, with the end result that they're treated as atoms that start with uppercase letters rather than as variables?
You can use the ISO core standard variable_names/1 read and write option. Here is some example code, that replaces anonymous variables in a variable name mapping:
% replace_anon(+Map, +Map, -Map)
replace_anon([_=V|M], S, ['_'=V|N]) :- member(_=W, S), W==V, !,
replace_anon(M, S, N).
replace_anon([A=V|M], S, [A=V|N]) :-
replace_anon(M, S, N).
replace_anon([], _, []).
variable_names/1 is ISO core standard. It was always a read option. It then became a write option as well. See also: https://www.complang.tuwien.ac.at/ulrich/iso-prolog/WDCor3
Here is an example run:
Welcome to SWI-Prolog (threaded, 64 bits, version 7.7.25)
?- read_term(X,[variable_names(M),singletons(S)]),
replace_anon(M,S,N),
write_term(X,[variable_names(N)]).
|: p(X,Y,X).
p(X,_,X)
To use the old numbervars/3 is not recommended, since its not compatible with attribute variables. You cannot use it for example in the presence of CLP(FD).
Is it possible to get (as atoms) the variable names for terms that are not obtained through direct user input?
if you want to get variable names from source files you should read them from there.
The easiest way to do so using term expansion.
Solution:
read_term_from_atom(+Atom, -Term, +Options)
Use read_term/3 to read the next term from Atom.
Atom is either an atom or a string object.
It is not required for Atom to end with a full-stop.
Use Atom as input to read_term/2 using the option variable_names and return the read term in Term and the variable bindings in variable_names(Bindings).
Bindings is a list of Name = Var couples, thus providing access to the actual variable names. See also read_term/2.
If Atom has no valid syntax, a syntax_error exception is raised.
write_term( Term ) :-
numbervars(Term, 0, End),
write_canonical(Term), nl.

Jetbrains IDE: How to generate custom "todo" tags?

I have figured out how to download and install new color schemes.
It is after I did this that I noticed that IntelliJ will still color the following line yellow:
// ToDo: implement
Further, this coloration is independent of the color schemes I download. So, I now surmise that it is colored that way due to some logic specific to the Intellij.
I also use Pycharm and CLion, and suspect it would be the same situation across all three.
Here is the question: how do I access these settings/xml/logic and specify that I want say, 5 types of comment tags with colors A, B, C, D, E, such that I can call them by saying stuff like:
// T-A: File read in (t would be type)
// T-B: transform data
// T-C: linear section
// T-B: transform again
// T-D: parallel section
// T-E: MPI update
// T-B: array read in
// T-A: File read out
// etc.
So that I can basically color code the regions of a project, rather than just use the "ToDo" line?
You can go to Preferences | Editor | TODO. And there you can add / remove / edit your own patterns and filters, including color scheme:
After that, in your TODO window there's a Filter button with option to Edit filters, so you can easily find all places in your code with your custom patterns.
The problem was already answered quite well but I would like to add the usage of non-word tags like ???.
This requires to adopt the regex boundary character from \b (word boundary) to \B (non-word boundary). This leads to the final pattern \B\?\?\?\B.* to match:
code // ??? comment
code // ???: comment
This was not directly asked but may helps other with the same problem as I met...
See also https://www.jetbrains.com/help/idea/regular-expression-syntax-reference.html

What is the meaning of :: in selenium

What is the exact meaning of :: ?
And apart from parent, what else are the different things we can use?
By.xpath("parent::*/parent::*")
The shortest answer I can manage
:: separates an axis name from a node test in an XPath expression.
The longer answer
It does not make much sense to ask about the meaning of ":: in Selenium", because it's not a feature of Selenium. It belongs to XPath, which is a W3C specification in its own right and is used to navigate XML or XHTML documents.
By.xpath(" parent::*/parent::* ")
^ ^ ^
Selenium XPath Selenium
Selenium just happens to embed XPath in their web application framework (which is a good thing!).
So, I've taken the liberty to answer the question: What is the meaning of :: in XPath?
The meaning of :: in XPath
In XPath, :: does not mean anything on its own and only makes sense if there is
a valid XPath axis identifier to the left
a valid node test to the right
For example, parent::* is a valid XPath expression1. Here, parent is an XPath axis name, * is a node test2 - and :: marks the transition from the axis to the node test. Other possible axes are
ancestor following-sibling
ancestor-or-self namespace
attribute parent
child preceding
descendant preceding-sibling
descendant-or-self self
following
Of course those are not just names, they have a very clear-cut semantic dimension: each of them defines a unique way to navigate an XML document (or, rather, a tree-like representation of such a document). Their meaning is straightforward in most cases, for instance, following:: identifies something that "follows" the current context.
These tuples of axis and node test (or triples, also counting predicates) can be "chained together" with the binary / operator to form paths with several steps:
outermost-element/other/third
Navigating a simple document
<root>
<person>James Clark</person>
<person>Steve DeRose</person>
</root>
Naturally, navigation might depend very much on your current whereabouts. There are both absolute and relative path expressions. An example for an absolute path expression is
/child::root/child::person | abbreviated syntax: /root/person
As you can see, there is a / at the beginning of an absolute path expression. It stands for the document node (the outermost node of a tree, which is different from the outermost element node of a a tree). Relative path expressions look like
child::person | abbreviated syntax: person
The relative path expression will only find the person element node if the current context is the root element node. Otherwise, it will fail to locate anything.
Your XPath expression
To sum up and use what we have learned so far:
By.xpath("parent::*/parent::*")
finds the element node that is the grandparent of the current node. The names of both the parent and the grandparent node do not matter (that's what *is for). There's no / at the beginning, so it must be a relative path.
1 In fact, it is a location path, a special kind of XPath expression. Also, I have left out one important concept: predicates. Good things always come in threes, and XPath expressions come with an axis, a node test and with zero or more predicates.
2 A node test must be either a name test (testing the name of a node) or a kind test (testing the kind of node). Find ample information about node tests in the relevant part of the XPath specification.
This is xpath syntax, you can do other things like :
child::* Selects all element children of current node
attribute::* Selects all attributes of current node
child::text() Selects all text node children of current node
child::node() Selects all children of current node
Check a tutorial, especially about axes :
http://www.w3schools.com/xpath/xpath_axes.asp