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

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

From: Lund, Ben <B.Lund@nature.com>
Date: Wed, 8 Sep 2004 10:20:00 +0100
Message-ID: <125F7834E11A5741A7D79412EE3504F90B17ED61@UK1APPS2.nature.com>
To: "'Jones, David H'" <david.h.jones@boeing.com>
Cc: public-cwm-talk@w3.org

Hi David,

Jones, David H wrote:
> 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.
> 

You should explicitly name a variable for the node you want.  Changing your
rule to:
----
{
  ?y.:myLetterGrade string:equalIgnoringCase ?x.:letterGrade .
  ?x :numberGrade ?num . 
} 
=> 
{ ?y :myNumberGrade ?num } .
----

gives you what you need.

$ cwm table.n3 results.n3  --filter=rules.n3
#Processed by Id: cwm.py,v 1.144 2003/09/14 20:20:20 timbl Exp
        #    using base file:/home/ben/devel/temp/

#  Notation3 generation by
#       notation3.py,v 1.146 2003/09/14 20:20:24 timbl Exp

#   Base was: file:/home/ben/devel/temp/
     @prefix : <results.n3#> .
     @prefix log: <http://www.w3.org/2000/10/swap/log#> .
     @prefix math: <http://www.w3.org/2000/10/swap/math#> .
     @prefix owl: <http://www.w3.org/2002/07/owl#> .
     @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
     @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
     @prefix string: <http://www.w3.org/2000/10/swap/string#> .
     @prefix table: <table.n3#> .

    :Dave     :myNumberGrade 7 .

    :Kathy     :myNumberGrade 10 .

#ENDS

(table.n3 contains the table, results.n3 contains the myLetterGrade
statements and rules.n3 contains the rule)



Ta,
Ben

---



********************************************************************************
DISCLAIMER: This e-mail is confidential and should not be used by anyone who is not the original intended recipient. If you have received this e-mail in error please inform the sender and delete it from your mailbox or any other storage mechanism. Neither Macmillan Publishers Limited nor any of its agents accept liability for any statements made which are clearly the sender's own and not expressly made on behalf of Macmillan Publishers Limited or one of its agents. Please note that neither Macmillan Publishers Limited nor any of its agents accept any responsibility for viruses that may be contained in this e-mail or its attachments and it is your responsibility to scan the e-mail and attachments (if any). No contracts may be concluded on behalf of Macmillan Publishers Limited or its agents by means of e-mail communication. Macmillan Publishers Limited Registered in England and Wales with registered number 785998 Registered Office Brunel Road, Houndmills, Basingstoke RG21 6XS
********************************************************************************
Received on Wednesday, 8 September 2004 09:20:38 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 8 January 2008 14:11:01 GMT