SPARQL可以处理特定单元格的空白结果吗?使用Optional不起作用

问题描述

我具有以下类别限制,该类别限制将材料子类别(在这种情况下为胶带和盒子)连接到每个具有属性“ included_in”的包装个体。因此,我的三元组具有以下结构:

Subclass.included_in.Individuals

一个小例子:

ABC_tape“ included_in” SNR2_packing。 (这里ABC_tape是Tape的子类)

ABC_Box“ included_in” SNR1_packing。 (这里ABC_BoxBox的子类)

我用来查看此连接的查询如下:

Select distinct ?packing  ?Box

Where {  ?packing_instances rdf:type :packing.

         ?s owl:hasValue ?packing_instances.
         ?s owl:onProperty :included_in.
         ?Box rdfs:subClassOf ?s.
         ?Box rdfs:subClassOf :Box.
      } 

其中显示了物料子类: ABC_Box ,它包含在包装实例 SNR1_packing

问题是,何时我想为其他材料(如本例中的胶带)使用单独的列。

Select distinct ?packing  ?Box ?tape

Where {  ?packing_instances rdf:type :packing.
         
         ?s owl:hasValue ?packing_instances.
         ?s owl:onProperty :included_in.
         ?Box rdfs:subClassOf ?s.
         ?Box rdfs:subClassOf :Box.

         ?s1 owl:hasValue ?packing_instances.
         ?s1 owl:onProperty :included_in.
         ?tape rdfs:subClassOf ?s.
         ?tape rdfs:subClassOf :tape.
} 

我没有结果,因为 SNR1_packing (其中包括一个盒子,不包括磁带)。 我已经尝试添加可选内容,但只获得包装盒的结果(SNR1_packing),而不是磁带。

Select         ?packing_instances ?Box ?tape

Where {                                   
                ?packing_instances rdf:type :packing. 
                ?s owl:hasValue ?packing_instances.
                ?s owl:onProperty :included_in.
                ?Box rdfs:subClassOf ?s.
                ?Box rdfs:subClassOf :Box. 
    optional {
                ?s1 owl:hasValue ?packing_instances.
                ?s1 owl:onProperty :included_in.
                ?tape rdfs:subClassOf ?s1.
                ?tape rdfs:subClassOf :tape. }

我在做错什么吗?

谢谢

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...