Re: Example how to count in N3

Sweeet! As bonus with both examples I also got more insights how lists work internally 🙂
________________________________
From: Jos De Roo <josderoo@gmail.com>
Sent: 22 July 2022 21:09
To: William Van Woensel <william.vanwoensel@gmail.com>
Cc: Patrick Hochstenbach <Patrick.Hochstenbach@UGent.be>; public-n3-dev@w3.org <public-n3-dev@w3.org>
Subject: Re: Example how to count in N3

Exactly!
Another way that would also work with Cwm is

@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#<https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.w3.org%2F1999%2F02%2F22-rdf-syntax-ns%23&data=05%7C01%7CPatrick.Hochstenbach%40ugent.be%7C3feda747fd9f4468a6c608da6c15b739%7Cd7811cdeecef496c8f91a1786241b99c%7C1%7C0%7C637941137759280214%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=aQ1tsMf5nEX5flkhSaYOULxUQB6nx1wd6WJrJ7is%2Fzo%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%7C3feda747fd9f4468a6c608da6c15b739%7Cd7811cdeecef496c8f91a1786241b99c%7C1%7C0%7C637941137759280214%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=9XpBhlHpdvUdyKQ7J64Khqc98bY0IuDs6TqcT3TYh4Y%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%7C3feda747fd9f4468a6c608da6c15b739%7Cd7811cdeecef496c8f91a1786241b99c%7C1%7C0%7C637941137759280214%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=Ro4Wzt%2FQNXaPeCki67WOWTmcayYJqyrfkNXT9NeNPxw%3D&reserved=0>>.

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

{
  ?subject :parts ?parts.
  ?parts rdf:first ?part.
  ?parts rdf:rest ?rest.
  ?rest math:memberCount ?count.
}
=>
{
  ?part :order ?count .
  ?x :parts ?rest .
}.

giving

$ cwm /tmp/count.n3 --think --data
#Processed by Id
        #    using base file:///tmp/count.n3
             @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%7C3feda747fd9f4468a6c608da6c15b739%7Cd7811cdeecef496c8f91a1786241b99c%7C1%7C0%7C637941137759280214%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=Ro4Wzt%2FQNXaPeCki67WOWTmcayYJqyrfkNXT9NeNPxw%3D&reserved=0>> .

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

    :part1     :order 2 .

    :part2     :order 1 .

    :part3     :order 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%7C3feda747fd9f4468a6c608da6c15b739%7Cd7811cdeecef496c8f91a1786241b99c%7C1%7C0%7C637941137759280214%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=Tp53zPD2R%2B%2FN3MUwLX3ng19yiOxOj0sNWJ2rDuQI%2BjU%3D&reserved=0>


On Fri, Jul 22, 2022 at 8:54 PM William Van Woensel <william.vanwoensel@gmail.com<mailto:william.vanwoensel@gmail.com>> wrote:
Hi Patrick

Try list:iterate<https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Feulersharp.sourceforge.net%2F2003%2F03swap%2Feye-builtins.html&data=05%7C01%7CPatrick.Hochstenbach%40ugent.be%7C3feda747fd9f4468a6c608da6c15b739%7Cd7811cdeecef496c8f91a1786241b99c%7C1%7C0%7C637941137759280214%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=Awv%2B58kc%2BsaftLB0hGwpS40jrCqgvwMPeQNV20iU0zM%3D&reserved=0>. See http://ppr.cs.dal.ca:3002/n3/editor/s/2rJmxYti<https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fppr.cs.dal.ca%3A3002%2Fn3%2Feditor%2Fs%2F2rJmxYti&data=05%7C01%7CPatrick.Hochstenbach%40ugent.be%7C3feda747fd9f4468a6c608da6c15b739%7Cd7811cdeecef496c8f91a1786241b99c%7C1%7C0%7C637941137759280214%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=xX8%2BaNTVe4yV%2F3gYFp1cyZx3fzSZ297WtBkrapqpJkQ%3D&reserved=0> for an example.

(This is a new builtin introduced by the community group and supported by eye and jen3.)


W

On Jul 22, 2022, at 9:49 AM, Patrick Hochstenbach <Patrick.Hochstenbach@ugent.be<mailto:Patrick.Hochstenbach@ugent.be>> wrote:

Hi all,

I need a way to count things using N3 but I don't know yet how this could be done.
E.g. as data input I have:

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

As output I would like to get

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

I know I can loop over a list using the list:member:

@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%7C3feda747fd9f4468a6c608da6c15b739%7Cd7811cdeecef496c8f91a1786241b99c%7C1%7C0%7C637941137759280214%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=0uMBXd3SL%2Fa9aM8Jhc9OgB5WOFfSwFcyHcIIR8fS%2BMM%3D&reserved=0>>.

{
  ?subject :parts ?parts .
  ?parts list:member ?part .
}
=>
{
  ?part :order 1 .
}.

But I fail to find a way to add a counter for order. Any hints available?

BR

Patrick

Received on Saturday, 23 July 2022 04:50:24 UTC