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 00:14:31 +0200
To: david.h.jones@boeing.com
Cc: public-cwm-talk@w3.org, public-cwm-talk-request@w3.org
Message-ID: <OFBA8220D1.8CA2A38E-ONC1256F09.0079272F-C1256F09.007A352C@agfa.com>

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 22:15:11 UTC

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