diff options
| author | Federico Igne <federico.igne@cs.ox.ac.uk> | 2021-01-05 17:00:29 +0000 |
|---|---|---|
| committer | Federico Igne <federico.igne@cs.ox.ac.uk> | 2021-01-05 17:00:29 +0000 |
| commit | ad58eea444d9f1f16a2498a32777719911203a23 (patch) | |
| tree | 31a29bf0d2f34fb5aec16da6d5cdf3e177af8a65 | |
| parent | c29174ade7131639e9ea01c3ce408ee0a873c962 (diff) | |
| download | RSAComb-ad58eea444d9f1f16a2498a32777719911203a23.tar.gz RSAComb-ad58eea444d9f1f16a2498a32777719911203a23.zip | |
Add external script to execute benchmarks and gather results.
| -rwxr-xr-x | run_tests.bash | 203 | ||||
| -rw-r--r-- | src/main/scala/uk/ac/ox/cs/rsacomb/Main.scala | 2 | ||||
| -rw-r--r-- | src/main/scala/uk/ac/ox/cs/rsacomb/RSAOntology.scala | 16 | ||||
| -rw-r--r-- | src/main/scala/uk/ac/ox/cs/rsacomb/util/Logger.scala | 2 |
4 files changed, 214 insertions, 9 deletions
diff --git a/run_tests.bash b/run_tests.bash new file mode 100755 index 0000000..17cbf01 --- /dev/null +++ b/run_tests.bash | |||
| @@ -0,0 +1,203 @@ | |||
| 1 | #!/usr/bin/env bash | ||
| 2 | |||
| 3 | NC='\033[0m' | ||
| 4 | RED='\033[0;31m' | ||
| 5 | GREEN='\033[0;32m' | ||
| 6 | YELLOW='\033[0;33m' | ||
| 7 | |||
| 8 | msg_info() { | ||
| 9 | echo -e "${GREEN}$1${NC}" | ||
| 10 | } | ||
| 11 | |||
| 12 | msg_warn() { | ||
| 13 | echo -e "${YELLOW}$1${NC}" | ||
| 14 | } | ||
| 15 | |||
| 16 | msg_error() { | ||
| 17 | echo -e "${RED}$1${NC}" | ||
| 18 | } | ||
| 19 | |||
| 20 | print_help() { | ||
| 21 | echo | ||
| 22 | echo "testRSA - a quick script to run tests all night long" | ||
| 23 | echo | ||
| 24 | echo "USAGE:" | ||
| 25 | echo " testRSA OPTION [...]" | ||
| 26 | echo | ||
| 27 | echo "OPTIONs are:" | ||
| 28 | echo " -o | --ontology <path>:" | ||
| 29 | echo " path to ontology." | ||
| 30 | echo " -d | --data <path>:" | ||
| 31 | echo " path to a folder containing data for the ontology." | ||
| 32 | echo " -q | --queries <path>:" | ||
| 33 | echo " path to a folder containing SPARQL query files to be" | ||
| 34 | echo " executed against the ontology and data." | ||
| 35 | echo " -p | --prefix <path>:" | ||
| 36 | echo " provides a folder to prefix to the output files." | ||
| 37 | echo " Defaults to './results'." | ||
| 38 | echo " -h | -? | --help:" | ||
| 39 | echo " print this help" | ||
| 40 | echo | ||
| 41 | } | ||
| 42 | |||
| 43 | ONTOLOGY="" | ||
| 44 | DATA="" | ||
| 45 | QUERIES="" | ||
| 46 | PREFIX="./results" | ||
| 47 | |||
| 48 | while [[ $# -gt 0 ]] | ||
| 49 | do | ||
| 50 | case $1 in | ||
| 51 | -o|--ontology) | ||
| 52 | shift | ||
| 53 | ONTOLOGY="$1" | ||
| 54 | [ ! -r "$ONTOLOGY" ] && \ | ||
| 55 | msg_error "Unable to read '$ONTOLOGY'" && \ | ||
| 56 | print_help && \ | ||
| 57 | exit 2 | ||
| 58 | ;; | ||
| 59 | -d|--data) | ||
| 60 | shift | ||
| 61 | DATA="$1" | ||
| 62 | [ ! -d "$DATA" ] && \ | ||
| 63 | msg_error "'$DATA' is not a directory" && \ | ||
| 64 | print_help && \ | ||
| 65 | exit 2 | ||
| 66 | ;; | ||
| 67 | -q|--queries) | ||
| 68 | shift | ||
| 69 | QUERIES="$1" | ||
| 70 | [ ! -d "$QUERIES" ] && \ | ||
| 71 | msg_error "'$QUERIES' is not a directory" && \ | ||
| 72 | print_help && \ | ||
| 73 | exit 2 | ||
| 74 | ;; | ||
| 75 | -p|--prefix) | ||
| 76 | shift | ||
| 77 | PREFIX="$1" | ||
| 78 | ;; | ||
| 79 | -h|-?|--help) | ||
| 80 | print_help | ||
| 81 | exit 0 | ||
| 82 | ;; | ||
| 83 | *) | ||
| 84 | msg_error "$OPTION: invalid option" | ||
| 85 | print_help | ||
| 86 | exit 1 | ||
| 87 | ;; | ||
| 88 | esac | ||
| 89 | shift | ||
| 90 | done | ||
| 91 | |||
| 92 | [ -z "$ONTOLOGY" ] && \ | ||
| 93 | msg_error "Use -o | --ontology to provide an ontology file" && \ | ||
| 94 | print_help && \ | ||
| 95 | exit 3 | ||
| 96 | |||
| 97 | [ -z "$DATA" ] && \ | ||
| 98 | msg_error "Use -d | --data to provide a data folder" && \ | ||
| 99 | print_help && \ | ||
| 100 | exit 3 | ||
| 101 | |||
| 102 | [ -z "$QUERIES" ] && \ | ||
| 103 | msg_error "Use -q | --queries to provide a query folder" && \ | ||
| 104 | print_help && \ | ||
| 105 | exit 3 | ||
| 106 | |||
| 107 | |||
| 108 | DATAS=`\ls $DATA/*` | ||
| 109 | mkdir -p "$PREFIX" | ||
| 110 | for QUERY in "$QUERIES"/*.sparql | ||
| 111 | do | ||
| 112 | sbt "run $QUERY $ONTOLOGY $DATAS" 2>&1 | tee "$PREFIX/answers_$(basename $QUERY .sparql).txt" | ||
| 113 | done | ||
| 114 | |||
| 115 | OUTPUT="$PREFIX/results.csv" | ||
| 116 | echo "NAME, TBOX, RBOX, ABOX, \ | ||
| 117 | CANONICAL MODEL GENERATION, \ | ||
| 118 | CANONICAL MODEL RULES, CANONICAL MODEL RULES LOADING, \ | ||
| 119 | CANONICAL MODEL FACTS, CANONICAL MODEL FACTS LOADING, \ | ||
| 120 | CANONICAL MODEL IDB, CANONICAL MODEL EDB, \ | ||
| 121 | FILTERING PROGRAM GENERATION, \ | ||
| 122 | FILTERING PROGRAM RULES, FILTERING PROGRAM RULES LOADING, \ | ||
| 123 | FILTERING PROGRAM FACTS, FILTERING PROGRAM FACTS LOADING, \ | ||
| 124 | FILTERING PROGRAM IDB, FILTERING PROGRAM EDB, \ | ||
| 125 | ANSWERING TIME, #ANSWERS, #UNFILTERED, #SPURIOUS, %SPURIOUS" > "$OUTPUT" | ||
| 126 | |||
| 127 | for RESULT in "$PREFIX"/*.txt | ||
| 128 | do | ||
| 129 | awk -v filename="$RESULT" ' | ||
| 130 | BEGIN { | ||
| 131 | OFS = ", " | ||
| 132 | name = filename | ||
| 133 | sub("^.*answers_", "", name) | ||
| 134 | sub(".txt$", "", name) | ||
| 135 | } | ||
| 136 | /Original TBox/ { tbox_size = $NF } | ||
| 137 | /Original RBox/ { rbox_size = $NF } | ||
| 138 | /Original ABox/ { abox_size = $NF } | ||
| 139 | /Generating canonical model program \(END\)/ { canon_gen_time = $NF } | ||
| 140 | /Generating filtering program \(END\)/ { filter_gen_time = $NF } | ||
| 141 | /Canonical model rules/ { | ||
| 142 | canon_rules = $NF | ||
| 143 | canon = 1 | ||
| 144 | } | ||
| 145 | /Canonical model facts/ { | ||
| 146 | canon_facts = $NF | ||
| 147 | canon = 1 | ||
| 148 | } | ||
| 149 | /Filtering program rules/ { | ||
| 150 | filter_rules = $NF | ||
| 151 | } | ||
| 152 | /Filtering program facts/ { | ||
| 153 | filter_facts = $NF | ||
| 154 | } | ||
| 155 | /Loading rules \(END\)/ { | ||
| 156 | if (canon) { | ||
| 157 | canon_rules_load = $NF | ||
| 158 | } else { | ||
| 159 | filter_rules_load = $NF | ||
| 160 | } | ||
| 161 | } | ||
| 162 | /Loading facts/ { | ||
| 163 | if (canon) { | ||
| 164 | canon_facts_load = $NF | ||
| 165 | } else { | ||
| 166 | filter_facts_load = $NF | ||
| 167 | } | ||
| 168 | } | ||
| 169 | /Aggregate number of IDB facts/ { | ||
| 170 | sub("^.*=", "") | ||
| 171 | sub(",$", "") | ||
| 172 | if (canon) { | ||
| 173 | canon_idb = $0 | ||
| 174 | } else { | ||
| 175 | filter_idb = $0 | ||
| 176 | } | ||
| 177 | } | ||
| 178 | /Aggregate number of EDB facts/ { | ||
| 179 | sub("^.*=", "") | ||
| 180 | sub(",$", "") | ||
| 181 | if (canon) { | ||
| 182 | canon_edb = $0 | ||
| 183 | canon = 0 | ||
| 184 | } else { | ||
| 185 | filter_edb = $0 | ||
| 186 | } | ||
| 187 | } | ||
| 188 | /Answers computation \(END\)/ { answers_time = $NF } | ||
| 189 | /Number of answers/ { answers = $(NF-1) } | ||
| 190 | /Number of unfiltered answers/ { unfiltered = $(NF-1) } | ||
| 191 | /Number of spurious answers/ { spurious = $(NF-1) } | ||
| 192 | /Percentage of spurious answers/ { spurious_perc = $NF } | ||
| 193 | END { print name, tbox_size, rbox_size, abox_size, \ | ||
| 194 | canon_gen_time, canon_rules, canon_rules_load, canon_facts, canon_facts_load, \ | ||
| 195 | canon_idb, canon_edb, \ | ||
| 196 | filter_gen_time, filter_rules, filter_rules_load, filter_facts, filter_facts_load, \ | ||
| 197 | filter_idb, filter_edb, \ | ||
| 198 | answers_time, answers, unfiltered, spurious, spurious_perc | ||
| 199 | } | ||
| 200 | ' "$RESULT" >> "$OUTPUT" | ||
| 201 | done | ||
| 202 | |||
| 203 | exit 0 | ||
diff --git a/src/main/scala/uk/ac/ox/cs/rsacomb/Main.scala b/src/main/scala/uk/ac/ox/cs/rsacomb/Main.scala index 0554dbc..bf96a31 100644 --- a/src/main/scala/uk/ac/ox/cs/rsacomb/Main.scala +++ b/src/main/scala/uk/ac/ox/cs/rsacomb/Main.scala | |||
| @@ -61,7 +61,7 @@ object RSAComb extends App { | |||
| 61 | case Some(query) => { | 61 | case Some(query) => { |
| 62 | val answers = ontology ask query | 62 | val answers = ontology ask query |
| 63 | Logger.print(s"$answers", Logger.QUIET) | 63 | Logger.print(s"$answers", Logger.QUIET) |
| 64 | Logger print s"Number of answer: ${answers.length} (${answers.lengthWithMultiplicity})" | 64 | Logger print s"Number of answers: ${answers.length} (${answers.lengthWithMultiplicity})" |
| 65 | 65 | ||
| 66 | /* Additional DEBUG information */ | 66 | /* Additional DEBUG information */ |
| 67 | if (Logger.level >= Logger.DEBUG) { | 67 | if (Logger.level >= Logger.DEBUG) { |
diff --git a/src/main/scala/uk/ac/ox/cs/rsacomb/RSAOntology.scala b/src/main/scala/uk/ac/ox/cs/rsacomb/RSAOntology.scala index 4ac5a77..8d5bf4c 100644 --- a/src/main/scala/uk/ac/ox/cs/rsacomb/RSAOntology.scala +++ b/src/main/scala/uk/ac/ox/cs/rsacomb/RSAOntology.scala | |||
| @@ -114,9 +114,9 @@ class RSAOntology(val ontology: OWLOntology) { | |||
| 114 | 114 | ||
| 115 | val axioms: List[OWLLogicalAxiom] = abox ::: tbox ::: rbox | 115 | val axioms: List[OWLLogicalAxiom] = abox ::: tbox ::: rbox |
| 116 | 116 | ||
| 117 | Logger.print(s"Original TBox: ${tbox.length} axioms", Logger.DEBUG) | 117 | Logger.print(s"Original TBox: ${tbox.length}", Logger.DEBUG) |
| 118 | Logger.print(s"Original RBox: ${rbox.length} axioms", Logger.DEBUG) | 118 | Logger.print(s"Original RBox: ${rbox.length}", Logger.DEBUG) |
| 119 | Logger.print(s"Original ABox: ${abox.length} axioms", Logger.DEBUG) | 119 | Logger.print(s"Original ABox: ${abox.length}", Logger.DEBUG) |
| 120 | 120 | ||
| 121 | /* Retrieve individuals in the original ontology | 121 | /* Retrieve individuals in the original ontology |
| 122 | */ | 122 | */ |
| @@ -358,16 +358,18 @@ class RSAOntology(val ontology: OWLOntology) { | |||
| 358 | 358 | ||
| 359 | //data.beginTransaction(TransactionType.READ_WRITE) | 359 | //data.beginTransaction(TransactionType.READ_WRITE) |
| 360 | 360 | ||
| 361 | Logger print s"Canonical model: ${canon.rules.length} rules" | 361 | Logger print s"Canonical model rules: ${canon.rules.length}" |
| 362 | RDFoxUtil.addRules(data, this.canonicalModel.rules) | 362 | RDFoxUtil.addRules(data, this.canonicalModel.rules) |
| 363 | 363 | ||
| 364 | Logger print s"Canonical model: ${canon.facts.length} facts" | 364 | Logger print s"Canonical model facts: ${canon.facts.length}" |
| 365 | RDFoxUtil.addFacts(data, this.canonicalModel.facts) | 365 | RDFoxUtil.addFacts(data, this.canonicalModel.facts) |
| 366 | 366 | ||
| 367 | Logger print s"Filtering program: ${filter.facts.length} facts" | 367 | RDFoxUtil printStatisticsFor data |
| 368 | |||
| 369 | Logger print s"Filtering program facts: ${filter.facts.length}" | ||
| 368 | RDFoxUtil.addFacts(data, filter.facts) | 370 | RDFoxUtil.addFacts(data, filter.facts) |
| 369 | 371 | ||
| 370 | Logger print s"Filtering program: ${filter.rules.length} rules" | 372 | Logger print s"Filtering program rules: ${filter.rules.length}" |
| 371 | RDFoxUtil.addRules(data, filter.rules) | 373 | RDFoxUtil.addRules(data, filter.rules) |
| 372 | 374 | ||
| 373 | //data.commitTransaction() | 375 | //data.commitTransaction() |
diff --git a/src/main/scala/uk/ac/ox/cs/rsacomb/util/Logger.scala b/src/main/scala/uk/ac/ox/cs/rsacomb/util/Logger.scala index 74797a2..56e9de0 100644 --- a/src/main/scala/uk/ac/ox/cs/rsacomb/util/Logger.scala +++ b/src/main/scala/uk/ac/ox/cs/rsacomb/util/Logger.scala | |||
| @@ -38,7 +38,7 @@ object Logger { | |||
| 38 | print(s"$desc (START)", lvl) | 38 | print(s"$desc (START)", lvl) |
| 39 | val result = expr | 39 | val result = expr |
| 40 | val t1 = System.currentTimeMillis() | 40 | val t1 = System.currentTimeMillis() |
| 41 | print(s"$desc (END): ${(t1 - t0).toFloat / 1000}s", lvl) | 41 | print(s"$desc (END): ${(t1 - t0).toFloat / 1000}", lvl) |
| 42 | result | 42 | result |
| 43 | } | 43 | } |
| 44 | 44 | ||
