{"id":22702393,"url":"https://github.com/phughesmcr/optimismo","last_synced_at":"2025-03-29T19:27:26.196Z","repository":{"id":57315806,"uuid":"89488152","full_name":"phughesmcr/optimismo","owner":"phughesmcr","description":"Calculate the optimism of a string.","archived":false,"fork":false,"pushed_at":"2018-09-20T09:23:41.000Z","size":53,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-04T20:19:18.545Z","etag":null,"topics":["mental-health","optimism","optimistic","text-analysis","text-mining","wellbeing"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/phughesmcr.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}},"created_at":"2017-04-26T14:06:58.000Z","updated_at":"2018-10-03T19:45:57.000Z","dependencies_parsed_at":"2022-09-18T20:52:16.669Z","dependency_job_id":null,"html_url":"https://github.com/phughesmcr/optimismo","commit_stats":null,"previous_names":["phugh/optimismo"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phughesmcr%2Foptimismo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phughesmcr%2Foptimismo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phughesmcr%2Foptimismo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phughesmcr%2Foptimismo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phughesmcr","download_url":"https://codeload.github.com/phughesmcr/optimismo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246233236,"owners_count":20744794,"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":["mental-health","optimism","optimistic","text-analysis","text-mining","wellbeing"],"created_at":"2024-12-10T07:13:18.734Z","updated_at":"2025-03-29T19:27:26.176Z","avatar_url":"https://github.com/phughesmcr.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# optimismo\n\nAnalyse the optimism of a string on a scale of 1 - 9\n\n## Usage\n```javascript\nconst optimismo = require('optimismo');\n// These are the default and recommended options\nconst opts = {\n  'encoding': 'binary',\n  'locale': 'US',\n  'logs': 3,\n  'max': Number.POSITIVE_INFINITY,\n  'min': Number.NEGATIVE_INFINITY,\n  'nGrams': [2, 3],\n  'noInt': false,\n  'output': 'lex',\n  'places': undefined,\n  'sortBy': 'freq',\n  'wcGrams': false,\n};\nconst str = 'A string of text....';\nconst output = optimismo(str, opts);\nconsole.log(output);  // {OPTIMISM: 4.89}\n```\nScale runs from 1 (Completely pessimistic) to 9 (completely optimistic). \n\nIf there are no matches optimismo will return null.\n\n## Default Output\n```javascript\n { OPTIMISM: 4.89 }\n```\n```Markdown\n1 = very pessimistic, 5 = neutral, 9 = very optimistic\n```\n\n## The Options Object\n\nThe options object is optional and provides a number of controls to allow you to tailor the output to your needs. However, for general use it is recommended that all options are left to their defaults.\n\n### \"encoding\"\n\n**string - valid options: \"binary\" (default), \"frequency\", or \"percent\"**\n\n*N.B - You probably don't want to change this, ever.*\n\nControls how the lexical value is calculated.\n\n__Binary__ is simply the addition of lexical weights, i.e. word1 + word2 + word3.\n\n__Frequency__ encoding takes the overall wordcount and word frequency into account, i.e. (word frequency / word count) * weight. Note that the encoding option accepts either 'freq' or 'frequency' to enable this option.\n\nAnother way to think of binary and frequency encoding is that 'binary' essentially sets all weights to '1', whereas frequency will generate a group norm. This is useful for predictive lexica, for example, when predicting age (see [predictAge](https://github.com/phugh/predictage)) we want to use frequency encoding because we care about the actual number generated - i.e. the lexical value *is* the predicted age. Whereas, when predicting optimism in this module 'binary' encoding is used because the final value doesn't particularly matter, only whether it is above or below 0 to indicate association.\n\n__Percent__ returns the percentage of total (non-unique) tokens matched against the lexicon in each category as a decimal, i.e. 0.48 = 48%.\n\n### 'locale'\n\n**String - valid options: 'US' (default), 'GB'**\n\nThe lexicon data is in American English (US), if the string(s) you want to analyse are in International / British English set the locale option to 'GB'.\n\n### 'logs'\n**Number - valid options: 0, 1, 2, 3 (default)**\nUsed to control console.log, console.warn, and console.error outputs.\n* 0 = suppress all logs\n* 1 = print errors only\n* 2 = print errors and warnings\n* 3 = print all console logs\n\n### 'max' and 'min'\n\n**Number - accepts floats**\n\nEach item in the lexicon data has an associated weight (number). Use these options to exclude words that have weights beyond a given maximum or minimum threshold.\n\nBy default these are set to infinity, ensuring that no words from the lexicon are excluded.\n\n### 'nGrams'\n\n**Array - valid options: [ number, number, ...]**\n\n*N.B the lexicon contains unigrams, bigrams, and trigrams. Including a value \u003e 3 makes no sense and will impact performance drastically.*\n\nn-Grams are contiguous pieces of text, bi-grams being chunks of 2, tri-grams being chunks of 3, etc.\n\nUse the nGrams option to include n-gram chunks. For example if you want to include both bi-grams and tri-grams, use like so:\n\n```javascript\n{\n  nGrams: [2, 3]\n}\n```\n\nIf you only want to include tri-grams:\n\n```javascript\n{\n  nGrams: [3]\n}\n```\n\nTo disable n-gram inclusion, use the following:\n\n```javascript\n{\n  nGrams: [0]\n}\n```\n\nIf the number of words in the string is less than the ngram number provided, the option will simply be ignored.\n\nFor accuracy it is recommended that n-grams are included, however including n-grams for very long strings can affect performance.\n\n### 'noInt'\n\n**Boolean - valid options: true or false (default)**\n\nThe lexica contain intercept values, set noInt to true to ignore these values.\n\nUnless you have a specific need to ignore the intercepts, it is recommended you leave this set to false.\n\n### 'output'\n\n**String - valid options: 'lex' (default), 'matches', 'full'**\n\n'lex' (default) returns an object of lexical values. See 'Defauly Output Example above.\n\n'matches' returns an object with data about matched words. See 'matches output example' below.\n\n'full' returns both of the above in one object with two keys, 'values' and 'matches'.\n\n### 'places'\n\n**Number - valid options between 0 and 20 inclusive.**\n\nNumber of decimal places to limit outputted values to.\n\nThe default is \"undefined\" which will simply return the value unchanged.\n\n### 'sortBy'\n\n**String - valid options: 'freq' (default), 'weight', or 'lex'**\n\nIf 'output' = 'matches', this option can be used to control how the outputted array is sorted.\n\n'lex' sorts by final lexical value, (N.B. when using binary encoding [see 'encoding' above] the lexical value and the weight are identical.)\n\n'weight' sorts the array by the matched words initial weight.\n\n'freq' (default) sorts by word frequency, i.e. the most used words appear first.\n\n### 'wcGrams'\n\n**boolean - valid options: true or false (default)**\n\nWhen set to true, the output from the nGrams option will be added to the word count.\n\nFor accuracy it is strongly recommended that this is set to false.\n\n## {output: 'matches'} Output Example\n\n```javascript\n{\n  OPTIMISM: {\n    matches: [\n      [ 'magnificent', 1, -192.0206116, -1.3914537072463768 ],\n      [ 'capital', 1, -133.9311307, -0.9705154398550726 ],\n      [ 'note', 3, -34.83417005, -0.7572645663043478 ],\n      [ 'america', 2, -49.21227355, -0.7132213557971014 ],\n      [ 'republic', 1, -75.5720402, -0.5476234797101449 ],\n    ],\n    info: {\n      total_matches: 100,\n      total_unique_matches: 63,\n      total_tokens: 200,\n      percent_matches: 50,\n    }\n  }\n};\n```\n\nThe items in each array represent: [0] - the term, [1] - number of times the term appears in string (frequency), [2] - the terms's weight, [3] - its final lexical value.\n\nThe final lexical value is affected by which 'encoding' option you're using.\n\n## Acknowledgements\n\nUsing the affect/intensity and prospection lexica data from [WWBP](http://www.wwbp.org/lexica.html)\n\nUsed under the [Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported](http://creativecommons.org/licenses/by-nc-sa/3.0/)\n\n# License\n(C) 2017-18 [P. Hughes](https://www.phugh.es). All rights reserved.\n\nShared under the [Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported](http://creativecommons.org/licenses/by-nc-sa/3.0/) license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphughesmcr%2Foptimismo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphughesmcr%2Foptimismo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphughesmcr%2Foptimismo/lists"}