Documentation
¶
Overview ¶
Package bibframe converts MARC 21 records to BIBFRAME 2.0, the Library of Congress linked-data model that replaces the flat MARC record with an RDF graph of related resources: a bf:Work (the intellectual content) and a bf:Instance (a particular publication of it), linked by bf:instanceOf / bf:hasInstance.
BIBFRAME is a different data model than MARC — a graph, not a leader+fields record — so this is a one-way MARC->BIBFRAME crosswalk, not a codec, following a subset of the LoC marc2bibframe2 mapping. Two serializations are produced, both hand-written with the standard library only (no RDF dependency):
- RDF/XML (Encode / Writer / WriteFile) — the canonical LoC serialization.
- JSON-LD (EncodeJSONLD / JSONLDWriter / WriteJSONLDFile).
The collection Writers implement codex.RecordWriter, so they plug into codex.Convert as conversion targets; both wrap their records in a container (an rdf:RDF element or a JSON-LD @graph) and must be closed:
w := bibframe.NewWriter(out) // RDF/XML; or NewJSONLDWriter for JSON-LD codex.Convert(iso2709.NewReader(src), w) w.Close()
The crosswalk covers the common fields (titles, contributions, subjects, language, classification, summary on the Work; title, provision, extent, edition, identifiers and electronic locator on the Instance). Fields outside that set are not carried, and BIBFRAME cannot round-trip back to full MARC.
Index ¶
- func Decode(data []byte) ([]*codex.Record, error)
- func Encode(r *codex.Record) ([]byte, error)
- func EncodeJSONLD(r *codex.Record) ([]byte, error)
- func EncodeNQuads(r *codex.Record, graph rdf.Term) ([]byte, error)
- func EncodeNTriples(r *codex.Record) ([]byte, error)
- func EncodeTurtle(r *codex.Record) ([]byte, error)
- func Provenance(graph, source, agent rdf.Term, generatedAt string) *rdf.Graph
- func ReadFile(path string) ([]*codex.Record, error)
- func RecordGraph(r *codex.Record) rdf.Term
- func WriteFile(path string, records []*codex.Record) error
- func WriteJSONLDFile(path string, records []*codex.Record) error
- func WriteNQuadsFile(path string, records []*codex.Record, graphFor func(*codex.Record) rdf.Term) error
- func WriteNTriplesFile(path string, records []*codex.Record) error
- func WriteTurtleFile(path string, records []*codex.Record) error
- type AdminMetadata
- type BIBFRAME
- type Classification
- type Contribution
- type Identifier
- type Instance
- type JSONLDWriter
- type NQuadsWriter
- type NTriplesWriter
- type Provision
- type Reader
- type Subject
- type Title
- type TurtleWriter
- type Work
- type Writer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Decode ¶ added in v0.3.0
Decode parses a BIBFRAME document — RDF/XML, JSON-LD, Turtle or N-Triples, autodetected — and reverse-crosswalks every bf:Work (with its linked bf:Instance) to a MARC 21 record. It reads the vocabulary the forward crosswalk emits and the common shape of LoC marc2bibframe2 output. BIBFRAME is a lossier model than MARC, so the result carries the crosswalked fields rather than reproducing the original record byte for byte; re-encoding it yields an equivalent BIBFRAME graph.
func EncodeJSONLD ¶
EncodeJSONLD converts a record to a standalone BIBFRAME JSON-LD document.
func EncodeNQuads ¶ added in v0.4.0
EncodeNQuads converts a record to a BIBFRAME N-Quads document whose statements are all tagged with the given graph term — the record's provenance, or named graph. A zero-value graph term produces plain N-Triples (the default graph).
func EncodeNTriples ¶ added in v0.3.0
EncodeNTriples converts a record to a standalone BIBFRAME N-Triples document.
func EncodeTurtle ¶ added in v0.3.0
EncodeTurtle converts a record to a standalone BIBFRAME Turtle document.
func Provenance ¶ added in v0.4.0
Provenance returns PROV-O triples describing a named graph as an entity that was generated from a source, attributed to an agent, at a time — the nanopublication / W3C PROV pattern of asserting provenance with the data-graph IRI itself as the subject, kept distinct from the data it describes. This complements the in-graph bf:AdminMetadata: AdminMetadata travels inside every serialization for BIBFRAME consumers, while these triples give an N-Quads dataset a separate, machine-readable provenance record about each named graph.
Zero-value source or agent terms and an empty generatedAt are omitted. Serialize the result into a provenance graph alongside the data graph named by graph, e.g. with an rdf.Encoder:
var enc rdf.Encoder buf = enc.AppendNQuads(buf, dataGraph, g) // the record, in graph g buf = enc.AppendNQuads(buf, bibframe.Provenance(g, src, who, ts), provGraph) // its provenance
func ReadFile ¶ added in v0.3.0
ReadFile reads and decodes every BIBFRAME record in the file at path.
func RecordGraph ¶ added in v0.4.0
RecordGraph returns a per-record provenance graph term derived from the record's control number (field 001), suitable as the graphFor argument to NewNQuadsWriter so each record's statements land in their own named graph.
func WriteJSONLDFile ¶
WriteJSONLDFile converts every record to a BIBFRAME JSON-LD file.
func WriteNQuadsFile ¶ added in v0.4.0
func WriteNQuadsFile(path string, records []*codex.Record, graphFor func(*codex.Record) rdf.Term) error
WriteNQuadsFile writes every record to path as one N-Quads document, tagging each record's statements with the graph term returned by graphFor.
func WriteNTriplesFile ¶ added in v0.3.0
WriteNTriplesFile writes every record to path as one N-Triples document.
func WriteTurtleFile ¶ added in v0.3.0
WriteTurtleFile writes every record to path as one Turtle document.
Types ¶
type AdminMetadata ¶ added in v0.4.0
type AdminMetadata struct {
ControlNumber string // field 001
ChangeDate string // field 005, as an xsd:dateTime string
DescriptionConventions string // field 040 $e (e.g. "rda")
}
AdminMetadata is administrative provenance about the record's description — the BIBFRAME bf:AdminMetadata carrying the record control number, the cataloging conventions, the last-change date, and the generation process that produced the RDF. It is what the LoC/BIBFRAME ecosystem reads for provenance.
type BIBFRAME ¶
BIBFRAME is the Work/Instance pair derived from one MARC record.
func FromRecord ¶
func FromRecord(r *codex.Record) *BIBFRAME
FromRecord maps a MARC record to a BIBFRAME Work/Instance pair in a single pass over the fields, following the common-field crosswalk.
type Classification ¶
type Classification struct {
Class string // "ClassificationLcc" or "ClassificationDdc"
Value string
}
Classification is a call number with its BIBFRAME class.
type Contribution ¶
type Contribution struct {
Primary bool // a bflc:PrimaryContribution (1xx) vs a plain bf:Contribution (7xx)
Class string // agent class: "Person", "Organization" or "Meeting"
Label string // agent name
Role string // role term, or ""
}
Contribution links an Agent to the Work with an optional role.
type Identifier ¶
Identifier is a typed identifier carried by the Instance.
type Instance ¶
type Instance struct {
Titles []Title
ResponsibilityStatement string
EditionStatement string
Provision *Provision
Extent []string
Identifiers []Identifier
ElectronicLocator []string
Admin *AdminMetadata
}
Instance is a particular publication of the Work (bf:Instance).
type JSONLDWriter ¶
type JSONLDWriter struct {
// contains filtered or unexported fields
}
JSONLDWriter converts records and writes them into a JSON-LD @graph array. Close must be called to terminate the document.
func NewJSONLDWriter ¶
func NewJSONLDWriter(w io.Writer) *JSONLDWriter
NewJSONLDWriter returns a Writer that writes a BIBFRAME JSON-LD document to w.
func (*JSONLDWriter) Close ¶
func (wr *JSONLDWriter) Close() error
func (*JSONLDWriter) Write ¶
func (wr *JSONLDWriter) Write(r *codex.Record) error
type NQuadsWriter ¶ added in v0.4.0
type NQuadsWriter struct {
// contains filtered or unexported fields
}
NQuadsWriter writes a collection of records as N-Quads, tagging each record's statements with a provenance graph term. It reuses one encoder so blank-node labels stay unique across the whole stream — otherwise two records that each number their blanks from scratch would collide and merge in the output.
func NewNQuadsWriter ¶ added in v0.4.0
func NewNQuadsWriter(w io.Writer, graphFor func(*codex.Record) rdf.Term) *NQuadsWriter
NewNQuadsWriter returns an NQuadsWriter over w. graphFor maps each record to its provenance graph term; a nil graphFor (or one returning a zero-value term) writes the default graph, equivalent to N-Triples. It implements codex.RecordWriter, so it works as a codex.Convert target. Pass RecordGraph for a per-record named graph keyed on the control number.
func (*NQuadsWriter) Close ¶ added in v0.4.0
func (nw *NQuadsWriter) Close() error
Close reports the first write error, if any.
func (*NQuadsWriter) Write ¶ added in v0.4.0
func (nw *NQuadsWriter) Write(r *codex.Record) error
Write serializes one record's BIBFRAME graph as N-Quads under its graph term.
type NTriplesWriter ¶ added in v0.3.0
type NTriplesWriter struct {
// contains filtered or unexported fields
}
NTriplesWriter writes a collection of records as N-Triples. Because N-Triples has no document framing, records simply concatenate; Close is a no-op kept for API symmetry with the other writers.
func NewNTriplesWriter ¶ added in v0.3.0
func NewNTriplesWriter(w io.Writer) *NTriplesWriter
NewNTriplesWriter returns an NTriplesWriter over w. It implements codex.RecordWriter, so it works as a codex.Convert target.
func (*NTriplesWriter) Close ¶ added in v0.3.0
func (nw *NTriplesWriter) Close() error
Close reports the first write error, if any.
func (*NTriplesWriter) Write ¶ added in v0.3.0
func (nw *NTriplesWriter) Write(r *codex.Record) error
Write serializes one record's BIBFRAME graph, keeping its blank-node labels distinct from every other record's in the stream.
type Reader ¶ added in v0.3.0
type Reader struct {
// contains filtered or unexported fields
}
Reader reads BIBFRAME records from a stream. A BIBFRAME document is a single RDF graph, so the first Read parses the whole input; successive calls return the reconstructed records in document order, then io.EOF.
type Subject ¶
type Subject struct {
Class string // "Topic", "Place", "Person", "Organization" or "Meeting"
Label string
}
Subject is a topical, geographic or name access point on the Work.
type Title ¶
type Title struct {
Type string // "" for the transcribed title, "uniform" for 130/240
MainTitle string
Subtitle string
PartNumber string
PartName string
}
Title is a bf:Title with its component portions.
type TurtleWriter ¶ added in v0.3.0
type TurtleWriter struct {
// contains filtered or unexported fields
}
TurtleWriter writes a collection of records as Turtle, emitting the @prefix header once before the first record.
func NewTurtleWriter ¶ added in v0.3.0
func NewTurtleWriter(w io.Writer) *TurtleWriter
NewTurtleWriter returns a TurtleWriter over w. It implements codex.RecordWriter.
func (*TurtleWriter) Close ¶ added in v0.3.0
func (tw *TurtleWriter) Close() error
Close reports the first write error, if any.
func (*TurtleWriter) Write ¶ added in v0.3.0
func (tw *TurtleWriter) Write(r *codex.Record) error
Write serializes one record, preceded by the prefix header on the first call, keeping its blank-node labels distinct from every other record's in the stream.
type Work ¶
type Work struct {
Class string // bf class refining bf:Work (e.g. "Text"), or ""
Titles []Title
Contributions []Contribution
Subjects []Subject
GenreForms []string
Languages []string // ISO 639-2 codes
Classifications []Classification
Summary []string
}
Work is the intellectual content (bf:Work) plus a specific content class.