【问题标题】:SPARQL Get all the properties from a Class or an IndividualSPARQL 获取类或个体的所有属性
【发布时间】:2014-04-22 15:10:56
【问题描述】:

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

| Asset_has_Confidentiality_Importance | High                                       |
| Asset_has_Availability_Importance....| Moderate                                   |
| Asset_has_Integrity_Importance.......| Moderate                                   |
| Asset_threatenedBy_ThreatEvent.......| Compromise_sensitive_information           |
| Asset_threatenedBy_ThreatEvent.......| Disclosure_of_sensitive_information        |
| Asset_threatenedBy_ThreatEvent.......| Exploit_exposed_unauthorized_information   |
| Asset_threatenedBy_ThreatEvent.......| Integrity_loss_by_corrupting_critital_data |
<owl:NamedIndividual rdf:about="&securityOntology_ITESM_UC3M;Secret_Data">
    <rdf:type rdf:resource="&securityOntology_ITESM_UC3M;Data"/>
    <Asset_has_Confidentiality_Importance rdf:datatype="&xsd;string">High</Asset_has_Confidentiality_Importance>
    <Asset_has_Availability_Importance rdf:datatype="&xsd;string">Moderate</Asset_has_Availability_Importance>
    <Asset_has_Integrity_Importance rdf:datatype="&xsd;string">Moderate</Asset_has_Integrity_Importance>
    <Asset_threatenedBy_ThreatEvent rdf:resource="&securityOntology_ITESM_UC3M;Compromise_sensitive_information"/>
    <Asset_threatenedBy_ThreatEvent rdf:resource="&securityOntology_ITESM_UC3M;Disclosure_of_sensitive_information"/>
    <Asset_threatenedBy_ThreatEvent rdf:resource="&securityOntology_ITESM_UC3M;Exploit_exposed_unauthorized_information"/>
    <Asset_threatenedBy_ThreatEvent rdf:resource="&securityOntology_ITESM_UC3M;Integrity_loss_by_corrupting_critital_data"/>
    <Asset_threatenedBy_ThreatEvent rdf:resource="&securityOntology_ITESM_UC3M;Obtain_unauthorized_access"/>
</owl:NamedIndividual>

我认为查询是这样的,(但是值的格式不正确,并且某些属性并不像“类型属性”那样重要):

PREFIX css:<http://www.semanticweb.org/evalues/ontologies/2014/3/securityOntology_ITESM_UC3M#>

SELECT DISTINCT ?property ?value
WHERE {
  css:Secret_Data ?property ?value.
}

【问题讨论】:

  • 你能展示一下实际的本体吗?您所展示的内容没有多大意义。 Class、SubClass1 和 SubClass2 建议您尝试显示类层次结构,但 Properties 不是类,它们也不“属于”类(方法可能属于单调度对象中的类的方式面向编程语言)。请展示您实际获得的数据,并告诉我们您想要的结果。
  • 好的,我贴了一张图片:D
  • 这有帮助,但是您能否发布实际的本体,以便网络可以查询?
  • 好的,我贴本体
  • 您的最后一次编辑完全改变了问题的性质。之前,您一直在询问获取类的限制超类的属性;现在你问的是获取个人的属性。

标签: sparql owl ontology


【解决方案1】:

回答更新的问题(关于个人的查询)

完整样本数据更容易回答问题。如果我们将您提供的数据与适当的命名空间声明捆绑在一起,我们最终会得到这样的结果:

<rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:owl="http://www.w3.org/2002/07/owl#"
    xmlns="http://stackoverflow.com/q/23223447/1281433/">
  <owl:NamedIndividual rdf:about="http://stackoverflow.com/q/23223447/1281433/Secret_Data">
    <Asset_has_Availability_Importance rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
    >Moderate</Asset_has_Availability_Importance>
    <rdf:type rdf:resource="http://stackoverflow.com/q/23223447/1281433/Data"/>
    <Asset_threatenedBy_ThreatEvent rdf:resource="http://stackoverflow.com/q/23223447/1281433/Integrity_loss_by_corrupting_critital_data"/>
    <Asset_has_Integrity_Importance rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
    >Moderate</Asset_has_Integrity_Importance>
    <Asset_threatenedBy_ThreatEvent rdf:resource="http://stackoverflow.com/q/23223447/1281433/Obtain_unauthorized_access"/>
    <Asset_threatenedBy_ThreatEvent rdf:resource="http://stackoverflow.com/q/23223447/1281433/Disclosure_of_sensitive_information"/>
    <Asset_threatenedBy_ThreatEvent rdf:resource="http://stackoverflow.com/q/23223447/1281433/Compromise_sensitive_information"/>
    <Asset_has_Confidentiality_Importance rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
    >High</Asset_has_Confidentiality_Importance>
    <Asset_threatenedBy_ThreatEvent rdf:resource="http://stackoverflow.com/q/23223447/1281433/Exploit_exposed_unauthorized_information"/>
  </owl:NamedIndividual>
</rdf:RDF>

在 Turtle 序列化中查看它通常很有帮助,因为它看起来更像查询。但是数据是相同的,当然,查询将针对任一序列化中的数据运行。

@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 .

您可以使用如下查询:

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 .
}
---------------------------------------------------------------------------------------
| 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   |
---------------------------------------------------------------------------------------

如果您不想在其中使用rdf:type,则可以使用filter ?property != rdf:type,或者如果您要排除多个属性,请使用filter ( ?property NOT IN ( 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 ) )
}
---------------------------------------------------------------------------------------
| 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 |

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

<owl:Class rdf:about="http://webprotege.stanford.edu/RiMIUJzVuVHCr4Ke4TkFwX">
    <rdfs:label>Psicology</rdfs:label>
    <rdfs:subClassOf rdf:resource="http://webprotege.stanford.edu/RDHbMG5sh4tyJ6ZoHwxLBHk"/>
    <rdfs:subClassOf>
        <owl:Restriction>
            <owl:onProperty rdf:resource="http://webprotege.stanford.edu/R9DdxIZDrtXApiHoBJ6NmAy"/>
            <owl:hasValue rdf:datatype="http://www.w3.org/2001/XMLSchema#integer">5</owl:hasValue>
        </owl:Restriction>
    </rdfs:subClassOf>
    <rdfs:subClassOf>
        <owl:Restriction>
            <owl:onProperty rdf:resource="http://webprotege.stanford.edu/R8WDOefPWzIoTChbjV31ela"/>
            <owl:hasValue rdf:datatype="http://www.w3.org/2001/XMLSchema#integer">1</owl:hasValue>
        </owl:Restriction>
    </rdfs:subClassOf>
</owl:Class>

或者用更易读的 Turtle 表示法:

<http://webprotege.stanford.edu/RiMIUJzVuVHCr4Ke4TkFwX>
        a                owl:Class ;
        rdfs:label       "Psicology" ;
        rdfs:subClassOf  <http://webprotege.stanford.edu/RDHbMG5sh4tyJ6ZoHwxLBHk> ;
        rdfs:subClassOf  [ a               owl:Restriction ;
                           owl:hasValue    5 ;
                           owl:onProperty  <http://webprotege.stanford.edu/R9DdxIZDrtXApiHoBJ6NmAy>
                         ] ;
        rdfs:subClassOf  [ a               owl:Restriction ;
                           owl:hasValue    1 ;
                           owl:onProperty  <http://webprotege.stanford.edu/R8WDOefPWzIoTChbjV31ela>

说,Psicology(顺便说一下,通常在英语中拼写为 Psychology)是属性 numPages 的值为 5 和属性 numChapters 的值为 1 的事物类别的子类。心理学也是 Libray 的一个子类。 (这应该是图书馆吗?)

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

无论如何,根据您的数据,我们可以检索您想要的结果。查看 Turtle 序列化很有用,因为它与 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 ] ] .
}
-------------------------
| property      | value |
=========================
| "numChapters" | 1     |
| "numPages"    | 5     |
-------------------------

【讨论】:

  • 我的 OWL 看起来很奇怪,因为它不是海龟符号,而是 RDF/XML,但我需要在这个“符号”中运行查询我将帖子更改为真正的“本体”跨度>
  • @angel.cazares RDF 可以以多种不同的格式进行序列化。 RDF/XML 是其中之一;乌龟是另一个。它们是 same RDF 图的序列化。我展示了 Turtle 序列化,因为它更接近 SPARQL 语法。查询针对任一格式的数据运行。
  • 我正在为 c# 使用一个 dll,它只与 RDF/XML sintaxis 一起运行:(
  • @angel.cazares 您不必更改数据。我只以不同的格式显示,因为这样更容易计算查询应该是什么样子。我提供的 SPARQL 查询可以很好地与您的本体的 RDF/XML 序列化配合使用。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-11-24
  • 2021-05-17
  • 1970-01-01
  • 2011-10-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多