- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
从一个包含多种化合物声明的 RDF 文件中,我想为每种化合物创建一个 RDF 文件。
为了做到这一点,我开始寻找一个 SPARQL 查询,它可以隔离链接到某个 URL 的所有三元组,无论中间有多少节点。
我从一个非常有趣的 SPARQL 查询 ( https://stackoverflow.com/a/33290642/5433896 ) 开始,这样它会(希望)返回与我的数据集中的化学化合物 :d1
相关的所有三元组,但不是关于另一个化合物:d10
:
CONSTRUCT {
:d1 ?prop ?val .
?child ?childProp ?childPropVal .
?someSubj ?incomingChildProp ?child .
}
WHERE {
:d1 ?prop ?val ;
(:overrides|!:overrides)+ ?child .
?child ?childProp ?childPropVal.
?someSubj ?incomingChildProp ?child.
}
但是,当我在简化的测试用例(python)上运行此命令时:
rdf = """<?xml version="1.0"?>
<!DOCTYPE rdf:RDF [
<!ENTITY owl "http://www.w3.org/2002/07/owl#" >
<!ENTITY owl11 "http://www.w3.org/2006/12/owl11#" >
<!ENTITY xsd "http://www.w3.org/2001/XMLSchema#" >
<!ENTITY owl11xml "http://www.w3.org/2006/12/owl11-xml#" >
<!ENTITY carcinogenesis "http://dl-learner.org/carcinogenesis#" >
<!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#" >
<!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#" >
]>
<rdf:RDF xmlns="http://dl-learner.org/carcinogenesis#"
xml:base="http://dl-learner.org/carcinogenesis"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:owl11="http://www.w3.org/2006/12/owl11#"
xmlns:carcinogenesis="http://dl-learner.org/carcinogenesis#"
xmlns:owl11xml="http://www.w3.org/2006/12/owl11-xml#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<owl:Ontology rdf:about=""/>
<owl:ObjectProperty rdf:about="#hasAtom">
<rdfs:domain rdf:resource="#Compound"/>
<rdfs:range rdf:resource="#Atom"/>
</owl:ObjectProperty>
<owl:ObjectProperty rdf:about="#hasBond">
<rdfs:domain rdf:resource="#Compound"/>
<rdfs:range rdf:resource="#Bond"/>
</owl:ObjectProperty>
<owl:ObjectProperty rdf:about="#hasStructure">
<rdfs:domain rdf:resource="#Compound"/>
<rdfs:range rdf:resource="#Structure"/>
</owl:ObjectProperty>
<owl:ObjectProperty rdf:about="#inBond">
<rdfs:range rdf:resource="#Atom"/>
<rdfs:domain rdf:resource="#Bond"/>
</owl:ObjectProperty>
<owl:DatatypeProperty rdf:about="#charge">
<rdfs:domain rdf:resource="#Atom"/>
<rdfs:range rdf:resource="&xsd;double"/>
</owl:DatatypeProperty>
<owl:DatatypeProperty rdf:about="#isMutagenic">
<rdfs:domain rdf:resource="#Compound"/>
<rdfs:range rdf:resource="&xsd;boolean"/>
</owl:DatatypeProperty>
<owl:Class rdf:about="#Atom"/>
<owl:Class rdf:about="#Bond">
<owl:disjointWith rdf:resource="#Structure"/>
<owl:disjointWith rdf:resource="#Atom"/>
</owl:Class>
<owl:Class rdf:about="#Bond-7">
<rdfs:subClassOf rdf:resource="#Bond"/>
</owl:Class>
<owl:Class rdf:about="#Carbon-22">
<rdfs:subClassOf rdf:resource="#Carbon"/>
</owl:Class>
<owl:Class rdf:about="#Compound">
<owl:disjointWith rdf:resource="#Structure"/>
<owl:disjointWith rdf:resource="#Atom"/>
<owl:disjointWith rdf:resource="#Bond"/>
</owl:Class>
<owl:Class rdf:about="#Six_ring">
<rdfs:subClassOf rdf:resource="#Ring"/>
</owl:Class>
<owl:Class rdf:about="#Ring">
<rdfs:subClassOf rdf:resource="#Structure"/>
</owl:Class>
<owl:Class rdf:about="#Structure">
<owl:disjointWith rdf:resource="#Atom"/>
</owl:Class>
<Compound rdf:about="#d1">
<hasBond rdf:resource="#bond1"/>
<hasAtom rdf:resource="#d1_2"/>
<hasAtom rdf:resource="#d1_3"/>
<hasStructure rdf:resource="#six_ring-1"/>
<isMutagenic rdf:datatype="&xsd;boolean">false</isMutagenic>
</Compound>
<Bond-7 rdf:about="#bond1">
<inBond rdf:resource="#d1_3"/>
<inBond rdf:resource="#d1_2"/>
</Bond-7>
<Carbon-22 rdf:about="#d1_2">
<charge rdf:datatype="&xsd;double">-0.133</charge>
</Carbon-22>
<Carbon-22 rdf:about="#d1_3">
<charge rdf:datatype="&xsd;double">-0.0030</charge>
</Carbon-22>
<Six_ring rdf:about="#six_ring-1"/>
<Compound rdf:about="#d10">
<hasBond rdf:resource="#bond40"/>
<hasAtom rdf:resource="#d10_12"/>
<hasAtom rdf:resource="#d10_13"/>
<isMutagenic rdf:datatype="&xsd;boolean">false</isMutagenic>
<hasStructure rdf:resource="#six_ring-9"/>
</Compound>
<Bond-1 rdf:about="#bond40">
<inBond rdf:resource="#d10_12"/>
<inBond rdf:resource="#d10_13"/>
</Bond-1>
<Six_ring rdf:about="#six_ring-9"/>
<Nitrogen-32 rdf:about="#d10_12">
<charge rdf:datatype="&xsd;double">-0.313</charge>
</Nitrogen-32>
<Nitrogen-32 rdf:about="#d10_13">
<charge rdf:datatype="&xsd;double">-0.313</charge>
</Nitrogen-32>
</rdf:RDF>
"""
# Inspired by https://stackoverflow.com/a/33290642/5433896:
sparql_query = """CONSTRUCT {
:d1 ?prop ?val .
?child ?childProp ?childPropVal .
?someSubj ?incomingChildProp ?child .
}
WHERE {
:d1 ?prop ?val ;
(:overrides|!:overrides)+ ?child .
?child ?childProp ?childPropVal.
?someSubj ?incomingChildProp ?child.
}
"""
# Trying this query out:
import rdflib
import logging
logger = logging.getLogger()
logger.setLevel("INFO")
graph = rdflib.Graph()
graph.parse(data=rdf, format='xml')
result = graph.query(sparql_query)
for s, p, o in result:
print(s, p, o)
if s.endswith('#d10') or s.endswith('#bond40') or s.endswith('#six_ring-9') or s.endswith('#d10_12') or s.endswith('#d10_13'):
logging.error('This triple should not be in the results! => {0} {1} {2}.'.format(s, p, o))
我遇到了两个我想避免的错误:
ERROR:root:This triple should not be in the results! => http://dl-learner.org/carcinogenesis#six_ring-9 http://www.w3.org/1999/02/22-rdf-syntax-ns#type http://dl-learner.org/carcinogenesis#Six_ring.
ERROR:root:This triple should not be in the results! => http://dl-learner.org/carcinogenesis#d10 http://www.w3.org/1999/02/22-rdf-syntax-ns#type http://dl-learner.org/carcinogenesis#Compound.
最佳答案
在添加我已经注意到的额外内容时,我找到了这个问题的答案。
由于 :d1 rdf:type :Compound
和 :d10 rdf:type :Compound
,实际上有一条从 :d1
到:d10
因此关于 :d10
的三元组也最终出现在我的查询结果中 - 这当然不是我想要的。
查看查询,我认为添加一个附加约束是有意义的,即 ?child
不得为 :d10
。并且,思考https://stackoverflow.com/a/33290642/5433896的海报的方式解释了他的查询,我还应该排除 ?someSubj
或 ?childPropVal
可以是 :d10
:
CONSTRUCT {
:d1 ?prop ?val .
?child ?childProp ?childPropVal .
?someSubj ?incomingChildProp ?child .
}
WHERE {
:d1 (:overrides|!:overrides)+ ?child .
?child ?childProp ?childPropVal.
?someSubj ?incomingChildProp ?child.
FILTER (?child != :d10)
FILTER (?childPropVal != :d10)
FILTER (?someSubj != :d10)
}
这从我的查询结果中删除了 :d10
。太棒了!
但是错误ERROR:root:This Triple不应该出现在结果中! => http://dl-learner.org/carcinogenesis#six_ring-9 http://www.w3.org/1999/02/22-rdf-syntax-ns#type http://dl-learner.org/carcinogenesis#Six_ring。
仍然存在。
我删除了一些可能导致此问题的三元组,发现三元组 { Six_ring rdf:about="#six_ring-9"}
是仍然存在 # 的原因查询结果中的 Six_ring-9
。因此,再次,rdf:type
(隐含在 rdf:about
中)导致了问题。
理想情况下,我们需要在 SPARQL 中描述我们有兴趣知道链接到 :d1
的对象的 rdf:types
是什么(例如 :Compound
、:Six_Ring
),但不包括链接到这些对象类型的其他对象。这将解决我们最初通过查询检测到的两个问题。
所以这个查询解决了这个问题:
CONSTRUCT {
:d1 ?prop ?val .
?child ?childProp ?childPropVal .
?someSubj ?incomingChildProp ?child .
}
WHERE {
:d1 (:overrides|!:overrides)+ ?child .
?child ?childProp ?childPropVal.
?someSubj ?incomingChildProp ?child.
FILTER (?incomingChildProp != rdf:type)
}
关于python - SPARQL:查询链接到一个 URL 但不链接到另一个 URL 的所有三元组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56639490/
我想知道javascript中if的简码是什么? 就像在 PHP 中一样: $res = ($x > $y)? $x: $y; 它在 JavaScript 中的转换是什么? 最佳答案 在 javasc
请问为什么下面的代码会报错? 错误: numberOne > numberTwo ? return "true" : return "false"; ^
在我的代码中,我检查系统函数是否等于零,如果是我返回另一个值,如果不是,我返回测试值。 (class.verylongfunc(arg, arg) == 0) ? othervar : cla
在 PHP 中,有没有一种方法可以使用三元条件连接两个字符串? 当我尝试这样做时,我得到的只是 else 而不是所需的 something else。 最佳答案 像这样把整个三元运算符放在方括号中:
似乎在三元运算符中存在某种类型混淆。我知道这已在其他 SO 线程中得到解决,但它始终与可空值有关。另外,就我而言,我真的只是在寻找更好的方法。 我希望能够使用 proc.Parameters[PARA
有没有办法在不进行赋值或伪造赋值的情况下进行 java 三元运算? 我喜欢在执行一堆 if/then/else 时的简洁三元代码。 我希望能够基于 boolean 代数语句调用两个 void 函数之一
我正在使用 XSLT 和 XML 来生成输出文档。 我在数据中拥有的(以我无法控制的 XML 形式)如下: 4 我需要在计算中使用这些。我看到为这些提供默认值需要对文档执行转换以提供一个有点冗长的
这个问题已经有答案了: Ternary operators in JavaScript without an "else" (13 个回答) 已关闭 4 年前。 我一直使用这样的三元表达式,但我不喜欢
我在 VB.NET 中发现了一个可以轻松重现的简单错误: Dim pDate As Date? Dim pString As String = "" ' works fine as expected
所以,我有这段代码,它实际上有效: (散列将是这样的对象:{"bob"=> "12, "Roger"=> "15", etc},并且 isGood(key) 是调用函数 isGood ,如果玩家好或坏
是否有以下 JavaScript bool 三元表达式的简写语法: var foo = (expression) ? true : false 最佳答案 当然,您只想将表达式转换为 bool 值: v
在 Java 中,如果我在常规 if 中使用三元 if 运算符,例如: if ((x > y - z) ? true : callLongWaitedMethod(many, parameteres)
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它. 关闭 7 年前。 Improve
var test = "Hello World!"; 在 Java 10+ 中,上面的代码片段可以编译,test 在编译时被推断为 String。 但是,我们可以使用条件(三元)运算符来返回不同的类型
嗨,我尝试在渲染内部使用三元条件,但遇到一些错误,这是我的代码: render() { return ( (this.emai
这里我有以下 JavaScript 代码,带有两个值。 var w = $("#id1").val(); var h = $("#id2").val(); (w == h) ? (w=350 , h
我一直想知道如何用 C++ 兼容语言编写 "A ? B : C" 语法。 我认为它的工作方式类似于:(伪代码) If A > B C = A Else C = B 有没有经验丰富的 C++
考虑两个 vector ,A 和 B,大小为 n,7 <= n <= 23 . A 和B 都只包含-1、0 和1。 我需要一个计算A 和B 内积的快速算法。 到目前为止,我一直在考虑使用以下编码将
按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
如果您一开始就讨厌三元条件运算符,则无需回复 ;) 我经常看到它与赋值表达式一起使用,例如: var foo = (some_condition) ? then_code : else_code; 但
我是一名优秀的程序员,十分优秀!