2017-02-10 125 views
0

我正在嘗試編寫一個SPARQL查詢,它將返回一組患者標識符代碼(?Crid),它們與特定的診斷代碼(?ICD9)相關聯,並且請勿在他們的招聘日期之前(?RecruitDate)與他們建立特定的藥物並且有訂單日期(?OrderDate)。我已將OBIB本體集成到了我的圖中。SPARQL查詢找到不符合特定條件的結果

這裏是我到目前爲止(有點簡單化,並通過省略可讀性/靈敏度曲線幾步):

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

我的直覺是,我無法正常使用減號。這個查詢返回主要是正確的結果:我期待10個結果,它返回12.多餘的2結果沒有采取「medication_1」,並有他們的招聘日期之前的訂單日期,所以我不希望他們被列入組。

萬一它很重要,我使用Stardog端點來運行此查詢並存儲我的圖形數據。

回答

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

我可能只是寫這沒有減號爲:

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

我想也可能考慮正則表達式是否是正確的工具,在這裏(會簡單字符串比較工作?),但這是一個不同的問題。

+0

感謝您的回覆。我認爲這種方法存在的問題是,它排除了已服用「medication_1」的患者,但他們的入職日期之後有一個訂單日期。爲了排除患者,他們需要在招聘日期之前訂購「medication_1」。 – hayfreed

+1

@hayfreed但是在任何情況下,MINUS本身都是一個返回結果集的圖形模式 - 在你的例子中它總是空的,因爲你沒有在MINUS子句中選擇任何三重模式。 – AKSW