Add Cloud Tour Libo knowledge graph platform
This commit is contained in:
@@ -48,9 +48,11 @@ TEXT_PROPS = (
|
||||
|
||||
PLACE_TYPE_LABELS = {
|
||||
"sight": "景点",
|
||||
"scenic_area": "景区",
|
||||
"eat": "美食",
|
||||
"hotel": "酒店",
|
||||
"mall": "商场",
|
||||
"transit": "交通设施",
|
||||
"transit_stop": "交通站点",
|
||||
}
|
||||
|
||||
@@ -59,6 +61,24 @@ STATION_TYPE_LABELS = {
|
||||
"地铁站": "地铁站",
|
||||
}
|
||||
|
||||
PLACE_SUBTYPE_LABELS = {
|
||||
"GeoCell": "片区",
|
||||
"ScenicSpot": "景点",
|
||||
"ScenicArea": "景区",
|
||||
"FoodPlace": "美食",
|
||||
"Hotel": "酒店",
|
||||
"TransitFacility": "交通设施",
|
||||
"BusStop": "公交站",
|
||||
"Mall": "商场",
|
||||
"MedicalPlace": "医疗保健",
|
||||
"EducationPlace": "科教文化",
|
||||
"LifeServicePlace": "生活服务",
|
||||
"Facility": "公共设施",
|
||||
"GovernmentPlace": "政府机构",
|
||||
"ResidentialPlace": "商务住宅",
|
||||
"EnterprisePlace": "公司企业",
|
||||
}
|
||||
|
||||
NL_TO_CYPHER_SYS = """你是城市知识图谱查询助手。请把用户自然语言问题转换成 FalkorDB/RedisGraph 只读 Cypher。
|
||||
|
||||
硬性要求:
|
||||
@@ -712,6 +732,8 @@ def _node_dict(n: Any) -> dict:
|
||||
visual_group = _place_visual_group(props)
|
||||
elif group == "Event":
|
||||
visual_group = _event_visual_group(props)
|
||||
elif group == "GeoCell":
|
||||
visual_group = "片区"
|
||||
|
||||
disp = ""
|
||||
station_type = props.get("station_type")
|
||||
@@ -726,7 +748,7 @@ def _node_dict(n: Any) -> dict:
|
||||
disp = str(v)
|
||||
break
|
||||
if not disp:
|
||||
disp = f"{group} #{nid}" # never a bare number
|
||||
disp = f"{visual_group} #{nid}" # never a bare number
|
||||
|
||||
return {
|
||||
"id": nid,
|
||||
@@ -835,10 +857,11 @@ def graph_overview(
|
||||
|
||||
label_result = g.query(
|
||||
"MATCH (n) WHERE n.shadow_node IS NULL OR n.shadow_node <> 1 "
|
||||
"RETURN labels(n) AS labels, count(n) AS count LIMIT 100"
|
||||
"UNWIND labels(n) AS label "
|
||||
"RETURN label, count(n) AS count LIMIT 100"
|
||||
)
|
||||
label_counts = [
|
||||
{"label": r[0][0] if r[0] else "(no label)", "count": r[1]}
|
||||
{"label": r[0] or "(no label)", "count": r[1]}
|
||||
for r in label_result.result_set
|
||||
]
|
||||
visual_counts: dict[str, int] = {}
|
||||
@@ -846,10 +869,15 @@ def graph_overview(
|
||||
label = item["label"]
|
||||
if label in {"Place", "Event"}:
|
||||
continue
|
||||
visual_counts[label] = visual_counts.get(label, 0) + int(item["count"] or 0)
|
||||
visual_label = PLACE_SUBTYPE_LABELS.get(label, label)
|
||||
visual_counts[visual_label] = (
|
||||
visual_counts.get(visual_label, 0) + int(item["count"] or 0)
|
||||
)
|
||||
|
||||
place_split_result = g.query(
|
||||
"MATCH (p:Place) WHERE p.shadow_node IS NULL OR p.shadow_node <> 1 "
|
||||
"MATCH (p:Place) "
|
||||
"WHERE (p.shadow_node IS NULL OR p.shadow_node <> 1) "
|
||||
"AND size(labels(p)) = 1 "
|
||||
"RETURN p.place_type AS place_type, p.station_type AS station_type, "
|
||||
"p.category AS category, count(p) AS count LIMIT 200"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user