Wednesday, November 30, 2022
HomeJavaCapitalize English Titles With Java, Quarkus & GraalVM - Java Code Geeks

Capitalize English Titles With Java, Quarkus & GraalVM – Java Code Geeks

Over time, I’ve been writing lots in English, which isn’t my mom tongue, and for writing titles (headlines, article titles, and so on.) I at all times need to assume which phrases to capitalize. Thus, I’ve created a small software, in fact written in Java, that I take advantage of as command line software, powered by Quarkus, Picocli, and GraalVM.

What I need to have is a technique that takes a single line or a number of traces and capitalizes them. For my writing, I take advantage of the APA fashion. You’ll be able to try other ways of capitalization in on-line instruments corresponding to this one.

I’ve created a small Java challenge that makes use of Quarkus, Picocli, and GraalVM to run the code as standalone utility on the command line. Particularly with native executables constructed by GraalVM, we will pace up the time the command line program takes. Whereas the JAR/JVM model takes a number of hundred milliseconds to finish, the native executable runs just about on the spot. For command line instruments, you’ll discover a distinction.

You will discover the code on GitHub.

The CapitalizeCommand class can run the entire thing as command line program. If you wish to construct the challenge your self, you merely have to clone and execute mvn package deal -P native and duplicate the ensuing goal/captalize-title-runner executable into your $PATH.

The produced executable works as follows:

You’ll be able to see a number of the particularities when capitalizing titles, as regards to prepositions, hyphenated phrases, and so on. It’s additionally essential to say {that a} easy software program answer that doesn’t carry out any Grammar evaluation gained’t at all times produce appropriate outcomes since some phrases would possibly happen otherwise as prepositions, conjunctions, adjective, or adverbs (e.g. but, out, so, and so on). However for my functions, this answer is sweet sufficient ™.

It’s additionally very good to incorporate the command in my regular writing editor, Vim in my case. The command ignores trailing particular characters, which makes it simple to invoke it in codecs corresponding to AsciiDoc:

For Vim, you possibly can set off the software as follows:

" in your .vimrc
nmap <chief>c :.!capitalize-title -<CR>
vnoremap <chief>c :.!capitalize-title -<CR>

You’ll be able to try the code on GitHub: Capitalize Titles



Please enter your comment!
Please enter your name here

Most Popular

Recent Comments