generated from coulomb/repo-seed
Improved candidate feature naming
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
from dataclasses import dataclass, field
|
||||
|
||||
from repo_registry.core.models import ContentChunk, ObservedFact, Repository, SourceReference
|
||||
@@ -126,7 +127,7 @@ class CandidateGraphGenerator:
|
||||
) -> CandidateCapabilityDraft:
|
||||
features = [
|
||||
CandidateFeatureDraft(
|
||||
name=fact.value or fact.name,
|
||||
name=self._feature_name(fact, chunks),
|
||||
type=self._feature_type(fact),
|
||||
location=fact.path,
|
||||
confidence=0.65 if fact.value else 0.45,
|
||||
@@ -194,6 +195,40 @@ class CandidateGraphGenerator:
|
||||
return "API"
|
||||
return "interface"
|
||||
|
||||
def _feature_name(self, fact: ObservedFact, chunks: list[ContentChunk]) -> str:
|
||||
route_name = self._route_feature_name(fact.value)
|
||||
if route_name:
|
||||
return route_name
|
||||
if self._feature_type(fact) == "CLI":
|
||||
function_name = self._function_name_near_fact(fact, chunks)
|
||||
if function_name:
|
||||
return f"CLI command {function_name}"
|
||||
return fact.value or fact.name
|
||||
|
||||
def _route_feature_name(self, value: str) -> str:
|
||||
match = re.search(r"@(?:app|router)\.(get|post|put|patch|delete)\((['\"])(.*?)\2", value)
|
||||
if match is None:
|
||||
return ""
|
||||
method = match.group(1).upper()
|
||||
path = match.group(3)
|
||||
return f"{method} {path}"
|
||||
|
||||
def _function_name_near_fact(
|
||||
self,
|
||||
fact: ObservedFact,
|
||||
chunks: list[ContentChunk],
|
||||
) -> str:
|
||||
line = fact.metadata.get("line")
|
||||
for chunk in chunks:
|
||||
if chunk.path != fact.path or chunk.kind != "interface":
|
||||
continue
|
||||
if isinstance(line, int) and not (chunk.start_line <= line <= chunk.end_line):
|
||||
continue
|
||||
match = re.search(r"^\s*def\s+([a-zA-Z_][a-zA-Z0-9_]*)\s*\(", chunk.text, re.MULTILINE)
|
||||
if match is not None:
|
||||
return match.group(1)
|
||||
return ""
|
||||
|
||||
def _ability_confidence(
|
||||
self,
|
||||
*,
|
||||
|
||||
Reference in New Issue
Block a user