drepr.planning.drepr_model_alignments#

Classes

CustomedDfs(stack, discovered)

THE FOLLOWING CODE IS ADAPTED FROM: https://docs.rs/petgraph/0.4.13/src/petgraph/visit/traversal.rs.html#38-43 so that DFS also yield the parent node

DReprModelAlignments(desc, aligns)

VisitMap(map)

A mapping for storing the visited status for NodeId N.

class DReprModelAlignments(desc: 'DRepr', aligns: 'dict[tuple[AttrId, AttrId], list[Alignment]]')[source]#

Bases: object

Parameters:
desc: DRepr#
aligns: dict[tuple[str, str], list[Union[drepr.models.align.RangeAlignment, drepr.models.align.ValueAlignment, drepr.models.align.IdenticalAlign, drepr.models.align.AutoAlignment]]]#
static create(desc: DRepr) DReprModelAlignments[source]#

Infer all possible alignments from the model.

Parameters:

desc (DRepr) –

Return type:

DReprModelAlignments

get_alignments(source: str, target: str) list[Union[drepr.models.align.RangeAlignment, drepr.models.align.ValueAlignment, drepr.models.align.IdenticalAlign, drepr.models.align.AutoAlignment]][source]#
Parameters:
  • source (str) –

  • target (str) –

Return type:

list[Union[drepr.models.align.RangeAlignment, drepr.models.align.ValueAlignment, drepr.models.align.IdenticalAlign, drepr.models.align.AutoAlignment]]

inference()[source]#
infer_subject(attrs: list[str]) list[str][source]#

Find all attributes that can be the subject of these attributes

The subject must has one to one mapping to all attrs and: (1) have no missing path (2) have missing path, but the missing path is the same for all attrs.

  1. has higher priority than (2).

Parameters:

attrs (list[str]) –

Return type:

list[str]

infer_func(xid: str, yid: str, zid: str) Optional[list[Union[drepr.models.align.RangeAlignment, drepr.models.align.ValueAlignment, drepr.models.align.IdenticalAlign, drepr.models.align.AutoAlignment]]][source]#

Infer an alignment function of xid and zid given alignments between (xid, yid) and (yid, zid)

If there is only one way to join values of xid and zid, then the chain join will be the correct one

Parameters:
Return type:

Optional[list[Union[drepr.models.align.RangeAlignment, drepr.models.align.ValueAlignment, drepr.models.align.IdenticalAlign, drepr.models.align.AutoAlignment]]]

estimate_cardinality(aligns: list[Union[drepr.models.align.RangeAlignment, drepr.models.align.ValueAlignment, drepr.models.align.IdenticalAlign, drepr.models.align.AutoAlignment]]) Cardinality[source]#
Parameters:

aligns (list[Union[drepr.models.align.RangeAlignment, drepr.models.align.ValueAlignment, drepr.models.align.IdenticalAlign, drepr.models.align.AutoAlignment]]) –

Return type:

Cardinality

optimize_chained_alignments(aligns: list[Union[drepr.models.align.RangeAlignment, drepr.models.align.ValueAlignment, drepr.models.align.IdenticalAlign, drepr.models.align.AutoAlignment]]) list[Union[drepr.models.align.RangeAlignment, drepr.models.align.ValueAlignment, drepr.models.align.IdenticalAlign, drepr.models.align.AutoAlignment]][source]#
Parameters:

aligns (list[Union[drepr.models.align.RangeAlignment, drepr.models.align.ValueAlignment, drepr.models.align.IdenticalAlign, drepr.models.align.AutoAlignment]]) –

Return type:

list[Union[drepr.models.align.RangeAlignment, drepr.models.align.ValueAlignment, drepr.models.align.IdenticalAlign, drepr.models.align.AutoAlignment]]

static auto_align(source: Attr, target: Attr) Optional[Union[RangeAlignment, IdenticalAlign]][source]#
Parameters:
Return type:

Optional[Union[RangeAlignment, IdenticalAlign]]

score_alignment(align: Union[RangeAlignment, ValueAlignment, IdenticalAlign, AutoAlignment]) int[source]#

Score an alignment function so we can justify if an alignment is new/better or not. Lower score is better.

Parameters:

align (Union[RangeAlignment, ValueAlignment, IdenticalAlign, AutoAlignment]) –

Return type:

int

class CustomedDfs(stack: list[tuple[str, str]], discovered: VisitMap)[source]#

Bases: object

THE FOLLOWING CODE IS ADAPTED FROM: https://docs.rs/petgraph/0.4.13/src/petgraph/visit/traversal.rs.html#38-43 so that DFS also yield the parent node

Visit nodes of a graph in a depth-first-search (DFS) emitting nodes in preorder (when they are first discovered).

The traversal starts at a given node and only traverses nodes reachable from it.

Dfs is not recursive.

Dfs does not itself borrow the graph, and because of this you can run a traversal over a graph while still retaining mutable access to it, if you use it like the following example:

``` use petgraph::Graph; use petgraph::visit::Dfs;

let mut graph = Graph::<_,()>::new(); let a = graph.add_node(0);

let mut dfs = Dfs::new(&graph, a); while let Some(nx) = dfs.next(&graph) {

// we can access graph mutably here still graph[nx] += 1;

}

assert_eq!(graph[a], 1); ```

Note: The algorithm may not behave correctly if nodes are removed during iteration. It may not necessarily visit added nodes or edges.

Parameters:
stack: list[tuple[str, str]]#
discovered: VisitMap#
static empty() CustomedDfs[source]#

Create a new Dfs using the graph’s visitor map, and no stack.

Return type:

CustomedDfs

static from_graph(graph: RetworkXStrDiGraph, start: str) CustomedDfs[source]#

Create a new Dfs, using the graph’s visitor map, and put start in the stack of nodes to visit.

Parameters:
  • graph (RetworkXStrDiGraph) –

  • start (str) –

Return type:

CustomedDfs

move_to(start: str)[source]#

Keep the discovered map, but clear the visit stack and restart the dfs from a particular node.

Parameters:

start (str) –

next(graph: RetworkXStrDiGraph, revisit: set[str]) Optional[tuple[str, str]][source]#
Parameters:
  • graph (RetworkXStrDiGraph) –

  • revisit (set[str]) –

Return type:

Optional[tuple[str, str]]

class VisitMap(map: set[str] = <factory>)[source]#

Bases: object

A mapping for storing the visited status for NodeId N.

Parameters:

map (set[str]) –

map: set[str]#
visit(a: str) bool[source]#

Mark a as visited.

Return true if this is the first visit, false otherwise.

Parameters:

a (str) –

Return type:

bool

is_visited(a: str) bool[source]#

Return whether a has been visited before.

Parameters:

a (str) –

Return type:

bool