Дело о подлинном предложении
Это не следует путать с "Заголовком дела". В случае с предложением используется только первое слово предложения; другие слова предложения остаются без изменений.
В различных статьях и ответах на Stackoverflow не рассматриваются вопросы, описанные ниже: Наиболее актуальным (хотя и 6 лет) является Преобразование строки в регистр предложения в javascript, но не работает.
Абзац (или статья) может включать несколько предложений, разделенных точками ".".
Я ищу код "SentenceCase", который должен, по крайней мере, обрабатывать случаи, описанные ниже.
Намерение состоит в том, чтобы ТОЛЬКО использовать заглавные буквы в первом слове (если применимо), а не в , пытаться изменить или попытаться исправить остальная часть текста предложения.
Функция должна охватывать следующие стандартные случаи:
// 1. Simple sentence (no full-stop):
// ----------------------------------
// Original: this is a sentence
// Becomes : This is a sentence
// 2. Two or more sentences:
// -------------------------
// Original: first sentence. second sentence . third sentence.
// Becomes : First sentence. Second sentence . Third sentence.
// 3. Sentences starting with a single char:
// -----------------------------------------
// Original: a world of fun. a world of fun.
// Becomes : A world of fun. A world of fun.
// 4. Sentences starting with a word that has an in-between cap:
// -------------------------------------------------------------
// Original: kHz is a unit of measure. kPascal too.
// Becomes : kHz is a unit of measure. kPascal too.
// Original: iPads are sold by Apple. iTones are too.
// Becomes : iPads are sold by Apple. iTones are too.
// 5. Sentences starting with a special chars/words:
// -------------------------------------------------
// Original: https//: is the web address. www.stack.com is another website.
// Becomes : https//: is the web address. www.stack.com is another website.
// Original: .Net is a programming language. foo_bar is a variable it uses.
// Becomes : .Net is a programming language. foo_bar is a variable it uses.
// Original: string_length is a snake case type variable.
// Becomes : string_length is a snake case type variable.
// Original: abc@domain.net is my email. defgh@dmain.net is his.
// Becomes : abc@domain.net is my email. defgh@dmain.net is his.
// Original: concrete5 is an open-source content management system.
// Becomes : concrete5 is an open-source content management system.
// 6. Text inside quotes:
// ----------------------
// Original: "we should stay home" said the governor. 'we will' we answered.
// Becomes : "we should stay home" said the governor. 'we will' we answered.
// Original: "this ". was text in quotes
// Becomes : "this ". Was text in quotes
// 7. Sentences with Abbreviations:
// --------------------------------
// Original: reporting time is 09:00 a.m. and leaving at 05:00 p.m. every day.
// Becomes : Reporting time is 09:00 a.m. and leaving at 05:00 p.m. every day.
// 8. Short sentences with single words:
// -------------------------------------
// Original: organization
// Becomes : Organization
// Original: development.
// Becomes : Development.