简体   繁体   English

提取类内容,例如(onProperty,somevalueFrom,unioinOf(包含集合)和等效类)

[英]Extracting Class content such as (onProperty, somevalueFrom , unioinOf (which contain a collection) and equivalentClass)

I'm trying to extract class's content from owl file which consists of onProperty and someValuesFrom where the someValueFrom consists of class that contain a unionOf (onProperty, someValueFrom and equivalentClass), I have created a SPARQL query to extract these data, however every time it returns blank nodes such as " :b0" and " :b1". 我试图从由onProperty和someValuesFrom组成的owl文件中提取类的内容,其中someValueFrom由包含unionOf的类组成(onProperty,someValueFrom和等效类),我创建了一个SPARQL查询来提取这些数据,但是每次返回空白节点,例如“ :b0”和“ :b1”。 Does anyone have any idea what should I do with my query in order to make it provide the needed results. 有谁知道我应该如何处理查询以使其提供所需的结果? This is my owl file: 这是我的猫头鹰文件:

<?xml version="1.0"?>
<rdf:RDF
    xmlns="http://owl.cs.manchester.ac.uk/2009/07/sssw/people#"
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
    xmlns:owl="http://www.w3.org/2002/07/owl#"
    xmlns:ns0="http://owl.cs.manchester.ac.uk/2009/07/sssw/people#"
    xml:base="http://owl.cs.manchester.ac.uk/2009/07/sssw/people">
  <owl:Ontology rdf:about="http://owl.cs.manchester.ac.uk/2009/07/sssw/people"/>
  <owl:Class rdf:about="http://www.w3.org/2002/07/owl#Thing"/>
  <owl:Class rdf:about="http://owl.cs.manchester.ac.uk/2009/07/sssw/people#haulage_worker">
    <rdfs:comment rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
    ></rdfs:comment>
    <owl:equivalentClass>
      <owl:Restriction>
         <owl:onProperty>
          <owl:ObjectProperty rdf:about="http://owl.cs.manchester.ac.uk/2009/07/sssw/people#works_for"/>
        </owl:onProperty>
        <owl:someValuesFrom>
          <owl:Class>
            <owl:unionOf rdf:parseType="Collection">
              <owl:Restriction>
                <owl:onProperty>
                  <owl:ObjectProperty rdf:about="http://owl.cs.manchester.ac.uk/2009/07/sssw/people#part_of"/>
                </owl:onProperty>
                <owl:someValuesFrom>
                  <owl:Class rdf:about="http://owl.cs.manchester.ac.uk/2009/07/sssw/people#haulage_company"/>
                </owl:someValuesFrom>
               </owl:Restriction>
              <owl:Class rdf:about="http://owl.cs.manchester.ac.uk/2009/07/sssw/people#haulage_company"/>
            </owl:unionOf>
          </owl:Class>
         </owl:someValuesFrom>
      </owl:Restriction>
    </owl:equivalentClass>
    <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
    >haulage worker</rdfs:label>
  </owl:Class>
 </rdf:RDF>

and This is my SPARQL query that I have created : 这是我创建的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

and This is the result that I had got : 这是我得到的结果:

-------------------------------------------------------------------------------
| class               | ObjectProperty | someValuesFrom | otherClass          |
===============================================================================
| abc:haulage_company |                |                |                     |
| abc:haulage_worker  | _:b0           | _:b1           | _:b0                |
| abc:haulage_worker  | _:b0           | _:b1           | abc:haulage_company |
| owl:Thing           |                |                |                     |
-------------------------------------------------------------------------------

but the expected result is : 但预期结果是:

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

What should I do with my SPARQL query in order to make return this result? 为了使该结果返回,我该如何处理SPARQL查询?

Many thanks in advance :) 提前谢谢了 :)

The problem with your query: 您的查询问题:

It may be easier to understand the results of the SPARQL query if you look at your data in the Turtle serialization rather than the RDF/XML serialization. 如果您在Turtle序列化而不是RDF / XML序列化中查看数据,则可能更容易理解SPARQL查询的结果。 The relevant portion of your data is: 数据的相关部分是:

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

Consider the match for the part about owl:unionOf . 考虑有关owl:unionOf的部分的匹配。 In your query, it's 在您的查询中

owl:unionOf  ( [ a                   owl:Restriction ;
                 owl:onProperty      ns0:part_of ;
                 owl:someValuesFrom  ns0:haulage_company ]
               ns0:haulage_company )

The elements of the list are a blank node with some properties, and ns0:haulage_company . 列表的元素是具有某些属性的空白节点和ns0:haulage_company The query that should match some of this data is: 与某些数据匹配的查询为:

owl:unionOf [ rdf:first ?ObjectProperty; 
              rdf:rest ?someValuesFrom ;
              rdf:rest*/rdf:first ?otherClass ]] .  

The thing that will match ?ObjectProperty is the first element of the list which, in this case, is not an object property, but is a blank node. 将匹配?ObjectProperty是列表的第一个元素,在这种情况下,它不是对象属性,而是一个空白节点。 The thing that will match ?someValuesFrom is the list node representing the rest of the list. ?someValuesFrom匹配的事物是代表列表其余部分的列表节点。

Fixing your query: 解决您的查询:

I'm not quite sure exactly what you are trying to return from this query. 我不太确定您要从此查询返回什么。 Based on your expected results, it looks like you're saying that a class ?class can be related to an owl:someValuesFrom restriction, in which case you want to bind ?ObjectProperty and ?someValuesFrom to the object property and class (if it's not a blank node), and bind ?otherClass to other related (non-blank) classes otherwise. 根据您的预期结果,您似乎在说一个类?class可以与owl:someValuesFrom限制相关,在这种情况下,您想将?ObjectProperty?someValuesFrom绑定到对象属性和类(如果不是)空白节点),然后将?otherClass绑定到其他相关(非空白)类。 You said you expected these results: 您说您预期这些结果:

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

but if my understanding is correct, I think it would be easier and more useful to get something like: 但是,如果我的理解是正确的,我认为获得类似以下内容将变得更加容易和有用:

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

You can do that with a query like this: 您可以使用以下查询来做到这一点:

prefix :      <http://owl.cs.manchester.ac.uk/2009/07/sssw/people#>
prefix owl:   <http://www.w3.org/2002/07/owl#>
prefix rdf:   <http://www.w3.org/1999/02/22-rdf-syntax-ns#>

select distinct ?class ?onProperty ?someValuesFrom ?otherClass where {
  #-- Select each named class.
  ?class a owl:Class .
  filter( !isBlank( ?class ))

  optional {
    #-- Find "related" classes by following a somewhat complex
    #-- property path that will follow equivalent classes,
    #-- existential restrictions, and unionOf expressions.
    ?class (owl:equivalentClass
           |owl:someValuesFrom
           |(owl:unionOf/rdf:rest*/rdf:first))+ ?r .

    #-- Save non-blank related classes as ?otherClass.
    bind(if(isBlank(?r),?unbound,?r) as ?otherClass)

    #-- If the related class is a restriction, then we can 
    #-- take its owl:onProperty and owl:someValuesFrom.
    optional { 
      ?r owl:onProperty ?onProperty ;
         owl:someValuesFrom ?svf .
      bind( if(isBlank(?svf),?unbound,?svf) as ?someValuesFrom )
    }
  }
}
values ?unbound { UNDEF }

The pattern to save values that aren't bound to blank nodes is described in answers to an answers.semanticweb.com question, Binding a variable only when another is non-blank? 在answer.semanticweb.com问题的答案中描述了保存未绑定到空白节点的值的模式: 仅当另一个变量不是空白时才绑定变量吗? The idea is to use values ?unbound { UNDEF } to ensure that ?unbound always has an undefined value, and then to use bind and if to assign either ?unbound or some other value to a projected variable. 想法是使用values ?unbound { UNDEF }以确保?unbound始终具有未定义的值,然后使用bind以及if?unbound或某些其他值分配给投影变量。 In essence, it's this: 本质上是这样的:

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

The results are 结果是

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

This does include a row for :haulage_worker that doesn't have bindings for any of the other variables, but I think that's OK, since you already wanted such rows for owl:Thing and :haulage_company . 这确实包括:haulage_worker的行,该行没有任何其他变量的绑定,但是我认为还可以,因为您已经想要owl:Thing:haulage_company这样的行了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM