Exporting

Mapping

class qbindiff.mapping.Mapping(mapping: ExtendedMapping, unmatched_primary: set[Node], unmatched_secondary: set[Node])[source]

Bases: object

This class represents an interface to access the result of the matching analysis. Its interface is independent of the underlying Node type manipulated.

add_match(node1: Node, node2: Node, similarity: float, confidence: float, squares: int) None[source]

Add the given match between the two nodes.

Parameters:
  • node1 – node in primary

  • node2 – node in secondary

  • similarity – similarity metric as float

  • confidence – confidence in the result (0..1)

  • squares – Number of squares being made

is_match_primary(node: Node) bool[source]

Returns true if the node in primary has been matched with a node in secondary.

Parameters:

node – ndoe to match in primary

Returns:

whether the node has been matched

is_match_secondary(node: Node) bool[source]

Returns true if the node in secondary has been matched with a node in primary.

Parameters:

node – ndoe to match in secondary

Returns:

whether the node has been matched

match_primary(node: Node) Match | None[source]

Returns the match associated with the given primary node (if any).

Parameters:

node – node to match in primary

Returns:

optional match

match_secondary(node: Node) Match | None[source]

Returns the match associated with the given secondary node (if any).

Parameters:

node – node to match in secondary

Returns:

optional match

property nb_match: int

Number of matches

property nb_nodes_primary: int

Total number of nodes in primary

property nb_nodes_secondary: int

Total number of nodes in secondary.

property nb_unmatched_primary: int

Number of unmatched nodes in primary.

property nb_unmatched_secondary: int

Number of unmatched nodes in secondary.

property normalized_similarity: float

Normalized similarity of the diff (from 0 to 1)

property primary_matched: set[Node]

Set of nodes matched in primary

property primary_unmatched: set[Node]

Set of nodes unmatched in primary.

remove_match(match: Match) None[source]

Remove the given matching from the matching.

Parameters:

match – Match object to remove from the matching

Returns:

None

property secondary_matched: set[Node]

Set of nodes matched in the secondary object.

property secondary_unmatched: set[Node]

Set of nodes unmatched in the secondary object.

property similarity: float

Sum of similarities of the diff (unbounded value)

property squares: float

Number of matching squares

to_csv(path: PathLike, *extra_attrs: ExtraAttrsType) None[source]

Write the mapping into a csv file. Additional attributes of the nodes to put in the csv can be optionally specified.

For example:

1# Adding the attribute "primary_addr" and "secondary_addr". The value will be obtained
2# by accessing `function.addr`
3mapping.to_csv("result.csv", "addr")
4
5# Adding the attributes name and type. This will add the fields "primary_name",
6# "secondary_name", "primary_type", "secondary_type"
7mapping.to_csv("result.csv", ("name", lambda f: f.name.upper()), "type")
Parameters:
  • path – The file path of the csv file to write

  • extra_attrs – Additional attributes to put in the csv. Each attribute is either a tuple (attribute_name, attribute_function) or a string attribute_name