W3C home > Mailing lists > Public > public-cwm-talk@w3.org > July to September 2004

Re: How do you do 'table lookup' with n3?

From: Jos De_Roo <jos.deroo@agfa.com>
Date: Thu, 9 Sep 2004 01:01:13 +0200
To: Jos De_Roo <jos.deroo@agfa.com>
Cc: david.h.jones@boeing.com, public-cwm-talk@w3.org, public-cwm-talk-request@w3.org
Message-ID: <OF6261954B.97B703DE-ONC1256F09.007E1A92-C1256F09.007E7B8A@agfa.com>

It's always better to work with URI's :)

The test data is at
the query at
and the evidence at


Jos De Roo, AGFA http://www.agfa.com/w3c/jdroo/

Sent by: public-cwm-talk-request@w3.org
09/09/2004 00:14

        To:     david.h.jones@boeing.com
        cc:     public-cwm-talk@w3.org, public-cwm-talk-request@w3.org, (bcc: Jos 
        Subject:        Re: How do you do 'table lookup' with n3?

Hi, David

I tested your case with the N3 rule

{?P :myLetterGrade ?L. ?X :letterGrade ?L; :numberGrade ?N} => {?P
:myNumberGrade ?N}.

and the N3QL query

[] q:select {?P :myNumberGrade ?N}; q:where {?P :myNumberGrade ?N}.

and cwm testP.n3 --query=testC.n3 gives

:Dave     :myNumberGrade 7 .

:Kathy     :myNumberGrade 10 .

but you can also directly query your data with

[] q:select {?P :myNumberGrade ?N}; q:where {?P :myLetterGrade ?L. ?X
:letterGrade ?L; :numberGrade ?N}.

kind regards,

Jos De Roo, AGFA http://www.agfa.com/w3c/jdroo/

"Jones, David H" <david.h.jones@boeing.com>
Sent by: public-cwm-talk-request@w3.org
08/09/2004 02:40

To:     <public-cwm-talk@w3.org>
cc:     (bcc: Jos De_Roo/AMDUS/MOR/Agfa-NV/BE/BAYER)
Subject:        How do you do 'table lookup' with n3?

I'd like to be able to look up arbitrary values in a table-like structure
of rdf properties, but haven't been able figure out how to do it using n3.

Can some one show an example of how to do this.  Below is my attempt.

@prefix rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix owl:  <http://www.w3.org/2002/07/owl#> .
@prefix log: <http://www.w3.org/2000/10/swap/log#>.
@prefix math: <http://www.w3.org/2000/10/swap/math#>.
@prefix string: <http://www.w3.org/2000/10/swap/string#>.

# Lookup table
[:letterGrade "A"; :numberGrade 10].
[:letterGrade "B"; :numberGrade 7].
[:letterGrade "C"; :numberGrade 5].
[:letterGrade "D"; :numberGrade 3].
[:letterGrade "F"; :numberGrade 1].

:Dave :myLetterGrade "B".
:Kathy :myLetterGrade "A".

#Attempts at table lookup
#{?y. ?x. :temp :val ?x.:numberGrade. ?y.:myLetterGrade
string:equalIgnoringCase ?x.:letterGrade } => {?y :myNumberGrade
{?y.:myLetterGrade string:equalIgnoringCase ?x.:letterGrade } => {?y
:myNumberGrade ?x.:numberGrade}.

#Intended inferred properties
#:Dave :myNumberGrade 5.
#:Kathy :myNumberGrade 7.


David H. Jones
Boeing Phantom Works,
Mathematics & Computing Technology
425-865-2964 (FAX)
Received on Wednesday, 8 September 2004 23:01:58 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 20:01:04 UTC