-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcreate-semsql-db.sh
executable file
·109 lines (94 loc) · 2.62 KB
/
create-semsql-db.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
#!/bin/sh
DIR=`dirname "$0"`/..
# A POSIX variable
OPTIND=1 # Reset in case getopts has been used previously in the shell.
# Initialize our own variables:
db=""
verbose=0
while getopts "h?fvrd:" opt; do
case "$opt" in
h|\?)
show_help
exit 0
;;
f) force=1
;;
v) verbose=1
;;
r) report=1
;;
d) db=$OPTARG
;;
esac
done
shift $((OPTIND-1))
[ "${1:-}" = "--" ] && shift
if [[ $verbose == 1 ]]; then
echo "verbose=$verbose, db='$db', Files: $@, Path=$DIR"
fi
if [[ "$db" == "" ]]; then
echo "Must pass --db"
exit -1
fi
if [[ -f $db ]]; then
if [[ $force == 1 ]]; then
if [[ $verbose == 1 ]]; then
echo "Replacing: $db"
fi
rm $db
else
echo "ERROR: file exists: $db"
echo "Use -f to force replacement"
exit -1
fi
fi
export PATH="$DIR/bin:$PATH"
cat $DIR/ddl/semsql.sql | sqlite3 $db
sqlite3 -echo $db -cmd ".mode csv" -cmd ".import $DIR/prefixes/prefixes.csv prefix" "SELECT COUNT(*) FROM prefix"
echo loading "$@"
if [[ "$@" == "" ]]; then
echo "No files to load; exiting"
exit 0
fi
for owlf in "$@"
do
if [[ $verbose == 1 ]]; then
echo "Loading: $owlf"
fi
$DIR/bin/rdftab $db < $owlf
echo "Counting statements"
sqlite3 $db "SELECT COUNT(*) FROM statements"
echo "Loading relation-graph inferences"
bn="$(basename $owlf .owl)"
inf_file="inferences/$bn-inf.tsv"
#if [[ ! -f $inf_file ]]; then
# relation-graph --ontology-file $owlf --redundant-output-file $@ --non-redundant-output-file inferences/$*-nr.ttl --property http://purl.obolibrary.org/obo/BFO_0000050
#fi
if [[ -f $inf_file ]]; then
echo "Loading inferences $inf_file"
sqlite3 $db -cmd '.separator "\t"' ".import $inf_file entailed_edge"
sqlite3 $db "SELECT COUNT(*) AS num_edges FROM entailed_edge"
else
echo "No inference file: $inf_file"
echo "TODO: add ability to run command to generate this"
fi
done
echo "## Indexing"
cat $DIR/indexes/indexes.sql | sqlite3 $db
if [[ $report == 1 ]]; then
echo "## Problems"
sqlite3 $db "SELECT * FROM all_problems"
echo "## Predicates"
sqlite3 $db "SELECT * FROM count_of_predicates"
echo "## Class Count"
sqlite3 $db "SELECT * FROM count_of_instantiated_classes"
echo ## Reports
sqlite3 -cmd ".echo on" -cmd ".headers on" $db < reports/query-semsql.sql > reports/out.txt 2> reports/err.txt
if grep -q "Error" reports/err.txt; then
echo "ERRORS"
cat reports/err.txt
exit -1
else
exit 0
fi
fi