Skip to content

Commit de6c2e9

Browse files
committed
feat:generative analysis
0 parents  commit de6c2e9

8 files changed

+893
-0
lines changed

.gitignore

+130
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
lerna-debug.log*
8+
.pnpm-debug.log*
9+
10+
# Diagnostic reports (https://nodejs.org/api/report.html)
11+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
12+
13+
# Runtime data
14+
pids
15+
*.pid
16+
*.seed
17+
*.pid.lock
18+
19+
# Directory for instrumented libs generated by jscoverage/JSCover
20+
lib-cov
21+
22+
# Coverage directory used by tools like istanbul
23+
coverage
24+
*.lcov
25+
26+
# nyc test coverage
27+
.nyc_output
28+
29+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
30+
.grunt
31+
32+
# Bower dependency directory (https://bower.io/)
33+
bower_components
34+
35+
# node-waf configuration
36+
.lock-wscript
37+
38+
# Compiled binary addons (https://nodejs.org/api/addons.html)
39+
build/Release
40+
41+
# Dependency directories
42+
node_modules/
43+
jspm_packages/
44+
45+
# Snowpack dependency directory (https://snowpack.dev/)
46+
web_modules/
47+
48+
# TypeScript cache
49+
*.tsbuildinfo
50+
51+
# Optional npm cache directory
52+
.npm
53+
54+
# Optional eslint cache
55+
.eslintcache
56+
57+
# Optional stylelint cache
58+
.stylelintcache
59+
60+
# Microbundle cache
61+
.rpt2_cache/
62+
.rts2_cache_cjs/
63+
.rts2_cache_es/
64+
.rts2_cache_umd/
65+
66+
# Optional REPL history
67+
.node_repl_history
68+
69+
# Output of 'npm pack'
70+
*.tgz
71+
72+
# Yarn Integrity file
73+
.yarn-integrity
74+
75+
# dotenv environment variable files
76+
.env
77+
.env.development.local
78+
.env.test.local
79+
.env.production.local
80+
.env.local
81+
82+
# parcel-bundler cache (https://parceljs.org/)
83+
.cache
84+
.parcel-cache
85+
86+
# Next.js build output
87+
.next
88+
out
89+
90+
# Nuxt.js build / generate output
91+
.nuxt
92+
dist
93+
94+
# Gatsby files
95+
.cache/
96+
# Comment in the public line in if your project uses Gatsby and not Next.js
97+
# https://nextjs.org/blog/next-9-1#public-directory-support
98+
# public
99+
100+
# vuepress build output
101+
.vuepress/dist
102+
103+
# vuepress v2.x temp and cache directory
104+
.temp
105+
.cache
106+
107+
# Docusaurus cache and generated files
108+
.docusaurus
109+
110+
# Serverless directories
111+
.serverless/
112+
113+
# FuseBox cache
114+
.fusebox/
115+
116+
# DynamoDB Local files
117+
.dynamodb/
118+
119+
# TernJS port file
120+
.tern-port
121+
122+
# Stores VSCode versions used for testing VSCode extensions
123+
.vscode-test
124+
125+
# yarn v2
126+
.yarn/cache
127+
.yarn/unplugged
128+
.yarn/build-state.yml
129+
.yarn/install-state.gz
130+
.pnp.*

README.md

+128
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
# 📖 Narrative Analysis AI - @thebolarin/narrative-analysis-ai
2+
3+
An AI-powered narrative analysis tool that processes research articles to extract key narratives, analyze their dominance, and track their evolution. This package is built on OpenAI’s GPT models and designed for researchers, journalists, and analysts.
4+
5+
## 🚀 Features
6+
7+
**AI-Powered Narrative Analysis** – Identifies key narratives in research articles.
8+
**Dominance & Evolution Tracking** – Understands how narratives shift over time.
9+
**Aggregated Insights** – Combines data from multiple articles for broad analysis.
10+
**Statistical Data for Visualization** – Provides key metrics to build visual representations.
11+
**Research Question Alignment** – Ensures analysis aligns with your research focus.
12+
13+
---
14+
15+
## 📦 Installation
16+
17+
Install the package via npm:
18+
19+
```bash
20+
npm install @thebolarin/narrative-analysis-ai
21+
```
22+
23+
## 🛠 Usage
24+
25+
Import and use the package in your Node.js project:
26+
27+
```javascript
28+
import { NarrativeAnalysis } from "@thebolarin/narrative-analysis-ai";
29+
30+
const openai = new OpenAI({
31+
organization: OPENAI_ORGANIZATION,
32+
project: OPENAI_PROJECT,
33+
});
34+
35+
const narrativeAnalysis = new NarrativeAnalysis(openai, preferred_gpt_model);
36+
37+
const researchQuestion = "How has climate change been represented in media?";
38+
const articles = [
39+
{
40+
uniqueId: "1",
41+
title: "The Climate Crisis",
42+
summary: "The article explores global climate change trends."
43+
},
44+
{
45+
uniqueId: "2",
46+
title: "Green Energy Policies",
47+
summary: "Discusses global efforts to transition to renewable energy."
48+
}
49+
];
50+
51+
async function analyze() {
52+
const result = await narrativeAnalysis.generateAnalysis({ researchQuestion, articles });
53+
console.log(result);
54+
}
55+
56+
analyze();
57+
58+
```
59+
60+
## 📘 Features
61+
62+
- **Article Analysis**: Extracts key narratives, dominance, and evolution of narratives in a given set of articles.
63+
- **Aggregated Analysis**: Combines findings across multiple articles to identify broader trends.
64+
- **Statistical Insights**: Provides top 5 narratives with their prominence, useful for data visualization.
65+
- **Overall Conclusion**: Summarizes findings in relation to the research question.
66+
67+
68+
# 📌 API Methods
69+
70+
```javascript
71+
generateAnalysis(researchQuestion: string, articles: Article[]): Promise<AnalysisResult>
72+
```
73+
74+
Analyzes a set of articles and extracts narratives.
75+
76+
### Parameters:
77+
78+
- **`researchQuestion`** `(string)`
79+
The central question guiding the analysis.
80+
81+
- **`articles`** `(Article[])`
82+
Array of articles, each containing:
83+
- **`uniqueId`** `(string)` : Unique identifier for the article.
84+
85+
- **`title`** `(string)` : The article’s title.
86+
87+
- **`summary`** `(string)` : A brief summary of the article.
88+
89+
90+
### Returns:
91+
- **`Promise<AnalysisResult>`**
92+
An object containing:
93+
- **`articleAnalysis`** : Array of analyzed articles with their narratives.
94+
- **`statistics`** : Data for visualization (top 5 narratives).
95+
96+
- **`overallConclusion`** : Summarized conclusion based on the research question.
97+
98+
99+
### 📝 Example Response
100+
101+
```json
102+
{
103+
"articleAnalysis": [
104+
{
105+
"uniqueId": "1",
106+
"title": "Global Warming and Its Effects",
107+
"summary": "This article discusses the impact of global warming on sea levels and agriculture.",
108+
"narratives": [
109+
{"narrative": "Rising sea levels", "details": "Sea levels are rising due to melting ice caps."}
110+
],
111+
"dominance": [
112+
{"narrative": "Rising sea levels", "percentage": 60}
113+
],
114+
"evolution": "Over time, the focus shifted from local effects to global policy changes."
115+
}
116+
],
117+
"statistics": [
118+
{"narrative": "Climate Policy", "value": 45},
119+
{"narrative": "Renewable Energy", "value": 25}
120+
],
121+
"overallConclusion": "The research shows that climate policies and renewable energy are key narratives in climate discussions."
122+
}
123+
```
124+
125+
### 🛠️ Contributing
126+
127+
Contributions are welcome! Feel free to open an issue or submit a pull request.
128+

0 commit comments

Comments
 (0)