簡體   English   中英

在SPARQL中測試一組相同的值(雙重否定)

[英]Testing for identical sets of values in SPARQL (double negation)

在問答系統中,我需要比較用戶回答的問題集以匹配與個人資料相關聯的問題集,以將用戶分組到這些個人資料中。

我試圖在一個查詢中找到元組profile;user ,其中用戶已經回答了與該概要文件相關的所有問題,我傾向於將其解釋為,因為在任何情況下都不存在概要文件的問題未解決的問題。用戶 (雙重否定)。

這是一個預期答案為:profile1 :Alice的數據集:

@prefix :       <http://example/> .

# Alise has answered 2 questions
:alice a :User .
:alice :hasAnswer :a1, :a2 .
:a1 :question :q1 .
:a2 :question :q2 .

# Bob answered only q1
:bob a :User .
:bob :hasAnswer :b1 .
:b1 :question :q1 .

# Carl did not answered anything
:carl a :User .

# Profile 1 is associated to q1 and q2
:profile1 a :Profile .
:profile1 :associatedQuestion :q1, :q2 .

# Profile 2 is associated to q1 and q3
:profile2 a :Profile .
:profile2 :associatedQuestion :q1, :q3 .

這不起作用:

PREFIX :       <http://example/>
SELECT ?user ?profile
WHERE {
    ?user a :User .
    ?profile a :Profile .
    FILTER NOT EXISTS {
        ?profile :associatedQuestion ?q .
        FILTER NOT EXISTS {
            ?user :hasAnswer ?a .
            ?a :question ?q .
        }
    }
}

我嘗試使用MINUS而不是FILTER NOT EXISTS進行游戲,更改變量名稱等。

我嘗試使用一種不同的方式,即選擇與配置文件中回答的問題數量相同的用戶,但這似乎過分了,我對性能有所懷疑:

PREFIX :       <http://example/>
SELECT ?profile ?numberOfQuestions ?user (COUNT(?a) AS ?numberOfAnswers)
WHERE {
    ?profile a :Profile .
    ?profile :associatedQuestion ?question .
    OPTIONAL {
        ?user :hasAnswer ?a .
        ?a :question ?question .
    }

    {
        SELECT ?profile (COUNT(?question) AS ?numberOfQuestions)
        WHERE {
            ?profile a :Profile .
            ?profile :associatedQuestion ?question .
        }
        GROUP BY ?profile
    }
}
GROUP BY ?profile ?numberOfQuestions ?user
HAVING (?numberOfAnswers = ?numberOfQuestions)

有沒有辦法使用雙重否定來達到預期的結果? 哪種查詢模式將提供最佳性能? (我正在使用最新版本的Jena Fuseki工作)。

謝謝

畢竟,雙重否定查詢確實可以正常工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM