MCPcopy Create free account
hub / github.com/Graphify-Labs/graphify / _Graph

Class _Graph

tests/csharp_extension_harness.py:619–705  ·  view source on GitHub ↗

The graph facts every strategy is allowed to use.

Source from the content-addressed store, hash-verified

617
618
619class _Graph:
620 """The graph facts every strategy is allowed to use."""
621
622 def __init__(self, nodes: list[dict], edges: list[dict]) -> None:
623 self.nodes = nodes
624 self.node_by_id = {n["id"]: n for n in nodes if n.get("id")}
625 contained = {e.get("target") for e in edges if e.get("relation") == "contains"}
626 self.is_type = {
627 n["id"] for n in nodes
628 if n.get("id") in contained and n.get("source_file") and n.get("id") in self.node_by_id
629 }
630 self.type_index: dict[str, list[str]] = {}
631 for nid in self.is_type:
632 self.type_index.setdefault(_key(self.node_by_id[nid].get("label", "")), []).append(nid)
633
634 self.owner: dict[str, str] = {}
635 self.methods_by_owner: dict[tuple[str, str], list[str]] = {}
636 for e in edges:
637 if e.get("relation") != "method":
638 continue
639 owner, mid = e.get("source"), e.get("target")
640 mn = self.node_by_id.get(mid)
641 if not owner or mn is None:
642 continue
643 self.owner.setdefault(mid, owner)
644 self.methods_by_owner.setdefault((owner, _key(mn.get("label", ""))), []).append(mid)
645
646 self.supers: dict[str, set[str]] = {}
647 self.supers_unresolved: dict[str, bool] = {}
648 for e in edges:
649 if e.get("relation") not in ("inherits", "implements"):
650 continue
651 src, tgt = e.get("source"), e.get("target")
652 if not src or not tgt:
653 continue
654 self.supers.setdefault(src, set()).add(tgt)
655
656 # "a regular method in the corpus has this name" — extensions excluded,
657 # since they are the thing being resolved.
658 ext_ids = {
659 n["id"] for n in nodes
660 if isinstance(n.get("metadata"), dict) and n["metadata"].get("extension")
661 }
662 self.methods_by_name: dict[str, list[str]] = {}
663 for (owner, key), mids in self.methods_by_owner.items():
664 self.methods_by_name.setdefault(key, []).extend(mids)
665
666 self.regular_method_names = {
667 _key(self.node_by_id[mid].get("label", ""))
668 for mids in self.methods_by_owner.values() for mid in mids
669 if mid not in ext_ids
670 }
671
672 def type_closure(self, nid: str) -> tuple[set[str], bool]:
673 """(self + supertypes, unresolved?) — a source-less super is a stub."""
674 out: set[str] = set()
675 unresolved = False
676 stack = [nid]

Callers 1

apply_strategyFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected