{"id":24716727,"url":"https://github.com/baylorrae/smart-truncation","last_synced_at":"2026-04-15T13:33:53.511Z","repository":{"id":137877392,"uuid":"192943763","full_name":"BaylorRae/smart-truncation","owner":"BaylorRae","description":"An experiment to mimic human truncation by abbreviation instead of ellipsis.","archived":false,"fork":false,"pushed_at":"2019-06-23T12:12:39.000Z","size":18,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-04-04T01:42:05.118Z","etag":null,"topics":["abbreviation","csharp","nlp","python","ruby","truncation"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BaylorRae.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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,"zenodo":null}},"created_at":"2019-06-20T15:22:40.000Z","updated_at":"2019-06-23T05:02:06.000Z","dependencies_parsed_at":"2023-06-11T14:00:08.937Z","dependency_job_id":null,"html_url":"https://github.com/BaylorRae/smart-truncation","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/BaylorRae/smart-truncation","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BaylorRae%2Fsmart-truncation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BaylorRae%2Fsmart-truncation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BaylorRae%2Fsmart-truncation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BaylorRae%2Fsmart-truncation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BaylorRae","download_url":"https://codeload.github.com/BaylorRae/smart-truncation/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BaylorRae%2Fsmart-truncation/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31842954,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-15T13:28:40.153Z","status":"ssl_error","status_checked_at":"2026-04-15T13:28:29.396Z","response_time":63,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["abbreviation","csharp","nlp","python","ruby","truncation"],"created_at":"2025-01-27T09:14:03.261Z","updated_at":"2026-04-15T13:33:53.506Z","avatar_url":"https://github.com/BaylorRae.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Smart Truncation\n\n- CSharp\n  - [Dictionary Implementation][#csharp-1]\n\n- Python 3\n  - [Naive Implementation][#3]\n\n- Ruby\n  - [Naive Implementation][#1]\n  - [Dictionary Implementation][#2]\n\nLet’s say you have a container with a fixed width and need to truncate text.\n\n```\n| small diagonal | cross\n```\n\nTraditionally you’d use an ellipsis to truncate the words\n\n```\n| small diago... |\n```\n\nBut a human would abbreviate the words.\n\n```\n| sm diag cross  |\n```\n\n## Implementations\n\n### CSharp\n\n#### 1. CSharp Dictionary Implementation\n\nA simple abbreviator that finds the closest length by replacing words with their\nknown abbreviations.\n\n[Abbreviator.cs](./csharp/Abbreviator.cs) | [AbbreviatorTest.cs](./csharp/AbbreviatorTest.cs)\n\nTo run tests. `dotnet test` in the [`./csharp` directory](./csharp)\n\n### Python 3\n\n#### 1. Python Naive Implementation\n\nNaive approach that prioritzes longest-token truncation. Abbreviator limits\nminimum token word length to 1.\n\n[abbreviator.py](./python/abbreviator.py) | [test_abbreviator.py](./python/test_abbreviator.py)\n\nTo run tests, `pip install pytest` and execute `pytest` in the [Python](./python/)\ndirectory.\n\n### Ruby\n\n#### 1. Naive Implementation\n\nThe first implementation was a proof of concept to shorten the longest words\nfirst. This would eventually be combined with [#2] to remove any additional\ncharacters.\n\n[naive.rb](./ruby/lib/naive.rb) | [naive_spec.rb](./ruby/spec/naive_spec.rb)\n\n```\n| smal diag cros |\n```\n\n#### 2. Dictionary Implementation\n\nThe second approach utilizes a map of known abbreviations. This example has\na few more test cases to find the best replacements to match the desired length.\n\n[with_dictionary.rb](./ruby/lib/with_dictionary.rb) | [with_dictionary_spec.rb](./ruby/spec/with_dictionary_spec.rb)\n\n```\n// 14 chars\n  1..........14\n| sm diag cross     |\n\n// 16 chars\n  1.............16\n| small diag cross  |\n\n// 17 chars\n  1..............17\n| sm diagonal cross |\n```\n\n[#1]: #1-naive-implementation\n[#2]: #2-dictionary-implementation\n[#3]: #1-python-naive-implementation\n[#csharp-1]: #1-csharp-dictionary-implementation\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbaylorrae%2Fsmart-truncation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbaylorrae%2Fsmart-truncation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbaylorrae%2Fsmart-truncation/lists"}