Skip to content

Commit 4caed19

Browse files
committed
update to latest hdt commit, error out if not triples found, additional w3c testing
1 parent b0df3db commit 4caed19

4 files changed

Lines changed: 51 additions & 4 deletions

File tree

Cargo.lock

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ name = "benchmark"
1515
harness = false
1616

1717
[dependencies]
18+
anyhow = "1.0"
1819
chrono = "0.4"
1920
clap = { version = "4.5", features = ["derive","cargo"] }
2021
clap-verbosity-flag = "3.0"

src/builder.rs

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,19 @@ mod tests {
364364

365365
let res = build_hdt(vec![f.clone()], new_hdt.as_str(), Options::default());
366366
assert!(res.is_ok());
367+
368+
let source = std::fs::File::open(new_hdt).expect("failed to open hdt file");
369+
let hdt_reader = BufReader::new(source);
370+
let res = Hdt::new(hdt_reader);
371+
372+
match &res {
373+
Ok(_) => {}
374+
Err(e) => {
375+
eprintln!("{f} failed to load constructed hdt: {e}")
376+
}
377+
}
378+
379+
assert!(res.is_ok());
367380
}
368381
}
369382

@@ -387,7 +400,25 @@ mod tests {
387400
match &res {
388401
Ok(_) => {}
389402
Err(e) => {
390-
eprintln!("{f} failed to convert: {e}")
403+
// files with no triples should error out, the HDT library errors out as well
404+
if !f.contains("empty.ttl") {
405+
eprintln!("{f} failed to convert: {e}");
406+
}
407+
assert!(f.contains("empty.ttl"));
408+
continue;
409+
}
410+
}
411+
412+
assert!(res.is_ok());
413+
414+
let source = std::fs::File::open(new_hdt).expect("failed to open hdt file");
415+
let hdt_reader = BufReader::new(source);
416+
let res = Hdt::new(hdt_reader);
417+
418+
match &res {
419+
Ok(_) => {}
420+
Err(e) => {
421+
eprintln!("{f} failed to load constructed hdt: {e}")
391422
}
392423
}
393424

@@ -420,6 +451,19 @@ mod tests {
420451
}
421452

422453
assert!(res.is_ok());
454+
455+
let source = std::fs::File::open(new_hdt).expect("failed to open hdt file");
456+
let hdt_reader = BufReader::new(source);
457+
let res = Hdt::new(hdt_reader);
458+
459+
match &res {
460+
Ok(_) => {}
461+
Err(e) => {
462+
eprintln!("{f} failed to load constructed hdt: {e}")
463+
}
464+
}
465+
466+
assert!(res.is_ok());
423467
}
424468
}
425469

src/dictionary.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use hdt::{
55
containers::{self, ControlType, Sequence, vbyte::encode_vbyte},
66
dict_sect_pfc::DictSectPFC,
77
};
8-
use log::{debug, error, warn};
8+
use log::{debug, error};
99
use oxrdf::Term;
1010
use oxrdfio::RdfFormat::NTriples;
1111
use oxrdfio::RdfParser;
@@ -90,7 +90,8 @@ impl FourSectDictBuilder {
9090
object_terms.insert(term_to_hdt_bgp_str(&q.object)?);
9191
}
9292
if dict.predicate_terms.is_empty() {
93-
warn!("no triples found in provided RDF");
93+
error!("no triples found in provided RDF");
94+
return Err(anyhow::anyhow!("no triples found in the provided RDF file").into());
9495
}
9596

9697
dict.shared_terms = subject_terms.intersection(&object_terms).cloned().collect();

0 commit comments

Comments
 (0)