Shorthand:Path and lists, and @keywords学习笔记

rel="File-List" href="file:///C:%5CDOCUME%7E1%5CADMINI%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtmlclip1%5C01%5Cclip_filelist.xml"> rel="themeData" href="file:///C:%5CDOCUME%7E1%5CADMINI%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtmlclip1%5C01%5Cclip_themedata.thmx"> rel="colorSchemeMapping" href="file:///C:%5CDOCUME%7E1%5CADMINI%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtmlclip1%5C01%5Cclip_colorschememapping.xml">

地址:http://www.w3.org/2000/10/swap/doc/Shortcuts

Paths

很多时候不得不通过一个属性字符串间接地指明某物,比如“George's mother's assistant's home's address' zipcode”。这是一个图的遍历,在N3中可以这样处理:

[is con:zipcode of [
  
  
    is con:address of [
  
  
        is con:home of [
  
  
            is off:assistant of [
  
  
                is rel:mother of :George]]]]]
  
  

上面的表示可以读成"that which is the zipcode of that which is the address of that which is the home of that which is the assistant of that which is the mother of :George",但是这样读写很不方便。在面向对象的语言中,可以通过“.”将方法或者属性串联起来。在N3中可以很容易实现:

:George.rel:mother
  
  
          .off:assistant
  
  
            .con:home
  
  
              .con:address
  
  
                 .con:zipcode
  
  

点后面必须紧跟下一个东西,不能有空格。

每个点就是图的一次前向遍历。X.con:mailboxx’s mailbox,所以在英语中可以将“.”读成’s

使用^替换点可以实现后向遍历。:me.con:mailbox指我的邮箱,<mailto:ora@lassila.com>^con:mailbox指拥有邮箱<mailto:ora@lassila.com>的人。后向遍历很少用,但有时却是你需要的。

注意,对一个路径path的匹配并不是唯一的。:me.rel:parent指我的父母,:me.rel:parent^rel:parent指将我的父母作为父母的人(我,或我的兄弟姐妹)。在这个虚构的本体中,.rel:child^rel:parent是等价的。

无论.^的顺序是怎样的,在文档内都是从左往右读。

Lists

如何表示有序的一组事物?在RDF中,rdf:Collection。在N3中这样表示:所有的项放在小括号内,项之间以空格分隔。如:

( "Monday" "Tuesday" "Wednesday" )
  
  
(:x :y)
  
  
( :cust.bus:order.bus:number 
  
  
  :cust.bus:order
  
  
      .bus:referncedPurchaseOrder
  
  
          .bus:number )
  
  
上例实际上是使用rdf:firstrdf:rest连接空白节点的一种简写形式。Rdf:first表示一个列表和列表里面第一个项的关系,rdf:rest表示一个列表和列表中除第一项外所有其他项的关系,rdf:nil指空列表。所以( "Monday" "Tuesday" "Wednesday" )等价于
   
   
[ rdf:first "Monday";
  
  
  rdf:next [ rdf:first "Tuesday";
  
  
             rdf:rest [ rdf:first "Wednesday";
  
  
                        rdf:rest rdf:nil ]]]
  
  
列表的一个常见用途是,作为有多个变量的关系的参数。
   
   
(  "Dear " ?name " "," )   
  
  
             string:concatenation   ?salutation.
  
  
上例指明salutation称呼是三个字符串“Dear”、?name(无论它指什么)和逗号的字符串串联。--Jerin:不大懂这个例子,里面多了一个引号?
   
   
Get rid of the leading “:” with @keywords(通过@keywords不再使用冒号前缀)
    
    

在例子中,我们已经在使用一些默认命名空间中的术语,比如:me:father:People。使用引号是因为不想和一些关键字(他们是句法的一部分,如a, is, of, prefix等)混淆。更进一步,我们想在日后添加更多的关键字来扩展语法,而你肯定不想自己的文档使用过时的词汇。

解决方案是,如果你真的在写N3时不使用冒号做前缀,那么你可以通过@前缀和keywords关键字声明你将使用的关键词。由此,不在列表中的任何词汇,允许不加冒号前缀,而这些词汇也将视为名称。要真想使用关键字,那就需要明确的使用@符号,就像一直在用的prefix。例:

@keywords.
  
  
@prefix : <#>.
  
  
me @a Person.
  
  
Jo @a Person; @is sister @of me.
  
  
Jo father Alan; mother Flo.
  
  
Alan father Zak; brother Ed, Julian.
  
  

下例中声明了常用的关键字:

@keywords a, is, of, this.
  
  
@prefix : <#>.
  
  
me a Person.
  
  
Jo a Person; is sister of me.
  
  
Jo father Alan; mother Flo.
  
  
Alan father Zak; brother Ed, Julian.
  
  

注意,如果已经在关键字里声明了一些词,仍然可以在这些词上使用@前缀,和上面的@prefix类似。

显然,不能先将 a 声明为关键字,之后以变量的形式调用 a b c
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值