File size: 2,721 Bytes
72c2a85 56d2a83 72c2a85 56d2a83 72c2a85 56d2a83 72c2a85 56d2a83 72c2a85 56d2a83 72c2a85 56d2a83 72c2a85 56d2a83 72c2a85 56d2a83 | 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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | # -*- coding: utf-8 -*-
"""
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()
# Windows ํ๊ฒฝ ํ๊ธ ํฐํธ ์ค์
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()
|