Shorthand:Path and lists, and @keywords学习笔记
来源:互联网 发布:积分怎么编程 编辑:程序博客网 时间:2024/06/05 00:58
地址: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 thatwhich 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:mailbox指x’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:first和rdf: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。- Shorthand:Path and lists, and @keywords学习笔记
- Python学习笔记(7)Mouse Input, More Lists and Dictionaries
- Java学习笔记(20) Lists, Stacks, Queues, and Priority Queues
- Keywords and Reserved Words
- 《Java Generics and Collections》笔记-Lists/Maps
- Python学习——Lists and Dictionaries
- java keywords and language tutorial
- 数据结构与算法分析c版的学习笔记之Lists,Stacks,and Queues(一)
- Java学习笔记(24)Implementing Lists,Stacks,Queues,and Priority Queues
- Python学习笔记(4)——Python Lists and Dictionaries
- Python For Kids学习笔记03:Strings, Lists, Tuples, and Maps
- Tables, Matrices, and Lists
- Creating Lists and Cards
- 学习笔记 - Keywords
- linux命令学习:PATH and LDFLAGS and CFLAGS
- linux命令学习:PATH and LDFLAGS and CFLAGS
- linux命令学习:PATH and LDFLAGS and CFLAGS
- Robot: Duplicate Keywords in Library and Resource Keywords
- 天极网软件频道的用JS实现的图片切换特效
- 让vb6的数据表格可以输出多层表头
- ATL 调用MFC扩展dll
- 仿Office 2003的工具条[网页特效]
- python 宝典 笔记 第十二章 存储数据和对象 (各种对象转换成字符串)
- Shorthand:Path and lists, and @keywords学习笔记
- 开发自定义控件
- JavaScript 函数调用规则和if条件判断
- 一个项目的失败的原因
- 实现 clone 方法
- SqlServer的更新锁(UPDLOCK)
- 正则表达式的语法
- C#中动态扩展一个新类型的实现
- 如何使用 foreach 访问集合类