Can we store metadata on every words and let user modify it and still keep it? - draftjs

I’m new to lexcal and I’m developing annotation tool for speech-to-text.
I have used draftjs. I use entity and decorator to store and manage metadata on each words. every single words are entities and each entity has timestamp as metadata.
example: I have a cat
" I ", " have ", " a ", " cat " are entities.
entity data of cat is like
offset: 12,
length: 5,
data: {
original_word: 'cat',
start: 4.2,
end: 4,6,
}
So when user select a word and modify the word cat into kitten, I can still get start and end timestamps.
Do you think I can develop similar thing with lexical?
It’s okay for metadata to break when user delete multiple words at a time… No need to be perfect because I need to migrate to some editor library from draftjs anyway sooner or later…
Thanks in advance.

Approaches:
Monitor Lexical updates
An (entity) node that extends LexicalTextNode
A wrapper node on top of LexicalTextNode (like Comments)
Monitor Lexical updates
If I understand your problem correctly, that's the preferred approach.
editor.registerUpdateListener(({editorState, previousEditorState, dirtyLeaves, dirtyNodes}) => {
// You can diff editor state and each of the individual nodes that
// were modified (dirtyLeaves and dirtyNodes)
});
Note that a TextNode may contain multiple words.
Tradeoffs:
(+) It's neat. It works well with the existing Lexical nodes and doesn't modify the rendered DOM.
(-) Diffing nodes can be complicated.
An (entity) node that extends LexicalTextNode
Just like MentionNode you can have an Entity node that has your own data.
class MarkedNode extends TextNode {
__timestamps: {...};
setTimestamps() { this.getWritable().__timestamps = ... }
getTimestamps() { return this.__timestamps; }
}
Tradeoffs:
(+) It's easy to replace each word with a MarkedNode.
(-) Replacing TextNodes with your own custom nodes kills all the optimizations around TextNodes that are currently part of the reconciler (merging adjacent text nodes). Having multiple individual spans can also cause accessibility issues or other external plugins like Grammarly to misbehave and it can also drop the efficacy of other plugins that rely on TextNodes.
A wrapper node on top of LexicalTextNode (like Comments)
Just like the previous approach but instead of replacing TextNode, you create your own wrapper (Element) node on top. Given that diffing based on characters can be complicated and slow that is the approach we went for for the CommentPlugin.
Tradeoffs:
(+) It's easy to add custom wrapper nodes.
(-) It can still impact the overall app performance negatively. Overall, it's better than the previous approach because you don't override TextNode but shares most of the downsides.
What about TextNode marks?
First of all, a TextNode can contain multiple words. A mark on a TextNode can potentially refer to 1+ words.
Besides that, allowing arbitrary metadata on TextNodes means that it's hard to optimize later. For example, when merging nodes we look at the properties they have and only merge them whenever they share all properties (mode, details, style etc.). To preserve such optimization we would have to establish rules to determine whether two TextNodes nodes can indeed be merged.

Related

VS Code Regex search to remove references based on containing text in string

I am attempting to remove all references of a managed package that is going to be uninstalled that spans throughout code base in VS Code
I have using a query to find the field permissions but am wondering if there is a way to search for the reference outside of specifying the exact field name compared to the field containing only "agf" since they are all using it.
Below is the search query:
<fieldPermissions>
<editable>false</editable>
<field>User.agf_Certified_Product_Owner__c</field>
<readable>false</readable>
</fieldPermissions>
In the field, I want to be able to find and delete the 5 associated lines from multiple files if they match "agf" in any combination. Something like the below:
<fieldPermissions>
<editable>false</editable>
<field>agf</field>
<readable>false</readable>
</fieldPermissions>
With any combination of agf in the field, delete all from any file it appears in.
Not an answer but too long for a comment
You don't have to? Profiles/perm sets don't block package's delete. Probably neither do reports.
You'd use your time better by searching for all instances of agf__ (that's with double underscore), should find fields, objects... used in classes, flows, page layouts etc. And search for agf. (with dot) should find all instances where your Apex code calls their classes marked as global.
Alternatively Apex / VF pages with dependencies on package will have it listed in their "meta.xml", for example
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>54.0</apiVersion>
<packageVersions>
<majorNumber>236</majorNumber>
<minorNumber>1</minorNumber>
<namespace>SBQQ</namespace>
</packageVersions>
<status>Active</status>
</ApexClass>
Last but not least - why not just spawn a dev sandbox and attempt the delete there? If it succeeds - great. If not - it'll list the dependencies that blocked the delete. It'll be "the real thing", it'll smite you even if your VSCode project doesn't contain all flows, layouts and thus could lull you into false sense of security. I'd seriously do it in sandbox and then run all tests for good measure, just in case there are some dynamic soql queries that don't count as hard, delete-blocking references.
After delete's done - fetch Profiles / Permsets from this org and the field references will be gone from the xml.

How do I get the event tags for a Coverity issue?

If I am looking at an issue in the Coverity user interface, how do I get the event tag or tags? I need to know a tag in order to suppress the finding using code annotations, as described in the question "How can I disable coverity checking using code annotation?" but I'm not seeing it or maybe don't know where to look.
The event tag is the first identifier-like word in each line of commentary that makes up the issue report.
For example, on Github, RcppCore/Rcpp issue 760 contains a screenshot that I have reproduced at half-size resolution with some annotations:
Zooming in on the code panel:
There are three events here:
alloc_fn: Storage is returned from allocation function operator new.
noescape: Resource new Rcpp::Rostream<true>::Buffer is not freed or pointed-to in basic_ostream. ...
leaked_storage: Failing to save or free storage allocated by new Rcpp::Rostream<true>::Buffer leaks it.
The event tags are "alloc_fn", "noescape", and "leaked_storage".
In this instance, all of them are associated with the same line of code (line 49), but in general they may appear on different lines and spread across multiple files.
To navigate to all of the events, use the Occurrences panel:
The Occurrences panel shows all of the events, organized into a tree, where child nodes are events in callee functions. The entire list is generally ordered in program execution order, although some events may be chronologically disconnected, for example if the finding involves multiple execution paths.
Each entry in the Occurrences panel has an event number (again, nominally chronological), the event tag, and the file name and line number. Clicking on an entry navigates to that event in the code panel.
Here are a couple related Synopsys support articles:
how to add code annotation? I do not know which name should exist with //coverity[]
Is there a document that lists all defect 'events' with their name and descriptions?

IBM Chatbot Assistant - Array with same values

I have this piece of code in JSON editor of Watson:
"context": {
"array": "<? entities['spare_part'].![literal] ?>",
"array_size": "<?$array.size() ?>"
When the input of the user, for example, is "Hello, I need a valve, and the part number of the valve is 1234", the size of the array ends up being 2 since the user mentions the word "valve" twice in his input. Some nodes are being executed depending on size of the array. For instance if the size of the array is 1, some nodes will be ignored because they are only executed only if the size of the array is 2.
I want the array to store only the inputs with different values, which is basically I don`t want the array to store the values of the same type, in my case 2 valves. If it is possible somehow please show me a way.
All that can be done, but the best approach depends on the overall system architecture. Remember that Watson Assistant is a conversation service, not a data processing platform...
You can process JSON in either Watson Assistant directly using the built-in methods and SpEL, see these links to get started:
- https://console.bluemix.net/docs/services/conversation/expression-language.html#expressions-for-accessing-objects
- http://docs.spring.io/spring/docs/current/spring-framework-reference/html/expressions.html
- https://console.bluemix.net/docs/services/conversation/dialog-methods.html#expression-language-methods
That would require some coding within the dialog nodes. It could be ok. What I would recommend is to either process in your app that drives the dialog (you need that app anyway) or to code up small server actions to transform data.
If it is the word you are looking for, you can use contextual entities to train for this.
As an example I created the following intent (along with general intents from catalog).
For each example I highlighted the "valve" word that is the one I am interested in, and added to the entity.
Now when I test it I get the following.
All this was done in a couple of minutes. For production level you may want to add more examples, or think about how you want to annotate.

jsTree: How to *set* opened/selected node by path (not ID)?

So, I can get the full path of a selected node like so (thanks to #ggrandes for that one):
.on('changed.jstree', function (e, data) {
var path = data.instance.get_path(data.node,'/');
console.log('Selected: ' + path);
})
What I now need, is to set select/open a node according to a given path.
All the solutions I've found so far refer to some mysterious ID, which appears to simply assume that the data in question has IDs. My problem is that I don't. It's simply a recursive JSON dict/array describing a directory layout. All I have with each node, is its name and a list of its children (and their names and children and so forth).
So, what I need is something like:
data.instance.set_path('/some/arbitrary/path');
Is it possible to do this with jsTree in some reasonable way?
I ended up creating a full path of every item on the server-side and using that as an ID that could then be selected on the client-side. As far as I can tell, there is no other way, at the time of this writing.

LibXML: Comment-out a block of Elements

IS there a way to add/initate a comment ( e.g. $dom->createComment ... ) such that it comments out an entire block of xml tags. Basically I want to turn-off the content between the comment.
For example, it would look like this:
<TT>
<AA>keep</AA>
<!-- comment to blocking
<BB>hideme1</BB>
<CC>hideme2</CC>
-->
<DD>d's content is good</DD>
</TT>
Actually this question is a pre-cursor to my attempt to figure-out a method to be able to markup/label/identify the changes to an xml files in support of new client software functionality, but be able to have the ability to remove / back-out these xml changes in the rare event the client needs to fall back to the previous software version (and no I can't just simply point back to the original xml file because the client is allowed to make minor modifications to existing node text values). This is all going to be controlled via a perl script and LibXML's core modules (I can't use modules the client doesn't have).
So basically I've identified three possible types of xml changes as a result of new client sw functionality:
1.) ADD new element node(s) (typically to support new sw functionality)
2.) DELETE element node(s), or blocks of (would be rare, but never-the-less a possibility)
3.) CHANGE node text values (rare, but the new sw may require a new value)
For all three types, the client needs the ability to back out the changes. One thing I was thinking to use is ATTRIBUTES since the existing xml files don't use them. For example, for an ADD change type, I could include an atribute like 'ADD="sw version 4.1"' . This way if it needs to be removed, I could just simply have the perl script find those attribute strings and delete them (using LibXML methods). Same thing with CHANGE change type - I could use an attribute like CHG="newvalue_oldvalue", then again use straight perl (or LibXML) to switch back the value based on the contents of the attribute. The DELETE change type is giving me a problem though (as welll as the others lol!). I want to be able to "keep" the deleted lines in the xml file soley for the purposes if the sw falls back a version (at some late point the perl script could eventually cleanup/delete them).
I know this is a lot, I'm new to LibXML (but not to perl). I was just wonder if any of you have any thoughts as to how to go about it or seen anything resembling this kind of request ... I'd be grateful for any kind of advice! Thank you...