我是语义网和sparql的新手。我有一个内部本体,使用 SmartLogic 来管理数据。
我正在编写一些简单的查询来开始。
CalendarContract.Instances._ID
CalendarContract.Instances.EVENT_ID
CalendarContract.Instances.TITLE
CalendarContract.Instances.BEGIN
CalendarContract.Instances.END
CalendarContract.Instances.ALL_DAY
CalendarContract.Instances.DESCRIPTION
CalendarContract.Instances.EVENT_LOCATION
CalendarContract.Instances.EVENT_COLOR
CalendarContract.Instances.CALENDAR_COLOR
CalendarContract.Instances.OWNER_ACCOUNT
CalendarContract.Instances.VISIBLE
CalendarContract.Instances.CALENDAR_ID
CalendarContract.Reminders.EVENT_ID
CalendarContract.Reminders.MINUTES
CalendarContract.Reminders.METHOD
CalendarContract.Attendees.EVENT_ID
CalendarContract.Attendees.ATTENDEE_EMAIL
CalendarContract.Attendees.ATTENDEE_NAME
CalendarContract.Attendees.ATTENDEE_STATUS
CalendarContract.Attendees.ATTENDEE_RELATIONSHIP
此查询返回如下所示的结果:
我正在尝试合并PREFIX skos: <http://www.w3.org/2004/02/skos/core#> # Simple Knowledge Organization System - https://www.w3.org/2004/02/skos/
PREFIX skosxl: <http://www.w3.org/2008/05/skos-xl#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <https://www.w3.org/TR/rdf-schema/>
prefix owl: <http://www.w3.org/2002/07/owl#>
prefix ap: <http://cv.ap.org/ns>
SELECT DISTINCT
?subjectPrefLabel ?p ?o ?oL
WHERE {
{
?subject skosxl:prefLabel ?subjectLabel .
?subjectLabel skosxl:literalForm ?subjectPrefLabel .
?subject ?p ?o .
OPTIONAL {?o skos:prefLabel ?oL}
}
FILTER regex(?subjectPrefLabel, "Trump", 'i')
} order by ?subjectPrefLabel
字段,以便当且仅当有?o and ?oL
字段
?o
字段
我还没有能够搞清楚。如果有任何建议请告诉我。
答案 0 :(得分:1)
没有用于测试查询的数据有点困难,但在SPARQL 1.1中,您可以使用BIND(IF(condition,then,else) as ?result )
:
PREFIX skosxl: <http://www.w3.org/2008/05/skos-xl#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX rdfs: <https://www.w3.org/TR/rdf-schema/>
PREFIX ap: <http://cv.ap.org/ns>
SELECT DISTINCT ?subjectPrefLabel ?p ?o
WHERE
{ ?subject skosxl:prefLabel ?subjectLabel .
?subjectLabel
skosxl:literalForm ?subjectPrefLabel .
?subject ?p ?o_tmp
OPTIONAL
{ ?o_tmp skos:prefLabel ?oL }
BIND(if(bound(?oL), ?oL, ?o_tmp) AS ?o)
FILTER regex(?subjectPrefLabel, "Trump", "i")
}
ORDER BY ?subjectPrefLabel