SPARQL 查询以查找不符合特定条件的结果

SPARQL Query to find results which do not meet a certain criteria

我正在尝试编写一个 SPARQL 查询,该查询将 return 一组患者标识符代码 (?Crid),这些代码与特定的诊断代码 (?ICD9) 相关联,但没有与之相关联一种特定的药物并且在他们的招募日期 (?RecruitDate) 之前有一个订购日期 (?OrderDate)。我已将 OBIB ontology 合并到我的图表中。

这是我目前所掌握的(稍微简化了一些,并且在 readability/sensitivity 中省略了图表中的几个步骤):

SELECT DISTINCT ?Crid WHERE 
{?Crid a obib:CRID .

#-- Return CRIDs with a diagnosis
?Crid obib:hasPart ?ICD9 .
?ICD9 a obib:diagnosis .

#-- Return CRIDs with a medical prescription record
?Crid obib:hasPart ?medRecord .
?medRecord a obib:medicalRecord .

#-- Return CRIDs with an order date
?medRecord obib:hasPart ?OrderDate .
?OrderDate a obib:dateOfDataEntry .

#-- Return CRIDs with a recruitment date
?Crid obib:hasPart ?FormFilling .
?FormFilling a obib:formFilling .
?RecruitDate obib:isAbout ?FormFilling .
?RecruitDate a obib:dateOfDataEntry .

#-- Filter results for specific ICD9 codes
FILTER (?ICD9 = '1')

#-- Subtract Results with Certain Medication and Order Date Prior to Recruitment
#-- This is the part that I think is giving me a problem
MINUS {
    FILTER (regex (?medRecord, "medication_1", "i"))
    FILTER (?RecruitDate-?OrderDate < "P0D"^^xsd:dayTimeDuration)
      }
}

我的直觉是我没有正确使用 MINUS。此查询 returns 大部分 正确的结果:我期待 10 个结果,它是 returning 12。无关的 2 个结果确实需要 "medication_1"并且订单日期早于他们的招募日期,所以我不希望他们包含在集合中。

以防万一,我正在使用 Stardog 端点来 运行 此查询并存储我的图形数据。

而不是

#-- Subtract Results with Certain Medication and Order Date Prior to Recruitment
#-- This is the part that I think is giving me a problem
MINUS {
    FILTER (regex (?medRecord, "medication_1", "i"))
    FILTER (?RecruitDate-?OrderDate < "P0D"^^xsd:dayTimeDuration)
      }
}

我可能会在没有 MINUS 的情况下写成:

FILTER (!regex(?medRecord, "medication_1", "i"))
FILTER (?RecruitDate-?OrderDate >= "P0D"^^xsd:dayTimeDuration)

我也可能会考虑 REGEX 是否是这里的正确工具(简单的字符串比较有用吗?),但这是一个不同的问题。