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

-- 
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 
:temp.:val}.
{?y.:myLetterGrade string:equalIgnoringCase ?x.:letterGrade } => {?y 
:myNumberGrade ?x.:numberGrade}.

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

Regards,

David H. Jones
Boeing Phantom Works,
Mathematics & Computing Technology
425-865-6924
425-865-2964 (FAX)
david.h.jones@boeing.com

Received on Wednesday, 8 September 2004 22:15:11 UTC