:mod:`lookout.style.format.uast_stability_checker` ================================================== .. py:module:: lookout.style.format.uast_stability_checker .. autoapi-nested-parse:: Module to check if predictions change the UAST structure of the processed files. Module Contents --------------- .. py:class:: UASTStabilityChecker(feature_extractor:FeatureExtractor, debug:bool=False) Check if predictions change the UAST structure of the processed files. See `check()` or `file_check()` for more info. .. attribute:: _log .. attribute:: _check_return_type .. method:: _parse_code(self, vnode:VirtualNode, parent:bblfsh.Node, content:str, stub:'bblfsh.aliases.ProtocolServiceStub', node_parents:Mapping[int, bblfsh.Node], path:str) Find a parent node that Babelfish can parse and parse it. Iterates over the parents of the current virtual node until it is parsable and returns the parsed UAST or None if it reaches the root without finding a parsable parent. The cache will be used to avoid recomputations for parents that have already been considered. :param vnode: Vnode that is modified. Used to check that we retrieve the correct parent. :param parent: First virtual node to try to parse. Will go up in the tree if it fails. :param content: Content of the file. :param stub: Babelfish GRPC service stub. :param node_parents: Parents mapping of the input UASTs. :param path: Path of the file being parsed. :return: tuple of the parsed UAST and the corresponding starting and ending offsets. None if Babelfish failed to parse the whole file. .. method:: _check_file(self, y:numpy.ndarray, y_pred:numpy.ndarray, vnodes_y:Sequence[VirtualNode], vnodes:Sequence[VirtualNode], file:File, stub:'bblfsh.aliases.ProtocolServiceStub', vnode_parents:Mapping[int, bblfsh.Node], node_parents:Mapping[int, bblfsh.Node], rule_winners:numpy.ndarray, grouped_quote_predictions:QuotedNodeTripleMapping) .. method:: check(self, y:numpy.ndarray, y_pred:numpy.ndarray, vnodes_y:Sequence[VirtualNode], vnodes:Sequence[VirtualNode], files:Sequence[File], stub:'bblfsh.aliases.ProtocolServiceStub', vnode_parents:Mapping[int, bblfsh.Node], node_parents:Mapping[int, bblfsh.Node], rule_winners:numpy.ndarray, grouped_quote_predictions:QuotedNodeTripleMapping) Filter the model's predictions that modify the UAST apart from changing Node positions. :param y: Numpy 1-dimensional array of labels. :param y_pred: Numpy 1-dimensional array of predicted labels by the model. :param vnodes_y: Sequence of the labeled `VirtualNode`-s corresponding to labeled samples. :param vnodes: Sequence of all the `VirtualNode`-s corresponding to the input. :param files: File or Sequence of File-s with content, uast and path. :param stub: Babelfish GRPC service stub. :param vnode_parents: `VirtualNode`-s' parents mapping as the LCA of the closest left and right babelfish nodes. :param node_parents: Parents mapping of the input UASTs. :param rule_winners: Numpy array with the indexes of the winning rules for each sample. :param grouped_quote_predictions: Quotes predictions (handled differenlty from the rest). :return: List of predictions indices that are considered valid i.e. that are not breaking the UAST. .. staticmethod:: check_uasts_equivalent(uast1:bblfsh.Node, uast2:bblfsh.Node) Check if 2 UAST nodes are identical regarding `roles`, `internal_type` and `token` of their subtree members. :param uast1: The bblfsh.Node of the first UAST to compare. :param uast2: The bblfsh.Node of the second UAST to compare. :return: True if the 2 input UASTs are identical and False otherwise.