SPARQL从类或个人获取所有属性 [英] SPARQL Get all the properties from a Class or an Individual

查看:87
本文介绍了SPARQL从类或个人获取所有属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

What I want to do is to get the property list from the Individual1 or from a class, Get all properties from "something" The result should be something like this (for 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>

我认为查询是这样的(但该值的格式设置不正确,并且某些属性不是importart之类的类型属性"):

I think the query is something like this, (But the value is not well formatted, and some properties are not importart like "type property"):

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

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

推荐答案

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

使用 complete 示例数据回答问题要容易得多.如果我们使用适当的名称空间声明将您提供的数据捆绑在一起,那么最终结果将是这样:

Answer to updated question (a query about individuals)

It's much easier to answer question with complete sample data. If we bundle up the data that you've given with appropriate namespace declarations, we end up with something like this:

<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序列化中查看此内容通常会很有帮助,因为它看起来更像查询.数据是一样的,当然,查询将以序列化方式针对数据进行.

It's often helpful to view this in Turtle serialization, since it will look more like the query. The data is the same though, and the query will run against the data in either serialization, of course.

@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 … ) ):

If you don't want rdf:type in there, you could use filter ?property != rdf:type, or if there are multiple properties that you want to exclude, 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   |
---------------------------------------------------------------------------------------

原始问题的答案(有关类的查询)

在问题的原始版本中,您给出了本体的图像,并要求其后的结果:

Answer to the original question (a query about classes)

In the original version of the question, you gave this image of your ontology and asked for results that are after it:

| numberChapters  | 1 |
| numberPages     | 5 |

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

In the RDF/XML serialization of that ontology (since removed from the question), the description of the Psicology class was as follows:

<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表示法:

or in the more human-readable Turtle notation:

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

表示,心理学(通常用英语拼写为Psychology)是属性numPages的值为5且属性numChapters的值为1的事物的子类.心理学也是Libray的子​​类. (这应该是图书馆吗?)

says that Psicology (which is usually spelled Psychology in English, by the way) is a subclass of the class of things that have the value 5 for the property numPages and the things that have the value 1 for the property numChapters. Psicology is also a subclass of Libray. (Is this supposed to be Library?)

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

These seem like strange axioms to me, and I wonder if there might be some sort of modeling error going on. I'm not sure what a Psicology is, but you're saying that for any Psicology p, it's the case that numPages(p,5) and numChapters(p,1). Is that really what you want to do?

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

At any rate, given your data, we can retrieve the results that you want. Looking at the Turtle serialization is useful, because it's very similar to the SPARQL query syntax. The query you want is:

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

这篇关于SPARQL从类或个人获取所有属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆