rdfjs / N3.js

Lightning fast, spec-compatible, streaming RDF for JavaScript
http://rdf.js.org/N3.js/
Other
676 stars 127 forks source link

Support resource path syntax #348

Open tpluscode opened 1 year ago

tpluscode commented 1 year ago

Defined in: https://w3c.github.io/N3/spec/#paths

Here is an example of a concise rule which drops the unnecessary intermediate variables using the ! for resource paths:

@prefix string: <http://www.w3.org/2000/10/swap/string#> .
@prefix log: <http://www.w3.org/2000/10/swap/log#>.
@prefix : <https://example.com/> .

:this :badUrl <http://wrong.com/foo> .

{
  :this :badUrl ?badUrl .

  ?goodUrl log:uri ("http://good.stuff/" ( ?badUrl!log:uri "/(\\w+)$" )!string:scrape)!string:concatenation .
}
=>
{
  :this :goodUrl ?goodUrl .
} .

It fails to parse and would be equivalent to

@prefix string: <http://www.w3.org/2000/10/swap/string#> .
@prefix log: <http://www.w3.org/2000/10/swap/log#>.
@prefix : <https://example.com/> .

:this :badUrl <http://wrong.com/foo> .

{
  :this :badUrl ?badUrl .

  ?badUrl log:uri ?badUrlStr .
  ( ?badUrlStr "/(\\w+)$" ) string:scrape ?foo .
  ("http://good.stuff/" ?foo) string:concatenation ?gooUrlStr .

  ?goodUrl log:uri ?gooUrlStr .
}
=>
{
  :this :goodUrl ?goodUrl .
} .
jeswr commented 1 year ago

Already have this implemented that syntax the v2 branch :), the primary issue was ! and ^ not being recognised at the end of lists. I am working towards having full spec compliance for that updated N3 specification. Will close the issue after v2 release