{"id":29142229,"url":"https://github.com/ethanz-code/emotional-percentage","last_synced_at":"2025-10-24T00:04:39.304Z","repository":{"id":192095085,"uuid":"686052679","full_name":"ethanz-code/emotional-percentage","owner":"ethanz-code","description":"一个可以将一组中文字符串提取正负面情绪字词并转换为百分比的库。","archived":false,"fork":false,"pushed_at":"2023-09-03T05:03:25.000Z","size":139,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-24T12:53:13.276Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ethanz-code.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-09-01T16:14:35.000Z","updated_at":"2023-09-01T16:18:05.000Z","dependencies_parsed_at":"2024-10-23T08:54:43.655Z","dependency_job_id":"2c271f08-3a4c-48fe-abc4-f6343ec9f693","html_url":"https://github.com/ethanz-code/emotional-percentage","commit_stats":{"total_commits":9,"total_committers":2,"mean_commits":4.5,"dds":"0.11111111111111116","last_synced_commit":"30c7c1b828c1cdab2f42482364b5cbbc77cbe31d"},"previous_names":["yassine-zhang/emotional-percentage","ethanz-code/emotional-percentage"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ethanz-code/emotional-percentage","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ethanz-code%2Femotional-percentage","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ethanz-code%2Femotional-percentage/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ethanz-code%2Femotional-percentage/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ethanz-code%2Femotional-percentage/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ethanz-code","download_url":"https://codeload.github.com/ethanz-code/emotional-percentage/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ethanz-code%2Femotional-percentage/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262454800,"owners_count":23313919,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-06-30T19:10:20.160Z","updated_at":"2025-10-24T00:04:34.265Z","avatar_url":"https://github.com/ethanz-code.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Emotional Percentage\nPercentage of positive and negative emotions\n\n一个可以将一组中文字符串提取正负面情绪字词并转换为百分比的库。\n\n# 安装\n```\nnpm install yassine-zhang/emotional-percentage\n```\n\n# 使用\n下面是最简单的使用教程，其中返回值数组第一个代表负面情绪占比，第二个代表正面情绪占比\n```ts\nimport { refresh } from 'yassine-zhang/emotional-percentage'\n\n// return: [ '0%', '100%' ]\nrefresh(\"学习ngnix\")\n```\n\n## 异步加载源过滤数据文件\n分为两个文件，一个是正面情绪词汇收集文件，一个是负面情绪词汇收集文件，文件中应以中文“、”分割开每个过滤词，如下图所示：\n![Alt text](/src/image.png)\n\n下面是使用自定义源过滤数据文件的写法（目前只支持本地文件地址，并不支持文件描述符和远程URL）\n```ts\nimport { loadRawData, PathOrUrlRole } from 'yassine-zhang/emotional-percentage'\n\nconst option: PathOrUrlRole = {\n    positive: '\u003cYour path or URL address\u003e',\n    negative: '\u003cYour path or URL address\u003e'\n}\nconst callback = (data) =\u003e {\n    console.log(data)\n}\n\nloadRawData(option, callback)\nloadRawData(option).then(data =\u003e console.log(data))\nconsole.log('I execute first')\n```\n\n当然你也可以调用同步函数，loadRawDataSync，需要另外引入\n\n\n## 源过滤数据文件查重保留唯一\n下面代码将读取本地源过滤数据文件并替换重复项，最后返回一个字符串（字符串内每个过滤词都是通过中文“、”分割）\n```ts\nimport { arrayReplaceMultp } from 'yassine-zhang/emotional-percentage'\nimport * as fs from 'fs-extra';\nimport { resolve } from 'path';\n\nconst info = fs.readFileSync(resolve(__dirname, '../../../diff_res/正面情绪词汇收集.txt'), 'utf-8')\n\narrayReplaceMultp(info)\n```\n\n\n# 帮助\n如果你对此还有任何疑问，可以在`github`提issues或者查看`lib/*/__tests__/*.test.ts`中对每个功能的用法","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fethanz-code%2Femotional-percentage","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fethanz-code%2Femotional-percentage","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fethanz-code%2Femotional-percentage/lists"}