On 22/04/2025 23:25, Waldek Hebisch wrote:
On Mon, Apr 21, 2025 at 02:56:05AM -0700, Kurt Pagani wrote:
I wanted to create a sqlite database combining libdb.text and comdb.text.
Naively, I converted the files to csv assuming the pointers in the both
files would match -- without checking before :(

The attached FrICAS file joins back libdb and comdb.  Usage like:

Great, you're a wizard. It perfectly worked ('diff' gives nil).

In the meantime I recognized that one can import this file directly, i.e. without converting to csv first. The sqlitebrowser also accepts the backtick as a separator. The first character (kind, e.g. cAbelianGroup) may be easily handled/separated in SQL.

Thank you.


)read joindb.input
p1 := "../fr-build110/target/x86_64-linux-gnu/algebra/libdb.text"
p2 := "../fr-build110/target/x86_64-linux-gnu/algebra/comdb.text"
joindb(p1, p2, "sum.out")


--
You received this message because you are subscribed to the Google Groups "FriCAS - 
computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to fricas-devel+unsubscr...@googlegroups.com.
To view this discussion visit 
https://groups.google.com/d/msgid/fricas-devel/f75a9ef2-30c4-4cfa-8497-bbdc49e923ac%40gmail.com.
)read joindb.input
p1 := "../text/libdb.text"
p2 := "../text/comdb.text"
joindb(p1, p2, "libcomdb.text")

Checking for foreign routines
FRICAS="/home/kfp/apps/lib/fricas/target/x86_64-linux-gnu"
spad-lib="/home/kfp/apps/lib/fricas/target/x86_64-linux-gnu/lib/libspad.so"
foreign routines found
openServer result -2
                       FriCAS Computer Algebra System
           Version: FriCAS 2025-04-14 built with sbcl 2.2.9.debian
                  Timestamp: Sun 20 Apr 16:43:56 CEST 2025
-----------------------------------------------------------------------------
   Issue )copyright to view copyright notices.
   Issue )summary for a summary of useful system commands.
   Issue )quit to leave FriCAS and return to shell.
-----------------------------------------------------------------------------

   Function declaration sixel : TexFormat -> Void has been added to
      workspace.
   Function declaration lisp : String -> SExpression has been added to
      workspace.
)read joindb.input

char_tick := elt("`", 1)


   (8)  `
                                                              Type: Character
find_ptr_pos(s) ==
    res : Integer := 0
    for i in 1..6 repeat
        res := position(char_tick, s, res + 1)
    res

                                                                   Type: Void

joindb1(lf : TextFile, cf : TextFile, of : TextFile) : Void ==
    -- discard fake entry
    c := readLine!(cf)
    -- read lookahead line
    cu := readLineIfCan!(cf)
    repeat
        ilu := readLineIfCan!(lf)
        ilu case "failed" => break
        il := ilu::String
        ptr_pos := find_ptr_pos(il)
        il1 := il(1..ptr_pos)
        il2 := il((ptr_pos + 1)..#il)
        il2 = "0" =>
            writeLine!(of, il1)
        write!(of, il1)
        cu case "failed" =>
            error "Missing comment"
        c := cu::String
        ptr_pos := position(char_tick, c)
        c1 := c(1..ptr_pos)
        c2 := c((ptr_pos + 1)..#c)
        write!(of, c2)
        repeat
            cu := readLineIfCan!(cf)
            cu case "failed" => break
            c := cu::String
            c1 = c(1..ptr_pos) =>
                c2 := c((ptr_pos + 1)..#c)
                write!(of, c2)
            break
        writeLine!(of)

   Function declaration joindb1 : (TextFile, TextFile, TextFile) ->
      Void has been added to workspace.
                                                                   Type: Void

joindb(lfn : String, cfn : String, ofn : String) : Void ==
    lf := open(lfn)$TextFile
    cf := open(cfn)$TextFile
    of := open(ofn, "output")$TextFile
    joindb1(lf, cf, of)
    close!(lf)$TextFile
    close!(cf)$TextFile
    close!(of)$TextFile

   Function declaration joindb : (String, String, String) -> Void has
      been added to workspace.
                                                                   Type: Void
p1 := "../text/libdb.text"


   (12)  "../text/libdb.text"
                                                                 Type: String
p2 := "../text/comdb.text"


   (13)  "../text/comdb.text"
                                                                 Type: String
joindb(p1, p2, "libcomdb.text")

   Compiling function find_ptr_pos with type String -> Integer
   Compiling function joindb1 with type (TextFile, TextFile, TextFile)
       -> Void
   Compiling function joindb with type (String, String, String) -> Void

                                                                   Type: Void
(15) -> )q


kfp@omega:~/devel/fricas.db/input$ diff ../text/olibdb.text libcomdb.text
kfp@omega:~/devel/fricas.db/input$


Reply via email to