From 9b7141891557f3cd6e7811b833d3f86af883f433 Mon Sep 17 00:00:00 2001 From: Matteo Cacciola Date: Mon, 3 Apr 2023 04:10:16 +0200 Subject: [PATCH] fix --- .eslintignore | 2 -- README.md | 2 +- docs/libraries/naive-bayes.md | 2 +- libraries/naive-bayes/.eslintrc.js | 8 ------- libraries/naive-bayes/.gitignore | 17 ------------- libraries/naive-bayes/package.json | 24 ------------------- libraries/naive-bayes/tsconfig.json | 19 --------------- package-lock.json | 18 ++++---------- package.json | 9 +++---- .../libraries/naive-bayes}/classifier.ts | 0 .../libraries/naive-bayes}/corpus.ts | 0 .../naive-bayes/data/negative/1.txt | 0 .../naive-bayes/data/negative/2.txt | 0 .../naive-bayes/data/negative/3.txt | 0 .../naive-bayes/data/negative/4.txt | 0 .../naive-bayes/data/negative/5.txt | 0 .../naive-bayes/data/positive/1.txt | 0 .../naive-bayes/data/positive/2.txt | 0 .../naive-bayes/data/positive/3.txt | 0 .../naive-bayes/data/positive/4.txt | 0 .../naive-bayes/data/positive/5.txt | 0 .../libraries/naive-bayes}/document.ts | 0 .../libraries/naive-bayes}/helpers.ts | 0 .../libraries/naive-bayes}/index.ts | 0 .../libraries/naive-bayes}/sentiment.ts | 4 ++-- .../libraries/naive-bayes}/types.ts | 0 src/strategies/bayes.ts | 2 +- tsconfig.json | 6 ++--- vite.config.ts | 2 +- 29 files changed, 15 insertions(+), 100 deletions(-) delete mode 100644 libraries/naive-bayes/.eslintrc.js delete mode 100644 libraries/naive-bayes/.gitignore delete mode 100644 libraries/naive-bayes/package.json delete mode 100644 libraries/naive-bayes/tsconfig.json rename {libraries/naive-bayes/src => src/libraries/naive-bayes}/classifier.ts (100%) rename {libraries/naive-bayes/src => src/libraries/naive-bayes}/corpus.ts (100%) rename {libraries => src/libraries}/naive-bayes/data/negative/1.txt (100%) rename {libraries => src/libraries}/naive-bayes/data/negative/2.txt (100%) rename {libraries => src/libraries}/naive-bayes/data/negative/3.txt (100%) rename {libraries => src/libraries}/naive-bayes/data/negative/4.txt (100%) rename {libraries => src/libraries}/naive-bayes/data/negative/5.txt (100%) rename {libraries => src/libraries}/naive-bayes/data/positive/1.txt (100%) rename {libraries => src/libraries}/naive-bayes/data/positive/2.txt (100%) rename {libraries => src/libraries}/naive-bayes/data/positive/3.txt (100%) rename {libraries => src/libraries}/naive-bayes/data/positive/4.txt (100%) rename {libraries => src/libraries}/naive-bayes/data/positive/5.txt (100%) rename {libraries/naive-bayes/src => src/libraries/naive-bayes}/document.ts (100%) rename {libraries/naive-bayes/src => src/libraries/naive-bayes}/helpers.ts (100%) rename {libraries/naive-bayes/src => src/libraries/naive-bayes}/index.ts (100%) rename {libraries/naive-bayes/src => src/libraries/naive-bayes}/sentiment.ts (75%) rename {libraries/naive-bayes/src => src/libraries/naive-bayes}/types.ts (100%) diff --git a/.eslintignore b/.eslintignore index b6a962f..a975693 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,5 +1,3 @@ dist/* node_modules/* -libraries/**/dist/* -libraries/**/node_modules/* .eslintrc.js diff --git a/README.md b/README.md index e3a2eec..ebaf0b9 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Sentiment Analysis for Node.js -[![Coverage Status](https://coveralls.io/repos/github/matteocacciola/sentiment/badge.svg?branch=v1.0.3)](https://coveralls.io/github/matteocacciola/sentiment?branch=v1.0.3) +[![Coverage Status](https://coveralls.io/repos/github/matteocacciola/sentiment/badge.svg?branch=v1.0.4)](https://coveralls.io/github/matteocacciola/sentiment?branch=v1.0.4) This library aims to provide a support for the analysis of texts, like the evaluation of Sentiment or Text Matching. Please, consult the various methods here provided in order to have a wide overview of the possible features provided diff --git a/docs/libraries/naive-bayes.md b/docs/libraries/naive-bayes.md index e5aec76..a9ed519 100644 --- a/docs/libraries/naive-bayes.md +++ b/docs/libraries/naive-bayes.md @@ -16,5 +16,5 @@ classifier.classify('it is very sunny today'); naive-bayes contains a default set of positive and negative data enough to seed the algorithm and produce decent results. The constructor function can optionally be passed custom paths to directories containing files with your own data. -See [sentiment.ts](https://github.com/matteocacciola/sentiment/blob/master/libraries/naive-bayes/src/sentiment.ts) if +See [sentiment.ts](https://github.com/matteocacciola/sentiment/blob/master/src/libraries/naive-bayes/sentiment.ts) if you need more details. diff --git a/libraries/naive-bayes/.eslintrc.js b/libraries/naive-bayes/.eslintrc.js deleted file mode 100644 index a759acf..0000000 --- a/libraries/naive-bayes/.eslintrc.js +++ /dev/null @@ -1,8 +0,0 @@ -module.exports = { - parserOptions: { - project: './tsconfig.json', - ecmaVersion: 2021, - sourceType: 'module', - tsconfigRootDir: __dirname, - }, -}; diff --git a/libraries/naive-bayes/.gitignore b/libraries/naive-bayes/.gitignore deleted file mode 100644 index 990168b..0000000 --- a/libraries/naive-bayes/.gitignore +++ /dev/null @@ -1,17 +0,0 @@ -lib-cov -*.seed -*.log -*.csv -*.dat -*.out -*.pid -*.gz -.DS_Store -Thumbs.db - -pids -logs -results - -npm-debug.log -node_modules/ diff --git a/libraries/naive-bayes/package.json b/libraries/naive-bayes/package.json deleted file mode 100644 index 8db1fe7..0000000 --- a/libraries/naive-bayes/package.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "author": { - "name": "Matteo Cacciola", - "email": "matteo.cacciola@gmail.com" - }, - "description": "A simple naive Bayes classifier for textual sentiment analysis", - "devDependencies": { - "@types/node": "^18.15.11" - }, - "engines": { - "node": "18.12.1" - }, - "files": ["dist", "package.json"], - "main": "dist/index.js", - "name": "@matteocacciola/naive-bayes-sentiment-classifier", - "scripts": { - "build": "npm install --no-package-lock && tsc", - "clean": "if [ -d 'dist/' ]; then rm -rf dist; fi", - "lint": "npm run prebuild && tsc --noEmit", - "prebuild": "npm run clean", - "prepublishOnly": "npm run build" - }, - "version": "0.0.1" -} diff --git a/libraries/naive-bayes/tsconfig.json b/libraries/naive-bayes/tsconfig.json deleted file mode 100644 index 10055b3..0000000 --- a/libraries/naive-bayes/tsconfig.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "compilerOptions": { - "target": "ES2019", - "module": "commonjs", - "allowJs": false, - "declaration": true, - "declarationMap": true, - "sourceMap": true, - "outDir": "./dist/", - "rootDir": "./src/", - "strict": true, - "alwaysStrict": true, - "esModuleInterop": false, - "allowSyntheticDefaultImports": false, - "skipLibCheck": true, - "types": ["node"] - }, - "include": ["./src/**/*", "./data/*"], -} diff --git a/package-lock.json b/package-lock.json index 785e7dc..4e768c4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,17 +1,15 @@ { "name": "@matteocacciola/sentiment", - "version": "1.0.3", + "version": "1.0.4", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@matteocacciola/sentiment", - "version": "1.0.3", - "hasInstallScript": true, + "version": "1.0.4", "license": "MIT", "dependencies": { "@google-cloud/language": "^5.2.1", - "@matteocacciola/naive-bayes-sentiment-classifier": "file:libraries/naive-bayes", "axios": "^1.3.4", "dotenv": "^16.0.3", "google-gax": "^3.5.8", @@ -26,6 +24,7 @@ }, "devDependencies": { "@types/lodash": "^4.14.191", + "@types/node": "^18.15.11", "@types/sentiment": "^5.0.1", "@typescript-eslint/eslint-plugin": "^5.55.0", "@typescript-eslint/parser": "^5.55.0", @@ -48,6 +47,7 @@ "libraries/naive-bayes": { "name": "@matteocacciola/naive-bayes-sentiment-classifier", "version": "0.0.1", + "extraneous": true, "devDependencies": { "@types/node": "^18.15.11" }, @@ -1055,10 +1055,6 @@ "node": ">=v12.0.0" } }, - "node_modules/@matteocacciola/naive-bayes-sentiment-classifier": { - "resolved": "libraries/naive-bayes", - "link": true - }, "node_modules/@nodelib/fs.scandir": { "version": "2.1.5", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", @@ -6761,12 +6757,6 @@ "lodash": "^4.17.21" } }, - "@matteocacciola/naive-bayes-sentiment-classifier": { - "version": "file:libraries/naive-bayes", - "requires": { - "@types/node": "^18.15.11" - } - }, "@nodelib/fs.scandir": { "version": "2.1.5", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", diff --git a/package.json b/package.json index 4d6342e..3a4dae7 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,6 @@ }, "dependencies": { "@google-cloud/language": "^5.2.1", - "@matteocacciola/naive-bayes-sentiment-classifier": "file:libraries/naive-bayes", "axios": "^1.3.4", "dotenv": "^16.0.3", "google-gax": "^3.5.8", @@ -21,6 +20,7 @@ "description": "Collection of functions for sentiment analysis", "devDependencies": { "@types/lodash": "^4.14.191", + "@types/node": "^18.15.11", "@types/sentiment": "^5.0.1", "@typescript-eslint/eslint-plugin": "^5.55.0", "@typescript-eslint/parser": "^5.55.0", @@ -41,7 +41,6 @@ }, "files": [ "dist", - "libraries/**/dist", "node_modules", "README.md", "package.json" @@ -67,16 +66,14 @@ }, "scripts": { "build": "tsc -p ./tsconfig-build.json", - "build:bayes": "cd libraries/naive-bayes/ && npm run build", "ci": "npm run lint && npm run build && npm run test", "clean": "if [ -d 'dist/' ]; then rm -rf dist; fi; if [ -f 'tsconfig-build.tsbuildinfo' ]; then rm tsconfig-build.tsbuildinfo; fi", "lint": "eslint 'src/**/*.ts'", "lint:fix": "eslint 'src/**/*.ts' --fix --ext .js,.ts .", - "preinstall": "npm run build:bayes", - "prebuild": "npm run clean && npm run build:bayes", + "prebuild": "npm run clean", "prepare": "husky install", "prepublishOnly": "npm run build", "test": "TZ=utc NODE_ENV=test vitest run --coverage" }, - "version": "1.0.3" + "version": "1.0.4" } diff --git a/libraries/naive-bayes/src/classifier.ts b/src/libraries/naive-bayes/classifier.ts similarity index 100% rename from libraries/naive-bayes/src/classifier.ts rename to src/libraries/naive-bayes/classifier.ts diff --git a/libraries/naive-bayes/src/corpus.ts b/src/libraries/naive-bayes/corpus.ts similarity index 100% rename from libraries/naive-bayes/src/corpus.ts rename to src/libraries/naive-bayes/corpus.ts diff --git a/libraries/naive-bayes/data/negative/1.txt b/src/libraries/naive-bayes/data/negative/1.txt similarity index 100% rename from libraries/naive-bayes/data/negative/1.txt rename to src/libraries/naive-bayes/data/negative/1.txt diff --git a/libraries/naive-bayes/data/negative/2.txt b/src/libraries/naive-bayes/data/negative/2.txt similarity index 100% rename from libraries/naive-bayes/data/negative/2.txt rename to src/libraries/naive-bayes/data/negative/2.txt diff --git a/libraries/naive-bayes/data/negative/3.txt b/src/libraries/naive-bayes/data/negative/3.txt similarity index 100% rename from libraries/naive-bayes/data/negative/3.txt rename to src/libraries/naive-bayes/data/negative/3.txt diff --git a/libraries/naive-bayes/data/negative/4.txt b/src/libraries/naive-bayes/data/negative/4.txt similarity index 100% rename from libraries/naive-bayes/data/negative/4.txt rename to src/libraries/naive-bayes/data/negative/4.txt diff --git a/libraries/naive-bayes/data/negative/5.txt b/src/libraries/naive-bayes/data/negative/5.txt similarity index 100% rename from libraries/naive-bayes/data/negative/5.txt rename to src/libraries/naive-bayes/data/negative/5.txt diff --git a/libraries/naive-bayes/data/positive/1.txt b/src/libraries/naive-bayes/data/positive/1.txt similarity index 100% rename from libraries/naive-bayes/data/positive/1.txt rename to src/libraries/naive-bayes/data/positive/1.txt diff --git a/libraries/naive-bayes/data/positive/2.txt b/src/libraries/naive-bayes/data/positive/2.txt similarity index 100% rename from libraries/naive-bayes/data/positive/2.txt rename to src/libraries/naive-bayes/data/positive/2.txt diff --git a/libraries/naive-bayes/data/positive/3.txt b/src/libraries/naive-bayes/data/positive/3.txt similarity index 100% rename from libraries/naive-bayes/data/positive/3.txt rename to src/libraries/naive-bayes/data/positive/3.txt diff --git a/libraries/naive-bayes/data/positive/4.txt b/src/libraries/naive-bayes/data/positive/4.txt similarity index 100% rename from libraries/naive-bayes/data/positive/4.txt rename to src/libraries/naive-bayes/data/positive/4.txt diff --git a/libraries/naive-bayes/data/positive/5.txt b/src/libraries/naive-bayes/data/positive/5.txt similarity index 100% rename from libraries/naive-bayes/data/positive/5.txt rename to src/libraries/naive-bayes/data/positive/5.txt diff --git a/libraries/naive-bayes/src/document.ts b/src/libraries/naive-bayes/document.ts similarity index 100% rename from libraries/naive-bayes/src/document.ts rename to src/libraries/naive-bayes/document.ts diff --git a/libraries/naive-bayes/src/helpers.ts b/src/libraries/naive-bayes/helpers.ts similarity index 100% rename from libraries/naive-bayes/src/helpers.ts rename to src/libraries/naive-bayes/helpers.ts diff --git a/libraries/naive-bayes/src/index.ts b/src/libraries/naive-bayes/index.ts similarity index 100% rename from libraries/naive-bayes/src/index.ts rename to src/libraries/naive-bayes/index.ts diff --git a/libraries/naive-bayes/src/sentiment.ts b/src/libraries/naive-bayes/sentiment.ts similarity index 75% rename from libraries/naive-bayes/src/sentiment.ts rename to src/libraries/naive-bayes/sentiment.ts index edf95ba..aeb3766 100644 --- a/libraries/naive-bayes/src/sentiment.ts +++ b/src/libraries/naive-bayes/sentiment.ts @@ -5,8 +5,8 @@ export const bayesSentiment = (text: string, positivePath?: string, negativePath const positiveCorpus = new Corpus(); const negativeCorpus = new Corpus(); - if (!positivePath) positivePath = __dirname + '/../data/positive'; - if (!negativePath) negativePath = __dirname + '/../data/negative'; + if (!positivePath) positivePath = __dirname + '/data/positive'; + if (!negativePath) negativePath = __dirname + '/data/negative'; positiveCorpus.loadFromDirectory(positivePath); negativeCorpus.loadFromDirectory(negativePath); diff --git a/libraries/naive-bayes/src/types.ts b/src/libraries/naive-bayes/types.ts similarity index 100% rename from libraries/naive-bayes/src/types.ts rename to src/libraries/naive-bayes/types.ts diff --git a/src/strategies/bayes.ts b/src/strategies/bayes.ts index 6c00d3f..3c63a9c 100644 --- a/src/strategies/bayes.ts +++ b/src/strategies/bayes.ts @@ -1,6 +1,6 @@ -import { bayesSentiment } from '@matteocacciola/naive-bayes-sentiment-classifier'; import { Strategy } from './interfaces'; import { BayesStrategyOptions, ScoreStrategyOptions, ScoreStrategyType, SENTIMENTS, SentimentsType } from './types'; +import { bayesSentiment } from '../libraries/naive-bayes'; const strategy: Strategy = { async evaluateScores( diff --git a/tsconfig.json b/tsconfig.json index b644839..9e0e6f8 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -21,10 +21,8 @@ "baseUrl": "." }, "include": [ - "libraries/**/src/**/*", "src/**/*.ts", "package.json", - "vite.config.ts", - ], - "exclude": ["libraries/**/src/index.ts"] + "vite.config.ts" + ] } diff --git a/vite.config.ts b/vite.config.ts index ea6d5c5..b68b0c5 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -3,7 +3,7 @@ import { configDefaults, defineConfig } from 'vitest/config'; export default defineConfig({ test: { coverage: { - exclude: [...configDefaults.exclude, '**/utils/*', '**/index.ts', '**/__tests__/*', './libraries/**'], + exclude: [...configDefaults.exclude, '**/utils/*', '**/index.ts', '**/__tests__/*', '**/libraries/*'], provider: 'istanbul', reporter: ['text', 'json', 'html', 'lcov'], enabled: true,