eye icon indicating copy to clipboard operation
eye copied to clipboard

Ability to provide base IRI for parsing relative IRIs in input files

Open tpluscode opened this issue 1 year ago • 6 comments

When an input has no @base, the file's URL is used to parse relative references.

I would like to ask for a --base or --base-iri CLI option to set the base for parsing if the base directive is missing.

tpluscode avatar Jan 26 '25 21:01 tpluscode

For eye you can use

--wcache <uri> <file>           to tell that <uri> is cached as <file>

josd avatar Jan 27 '25 12:01 josd

Hm, that did not work.

I have a base.n3 file:

PREFIX ex: <http://example.org/>

<foobar> a ex:Foo .

{
  <http://localhost/foobar> a ex:Foo .
} => {
  <http://localhost/foobar> a ex:Bar .
} .

I expected that calling with --wcache http://localhost/ base.n3 would do the trick but it still parses the relative reference as file:// URL

> eye --nope --quiet --pass --wcache http://localhost/ base.n3 base.n3  
@prefix ex: <http://example.org/>.

<file:///absolute/path/foobar> a ex:Foo.

tpluscode avatar Jan 27 '25 13:01 tpluscode

I'm also unsure how this is going to work when there are multiple files like that. Consider foo.n3 and bar.n3

eye --nope --quiet --pass --wcache http://localhost/ foo.n3 foo.n3 --wcache http://localhost/ bar.n3 bar.n3  

The description of --wcache suggests that this is not valid usage and each usage should have a different value of <uri>?

tpluscode avatar Jan 27 '25 13:01 tpluscode

It works as follows:

$ eye --nope --quiet --pass --wcache http://localhost . http://localhost/base.n3
@prefix ex: <http://example.org/>.

<http://localhost/foobar> a ex:Foo.
<http://localhost/foobar> a ex:Bar.

and we use it all the time for multiple files, either by specifying a "directory", like the above . or by multiple --wcache options

josd avatar Jan 27 '25 14:01 josd

for examples see all test files in the subdirectories of https://github.com/eyereasoner/eye/tree/master/reasoning

josd avatar Jan 27 '25 14:01 josd

It took me a while to understand that in a sense it is the opposite of specifying base - instead of specifying what base to use to interpret a local file, wcache specifies what local cache to use for a given remote URL.

My use case involved globbing files. I therefore needed to instead use string manipulation to construct the remote URLs based on the local paths.

eye --nope --quiet --pass --wcache https://remote .  $(find main/ -maxdepth 1 -type f -name '*.ttl' -printf 'https://remote/%f\n')

Edit: This was a partial solution because the files in question used the convention that https://remote/resource maps to the local file resource$.ttl. As a workaround I post processed the generated triples to remove the $.ttl:

sed 's/\$.ttl//g'

jg10-mastodon-social avatar Nov 10 '25 09:11 jg10-mastodon-social