Skip to content

Instantly share code, notes, and snippets.

@ftrain
Last active April 30, 2021 16:54

Revisions

  1. ftrain revised this gist Oct 25, 2020. No changes.
  2. ftrain revised this gist Oct 25, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion triples.sql
    Original file line number Diff line number Diff line change
    @@ -5,4 +5,4 @@ CREATE TABLE triples (
    olit TEXT DEFAULT NULL
    );

    % also add a bunch of indexes especially around p and o
    -- also add a bunch of indexes especially around p and o
  3. ftrain revised this gist Oct 25, 2020. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions triples.sql
    Original file line number Diff line number Diff line change
    @@ -4,3 +4,5 @@ CREATE TABLE triples (
    o TEXT DEFAULT NULL,
    olit TEXT DEFAULT NULL
    );

    % also add a bunch of indexes especially around p and o
  4. ftrain created this gist Oct 25, 2020.
    20 changes: 20 additions & 0 deletions n3tosql.pl
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    #!/usr/bin/perl

    while (<>) {
    s/'/''/g;
    /^([^\s]+)\s*([^\s]+)\s*(.+)\s+\.\s*$/;
    my $s = $1;
    my $p = $2;
    my $o = $3;
    $s=~s/[<>]//g;
    $p=~s/[<>]//g;
    # Is it an object literal?
    if ($o=~/^\"/) {
    $o=~s/"//g;
    print "INSERT INTO triples VALUES ('$s', '$p', NULL, '$o');\n";
    }
    else {
    $o=~s/[<>]//g;
    print "INSERT INTO triples VALUES ('$s', '$p', '$o', NULL);\n";
    }
    }
    6 changes: 6 additions & 0 deletions triples.sql
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    CREATE TABLE triples (
    s TEXT NOT NULL,
    p TEXT NOT NULL,
    o TEXT DEFAULT NULL,
    olit TEXT DEFAULT NULL
    );
    5 changes: 5 additions & 0 deletions whatever.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    # something like this, I can't remember exactly

    sqlite3 triples < triples.sql

    cat n3file.n3 | n3tosql.pl | sqlite triples