Android Question Parsing a date with complex conditions using AI

Sergey_New

Well-Known Member
Licensed User
Longtime User
The date is represented as, for example, "BET 1 JAN 1852 AND 31 DEC 1852".
I decided to try using DeepSeek neural network.
The task was to parse a date and date range using the B4A language.
Conditions:
The year of the date contains 4 digits. To calculate the number of digits, leading zeros should not be counted.
The month name must be one of the 3 specified Latin characters in uppercase.
The day of the date must be from 1 to 31. Leap years must be taken into account.
The date may have prefixes.
For a single date: ABT, CAL, EST, AFT, BEF, FROM.
For the first date of the date range: ABT, CAL, EST, AFT, BEF, BET, FROM.
For the second date of the date range: TO, AND.
The BET prefix of the first date must be used with the AND prefix of the second date.
The FROM prefix of the first date must be used with the TO prefix of the second date.
For each date, five string values must be returned: prefix, day, month, year, and the parsing success result. If any value is missing, a blank is returned.

The problem was almost completely solved in the few hours it took me to clarify the requirements and test the code.
I received the parser and activity codes with comments in the native language.
Ultimately, the AI was unable to correctly attribute the parsing error of the second date prefix to the second date, assigning it to the first date in the range.
If you are interested in the resulting code, let me know, and I'll post it.
 

emexes

Expert
Licensed User
Longtime User
IMHO it is far better, simple and quick enough to program those conversion by yourself and know exactly what it does. YMMV though.

My mileage did vary.

I thought I'd test Grok on it, with the one sentence request:

please write a gedcom date parser in basic (ideally the anywhere software b4j / basic4java dialect) that returns an array of 8 elements being the 0, 1 or 2 keywords (eg ABT, CAL, EST, AFT, BEF, BET, FROM) and the day, month and year components of the 1 or 2 dates


and it came back with code that worked after I removed a duplicate declaration by changing Dim i as Int = 0 to i = 0 and added .As(List) to the test code so that the returned String arrays were readable.

B4X:
Sub AppStart (Args() As String)
    Log("Hello world!!!")
    TestGEDCOMDates
End Sub

Sub TestGEDCOMDates
    Log(ParseGEDCOMDate("15 JUN 1892").As(List))             ' normal date
    Log(ParseGEDCOMDate("ABT 1845").As(List))                ' about
    Log(ParseGEDCOMDate("BET 12 MAR 1880 AND 15 APR 1881").As(List))
    Log(ParseGEDCOMDate("FROM 1902 TO 1907").As(List))
    Log(ParseGEDCOMDate("AFT 3 FEB 1999").As(List))
    Log(ParseGEDCOMDate("BEF DEC 1945").As(List))
    Log(ParseGEDCOMDate("CAL 1720").As(List))
End Sub
Log output:
Waiting for debugger to connect...
Program started.
Hello world!!!
(ArrayList) [, , 15, JUN, 1892, , , ]
(ArrayList) [ABT, , , , 1845, , , ]
(ArrayList) [BET, AND, 12, MAR, 1880, 15, APR, 1881]
(ArrayList) [FROM, TO, , , 1902, , , 1907]
(ArrayList) [AFT, , 3, FEB, 1999, , , ]
(ArrayList) [BEF, , , DEC, 1945, , , ]
(ArrayList) [CAL, , , , 1720, , , ]
Program terminated (StartMessageLoop was not called).

and the code looks right, to the point that I'd say the chances of it having a bug is less than the chances of me writing it bugfree from scratch.

Even if it did have bugs, it's still a useful starting point, and includes niceties that I would probably have missed, eg handling full month names.
 
Upvote 0
Top