This repository has been archived by the owner on Nov 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmetadata.xqy
57 lines (46 loc) · 1.61 KB
/
metadata.xqy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
xquery version "1.0-ml";
module namespace meta = "http://marklogic.com/sem-app/metadata";
import module namespace search = "http://marklogic.com/appservices/search"
at "/MarkLogic/appservices/search/search.xqy";
declare default function namespace "http://www.w3.org/2005/xpath-functions";
declare option xdmp:mapping "false";
declare function meta:categories($uri, $results) {
let $categories :=
distinct-values(
xdmp:document-properties($uri)//sem:triple
[sem:predicate eq 'http://s.opencalais.com/1/pred/categoryName']
/sem:object
)
! (
let $cat := .
return $results/search:facet[@name eq 'cat']/search:facet-value[@name eq $cat]
)
return
for $c in $categories order by $c/@name return $c
};
(: Here's how you might do the same thing using SPARQL,
e.g. when the desired property values aren't already stored
in the document's properties fragment.
declare function meta:categories($uri, $results) {
let $doc-id := doc($uri)/*:html/*:head/@resource/string()
let $categories :=
sem:sparql("
PREFIX c: <http://s.opencalais.com/1/pred/>
PREFIX r: <http://s.opencalais.com/1/type/er/>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
SELECT DISTINCT ?cat
WHERE {
?DocInfo owl:sameAs <"||$doc-id||"> .
?DocCat c:docId ?DocInfo ;
c:categoryName ?cat .
}
")
! map:get(., "cat")
! (
let $cat := .
return $results/search:facet[@name eq 'cat']/search:facet-value[@name eq $cat]
)
return
for $c in $categories order by $c/@name return $c
};
:)