Rdf 提取类内容,例如(onProperty、somevalueFrom、unioinOf(包含集合)和equivalentClass)

Rdf 提取类内容,例如(onProperty、somevalueFrom、unioinOf(包含集合)和equivalentClass),rdf,sparql,jena,owl,reasoning,Rdf,Sparql,Jena,Owl,Reasoning,我试图从owl文件中提取类的内容,该文件由onProperty和SomeValues组成,someValueFrom由包含unionOf(onProperty、someValueFrom和equivalentClass)的类组成。我创建了一个SPARQL查询来提取这些数据,但每次它都返回空白节点,如“:b0”和“:b1”。有没有人知道我应该如何处理我的查询以使其提供所需的结果。这是我的owl文件: 运输工人 这是我创建的SPARQL查询: prefix abc: <http:/

我试图从owl文件中提取类的内容,该文件由onProperty和SomeValues组成,someValueFrom由包含unionOf(onProperty、someValueFrom和equivalentClass)的类组成。我创建了一个SPARQL查询来提取这些数据,但每次它都返回空白节点,如“:b0”和“:b1”。有没有人知道我应该如何处理我的查询以使其提供所需的结果。这是我的owl文件:


运输工人
这是我创建的SPARQL查询:

    prefix abc: <http://owl.cs.manchester.ac.uk/2009/07/sssw/people#>
    prefix ghi: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
    prefix mno: <http://www.w3.org/2001/XMLSchema#>
    prefix owl: <http://www.w3.org/2002/07/owl#>
    prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
    prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
    prefix list: <http://jena.hpl.hp.com/ARQ/list#>

    select distinct ?class ?ObjectProperty ?someValuesFrom ?otherClass where { ?class a  owl:Class .


    OPTIONAL{
       ?class owl:equivalentClass ?e .
        ?e a owl:Restriction .
#       ?e owl:onProperty ?ObjectProperty .
        ?e owl:someValuesFrom [ a owl:Class; 
                                    owl:unionOf [ rdf:first ?    ObjectProperty; 
                                    rdf:rest ?someValuesFrom ;     rdf:rest*/rdf:first ?otherClass]] .  


      }
     FILTER( STRSTARTS(STR(?class),STR(owl:)) || STRSTARTS(STR(?class),STR(abc:)))  
    }group by ?class  ?ObjectProperty ?someValuesFrom ?otherClass
    order by ?class
但预期结果是:

-----------------------------------------------------------------------------
| class               | ObjectProperty | someValuesFrom   | otherClass      |
=============================================================================
| abc:haulage_company |                |                  |                 |
| abc:haulage_worker  | abc:works_for  |                  |                 |
| abc:haulage_worker  | abc:part_of    | haulage_company  | haulage_company |
| owl:Thing           |                |                  |                 |
-----------------------------------------------------------------------------
我应该如何处理SPARQL查询才能返回此结果

非常感谢:)

您的查询问题: 如果在Turtle序列化而不是RDF/XML序列化中查看数据,则可能更容易理解SPARQL查询的结果。您的数据的相关部分是:

ns0:haulage_worker  a        owl:Class ;
        rdfs:comment         ""^^xsd:string ;
        rdfs:label           "haulage worker"^^xsd:string ;
        owl:equivalentClass  [ a                   owl:Restriction ;
                               owl:onProperty      ns0:works_for ;
                               owl:someValuesFrom  [ a            owl:Class ;
                                                     owl:unionOf  ( [ a                   owl:Restriction ;
                                                                      owl:onProperty      ns0:part_of ;
                                                                      owl:someValuesFrom  ns0:haulage_company
                                                                    ] ns0:haulage_company )
                                                   ]
考虑关于
owl:unionOf
部分的匹配。在您的查询中,它是

owl:unionOf  ( [ a                   owl:Restriction ;
                 owl:onProperty      ns0:part_of ;
                 owl:someValuesFrom  ns0:haulage_company ]
               ns0:haulage_company )
列表的元素是一个带有某些属性的空白节点,并且
ns0:haulage\u company
。应与某些数据匹配的查询为:

owl:unionOf [ rdf:first ?ObjectProperty; 
              rdf:rest ?someValuesFrom ;
              rdf:rest*/rdf:first ?otherClass ]] .  
匹配
?ObjectProperty
的是列表的第一个元素,在本例中,该元素不是对象属性,而是一个空白节点。与中的somevalues匹配的是表示列表其余部分的列表节点

修复您的查询: 我不太确定您正试图从这个查询中返回什么。根据您的预期结果,您似乎在说一个类
?class
可以与
owl:somevalues from
限制相关,在这种情况下,您希望将
?ObjectProperty
?somevalues from
绑定到对象属性和类(如果它不是空节点),并将
?otherClass
绑定到其他相关(非空)类。你说你期待这些结果:

-----------------------------------------------------------------------------
| class               | ObjectProperty | someValuesFrom   | otherClass      |
=============================================================================
| abc:haulage_company |                |                  |                 |
| abc:haulage_worker  | abc:works_for  |                  |                 |
| abc:haulage_worker  | abc:part_of    | haulage_company  | haulage_company |
| owl:Thing           |                |                  |                 |
-----------------------------------------------------------------------------
但如果我的理解是正确的,我认为获得以下信息会更容易、更有用:

-----------------------------------------------------------------------------
| class               | ObjectProperty | someValuesFrom   | otherClass      |
=============================================================================
| abc:haulage_company |                |                  |                 |
| abc:haulage_worker  | abc:works_for  |                  |                 |
| abc:haulage_worker  | abc:part_of    | haulage_company  |                 |
| abc:haulage_worker  |                |                  | haulage_company |
| owl:Thing           |                |                  |                 |
-----------------------------------------------------------------------------
您可以使用如下查询来完成此操作:

前缀:
前缀owl:
前缀rdf:
从其他类中选择不同的类on属性somevalues,其中{
#--选择每个命名类。
?a级猫头鹰:a级猫头鹰。
过滤器(!isBlank(?class))
可选的{
#--按照一个比较复杂的步骤查找“相关”类
#--将遵循等效类的属性路径,
#--存在限制和表达式的联合。
?类别(owl:等效类别)
|猫头鹰:一些来自
|(owl:unionOf/rdf:rest*/rdf:first))+?r。
#--将非空的相关类另存为?otherClass。
绑定(如果(为空白(?r),?未绑定,?r)作为其他类)
#--如果相关类是一个限制,那么我们可以
#--从中获取其owl:on属性和owl:somevalues。
可选{
?r owl:onProperty?onProperty;
猫头鹰:一些来自svf的值。
绑定(如果(为空白(?svf),?未绑定,?svf)作为来自的某些值)
}
}
}
值?未绑定{unde}
在answers.semanticweb.com问题的答案中描述了保存未绑定到空白节点的值的模式,其思想是使用
values?unbound{unde}
确保
?unbound
始终具有未定义的值,然后使用
bind
if
或其他值指定给投影变量。本质上是这样的:

bind(if(isBlank(...),?unbound,...) as ...)
values ?unbound { UNDEF }
结果是

-----------------------------------------------------------------------
| class            | onProperty | someValuesFrom   | otherClass       |
=======================================================================
| owl:Thing        |            |                  |                  |
| :haulage_company |            |                  |                  |
| :haulage_worker  |            |                  |                  |
| :haulage_worker  | :works_for |                  |                  |
| :haulage_worker  | :part_of   | :haulage_company |                  |
| :haulage_worker  |            |                  | :haulage_company |
-----------------------------------------------------------------------

这确实包括一行用于
:haulage\u worker
,该行没有任何其他变量的绑定,但我认为这没关系,因为您已经想为
owl:Thing
:haulage\u company

创建这样的行,亲爱的,我对SPARQL查询做了一些更改,更改了显示的结果,因此,如果有人知道我应该如何处理SPARQL查询以达到预期的结果,请提供帮助。非常感谢你到底想回报什么?从“预期结果”部分不清楚第二行和第三行应该代表什么。非常感谢@Joshua。我试过你的答案,效果很好。对不起,回复晚了,我认为这是一个未解决的问题。我看到了解决办法
-----------------------------------------------------------------------
| class            | onProperty | someValuesFrom   | otherClass       |
=======================================================================
| owl:Thing        |            |                  |                  |
| :haulage_company |            |                  |                  |
| :haulage_worker  |            |                  |                  |
| :haulage_worker  | :works_for |                  |                  |
| :haulage_worker  | :part_of   | :haulage_company |                  |
| :haulage_worker  |            |                  | :haulage_company |
-----------------------------------------------------------------------