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


Below the code:

@prefix math: <http://www.w3.org/2000/10/swap/math#> .
@prefix log: <http://www.w3.org/2000/10/swap/log#>.
@prefix list: <http://www.w3.org/2000/10/swap/list#>.
@prefix math: <http://www.w3.org/2000/10/swap/math#>.
@prefix : <http://example.org/ns#>.

: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#>.
@prefix log: <http://www.w3.org/2000/10/swap/log#>.
@prefix list: <http://www.w3.org/2000/10/swap/list#>.
@prefix : <http://example.org/ns#>.

(: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

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


Jos

-- https://josd.github.io<https://josd.github.io/>


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%7C47a1fd72b6914828b72a08da88200304%7Cd7811cdeecef496c8f91a1786241b99c%7C1%7C0%7C637971968311225997%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=fZFrBtXU7PrSHGcB3SWgvl7TYmtD6r1tX5pV1TcBZrs%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%7C47a1fd72b6914828b72a08da88200304%7Cd7811cdeecef496c8f91a1786241b99c%7C1%7C0%7C637971968311225997%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=9tpWr7H57K%2F71UXpZwtGSpMtH%2B6PNsWQCWfDjUOX1vo%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%7C47a1fd72b6914828b72a08da88200304%7Cd7811cdeecef496c8f91a1786241b99c%7C1%7C0%7C637971968311225997%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=iIKo044fHRfJmpYBLUlqY2uGxeoZLwPBuLZYQLxD21I%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%7C47a1fd72b6914828b72a08da88200304%7Cd7811cdeecef496c8f91a1786241b99c%7C1%7C0%7C637971968311225997%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=fZFrBtXU7PrSHGcB3SWgvl7TYmtD6r1tX5pV1TcBZrs%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%7C47a1fd72b6914828b72a08da88200304%7Cd7811cdeecef496c8f91a1786241b99c%7C1%7C0%7C637971968311225997%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=9tpWr7H57K%2F71UXpZwtGSpMtH%2B6PNsWQCWfDjUOX1vo%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%7C47a1fd72b6914828b72a08da88200304%7Cd7811cdeecef496c8f91a1786241b99c%7C1%7C0%7C637971968311225997%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=iIKo044fHRfJmpYBLUlqY2uGxeoZLwPBuLZYQLxD21I%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%7C47a1fd72b6914828b72a08da88200304%7Cd7811cdeecef496c8f91a1786241b99c%7C1%7C0%7C637971968311225997%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=6%2FiZa1XDzAsc7an79xSOesC9gfhmDH%2BoGbqjt9g4GYY%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%7C47a1fd72b6914828b72a08da88200304%7Cd7811cdeecef496c8f91a1786241b99c%7C1%7C0%7C637971968311225997%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=9AFSD88vwK1WDKRKraRNrN1T3bXLsLLWnSTuQ2mKnWk%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 15:51:34 UTC