Re: Example from sequence of triples to an RDF List

Wow, thanks! Yes, I was planning list:append because for my schema alignment I still try to introduce as few built-ins as possible. The collectAllIn provides indeed much possibilities.

It took a little time to understand the solution but it is a neat trick. The scoped negation is in the collectAllIn which also could be written as:

      ( [] {?part :order ?n.} () ) log:collectAllIn _:x.

You are searching for the biggest interim list. And that is the list for which there is no total count of parts that is one bigger than the biggest interim list.

Patrick
________________________________
From: Doerthe Arndt <doerthe.arndt@tu-dresden.de>
Sent: 31 August 2022 17:50
To: Jos De Roo <josderoo@gmail.com>
Cc: Patrick Hochstenbach <Patrick.Hochstenbach@UGent.be>; public-n3-dev@w3.org <public-n3-dev@w3.org>
Subject: Re: Example from sequence of triples to an RDF List

Hi Patrick,

I created an alternative solution to your problem using list:append (just because you mentioned that). The solution uses scoped negation as failure (with collectAllIn, I originally wanted to avoid that). I think that Jos’ way is more elegant in the sense that we do not need to create interim lists (not even internally), but I hope that you can see that you get far even without the very powerful collectAllIn. Here the link: http://ppr.cs.dal.ca:3002/n3/editor/s/cNbBrzeo<https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fppr.cs.dal.ca%3A3002%2Fn3%2Feditor%2Fs%2FcNbBrzeo&data=05%7C01%7CPatrick.Hochstenbach%40ugent.be%7C6ee9b4651eab4872626a08da8b68a5ea%7Cd7811cdeecef496c8f91a1786241b99c%7C1%7C0%7C637975578822868987%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=mlnFJEMIYU%2BfuiVoJ%2FAV%2FoQhsb%2FkZG%2FAmVv%2FYkFCcEs%3D&reserved=0>

Below the code:

@prefix math: <http://www.w3.org/2000/10/swap/math#<https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.w3.org%2F2000%2F10%2Fswap%2Fmath%23&data=05%7C01%7CPatrick.Hochstenbach%40ugent.be%7C6ee9b4651eab4872626a08da8b68a5ea%7Cd7811cdeecef496c8f91a1786241b99c%7C1%7C0%7C637975578822868987%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=TrkFSCBpgZTC8rIL3DMpEmq1BDl3VWScyo8vRP%2BRL9E%3D&reserved=0>> .
@prefix log: <http://www.w3.org/2000/10/swap/log#<https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.w3.org%2F2000%2F10%2Fswap%2Flog%23&data=05%7C01%7CPatrick.Hochstenbach%40ugent.be%7C6ee9b4651eab4872626a08da8b68a5ea%7Cd7811cdeecef496c8f91a1786241b99c%7C1%7C0%7C637975578822868987%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=4q0%2F%2FGu7okkc9u4dAZ1s%2F76XPK7Oo2sQjT20pOB%2BnS8%3D&reserved=0>>.
@prefix list: <http://www.w3.org/2000/10/swap/list#<https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.w3.org%2F2000%2F10%2Fswap%2Flist%23&data=05%7C01%7CPatrick.Hochstenbach%40ugent.be%7C6ee9b4651eab4872626a08da8b68a5ea%7Cd7811cdeecef496c8f91a1786241b99c%7C1%7C0%7C637975578822868987%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=w%2FqCo5RCVjwNlG%2B4pNFYpfZW%2F6RhaXj734S7A13VY0c%3D&reserved=0>>.
@prefix math: <http://www.w3.org/2000/10/swap/math#<https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.w3.org%2F2000%2F10%2Fswap%2Fmath%23&data=05%7C01%7CPatrick.Hochstenbach%40ugent.be%7C6ee9b4651eab4872626a08da8b68a5ea%7Cd7811cdeecef496c8f91a1786241b99c%7C1%7C0%7C637975578822868987%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=TrkFSCBpgZTC8rIL3DMpEmq1BDl3VWScyo8vRP%2BRL9E%3D&reserved=0>>.
@prefix : <http://example.org/ns#<https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fexample.org%2Fns%23&data=05%7C01%7CPatrick.Hochstenbach%40ugent.be%7C6ee9b4651eab4872626a08da8b68a5ea%7Cd7811cdeecef496c8f91a1786241b99c%7C1%7C0%7C637975578822868987%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=hJhs%2BkdAyhCpa3W1U7E42C22mIGHRkyYcI%2Bu3O670pQ%3D&reserved=0>>.

:part1 :order 1 .
:part3 :order 3.
:part2 :order 2.

{?part :order 1.  }=>{(?part) :list 1}.

#built up lists
{?part :order ?n.
 ?list :list ?m.
 (?m 1) math:sum ?n.
 (?list (?part)) list:append ?nlist
}=>{?nlist :list ?n}.

#(scoped) negation as failure to see that we are done
{

 ?list :list ?m.
 (?m 1) math:sum ?n.
  ((1) {?part :order ?n.} ()) log:collectAllIn ?SCOPE.
} => {
    :Collection :parts ?list.
}.

Which produces:
@prefix math: <http://www.w3.org/2000/10/swap/math#<https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.w3.org%2F2000%2F10%2Fswap%2Fmath%23&data=05%7C01%7CPatrick.Hochstenbach%40ugent.be%7C6ee9b4651eab4872626a08da8b68a5ea%7Cd7811cdeecef496c8f91a1786241b99c%7C1%7C0%7C637975578822868987%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=TrkFSCBpgZTC8rIL3DMpEmq1BDl3VWScyo8vRP%2BRL9E%3D&reserved=0>>.
@prefix log: <http://www.w3.org/2000/10/swap/log#<https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.w3.org%2F2000%2F10%2Fswap%2Flog%23&data=05%7C01%7CPatrick.Hochstenbach%40ugent.be%7C6ee9b4651eab4872626a08da8b68a5ea%7Cd7811cdeecef496c8f91a1786241b99c%7C1%7C0%7C637975578822868987%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=4q0%2F%2FGu7okkc9u4dAZ1s%2F76XPK7Oo2sQjT20pOB%2BnS8%3D&reserved=0>>.
@prefix list: <http://www.w3.org/2000/10/swap/list#<https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.w3.org%2F2000%2F10%2Fswap%2Flist%23&data=05%7C01%7CPatrick.Hochstenbach%40ugent.be%7C6ee9b4651eab4872626a08da8b68a5ea%7Cd7811cdeecef496c8f91a1786241b99c%7C1%7C0%7C637975578822868987%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=w%2FqCo5RCVjwNlG%2B4pNFYpfZW%2F6RhaXj734S7A13VY0c%3D&reserved=0>>.
@prefix : <http://example.org/ns#<https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fexample.org%2Fns%23&data=05%7C01%7CPatrick.Hochstenbach%40ugent.be%7C6ee9b4651eab4872626a08da8b68a5ea%7Cd7811cdeecef496c8f91a1786241b99c%7C1%7C0%7C637975578822868987%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=hJhs%2BkdAyhCpa3W1U7E42C22mIGHRkyYcI%2Bu3O670pQ%3D&reserved=0>>.

(:part1) :list 1 .
(:part1 :part2) :list 2 .
(:part1 :part2 :part3) :list 3 .
:Collection :parts (:part1 :part2 :part3).

Kind regards,
Dörthe

Am 27.08.2022 um 16:02 schrieb Jos De Roo <josderoo@gmail.com<mailto:josderoo@gmail.com>>:

Hi Patrick,

The core built-ins will be described in detail in https://w3c.github.io/N3/files/builtin_spec.html<https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fw3c.github.io%2FN3%2Ffiles%2Fbuiltin_spec.html&data=05%7C01%7CPatrick.Hochstenbach%40ugent.be%7C6ee9b4651eab4872626a08da8b68a5ea%7Cd7811cdeecef496c8f91a1786241b99c%7C1%7C0%7C637975578823025203%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=Cw11F%2BzKtWUe5I0FgrUSbPAghjcMnKXw%2B697FD6U%2Fuw%3D&reserved=0>
For the moment consider log:collectAllIn owl:inverse e:findall where the latter is
(briefly) documented at http://eulersharp.sourceforge.net/2003/03swap/log-rules.html#findall<https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Feulersharp.sourceforge.net%2F2003%2F03swap%2Flog-rules.html%23findall&data=05%7C01%7CPatrick.Hochstenbach%40ugent.be%7C6ee9b4651eab4872626a08da8b68a5ea%7Cd7811cdeecef496c8f91a1786241b99c%7C1%7C0%7C637975578823025203%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=uGzOFf%2FJn4M5EmKNtf8CQL7nTjxoeG6VwhRVjW7Hz7o%3D&reserved=0>

Jos

-- https://josd.github.io<https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fjosd.github.io%2F&data=05%7C01%7CPatrick.Hochstenbach%40ugent.be%7C6ee9b4651eab4872626a08da8b68a5ea%7Cd7811cdeecef496c8f91a1786241b99c%7C1%7C0%7C637975578823025203%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=bFs1KCILyE7LOUbVbaZJ9owGDeS1F%2Fg09Ay2ALKvvVE%3D&reserved=0>


On Sat, Aug 27, 2022 at 2:14 PM Patrick Hochstenbach <Patrick.Hochstenbach@ugent.be<mailto:Patrick.Hochstenbach@ugent.be>> wrote:
Yes, indeed! This I certainly was something I couldn't have produced.

I didn't come across  log:collectAllIn before.

I assume

( ?Params ?FormA ?Collection ) log:collectAllIn ?FormB

Means some kind of 'Params' extraction from 'FormA' into a 'Collection'
..and then the 'FormB' is [?].

Thanks
Patrick

________________________________
From: Jos De Roo <josderoo@gmail.com<mailto:josderoo@gmail.com>>
Sent: 27 August 2022 13:33
To: Patrick Hochstenbach <Patrick.Hochstenbach@UGent.be<mailto:Patrick.Hochstenbach@UGent.be>>
Cc: public-n3-dev@w3.org<mailto:public-n3-dev@w3.org> <public-n3-dev@w3.org<mailto:public-n3-dev@w3.org>>
Subject: Re: Example from sequence of triples to an RDF List

Hi Patrick,

The following should work fine

$ cat test.n3
@prefix log: <http://www.w3.org/2000/10/swap/log#<https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.w3.org%2F2000%2F10%2Fswap%2Flog%23&data=05%7C01%7CPatrick.Hochstenbach%40ugent.be%7C6ee9b4651eab4872626a08da8b68a5ea%7Cd7811cdeecef496c8f91a1786241b99c%7C1%7C0%7C637975578823025203%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=6IuJGJ5gchtQQfdSl9Yt9Uilni2X6CsLfG8ChuupfGQ%3D&reserved=0>>.
@prefix list: <http://www.w3.org/2000/10/swap/list#<https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.w3.org%2F2000%2F10%2Fswap%2Flist%23&data=05%7C01%7CPatrick.Hochstenbach%40ugent.be%7C6ee9b4651eab4872626a08da8b68a5ea%7Cd7811cdeecef496c8f91a1786241b99c%7C1%7C0%7C637975578823025203%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=V3c9zIcl1g%2ByawJ%2BP4FgGt2HZA3lUcPySg%2F3X%2FSBuQg%3D&reserved=0>>.
@prefix : <http://example.org/ns#<https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fexample.org%2Fns%23&data=05%7C01%7CPatrick.Hochstenbach%40ugent.be%7C6ee9b4651eab4872626a08da8b68a5ea%7Cd7811cdeecef496c8f91a1786241b99c%7C1%7C0%7C637975578823025203%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=mPvM9OWeYSfXSzxEzY8%2F9wXUNY1%2BUVQ%2BT97swv13Lqs%3D&reserved=0>>.

:part1 :order 1 .
:part3 :order 3.
:part2 :order 2.

{   ((?B ?A) {?A :order ?B} ?C) log:collectAllIn ?SCOPE.
    ?C list:unique ?D.
    (?F {?D list:member (?E ?F)} ?G) log:collectAllIn ?SCOPE.
} => {
    :Collection :parts ?G.
}.

With the latest version of eye (supporting list:unique) you should get

$ eye --nope --quiet test.n3 --pass 2>/dev/null
@prefix log: <http://www.w3.org/2000/10/swap/log#<https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.w3.org%2F2000%2F10%2Fswap%2Flog%23&data=05%7C01%7CPatrick.Hochstenbach%40ugent.be%7C6ee9b4651eab4872626a08da8b68a5ea%7Cd7811cdeecef496c8f91a1786241b99c%7C1%7C0%7C637975578823025203%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=6IuJGJ5gchtQQfdSl9Yt9Uilni2X6CsLfG8ChuupfGQ%3D&reserved=0>>.
@prefix list: <http://www.w3.org/2000/10/swap/list#<https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.w3.org%2F2000%2F10%2Fswap%2Flist%23&data=05%7C01%7CPatrick.Hochstenbach%40ugent.be%7C6ee9b4651eab4872626a08da8b68a5ea%7Cd7811cdeecef496c8f91a1786241b99c%7C1%7C0%7C637975578823025203%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=V3c9zIcl1g%2ByawJ%2BP4FgGt2HZA3lUcPySg%2F3X%2FSBuQg%3D&reserved=0>>.
@prefix : <http://example.org/ns#<https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fexample.org%2Fns%23&data=05%7C01%7CPatrick.Hochstenbach%40ugent.be%7C6ee9b4651eab4872626a08da8b68a5ea%7Cd7811cdeecef496c8f91a1786241b99c%7C1%7C0%7C637975578823025203%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=mPvM9OWeYSfXSzxEzY8%2F9wXUNY1%2BUVQ%2BT97swv13Lqs%3D&reserved=0>>.

:part1 :order 1 .
:part3 :order 3 .
:part2 :order 2 .
:Collection :parts (:part1 :part2 :part3).


Jos

-- https://josd.github.io<https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fjosd.github.io%2F&data=05%7C01%7CPatrick.Hochstenbach%40ugent.be%7C6ee9b4651eab4872626a08da8b68a5ea%7Cd7811cdeecef496c8f91a1786241b99c%7C1%7C0%7C637975578823025203%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=bFs1KCILyE7LOUbVbaZJ9owGDeS1F%2Fg09Ay2ALKvvVE%3D&reserved=0>


On Sat, Aug 27, 2022 at 9:43 AM Patrick Hochstenbach <Patrick.Hochstenbach@ugent.be<mailto:Patrick.Hochstenbach@ugent.be>> wrote:
Hi,

I'm still struggling with RDF List and to use N3 (or SPARQL) for schema alignment.
I the past the group provided solution to go from an RDF List to a sequence of triples (See: "Example how to count in N3" thread https://lists.w3.org/Archives/Public/public-n3-dev/2022Jul/0022.html<https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.w3.org%2FArchives%2FPublic%2Fpublic-n3-dev%2F2022Jul%2F0022.html&data=05%7C01%7CPatrick.Hochstenbach%40ugent.be%7C6ee9b4651eab4872626a08da8b68a5ea%7Cd7811cdeecef496c8f91a1786241b99c%7C1%7C0%7C637975578823025203%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=HCNZIRpB23JXF0d74dh5cOPXppDcfUOjw2aU%2B6BUieM%3D&reserved=0>).

But how could the opposite route be done?

From:

:part1 :order 1 .
:part2 :order 2.
:part3 :order 3.

to

:Collection :parts (:part1 :part2 :part3 ).

I tried my best and can invent rules to generate any combination of (infinite) lists, but not this example. I tried to list:append or trying to create a list by hand using rdf:next ..but this keeps producing blank nodes in a loop.

In general, it is a question how to create an RDF List from scratch in N3 using the input data.

Patrick

Received on Wednesday, 31 August 2022 18:12:30 UTC