- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
我用 RDF/XML 创建了一个小地铁 map ,想知道如何查询两个站点之间的距离。我是 SPARQL 的新手,不知道如何开始。
“距离”的意思是,我想知道两个站点之间有多少个站点。后面想计算时长,那是另外一回事了。
这是我的第一种方法:
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX ex: <http://example.com>
SELECT (count(?mid) as ?distance) WHERE {
<http://example.com/StopD> ex:via* ?mid .
?mid ex:via+ <http://example.com/StopC> .
}
我认为我的查询不起作用是因为我使用的是空白节点吗?不起作用意味着我没有得到两个停靠点(如 StopA 和 StopB)之间的图表数量。我脑子里有这样的东西:http://answers.semanticweb.com/questions/3491/how-can-i-calculate-the-length-of-a-path-between-2-graph-nodes-in-sparql/24609
那是我的 map 草图。线条旁边的数字代表两个站点之间的行程时间:
我的 RDF 代码描述了每个车站及其相邻车站的可用线路和旅行持续时间。乍一看它看起来很多余,但我想在未来包括单向路线(例如公交车),所以我认为第一次尝试就可以了。
RDF(在此处下载文件:http://gopeter.de/misc/metro.rdf)
<?xml version="1.0"?>
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:ex="http://example.com/">
<rdf:Description rdf:about="http://example.com/StopA">
<ex:via rdf:parseType="Resource">
<ex:Stop rdf:resource="http://example.com/StopB" />
<ex:Line rdf:resource="http://example.com/Line1" />
<ex:Duration>2</ex:Duration>
</ex:via>
<ex:via rdf:parseType="Resource">
<ex:Stop rdf:resource="http://example.com/StopB" />
<ex:Line rdf:resource="http://example.com/Line2" />
<ex:Duration>7</ex:Duration>
</ex:via>
<ex:via rdf:parseType="Resource">
<ex:Stop rdf:resource="http://example.com/StopD" />
<ex:Line rdf:resource="http://example.com/Line4" />
<ex:Duration>2</ex:Duration>
</ex:via>
<ex:via rdf:parseType="Resource">
<ex:Stop rdf:resource="http://example.com/StopD" />
<ex:Line rdf:resource="http://example.com/Line2" />
<ex:Duration>6</ex:Duration>
</ex:via>
<ex:via rdf:parseType="Resource">
<ex:Stop rdf:resource="http://example.com/StopE" />
<ex:Line rdf:resource="http://example.com/Line1" />
<ex:Duration>1</ex:Duration>
</ex:via>
<ex:via rdf:parseType="Resource">
<ex:Stop rdf:resource="http://example.com/StopF" />
<ex:Line rdf:resource="http://example.com/Line4" />
<ex:Duration>3</ex:Duration>
</ex:via>
</rdf:Description>
<rdf:Description rdf:about="http://example.com/StopB">
<ex:via rdf:parseType="Resource">
<ex:Stop rdf:resource="http://example.com/StopA" />
<ex:Line rdf:resource="http://example.com/Line1" />
<ex:Duration>2</ex:Duration>
</ex:via>
<ex:via rdf:parseType="Resource">
<ex:Stop rdf:resource="http://example.com/StopA" />
<ex:Line rdf:resource="http://example.com/Line2" />
<ex:Duration>7</ex:Duration>
</ex:via>
<ex:via rdf:parseType="Resource">
<ex:Stop rdf:resource="http://example.com/StopC" />
<ex:Line rdf:resource="http://example.com/Line2" />
<ex:Duration>10</ex:Duration>
</ex:via>
<ex:via rdf:parseType="Resource">
<ex:Stop rdf:resource="http://example.com/StopF" />
<ex:Line rdf:resource="http://example.com/Line3" />
<ex:Duration>2</ex:Duration>
</ex:via>
</rdf:Description>
<rdf:Description rdf:about="http://example.com/StopC">
<ex:via rdf:parseType="Resource">
<ex:Stop rdf:resource="http://example.com/StopB" />
<ex:Line rdf:resource="http://example.com/Line2" />
<ex:Duration>10</ex:Duration>
</ex:via>
</rdf:Description>
<rdf:Description rdf:about="http://example.com/StopD">
<ex:via rdf:parseType="Resource">
<ex:Stop rdf:resource="http://example.com/StopA" />
<ex:Line rdf:resource="http://example.com/Line2" />
<ex:Duration>6</ex:Duration>
</ex:via>
<ex:via rdf:parseType="Resource">
<ex:Stop rdf:resource="http://example.com/StopA" />
<ex:Line rdf:resource="http://example.com/Line4" />
<ex:Duration>2</ex:Duration>
</ex:via>
<ex:via rdf:parseType="Resource">
<ex:Stop rdf:resource="http://example.com/StopF" />
<ex:Line rdf:resource="http://example.com/Line3" />
<ex:Duration>2</ex:Duration>
</ex:via>
</rdf:Description>
<rdf:Description rdf:about="http://example.com/StopE">
<ex:via rdf:parseType="Resource">
<ex:Stop rdf:resource="http://example.com/StopA" />
<ex:Line rdf:resource="http://example.com/Line1" />
<ex:Duration>1</ex:Duration>
</ex:via>
</rdf:Description>
<rdf:Description rdf:about="http://example.com/StopF">
<ex:via rdf:parseType="Resource">
<ex:Stop rdf:resource="http://example.com/StopA" />
<ex:Line rdf:resource="http://example.com/Line4" />
<ex:Duration>3</ex:Duration>
</ex:via>
<ex:via rdf:parseType="Resource">
<ex:Stop rdf:resource="http://example.com/StopB" />
<ex:Line rdf:resource="http://example.com/Line3" />
<ex:Duration>2</ex:Duration>
</ex:via>
<ex:via rdf:parseType="Resource">
<ex:Stop rdf:resource="http://example.com/StopD" />
<ex:Line rdf:resource="http://example.com/Line3" />
<ex:Duration>2</ex:Duration>
</ex:via>
</rdf:Description>
</rdf:RDF>
最佳答案
让我们用更易于阅读的 Turtle 语法(如下)查看您的数据。 StopD 使用 ex:via 属性连接到三个空白节点。这意味着您将获得 ?mid
与 StopD ex:via* ?mid
的四个匹配项。但是,您不会得到更多,因为没有来自具有属性 ex:via 的空白节点的传出链接。这意味着?mid ex:via+ StopC
没有匹配,因为?mid 没有任何传出 ex:via 链接。像 ?mid ex:Stop/ex:via+ StopC
这样的东西会更好,因为 ex:Stop 链接让你从空白节点到另一个站点。
@prefix ex: <http://example.com/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
ex:StopD ex:via [ ex:Duration "6" ;
ex:Line ex:Line2 ;
ex:Stop ex:StopA
] ;
ex:via [ ex:Duration "2" ;
ex:Line ex:Line4 ;
ex:Stop ex:StopA
] ;
ex:via [ ex:Duration "2" ;
ex:Line ex:Line3 ;
ex:Stop ex:StopF
] .
即使您可以将附加项 ex:Stop 添加到您的属性路径中,但这仍然不会按照您想要的方式计算距离,因为您不会被限制在一行中。即,您将在多条路径上获得优势。
我重新创建了一个更简单的场景:
@prefix : <https://stackoverflow.com/q/24538144/1281433/> .
# B
# * *
# 2 * * 4
# * *
# * *
# A +++++++++ C
# 3
#
# *** line 1
# +++ line 2
:StopA a :Stop ; :toLink :Link1 , :Link3 .
:StopB a :Stop ; :toLink :Link2 .
:StopC a :Stop .
:Link1 :hasDuration 2 ;
:toStop :StopB ;
:Line1Self :Link1 .
:Link2 :hasDuration 4 ;
:toStop :StopC ;
:Line1Self :Link2 .
:Link3 :hasDuration 3 ;
:toStop :StopC ;
:Line2Self :Link3 .
每个站点都可以通过 :toStop 连接到任意数量的链接。每个链接的行都用 rolification property 表示为线。例如,link2 line1self link2
表示 link2 在 line1 上。这意味着我们使用属性路径“保持在正确的线上”。然后,要查找第 1 行从 stopA 到 stopB 的行程持续时间,您可以使用如下查询:
prefix : <https://stackoverflow.com/q/24538144/1281433/>
select (sum(?duration) as ?length) where {
:StopA :toLink/(:toStop/:toLink)*/:Line1Self ?link .
?link :hasDuration ?duration ;
:toStop/(:toLink/:Line1Self/:toStop)* :StopC .
}
----------
| length |
==========
| 6 |
----------
要检查不同的行,您只需更改 :LineXSelf 属性。例如,对于第 2 行:
prefix : <https://stackoverflow.com/q/24538144/1281433/>
select (sum(?duration) as ?length) where {
:StopA :toLink/(:toStop/:toLink)*/:Line2Self ?link .
?link :hasDuration ?duration ;
:toStop/(:toLink/:Line2Self/:toStop)* :StopC .
}
----------
| length |
==========
| 3 |
----------
不过,这种方法有一些局限性。属性路径是您进行任意深度查询的唯一选择,但您不能在属性路径中使用变量,这意味着您不能执行以下操作来获取每条线上的距离:
prefix : <https://stackoverflow.com/q/24538144/1281433/>
select ?line (sum(?duration) as ?length) where {
values ?line { :Line1Self :Line2Self }
:StopA :toLink/(:toStop/:toLink)*/?line ?link .
?link :hasDuration ?duration ;
:toStop/(:toLink/?line/:toStop)* :StopC .
}
group by ?line
关于xml - 如何使用 SPARQL 查询两个事物之间的距离,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24538144/
我在网上搜索但没有找到任何合适的文章解释如何使用 javascript 使用 WCF 服务,尤其是 WebScriptEndpoint。 任何人都可以对此给出任何指导吗? 谢谢 最佳答案 这是一篇关于
我正在编写一个将运行 Linux 命令的 C 程序,例如: cat/etc/passwd | grep 列表 |剪切-c 1-5 我没有任何结果 *这里 parent 等待第一个 child (chi
所以我正在尝试处理文件上传,然后将该文件作为二进制文件存储到数据库中。在我存储它之后,我尝试在给定的 URL 上提供文件。我似乎找不到适合这里的方法。我需要使用数据库,因为我使用 Google 应用引
我正在尝试制作一个宏,将下面的公式添加到单元格中,然后将其拖到整个列中并在 H 列中复制相同的公式 我想在 F 和 H 列中输入公式的数据 Range("F1").formula = "=IF(ISE
问题类似于this one ,但我想使用 OperatorPrecedenceParser 解析带有函数应用程序的表达式在 FParsec . 这是我的 AST: type Expression =
我想通过使用 sequelize 和 node.js 将这个查询更改为代码取决于在哪里 select COUNT(gender) as genderCount from customers where
我正在使用GNU bash,版本5.0.3(1)-发行版(x86_64-pc-linux-gnu),我想知道为什么简单的赋值语句会出现语法错误: #/bin/bash var1=/tmp
这里,为什么我的代码在 IE 中不起作用。我的代码适用于所有浏览器。没有问题。但是当我在 IE 上运行我的项目时,它发现错误。 而且我的 jquery 类和 insertadjacentHTMl 也不
我正在尝试更改标签的innerHTML。我无权访问该表单,因此无法编辑 HTML。标签具有的唯一标识符是“for”属性。 这是输入和标签的结构:
我有一个页面,我可以在其中返回用户帖子,可以使用一些 jquery 代码对这些帖子进行即时评论,在发布新评论后,我在帖子下插入新评论以及删除 按钮。问题是 Delete 按钮在新插入的元素上不起作用,
我有一个大约有 20 列的“管道分隔”文件。我只想使用 sha1sum 散列第一列,它是一个数字,如帐号,并按原样返回其余列。 使用 awk 或 sed 执行此操作的最佳方法是什么? Accounti
我需要将以下内容插入到我的表中...我的用户表有五列 id、用户名、密码、名称、条目。 (我还没有提交任何东西到条目中,我稍后会使用 php 来做)但由于某种原因我不断收到这个错误:#1054 - U
所以我试图有一个输入字段,我可以在其中输入任何字符,但然后将输入的值小写,删除任何非字母数字字符,留下“。”而不是空格。 例如,如果我输入: 地球的 70% 是水,-!*#$^^ & 30% 土地 输
我正在尝试做一些我认为非常简单的事情,但出于某种原因我没有得到想要的结果?我是 javascript 的新手,但对 java 有经验,所以我相信我没有使用某种正确的规则。 这是一个获取输入值、检查选择
我想使用 angularjs 从 mysql 数据库加载数据。 这就是应用程序的工作原理;用户登录,他们的用户名存储在 cookie 中。该用户名显示在主页上 我想获取这个值并通过 angularjs
我正在使用 autoLayout,我想在 UITableViewCell 上放置一个 UIlabel,它应该始终位于单元格的右侧和右侧的中心。 这就是我想要实现的目标 所以在这里你可以看到我正在谈论的
我需要与 MySql 等效的 elasticsearch 查询。我的 sql 查询: SELECT DISTINCT t.product_id AS id FROM tbl_sup_price t
我正在实现代码以使用 JSON。 func setup() { if let flickrURL = NSURL(string: "https://api.flickr.com/
我尝试使用for循环声明变量,然后测试cols和rols是否相同。如果是,它将运行递归函数。但是,我在 javascript 中执行 do 时遇到问题。有人可以帮忙吗? 现在,在比较 col.1 和
我举了一个我正在处理的问题的简短示例。 HTML代码: 1 2 3 CSS 代码: .BB a:hover{ color: #000; } .BB > li:after {
我是一名优秀的程序员,十分优秀!