]>
Pierre Choffet | Git repositories - wdef_tools.git/blob - scripts/get_merged_element.sh
3 # get_merged_element.sh - Return an element in wdef:knowledge after it's been
5 # Copyright (C) 2022 Pierre Choffet
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of version 3 of the GNU General Public License as
9 # published by the Free Software Foundation.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 readonly SCRIPT_DIR
="$(dirname "$0")"
21 source "${SCRIPT_DIR}/rdf.sh"
25 # Any rdf cache older than this (in minutes) will be updated
26 RDFS_MAX_AGE
=${RDFS_MAX_AGE:=1440}
28 readonly CANONICALIZE_XSLT_PATH
="${SCRIPT_DIR}/../xslts/canonicalize.xslt"
29 readonly MERGE_XSLT_PATH
="${SCRIPT_DIR}/../xslts/merge_rdf.xslt"
33 USAGE: get_merged_element.sh <wdef_path> <QID>
35 Merge a RDF into an element inside a wdef file. A wdef file containing this
36 single element is returned.
46 readonly WDEF_PATH
="${1}"
47 readonly ELEMENT_QID
="${2}"
50 if [ ! -s "${WDEF_PATH}" ]
52 echo "WDEF file doesn't exist. Exiting" >&2
56 # Export element from wdef
57 readonly ELEMENT_PATH
="$(mktemp)"
58 xmlstarlet sel
-D -t -e 'wdef:knowledge' -m '/wdef:knowledge' -c "wdef:element[@wdef:id = '${ELEMENT_QID}']" "${WDEF_PATH}" | xmlstarlet fo
- > "${ELEMENT_PATH}"
60 # Check element is in temp file
61 if [ "$(xmlstarlet sel -t -i "/wdef:knowledge/wdef:element[@wdef:id = '${ELEMENT_QID}']" -v "'true'" "${ELEMENT_PATH}")" != 'true' ]
63 echo "Element not available in wdef. Exiting." >&2
68 readonly RDF_PATH
=$(cacheRDFMaxAge "${ELEMENT_QID}" "${RDFS_MAX_AGE}")
70 # Merge and return canonicalized result
71 xmlstarlet
tr "${MERGE_XSLT_PATH}" -s action
=reduce \
72 -s "rdf-path=${RDF_PATH}" \
73 "${WDEF_PATH}" | xmlstarlet
tr ${CANONICALIZE_XSLT_PATH} -