Skip to content

Commit

Permalink
suppression des doublons dans les occurences (#763)
Browse files Browse the repository at this point in the history
  • Loading branch information
emchateau committed Jul 11, 2020
1 parent 5441aa9 commit 0c5e5b8
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions models/teiBuilder.xqm
Expand Up @@ -486,7 +486,7 @@ declare function getOccurences($entry as element()) as map(*)* {
: this function get occurences of index entry
:
: @param $occurences refs
: @return
: @return a sequence of maps containing all the index entries for each text
:)
declare function getOccurences($entry as element()) as map(*)* {
for $item in $entry/tei:listRelation/tei:relation
Expand All @@ -495,20 +495,40 @@ declare function getOccurences($entry as element()) as map(*)* {
'item' : fn:normalize-space($type),
'occurences' : array{
let $ids := $item/@passive ! fn:tokenize(., ' ') ! fn:substring-after(., '#')
for $id in $ids
let $entry := getDivFromId($id)
let $uuid := $entry/@xml:id
let $occurences :=
for $id in $ids
let $entry := getDivFromId($id)
let $uuid := $entry/@xml:id
return map {
'id' : $id,
'title' : getSectionTitle($entry),
'uuid' : $uuid,
'path' : '/item/',
'url' : $gdp.globals:root || '/items/' || $uuid
}
return getDistinctMaps($occurences, map{})
}
}
};

(:~
: this function filters distinct maps in a sequence
: @param $maps a sequence of maps to filter
: @options $options
: @return a filtered list of maps
:)
declare function getDistinctMaps($maps as map(*)*, $options) as map(*)* {
fn:fold-left(
$maps,
(),
function($distinct-maps, $new-map) {
if (some $map in $distinct-maps satisfies fn:deep-equal($map, $new-map))
then $distinct-maps else ($distinct-maps, $new-map)
}
)
};

(:~
: this function get index values of an item
:
Expand Down

0 comments on commit 0c5e5b8

Please sign in to comment.