gpt4 book ai didi

SPARQL 从类或个人中获取所有属性

转载 作者:行者123 更新时间:2023-12-01 01:28:52 26 4
gpt4 key购买 nike

我想要做的是从 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.
}

最佳答案

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

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

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

回答原始问题(关于类的查询)

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

enter image description here
| 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 的事物类的子类。心理学也是图书馆的一个子类。 (这应该是图书馆吗?)

这些对我来说似乎是奇怪的公理,我想知道是否可能存在某种建模错误。我不确定 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 |
-------------------------

关于SPARQL 从类或个人中获取所有属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23223447/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com