Download scripts/delete_zero_rel_articles.py from dev-yuje/FinGraph: direct link, hf CLI and curl.
- Browser
- Download file 1.69 kB
-
https://huggingface.co/spaces/dev-yuje/FinGraph/resolve/main/scripts/delete_zero_rel_articles.py
- Command line
-
hf download hf://spaces/dev-yuje/FinGraph/scripts/delete_zero_rel_articles.py
-
curl -L -o delete_zero_rel_articles.py https://huggingface.co/spaces/dev-yuje/FinGraph/resolve/main/scripts/delete_zero_rel_articles.py
1.69 kB
| # -*- 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() | |