优化生成流程
This commit is contained in:
@@ -9,10 +9,28 @@ from app.settings import Settings
|
||||
|
||||
|
||||
TOKEN_PATTERN = re.compile(r"[a-zA-Z0-9_]+")
|
||||
CN_TOKEN_PATTERN = re.compile(r"[\u4e00-\u9fff]")
|
||||
|
||||
TERM_ALIASES = {
|
||||
"法兰": {"flange", "mounting_plate"},
|
||||
"套筒": {"sleeve", "tube", "cylinder"},
|
||||
"孔": {"hole", "circle", "circles"},
|
||||
"沉头": {"countersunk", "counterbore"},
|
||||
"沉孔": {"counterbore", "counterbored"},
|
||||
"槽": {"slot", "obround"},
|
||||
"底板": {"plate", "rectangle", "mounting_plate"},
|
||||
"轴": {"shaft", "cylinder"},
|
||||
}
|
||||
|
||||
|
||||
def tokens(value: str) -> set[str]:
|
||||
return {token.lower() for token in TOKEN_PATTERN.findall(value)}
|
||||
text = str(value or "").lower()
|
||||
result = {token.lower() for token in TOKEN_PATTERN.findall(text)}
|
||||
result.update(CN_TOKEN_PATTERN.findall(text))
|
||||
for term, aliases in TERM_ALIASES.items():
|
||||
if term in text:
|
||||
result.update(aliases)
|
||||
return result
|
||||
|
||||
|
||||
class CdslLibrary:
|
||||
@@ -38,6 +56,8 @@ class CdslLibrary:
|
||||
"profiles": record.get("profiles", []),
|
||||
"features": record.get("features", []),
|
||||
"summary": record.get("summary", ""),
|
||||
"family": record.get("family", ""),
|
||||
"atomics": record.get("features", []),
|
||||
}
|
||||
for record in self._records()[:limit]
|
||||
]
|
||||
@@ -46,6 +66,8 @@ class CdslLibrary:
|
||||
corpus = " ".join([
|
||||
record.get("part_id", ""),
|
||||
record.get("source_name", ""),
|
||||
record.get("summary", ""),
|
||||
record.get("family", ""),
|
||||
" ".join(record.get("profiles", [])),
|
||||
" ".join(record.get("features", [])),
|
||||
" ".join(record.get("parameters", [])),
|
||||
@@ -60,6 +82,8 @@ class CdslLibrary:
|
||||
"profiles": record.get("profiles", []),
|
||||
"features": record.get("features", []),
|
||||
"summary": record.get("summary", ""),
|
||||
"family": record.get("family", ""),
|
||||
"atomics": record.get("features", []),
|
||||
}
|
||||
for _, record in scored[:limit]
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user