You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
20 lines
690 B
20 lines
690 B
|
3 months ago
|
from neo4j import GraphDatabase
|
||
|
|
from pypinyin import lazy_pinyin
|
||
|
|
|
||
|
|
URI = "bolt://localhost:7687"
|
||
|
|
AUTH = ("neo4j", "12345678")
|
||
|
|
|
||
|
|
with GraphDatabase.driver(URI, auth=AUTH) as driver:
|
||
|
|
with driver.session() as session:
|
||
|
|
result = session.run("MATCH (d:Drug) WHERE d.name IS NOT NULL RETURN d.name AS name")
|
||
|
|
names = [record["name"] for record in result]
|
||
|
|
|
||
|
|
# 按拼音首字母 A-Z 排序(支持中英文混合)
|
||
|
|
def sort_key(name):
|
||
|
|
# 将每个字转为拼音,取首字母(如 "阿司匹林" → ['a', 'si', 'pi', 'lin'] → 拼成 "asipilin")
|
||
|
|
return ''.join(lazy_pinyin(name))
|
||
|
|
|
||
|
|
sorted_names = sorted(names, key=sort_key)
|
||
|
|
|
||
|
|
for name in sorted_names:
|
||
|
|
print(name)
|