-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvaliant_transform.sh
111 lines (90 loc) · 2.27 KB
/
valiant_transform.sh
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/bin/bash
printHelp() {
echo "Script expects installed Valiant tool (for executing XSLT) and his configuration file is located in /etc/valiant/"
echo "Arguments:"
echo "-s, --source\t\t Source dir with xml documents"
echo "-d, --destination\t Target dir for trasmormed documents"
echo "-x, --xslt \t\t Path to xslt file"
echo "-g, --graph \t\t Target graph URI where results will be loaded"
echo "Arguments for login to Virtuoso":
echo "-s, --port \t\t Server port"
echo "-u, --user \t\t Username"
echo "-p, --password \t\t Password"
echo "If -g, -d, -S, -U, -P arguments is present. Result will be uploaded to Virtuoso"
EXECUTE=0
}
CONFIG_FILE=/etc/valiant/valiant.properties
EXECUTE=1
if [ $# -eq 0 ]; then
printHelp
fi
#parsing parameters
while [ $# -gt 0 ]
do
key="$1"
shift
case $key in
-s|--source)
REPLACEMENT_VALUE="$1"
TARGET_KEY="inputfile"
shift
;;
-d|--destination)
REPLACEMENT_VALUE="$1"
TARGET_DIR="$1"
TARGET_KEY="rdfFolder"
shift
;;
-x|--xslt)
REPLACEMENT_VALUE="$1"
TARGET_KEY="xslPath"
shift
;;
-g|--graph)
REPLACEMENT_VALUE="$1"
TARGET_GRAPH="$1"
TARGET_KEY="baseURI"
shift
;;
-S|--port)
VIRT_PORT="$1"
shift
;;
-U|--username)
VIRT_USERNAME="$1"
shift
;;
-P|--password)
VIRT_PASSWORD="$1"
shift
;;
-h|--help)
printHelp
;;
*)
# unknown option
;;
esac
if [ -n "$REPLACEMENT_VALUE" ]; then
sudo sed -i "s@^\($TARGET_KEY\s*=\s*\).*\$@\1$REPLACEMENT_VALUE@" $CONFIG_FILE
fi
REPLACEMENT_VALUE=
done
#executing transformation
if [ $EXECUTE -eq 1 ]; then
echo "Executing Valiant transform"
sudo valiant
find $TARGET_DIR -name '*.graph' -delete
#loading data to Virtuoso
if [ -n "$TARGET_DIR" ] && [ -n "$TARGET_GRAPH" ] && [ -n "$VIRT_PORT" ] && [ -n "$VIRT_USERNAME" ] && [ -n "$VIRT_PASSWORD" ]; then
echo "Loading data to Virtuoso"
isql-vt -S $VIRT_PORT -U $VIRT_USERNAME -P $VIRT_PASSWORD <<EOF
log_enable(3,1);
SPARQL CLEAR GRAPH <$TARGET_GRAPH>;
DELETE from DB.DBA.load_list WHERE ll_state=2;
ld_dir('$TARGET_DIR','*.rdf','$TARGET_GRAPH');
rdf_loader_run();
exit;
EOF
fi
fi