我要查詢不是所有的記錄都記錄的屬性。是否有可能只使用在查詢和不使用可選基本圖形模式的值爲空,讓他們?匹配的可選的三倍,而無需使用可選
0
A
回答
4
甲變量綁定到一些值,以便爲了有匹配。 可選是個例外。在那裏你可以得到一個匹配,它是可選一個特定的模式匹配。如果你想爲一個匹配的可選變量,你必須使用可選。
從技術上講,您可以避免使用可選的聯合與可能發生的不同部分匹配。在這個意義上,你不會使用可選的,但它會是更加複雜:
@prefix : <urn:ex:>.
:a :hasName "Person A".
:b :hasAge 32 .
:c :hasName "Person C" ;
:hasAge 71 .
prefix : <urn:ex:>
select * where {
#-- ?age but no name
{ ?person :hasAge ?age
filter not exists { ?person :hasName ?name }}
union
#-- ?name but no age
{ ?person :hasName ?name
filter not exists { ?person :hasAge ?age }}
union
#-- ?name and ?age
{ ?person :hasName ?name ; :hasAge ?age }
}
-----------------------------
| person | age | name |
=============================
| :a | | "Person A" |
| :b | 32 | |
| :c | 71 | "Person C" |
-----------------------------
2
您可以通過使用一個構造查詢實現這一目標。使用帶簡單BGP的CONSTRUCT來檢索完整數據集的相關子集,然後對結果進行後處理。
例如,假設你有一組有關人員,其中有姓名,電子郵件地址,電話號碼記錄,但沒有這些屬性的一定都是充滿了每個人。
然後你可以只是做檢索所有屬性Person
類型的資源的查詢。這裏是(使用Sesame API)在Java中的例子:
// query to retrieve all properties of things of type Person
String queryString = "CONSTRUCT WHERE {?s a <urn:Person>; ?p ?o }";
GraphQuery query = conn.prepareGraphQuery(SPARQL, queryString);
Model result = QueryResults.asModel(query.evaluate());
您現在有一個包含所有可用的人數據的查詢結果。處理可能缺失的值現在只是處理結果的問題。例如:
for (Resource person: result.subjects()) {
Literal name = result.filter(person, FOAF.NAME, null).objectLiteral();
if (name == null) {
System.out.println("name is missing!");
}
else {
...
}
}
相關問題
- 1. Neo4j可選匹配
- 2. 可選匹配線
- 3. scanf可選匹配
- 4. 可選匹配的Neo4j
- 5. 可選匹配的空間
- 6. preg_replace()可選模式匹配
- 7. 匹配可選行尾
- 8. boost :: spirit :: qi - 可選匹配
- 9. Python可選匹配組
- 10. 可選變量匹配?
- 11. 匹配可選捕獲組
- 12. PHP - Preg_match_all可選匹配
- 13. DocumentDB:SQL來選擇可選元素匹配
- 14. 使用可選子集在無序集(數組)上匹配表
- 15. 匹配可選的特殊字符
- 16. 多個可選匹配的優化
- 17. Neo4j Cypher性能的可選匹配
- 18. Neo4j條件相交的可選匹配
- 19. Neo4j的v.2.0.0可選匹配查詢
- 20. 匹配部分的可選部分
- 21. 可選的正則表達式匹配
- 22. UITableViewCell無法選擇,而其accessoryView可選
- 23. 在可選匹配後創建沒有匹配的地方
- 24. 使用可選鍵的模式匹配地圖
- 25. 使用可選組獲得最短匹配的問題
- 26. 使用可選匹配的密碼NOT IN查詢
- 27. 如何使用PyParsing匹配可選的關鍵字後綴?
- 28. 如何使用可選的左括號來匹配模式?
- 29. 無而展開的可選值錯誤
- 30. 可選的泛型類型,而無需手動指定類型
正如你說的那樣,我認爲答案是「不,這是不可能的」。 –