Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

To be trialed: Import more than one reconciled CSV files to Virtuoso and convert them to RDF. #214

Closed
candlecao opened this issue Oct 30, 2024 · 2 comments
Assignees
Labels
documentation Improvements or additions to documentation Priority: high high priority

Comments

@candlecao
Copy link
Contributor

candlecao commented Oct 30, 2024

Following #104.

The CSV files should be related with Foreign Key Constraint.

As long as we realize this, it means that we can import various reconciled CSV files onto Virtuoso and "assemble them into a RDB(Relational Database)". So that with the facilities for RDB2RDF in Virtuoso, we may greatly improve our efficiency of "arbitrary conversion to RDF".

The ontology can also be automatically generated via "RDB2RDF in Virtuoso", which can be used for NLQ2SPARQL with ChatGPT.

@candlecao candlecao added the Priority: high high priority label Oct 30, 2024
@candlecao candlecao self-assigned this Oct 30, 2024
@candlecao candlecao changed the title To be trialed: Import more than one reconciled CSV files to Virtuoso and convert them to RDF. The 2 CSV files should be related with Foreign Key Constraint To be trialed: Import more than one reconciled CSV files to Virtuoso and convert them to RDF. The CSV files should be related with Foreign Key Constraint Oct 30, 2024
@candlecao candlecao changed the title To be trialed: Import more than one reconciled CSV files to Virtuoso and convert them to RDF. The CSV files should be related with Foreign Key Constraint To be trialed: Import more than one reconciled CSV files to Virtuoso and convert them to RDF. Oct 30, 2024
@candlecao
Copy link
Contributor Author

It's completed. I took the case from Cantus Database as an example:

  1. CSV1
Chant_ID,incipit,genre,src_link
562633,Ecce nunc palam loqueris et,http://www.wikidata.org/entity/Q582093,123756
671551,Dominus tamquam ovis ad victimam,http://www.wikidata.org/entity/Q582093,669163
562160,Seniores populi consilium fecerunt ut,http://www.wikidata.org/entity/Q604748,123756
467250,Ad te domine levavi animam,http://www.wikidata.org/entity/Q582093,123730
560736,Stephanus servus dei quem lapidabant,http://www.wikidata.org/entity/Q604748,123756
557534,Si diligis me Simon Petre,http://www.wikidata.org/entity/Q604748,123716
561787,Pater Abraham miserere mei et,http://www.wikidata.org/entity/Q582093,123756
670564,Sit nomen domini benedictum in,http://www.wikidata.org/entity/Q582093,669163
561208,Naturae genitor conserva morte redemptos,http://www.wikidata.org/entity/Q582093,123756
670715,Dives ille guttam aquae petiit,http://www.wikidata.org/entity/Q582093,669163
669638,Hic est beatissimus evangelista et,http://www.wikidata.org/entity/Q604748,669163
561604,Veni hodie ad fontem aquae,http://www.wikidata.org/entity/Q604748,123756
704158,Ponens Petrus genua sua oravit,http://www.wikidata.org/entity/Q582093,702611
  1. CSV2
Source_ID,title
123716,Wolfenb_
123730,Prague_
123756,Wroclaw_
669163,Sydney_
702611,Gent_

The key point is, the src_link attribute of CSV1 refers to a foreign key title from CSV2.
So I executed the R2RML plus the SQL script like this:

--the Name of the R2RML Graph:
SPARQL CLEAR GRAPH <http://temp/product>;
--the Name of the Graph:
SPARQL CLEAR GRAPH <http://example.com/trial>;

DB.DBA.TTLP ('
@prefix rr: <http://www.w3.org/ns/r2rml#> .
@prefix cantusDB: <https://cantusdatabase.org/> .
@prefix schema: <http://schema.org/> .
@prefix wdt: <http://www.wikidata.org/prop/direct/> .

<http://example.com/ns#TriplesMap1>
    a rr:TriplesMap;

    rr:logicalTable
    [
      rr:tableSchema "CSV";
      rr:tableOwner "DBA";
      rr:tableName "sampleCantusChant_csv"
    ];

    rr:subjectMap
    [
      rr:template "https://cantusdatabase.org/chant/{Chant_ID}";
      rr:class cantusDB:chant;
      rr:graph <http://example.com/trial>;
    ];

    rr:predicateObjectMap
    [
      rr:predicate wdt:P1922;
      rr:objectMap [ rr:column "incipit" ];
    ];

    rr:predicateObjectMap
    [
      rr:predicate wdt:P136;
      rr:objectMap [ rr:column "genre" ];
    ];

    rr:predicateObjectMap
    [
      rr:predicate cantusDB:sources;
      rr:objectMap [
        rr:parentTriplesMap <http://example.com/ns#TriplesMap2>;
        rr:joinCondition [
          rr:child "src_link";
          rr:parent "Source_ID";
        ]; 
      ];
    ];
.
<http://example.com/ns#TriplesMap2>
    a rr:TriplesMap;

    rr:logicalTable
    [
      rr:tableSchema "CSV";
      rr:tableOwner "DBA";
      rr:tableName "sampleCantusSource_csv"
    ];

    rr:subjectMap
    [
      rr:template "https://cantusdatabase.org/source/{Source_ID}";
      rr:class cantusDB:source;
      rr:graph <http://example.com/trial>;
    ];

    rr:predicateObjectMap
    [
      rr:predicate wdt:P1476;
      rr:objectMap [ rr:column "title" ];
    ];
.
', 'http://temp/product', 'http://temp/product' )
;


exec ('sparql ' || DB.DBA.R2RML_MAKE_QM_FROM_G ('http://temp/product'));

--sparql select distinct ?g where { graph ?g { ?s a ?t }};

SPARQL
SELECT * FROM <http://example.com/trial>
WHERE {?s ?p ?o .};

@candlecao candlecao added the documentation Improvements or additions to documentation label Oct 31, 2024
@candlecao
Copy link
Contributor Author

For more details, see my documentation about How to convert CSV to RDF into Virtuoso?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation Priority: high high priority
Projects
None yet
Development

No branches or pull requests

1 participant