Mayil-AI-Sandbox / kuzudb_jan15

MIT License
0 stars 0 forks source link

RDF Base IRIs not working (hashtag2765) #35

Open vikramsubramanian opened 4 months ago

vikramsubramanian commented 4 months ago

According to the [RDF Turtle file specification]( some IRIs can be specified as relative IRIs against a base IRI. The [specification of relative IRIs]( is as follows:

[IRIs]( may be written as relative or absolute IRIs or prefixed names. Relative and absolute IRIs are enclosed in '<' and '>' and may contain [numeric escape sequences]( (described below). For example <

Relative IRIs like are resolved relative to the current base IRI. A new base IRI can be defined using the ' or 'BASE' directive. Specifics of this operation are defined in [section 6.3 IRI References](

So for example, if you ingest the triples in the example in the specification:

 < .
 rdf: < .
 rdfs: < .
 foaf: < .
 rel: < .

<hashtaggreen-goblin>
    rel:enemyOf <hashtagspiderman> ;
    a foaf:Person ;    hashtag in the context of the Marvel universe
    foaf:name "Green Goblin" .

<hashtagspiderman>
    rel:enemyOf <hashtaggreen-goblin> ;
    a foaf:Person ;
    foaf:name "Spiderman", "Человек-паук" .

You would get for , " We currently ingest these as "hashtaggreen-goblin". )

mayil-ai[bot] commented 4 months ago

Summary: Issue with resolving relative IRIs against a base IRI in RDF Turtle files.

Possible Solution

The issue described pertains to the incorrect resolution of relative IRIs in RDF Turtle files. The expected behavior is that relative IRIs such as <hashtaggreen-goblin> and <hashtagspiderman> should be resolved against a base IRI, but they are currently being ingested incorrectly without resolution.

To address this issue, the following solution should be implemented:

Here is a pseudo-code outline of the changes to be made in the read_IRIREF function:

static SerdStatus
read_IRIREF(SerdReader* const reader, Ref* const dest) {
  // ... existing code ...

  // Check if the IRI is relative
  if (is_relative_iri(reader, *dest)) {
    // Resolve the relative IRI against the base IRI
    SerdURI resolved_uri;
    serd_uri_resolve(reader->base_iri, *dest, &resolved_uri);
    // Replace *dest with the resolved URI
    *dest = push_node_with_resolved_uri(reader, &resolved_uri);
  }

  // ... existing code ...
}

Additionally, ensure that the RdfReader::prefixHandle function correctly updates the base IRI when the BASE directive is encountered:

SerdStatus RdfReader::prefixHandle(void* handle, const SerdNode* /*name*/, const SerdNode* uri) {
  auto reader = reinterpret_cast<RdfReader*>(handle);
  if (is_base_directive(uri)) {
    // Update the base IRI
    reader->base_iri = reinterpret_cast<const char*>(uri->buf);
  }
  return SERD_SUCCESS;
}

Make sure to test the changes with RDF Turtle files containing relative IRIs to verify that they are now being resolved correctly against the base IRI.

Code snippets to check