| |
| """ |
| FinGraph ํค์๋ ์๊ฐํ ์ ํธ๋ฆฌํฐ |
| - ์ ์๊ถ: (c) 2026 yujetak / FinGraph Contributors (MIT License) |
| - ์ญํ : ์์ง๋ ์ ์ฒด ๋ด์ค ๋ฐ์ดํฐ๋ฒ ์ด์ค ๋ด AI ๊ด๋ จ ์ฃผ์ ํค์๋(๊ธฐ์
/๊ธฐ์ /์๋น์ค)์ ์ถํ ๋น๋๋ฅผ ๋ถ์ํ์ฌ |
| ์ข์ธก ๋์๋ณด๋ ํ๋ฉด์ ์ ์ฌํ ๊ณ ํ์ง ๋ง๋๊ทธ๋ํ ์ด๋ฏธ์ง(keyword_frequencies.png)๋ฅผ ์์ฑํฉ๋๋ค. |
| """ |
| import os |
|
|
| import dotenv |
| import matplotlib.pyplot as plt |
| import neo4j |
| import pandas as pd |
|
|
| dotenv.load_dotenv() |
|
|
|
|
| |
| plt.rc('font', family='Malgun Gothic') |
| plt.rcParams['axes.unicode_minus'] = False |
|
|
|
|
| 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 |
|
|
|
|
| def create_keyword_plot(): |
| driver = get_neo4j_driver() |
|
|
| query = """ |
| MATCH (a:Article)-[:MENTIONS]->(n) |
| WHERE NOT n:Content |
| RETURN n.name AS keyword, count(a) AS freq |
| ORDER BY freq DESC |
| LIMIT 20 |
| """ |
|
|
| with driver.session() as session: |
| res = session.run(query) |
| data = [dict(record) for record in res] |
|
|
| driver.close() |
|
|
| if not data: |
| print("ํค์๋ ๋ฐ์ดํฐ๊ฐ ์์ต๋๋ค.") |
| return |
|
|
| df = pd.DataFrame(data) |
| |
| |
| plt.figure(figsize=(10, 8)) |
| bars = plt.barh(df['keyword'][::-1], df['freq'][::-1], color='#3b5a82') |
| |
| plt.xlabel('์ถํ ๋น๋ (๊ด๋ จ ๊ธฐ์ฌ ์)', fontsize=12) |
| plt.ylabel('ํค์๋ (๊ธฐ์
/๊ธฐ์ /์๋น์ค)', fontsize=12) |
| plt.title('์์ 20๊ฐ AI ๊ด๋ จ ํค์๋ ์ถํ ๋น๋', fontsize=16, fontweight='bold') |
| |
| |
| for bar in bars: |
| width = bar.get_width() |
| plt.text(width + 0.1, bar.get_y() + bar.get_height() / 2, f'{int(width)}', |
| ha='left', va='center', fontsize=10) |
|
|
| plt.tight_layout() |
| output_path = 'keyword_frequencies.png' |
| plt.savefig(output_path, dpi=300, bbox_inches='tight') |
| print(f"Graph successfully saved to {output_path}") |
|
|
|
|
| if __name__ == "__main__": |
| create_keyword_plot() |
|
|