VOOZH about

URL: https://www.javacodegeeks.com/2022/11/capitalize-english-titles-with-java-quarkus-graalvm.html

⇱ Capitalize English Titles With Java, Quarkus & GraalVM - Java Code Geeks


Over the years, I’ve been writing a lot in English, which isn’t my mother tongue, and for writing titles (headlines, article titles, etc.) I always have to think which words to capitalize. Thus, I’ve created a small tool, of course written in Java, that I use as command line tool, powered by Quarkus, Picocli, and GraalVM.

What I want to have is a method that takes a single line or multiple lines and capitalizes them. For my writing, I use the APA style. You can check out different ways of capitalization in online tools such as this one.

I’ve created a small Java project that uses Quarkus, Picocli, and GraalVM to run the code as standalone application on the command line. Especially with native executables built by GraalVM, we can speed up the time the command line program takes. While the JAR/JVM version takes a few hundred milliseconds to complete, the native executable runs pretty much instant. For command line tools, you will notice a difference.

You can find the code on GitHub.

The CapitalizeCommand class can run the whole thing as command line program. If you want to build the project yourself, you simply need to clone and execute mvn package -P native and copy the resulting target/captalize-title-runner executable into your $PATH.

The produced executable works as follows:

You can see some of the particularities when capitalizing titles, with regards to prepositions, hyphenated words, etc. It’s also important to mention that a simple software solution that doesn’t perform any Grammar analysis won’t always produce correct results since some words might occur differently as prepositions, conjunctions, adjective, or adverbs (e.g. yet, out, so, etc). But for my purposes, this solution is good enough ™.

It’s also very nice to include the command in my usual writing editor, Vim in my case. The command ignores trailing special characters, which makes it easy to invoke it in formats such as AsciiDoc:

For Vim, you can trigger the tool as follows:

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

You can check out the code on GitHub: Capitalize Titles

Published on Java Code Geeks with permission by Sebastian Daschner, partner at our JCG program. See the original article here: Capitalize English Titles With Java, Quarkus & GraalVM

Opinions expressed by Java Code Geeks contributors are their own.

Do you want to know how to develop your skillset to become a Java Rockstar?
Subscribe to our newsletter to start Rocking right now!
To get you started we give you our best selling eBooks for FREE!
1. JPA Mini Book
2. JVM Troubleshooting Guide
3. JUnit Tutorial for Unit Testing
4. Java Annotations Tutorial
5. Java Interview Questions
6. Spring Interview Questions
7. Android UI Design
and many more ....
I agree to the Terms and Privacy Policy

Thank you!

We will contact you soon.

👁 Photo of Sebastian Daschner
Sebastian Daschner
November 22nd, 2022Last Updated: November 21st, 2022
0 213 2 minutes read

Sebastian Daschner

Sebastian Daschner is a self-employed Java consultant and trainer. He is the author of the book 'Architecting Modern Java EE Applications'. Sebastian is a Java Champion, Oracle Developer Champion and JavaOne Rockstar.
Subscribe

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Oldest
Newest Most Voted
Back to top button
Close
wpDiscuz