Sun-Tzu's Art of War App


#1

This is #4 in my “Wisdom of the Ages” series. #5 got published ahead of it (slightly), as it was easy to integrate the text, since I didn’t have to mess with the graphical design at all; with this app, I had to port the content (graphics and text) over from the previous, unstable, version of the app, so it was slightly more work.

“Art of War” uses the same framework (with very minor modifications) as my other apps, but a very different visual look and feel; my wife designed “bamboo” themed buttons, and I spent a couple of hours digging through “free font” sites to find a couple of Chinese themed fonts that were unambiguously freely useable. My wife also created the promo graphics from public domain images that I loaded.

Again, the biggest chunk of coding involved putting together the Perl script that pre-processed the original text file and converted it into XML. Had to recognize both Arabic and Roman numerals via regexp, intelligently handle white space, and then dynamically build headings that combined both chapter and paragraph numbering. I think I spent two or three hours writing the script, probably more than I would have just manually editing it.

The structure and quotability of the “Art of War” made it a near ideal match for my app design. I really enjoyed getting to know the book better in the process of compiling and testing out the app.


#2

I like these series. I am curious how the process looks like from taking the text and how your aia looks like. Are you willing to share that?


#3

Happy to share, Peter!

Summary:

  1. Find appropriately structured text file worthy of transformation into an app
  2. Edit/pre-process it into a structured format suitable for manipulation
  3. Run Perl script to wrap individual entries with appropriate XML (including dynamically generated unique element IDs)
  4. Download app .aia, extract Screen1.bky or equivalent from it following guidelines as posted elsewhere (replace files in situ, primarily), insert generated XML into it, and copy it back into .aia, upload revised .aia

Along with this, of course, there’s also the creation of “art” as appropriate (buttons, Google / Amazon app store imagery, background images) which, in my case, typically also involves finding images suitable for manipulation that are clearly public domain and thus don’t create any issues with intellectual property licensing.

The first step is to identify a meaningfully important text that is appropriately structured, i.e., is broken down by the author or translator into units no larger than a couple of paragraphs at most, which make coherent sense (generally) when viewed on a stand alone basis. The Gospel of Thomas, being a “sayings gospel”, with each component completely independent of any other, is an ideal example, but the Art of War, as well, fits that model. “Nuggets of wisdom”, so to speak.

The second / third step is to prepare the text for import and run a Perl script to wrap individual entries in XML. I copied and pasted the content into my first app, but manually creating a list of 80+ items, then copying and pasting text into it, is incredibly tedious and silly, given that (from being a sysadmin) I have high degree of facility and experience with manipulating text (aka XML) files using Perl and regular expressions. This means making sure that the content is reformatted in a consistent way that enables it to be programmatically manipulated.

This usually involves a bit of regexp based search and replace using “vi”, plus a visual scan to pick up any anomalies. I use markers of some sort (such as blank lines) to cue the Perl script as to when to insert the beginning and end XML sections that will be copied and pasted into the app’s ScreenX.bky file. I’ll also use the Perl script to dynamically assemble headings (such as with the Art of War app) that make sense. When reading the book, having a chapter heading appear once, then individual paragraph numbers follow it, makes sense, because you know where in the book you are. By contrast, the app’s selective excerpting of text requires that prepending the Chapter heading to each paragraph number, thus providing an indication of where in the book the excerpt comes from, in case the reader’s curiosity is sparked and they want to go directly there and read further. Primary purpose of the Perl script, though, is to pre and post pend XML to each entry so that the text can be imported into a .bky file and from there into an .aia file.

Final step is to carefully insert the generated XML into the .bky file’s associated list definition, making sure to update the number of items in it definition at the same time. The process of altering an .aia file without destroying its integrity is described elsewhere. The .bky files are sensitive to malformed XML, so you have to be precise about only replacing the content portion of the list containing the text file entries. Experience teaches me that it is best to isolate the list definition that will contain the text files at the bottom or top of the file.

From there, hopefully, it’s smooth sailing. Occasionally, I’ll notice that I’ve missed something, and have to go back and edit the original text file appropriately and go through the import process a second time. Rarely, I’ll be able to manually “fix” the problem by editing the list components in AB directly, but generally speaking, dealing with manually defined 100+ item list entries is not something you want to do given the constraints of the UI.

Does that answer the question? I posted some code elsewhere in the forums that illustrates how to dynamically generate a valid XML id, that’s really the only “unique” element to what I’m doing.


#4

Thank you for your answer. Yes it gives insite in the work it takes to make your app. What a project. :+1:


#5

Looks like you put a lot of work into this app! Super great job!!! <3


#7

also how do you extract .bky from .aia?


#8

VII Maneuvering/18

is immovability like a mountain -> in immovability …


#9

an aia file is just a renamed zip-file.