File size: 1,688 Bytes
72c2a85 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | # -*- coding: utf-8 -*-
"""
FinGraph ์ง์ ๊ทธ๋ํ ๋ฌด๊ฒฐ์ฑ ๊ด๋ฆฌ ์ ํธ๋ฆฌํฐ
- ์ ์๊ถ: (c) 2026 yujetak / FinGraph Contributors (MIT License)
- ์ญํ : ์ง์ ์ ์ธ ์ํฐํฐ ๊ฐ ๊ด๊ณ์ (DEVELOPS, APPLIES ๋ฑ)์ด 0๊ฐ์ธ ๊ณ ๋ฆฝ ๊ธฐ์ฌ ๋
ธ๋๋ฅผ ํ์ํ๊ณ ์ ๊ฑฐํ์ฌ
๊ทธ๋ํ์ ์ฐ๊ฒฐ ๋ฐ๋์ RAG ๊ฒ์ ๋ฌด๊ฒฐ์ฑ์ ๋์
๋๋ค.
"""
import os
import dotenv
import neo4j
dotenv.load_dotenv()
def get_neo4j_driver() -> neo4j.Driver:
uri = os.getenv("NEO4J_URI", "neo4j://localhost:7687")
client_id = os.getenv("NEO4J_CLIENT_ID")
client_secret = os.getenv("NEO4J_CLIENT_SECRET")
if client_id and client_secret:
try:
d = neo4j.GraphDatabase.driver(uri, auth=(client_id, client_secret))
d.verify_connectivity()
return d
except Exception:
pass
username = os.getenv("NEO4J_USERNAME", "neo4j")
password = os.getenv("NEO4J_PASSWORD", "password")
d = neo4j.GraphDatabase.driver(uri, auth=(username, password))
d.verify_connectivity()
return d
if __name__ == "__main__":
driver = get_neo4j_driver()
with driver.session() as s:
res = s.run('''
MATCH (a:Article)
OPTIONAL MATCH (a)-[:MENTIONS]->(n)
OPTIONAL MATCH (n)-[r:DEVELOPS|INVESTS_IN|PARTNERS_WITH|APPLIES|USED_IN|RELATED_TO]-()
WITH a, count(r) as rel_cnt
WHERE rel_cnt = 0
DETACH DELETE a
RETURN count(a) as deleted_count
''')
record = res.single()
if record:
print(f'Deleted articles with 0 relations: {record["deleted_count"]}')
driver.close()
|