为什么我的 Ontlgoy 中的某些类没有在我的 SPARQL 查询中返回?

如何解决为什么我的 Ontlgoy 中的某些类没有在我的 SPARQL 查询中返回?

我很困惑为什么我收到的结果太少(预期为 256,返回 224)。当我运行下面的代码时,一切都完全按照我的意愿返回,除了我错过了本体中位于最高级别或低于最高级别的所有类。我不明白我在查询中哪里过于“严格”,以至于这些类没有在表中返回。它们也都有父类(无论是本体的最顶层类“顶级概念”,还是枚举类型类之类的东西,无论哪种方式,仍然应该找到叶子。感谢我的代码可能的提示或指针无意中过滤掉了这些类。

SELECT disTINCT ?leaf ?parentclasses
WHERE {
GRAPH <>
#a leaf is the lowest level class: A class that does not have a subclass
{
    {
        {
            #I want anything which is a class
            {
                ?leaf rdf:type owl:Class.
            }
            #i also want the subclass of any superclass if that exists
            {
                ?leaf rdfs:subClassOf ?superclass .
            }
            #squeezed to specific section of OTL.
            filter strstarts(str(?leaf),"URIgoeshere")
            #Only keep the results that do not have a preflabel
            OPTIONAL {
                ?leaf skos:prefLabel ?subclasslabel.
                
            }
            #make sure the subclasslabel is in dutch
            #filter( langMatches(lang(?subclasslabel),"nl") )
            
            #give me the label of the superclass
            OPTIONAL {
                ?superclass skos:prefLabel ?superclasslabel.
            }
            #make sure it's in dutch
            FILTER (lang(?superclasslabel) = "nl")
            #if it exists,give me also the superclass of the superclass creating a supersuperclass
            {
                ?superclass rdfs:subClassOf ?supersuperclass.
                #give me the label of the supersuperclass
                OPTIONAL {
                    ?supersuperclass skos:prefLabel ?supersuperclasslabel.
                }
                #make sure it's in dutch
                FILTER (lang(?supersuperclasslabel) = "nl")
                #keep the leafs that are NOT The values whereby the subclass is not empty. (double negative for removing leafs where the subclass has a subclass below it)
                FILTER NOT EXISTS {
                    ?subclass rdfs:subClassOf ?leaf 
                    FILTER (?subclass != owl:nothing ) 
                }
                #concatenate the two parentclass variables into one    
                BIND(concat(str(?superclasslabel),str("-"),str(?supersuperclasslabel) ) as ?parentclasses) 
            }
        }
    }
}

}

这是一个与我的数据库结构相同的 ttl 文件https://file.io/jjwkAWbK4jrF

解决方法

以下是我对问题的最终解决方案。它比我预期的要复杂,但它确实有效。

问题是查询不接受这些没有父类的类。在某些联合情况下,这可以涵盖 0 个父类、1 个父类或 2 个父类。

SELECT DISTINCT ?leaf ?parentclasses
WHERE {
GRAPH <>
#a leaf is the lowest level class: A class that does not have a subclass
{{{{{
                    
                   
                    
        #I want anything which is a class
        {?leaf rdf:type owl:Class.}
                    
#squeezed 
        filter strstarts(str(?leaf),"graph")           
        #keep the leafs that are NOT The values whereby the subclass is not empty. 
 (double negative for removing leafs where the subclass has a subclass below it)
            FILTER NOT EXISTS {?subclass rdfs:subClassOf ?leaf 
            FILTER (?subclass != owl:Nothing ) }
 }              
                {
         {?leaf rdfs:subClassOf ?superclass .}
               
 #grab dutch label if available
optional {
?superclass skos:prefLabel ?superclassnllabel .
filter( langMatches(lang(?superclassnllabel),"nl") )
}

# take either as the label,but dutch over empty
                bind( coalesce( ?superclassnllabel,replace(str(? 
superclass),"^[^#]*#","" ) ) as ?superclasslabel )
            
                {
                    
                {?superclass rdfs:subClassOf ?supersuperclass.}
                

        #grab dutch label if available
 
?supersuperclass skos:prefLabel ?supersuperclassnllabel .
                    filter( langMatches(lang(?supersuperclassnllabel),"nl") )



 # take either as the label,but dutch over empty
                    bind( coalesce( ?supersuperclassnllabel,replace(str(? 
 supersuperclass),"" ) ) as ?supersuperclasslabel )
                BIND(concat(str(?superclasslabel),str(" - "),str(? 
supersuperclasslabel) ) as ?parentclasses)
                }
                union
                {
                    
                    {?superclass ?p ?o.filter(!isblank(?superclass))}
                    FILTER NOT EXISTS {?superclass rdfs:subClassOf ?supersuperclass}
                        BIND(concat(str(?superclasslabel),str("Top 
Concept") ) as ?parentclasses) 
                #concatenate the two parentclass variables into one    
                
                }


        
            }
            }
            
            union
            {
                   #figure this out,WHY IS IT HERE? 
                {?leaf rdf:type owl:Class .filter(!isblank(?leaf))}
                FILTER strstarts(str(?leaf),"graph") 
                FILTER NOT EXISTS {?leaf rdfs:subClassOf ?superclass}
                FILTER NOT EXISTS {?subclass rdfs:subClassOf ?leaf 
                FILTER (?subclass != owl:Nothing ) }
                BIND (str("Top Class")  as ?parentclasses )
                   
                
                }

            }}}}
            

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?
Java在半透明框架/面板/组件上重新绘画。
Java“ Class.forName()”和“ Class.forName()。newInstance()”之间有什么区别?
在此环境中不提供编译器。也许是在JRE而不是JDK上运行?
Java用相同的方法在一个类中实现两个接口。哪种接口方法被覆盖?
Java 什么是Runtime.getRuntime()。totalMemory()和freeMemory()?
java.library.path中的java.lang.UnsatisfiedLinkError否*****。dll
JavaFX“位置是必需的。” 即使在同一包装中
Java 导入两个具有相同名称的类。怎么处理?
Java 是否应该在HttpServletResponse.getOutputStream()/。getWriter()上调用.close()?
Java RegEx元字符(。)和普通点?