mod config;
mod converter;
mod namespaces;
mod rdf;
mod reverse_converter;
pub use config::{BibframeConfig, RdfFormat};
pub use namespaces::{
bflc, classes, properties, BF, BFLC, CARRIER_TYPES, CONTENT_TYPES, COUNTRIES, LANGUAGES,
LC_NAMES, LC_SUBJECTS, MADSRDF, MEDIA_TYPES, RDF, RDFS, RELATORS, XSD,
};
pub use rdf::{RdfGraph, RdfNode, RdfTriple};
use crate::error::Result;
use crate::record::Record;
#[must_use]
pub fn marc_to_bibframe(record: &Record, config: &BibframeConfig) -> RdfGraph {
converter::convert_marc_to_bibframe(record, config)
}
pub fn bibframe_to_marc(graph: &RdfGraph) -> Result<Record> {
reverse_converter::convert_bibframe_to_marc(graph)
}
#[cfg(test)]
mod tests {
use super::*;
use crate::leader::Leader;
fn make_test_leader() -> Leader {
Leader {
record_length: 1000,
record_status: 'n',
record_type: 'a',
bibliographic_level: 'm',
control_record_type: ' ',
character_coding: 'a',
indicator_count: 2,
subfield_code_count: 2,
data_base_address: 100,
encoding_level: ' ',
cataloging_form: 'a',
multipart_level: ' ',
reserved: "4500".to_string(),
}
}
#[test]
fn test_marc_to_bibframe_basic() {
let mut record = Record::new(make_test_leader());
record.add_control_field("001".to_string(), "12345".to_string());
let config = BibframeConfig::default();
let graph = marc_to_bibframe(&record, &config);
assert!(graph.len() >= 4);
}
#[test]
fn test_marc_to_bibframe_with_base_uri() {
let mut record = Record::new(make_test_leader());
record.add_control_field("001".to_string(), "test123".to_string());
let config = BibframeConfig::new().with_base_uri("http://example.org/");
let graph = marc_to_bibframe(&record, &config);
let nt = graph
.serialize(RdfFormat::NTriples)
.expect("serialization failed");
assert!(nt.contains("http://example.org/work/test123"));
assert!(nt.contains("http://example.org/instance/test123"));
}
#[test]
fn test_bibframe_to_marc_stub() {
let graph = RdfGraph::new();
let record = bibframe_to_marc(&graph).expect("conversion failed");
assert!(record.fields.is_empty());
}
#[test]
fn test_rdf_format_serialization() {
let mut record = Record::new(make_test_leader());
record.add_control_field("001".to_string(), "12345".to_string());
let config = BibframeConfig::default();
let graph = marc_to_bibframe(&record, &config);
let _ = graph
.serialize(RdfFormat::NTriples)
.expect("N-Triples serialization failed");
let _ = graph
.serialize(RdfFormat::Turtle)
.expect("Turtle serialization failed");
}
}