Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SPARQL从类或单个对象获取所有属性_Sparql_Owl_Ontology - Fatal编程技术网

SPARQL从类或单个对象获取所有属性

SPARQL从类或单个对象获取所有属性,sparql,owl,ontology,Sparql,Owl,Ontology,我想做的是从Individual1或类中获取属性列表, 从“某物”获取所有属性 结果应该是这样的(对于机密数据): 高 中庸的 中庸的 我认为查询是这样的(但是值的格式不好,有些属性不是像“type property”这样的importart): 前缀css: 选择不同的属性值 在哪里{ css:机密数据?属性?值。 } 更新问题的答案(关于个人的查询) 用完整的样本数据回答问题要容易得多。如果我们将您提供的数据与适当的命名空间声明捆绑在一起,我们最终会得到如下结果: 中庸的 中庸的 高

我想做的是从Individual1或类中获取属性列表, 从“某物”获取所有属性 结果应该是这样的(对于机密数据):


高
中庸的
中庸的
我认为查询是这样的(但是值的格式不好,有些属性不是像“type property”这样的importart):

前缀css:
选择不同的属性值
在哪里{
css:机密数据?属性?值。
}
更新问题的答案(关于个人的查询) 用完整的样本数据回答问题要容易得多。如果我们将您提供的数据与适当的命名空间声明捆绑在一起,我们最终会得到如下结果:


中庸的
中庸的
高
在海龟序列化中查看这一点通常很有帮助,因为它看起来更像查询。不过,数据是相同的,当然,查询将针对两种序列化方式中的数据运行

@prefix :      <http://stackoverflow.com/q/23223447/1281433/> .
@prefix owl:   <http://www.w3.org/2002/07/owl#> .
@prefix rdf:   <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .

:Secret_Data  a  owl:NamedIndividual , :Data ;
        :Asset_has_Availability_Importance
                "Moderate"^^<http://www.w3.org/2001/XMLSchema#string> ;
        :Asset_has_Confidentiality_Importance
                "High"^^<http://www.w3.org/2001/XMLSchema#string> ;
        :Asset_has_Integrity_Importance
                "Moderate"^^<http://www.w3.org/2001/XMLSchema#string> ;
        :Asset_threatenedBy_ThreatEvent
                :Integrity_loss_by_corrupting_critital_data , :Obtain_unauthorized_access , :Disclosure_of_sensitive_information , :Compromise_sensitive_information , :Exploit_exposed_unauthorized_information .
如果您不想在其中输入
rdf:type
,可以使用
filter?property!=rdf:type
,或者如果有多个属性要排除,则
过滤器(?属性不在(rdf:type…)中)

prefix :    <http://stackoverflow.com/q/23223447/1281433/>
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix owl: <http://www.w3.org/2002/07/owl#>
prefix xsd: <http://www.w3.org/2001/XMLSchema#>

select distinct ?property ?value where {
  :Secret_Data ?property ?value .
  filter ( ?property not in ( rdf:type ) )
}
对原始问题的回答(关于类的查询) 在问题的原始版本中,您给出了本体的这张图像,并要求获得在其之后的结果:

| numberChapters  | 1 |
| numberPages     | 5 |

在该本体的RDF/XML序列化中(从问题中删除),Psicology类的描述如下:


心灵学
5.
1.
或者用更容易理解的海龟符号:


猫头鹰:类;
rdfs:标签为“心灵学”;
rdfs:子类;
rdfs:子类[a owl:限制;
猫头鹰:hasvalue5;
owl:onProperty
] ;
rdfs:子类[a owl:限制;
猫头鹰:hasvalue1;
owl:onProperty
说Psicology(顺便说一句,它通常在英语中拼写为Psychology)是一类事物的子类,这些事物的属性numPages值为5,属性numChapters值为1。Psicology也是Library的一个子类。(这应该是Library吗?)

这些对我来说似乎是奇怪的公理,我想知道是否存在某种建模错误。我不确定心灵学是什么,但你是说对于任何心灵学p,都是numPages(p,5)和numChapters(p,1)。这真的是你想要做的吗

无论如何,给定您的数据,我们可以检索您想要的结果。查看海龟序列化非常有用,因为它与SPARQL查询语法非常相似。您想要的查询是:

prefix owl:   <http://www.w3.org/2002/07/owl#> 
prefix :      <http://webprotege.stanford.edu/project/Bnag2Z5E4j78tB27NnLq1L#> 
prefix rdfs:  <http://www.w3.org/2000/01/rdf-schema#> 

select ?property ?value where {
  ?class rdfs:label "Psicology" ;
         rdfs:subClassOf [ owl:hasValue ?value ; 
                           owl:onProperty [ rdfs:label ?property ] ] .
}

请你展示一下实际的本体,好吗?你所展示的并没有多大意义。类、子类1和子类2表明你试图展示一个类层次结构,但属性不是类,也不“属于”类(方法可能属于单一分派面向对象编程语言中的类的方式)。请显示您实际获得的数据,并告诉我们您希望得到的结果。好的,我发布了一个图像:d这很有帮助,但您能否发布实际的本体,以便web有一些可查询的内容?好的,我粘贴本体。您上次编辑完全改变了问题的性质。之前,您一直在询问获取的属性一个类的限制超类;现在你问的是如何获取一个个体的属性。我的OWL看起来很奇怪,因为它不是海龟符号,而是RDF/XML,但我需要在这个“符号”中运行查询。我将post更改为真正的“本体”@angel.cazares RDF可以以多种不同的格式序列化。RDF/XML是一种格式,Turtle是另一种格式。不过,它们是同一个RDF图的序列化。我展示了Turtle序列化,因为它更接近SPARQL语法。查询针对任何一种格式的数据运行。我使用的c#dll只与RD一起运行F/XML sintaxis:(@angel.cazares)您不必更改数据。我只是以不同的格式显示,因为这样可以更容易地确定查询应该是什么样子。我提供的SPARQL查询可以与本体的RDF/XML序列化配合使用。
---------------------------------------------------------------------------------------
| property                              | value                                       |
=======================================================================================
| rdf:type                              | owl:NamedIndividual                         |
| :Asset_has_Availability_Importance    | "Moderate"^^xsd:string                      |
| rdf:type                              | :Data                                       |
| :Asset_threatenedBy_ThreatEvent       | :Integrity_loss_by_corrupting_critital_data |
| :Asset_has_Integrity_Importance       | "Moderate"^^xsd:string                      |
| :Asset_threatenedBy_ThreatEvent       | :Obtain_unauthorized_access                 |
| :Asset_threatenedBy_ThreatEvent       | :Disclosure_of_sensitive_information        |
| :Asset_threatenedBy_ThreatEvent       | :Compromise_sensitive_information           |
| :Asset_has_Confidentiality_Importance | "High"^^xsd:string                          |
| :Asset_threatenedBy_ThreatEvent       | :Exploit_exposed_unauthorized_information   |
---------------------------------------------------------------------------------------
prefix :    <http://stackoverflow.com/q/23223447/1281433/>
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix owl: <http://www.w3.org/2002/07/owl#>
prefix xsd: <http://www.w3.org/2001/XMLSchema#>

select distinct ?property ?value where {
  :Secret_Data ?property ?value .
  filter ( ?property not in ( rdf:type ) )
}
---------------------------------------------------------------------------------------
| property                              | value                                       |
=======================================================================================
| :Asset_has_Availability_Importance    | "Moderate"^^xsd:string                      |
| :Asset_threatenedBy_ThreatEvent       | :Integrity_loss_by_corrupting_critital_data |
| :Asset_has_Integrity_Importance       | "Moderate"^^xsd:string                      |
| :Asset_threatenedBy_ThreatEvent       | :Obtain_unauthorized_access                 |
| :Asset_threatenedBy_ThreatEvent       | :Disclosure_of_sensitive_information        |
| :Asset_threatenedBy_ThreatEvent       | :Compromise_sensitive_information           |
| :Asset_has_Confidentiality_Importance | "High"^^xsd:string                          |
| :Asset_threatenedBy_ThreatEvent       | :Exploit_exposed_unauthorized_information   |
---------------------------------------------------------------------------------------
| numberChapters  | 1 |
| numberPages     | 5 |
prefix owl:   <http://www.w3.org/2002/07/owl#> 
prefix :      <http://webprotege.stanford.edu/project/Bnag2Z5E4j78tB27NnLq1L#> 
prefix rdfs:  <http://www.w3.org/2000/01/rdf-schema#> 

select ?property ?value where {
  ?class rdfs:label "Psicology" ;
         rdfs:subClassOf [ owl:hasValue ?value ; 
                           owl:onProperty [ rdfs:label ?property ] ] .
}
-------------------------
| property      | value |
=========================
| "numChapters" | 1     |
| "numPages"    | 5     |
-------------------------