The blocks
function
The blocks
function can:
- parse a CEX data source into
Block
s, optionally filtering it by block type - filter a list of
Block
s by block type
It always returns a (possibly empty) Vector of Block
s.
Parsing a CEX data source
The following examples parse a CEX source with two blocks, one a ctscatalog
block, the other a ctsdata
block. They parse identical data from a URL, a file (f
in the example below is test/assets/burneyex.cex
in this github repository), and a string value using blocks
with a specified "reader".
Parse CEX from a URL:
using CiteEXchange
using CitableBase
url = "https://raw.githubusercontent.com/cite-architecture/CiteEXchange.jl/main/test/assets/burneyex.cex"
urlblocks = blocks(url, UrlReader)
2-element Vector{Block}:
Block("ctscatalog", SubString{String}["urn|citationScheme|groupName|workTitle|versionLabel|exemplarLabel|online|language", "urn:cts:greekLit:tlg5026.burney86.hmt:|book, scholion|Scholia to the Iliad|Main scholia to the Iliad of British Library, Burney 86|British Library, Burney 86||true|grc", "urn:cts:greekLit:tlg5026.burney86int.hmt:|book,scholion,section|Scholia to the Iliad|Interior scholia of British Library, Burney 86|British Library, Burney 86||true|grc"])
Block("ctsdata", SubString{String}["urn:cts:greekLit:tlg5026.burney86.normed:8.73r_1.ref|urn:cts:greekLit:tlg0012.tlg001.burney86:8.title", "urn:cts:greekLit:tlg5026.burney86.normed:8.73r_1.comment|Τὴν ῥαψῳδίαν κῶλον μάχην καλοῦσι: συντέμνει γὰρ τὴν διήγησιν συναχθόμενος τοῖς Ἀχαιοῖς ⁑", "urn:cts:greekLit:tlg5026.burney86.normed:8.73r_2.lemma|κροκόπεπλος"])
From a file:
fileblocks = blocks(f, FileReader)
2-element Vector{Block}:
Block("ctscatalog", SubString{String}["urn|citationScheme|groupName|workTitle|versionLabel|exemplarLabel|online|language", "urn:cts:greekLit:tlg5026.burney86.hmt:|book, scholion|Scholia to the Iliad|Main scholia to the Iliad of British Library, Burney 86|British Library, Burney 86||true|grc", "urn:cts:greekLit:tlg5026.burney86int.hmt:|book,scholion,section|Scholia to the Iliad|Interior scholia of British Library, Burney 86|British Library, Burney 86||true|grc"])
Block("ctsdata", SubString{String}["urn:cts:greekLit:tlg5026.burney86.normed:8.73r_1.ref|urn:cts:greekLit:tlg0012.tlg001.burney86:8.title", "urn:cts:greekLit:tlg5026.burney86.normed:8.73r_1.comment|Τὴν ῥαψῳδίαν κῶλον μάχην καλοῦσι: συντέμνει γὰρ τὴν διήγησιν συναχθόμενος τοῖς Ἀχαιοῖς ⁑", "urn:cts:greekLit:tlg5026.burney86.normed:8.73r_2.lemma|κροκόπεπλος"])
From a string:
cexstring = read(f, String)
stringblocks = blocks(cexstring, StringReader)
2-element Vector{Block}:
Block("ctscatalog", SubString{String}["urn|citationScheme|groupName|workTitle|versionLabel|exemplarLabel|online|language", "urn:cts:greekLit:tlg5026.burney86.hmt:|book, scholion|Scholia to the Iliad|Main scholia to the Iliad of British Library, Burney 86|British Library, Burney 86||true|grc", "urn:cts:greekLit:tlg5026.burney86int.hmt:|book,scholion,section|Scholia to the Iliad|Interior scholia of British Library, Burney 86|British Library, Burney 86||true|grc"])
Block("ctsdata", SubString{String}["urn:cts:greekLit:tlg5026.burney86.normed:8.73r_1.ref|urn:cts:greekLit:tlg0012.tlg001.burney86:8.title", "urn:cts:greekLit:tlg5026.burney86.normed:8.73r_1.comment|Τὴν ῥαψῳδίαν κῶλον μάχην καλοῦσι: συντέμνει γὰρ τὴν διήγησιν συναχθόμενος τοῖς Ἀχαιοῖς ⁑", "urn:cts:greekLit:tlg5026.burney86.normed:8.73r_2.lemma|κροκόπεπλος"])
The default is to parse from a string.
defaultblocks = blocks(cexstring)
2-element Vector{Block}:
Block("ctscatalog", SubString{String}["urn|citationScheme|groupName|workTitle|versionLabel|exemplarLabel|online|language", "urn:cts:greekLit:tlg5026.burney86.hmt:|book, scholion|Scholia to the Iliad|Main scholia to the Iliad of British Library, Burney 86|British Library, Burney 86||true|grc", "urn:cts:greekLit:tlg5026.burney86int.hmt:|book,scholion,section|Scholia to the Iliad|Interior scholia of British Library, Burney 86|British Library, Burney 86||true|grc"])
Block("ctsdata", SubString{String}["urn:cts:greekLit:tlg5026.burney86.normed:8.73r_1.ref|urn:cts:greekLit:tlg0012.tlg001.burney86:8.title", "urn:cts:greekLit:tlg5026.burney86.normed:8.73r_1.comment|Τὴν ῥαψῳδίαν κῶλον μάχην καλοῦσι: συντέμνει γὰρ τὴν διήγησιν συναχθόμενος τοῖς Ἀχαιοῖς ⁑", "urn:cts:greekLit:tlg5026.burney86.normed:8.73r_2.lemma|κροκόπεπλος"])
The results are equivalent.
urlblocks == fileblocks == stringblocks == defaultblocks
true
Filter CEX source by type
Specify the String value of a CEX block type as an additional parameter to filter the resulting Vector of Block
s to include only blocks of that type.
urlcatalog = blocks(url, UrlReader, "ctscatalog")
filecatalog = blocks(f, FileReader, "ctscatalog")
stringcatalog = blocks(cexstring, StringReader, "ctscatalog")
defaultcatalog = blocks(cexstring, "ctscatalog")
1-element Vector{Block}:
Block("ctscatalog", SubString{String}["urn|citationScheme|groupName|workTitle|versionLabel|exemplarLabel|online|language", "urn:cts:greekLit:tlg5026.burney86.hmt:|book, scholion|Scholia to the Iliad|Main scholia to the Iliad of British Library, Burney 86|British Library, Burney 86||true|grc", "urn:cts:greekLit:tlg5026.burney86int.hmt:|book,scholion,section|Scholia to the Iliad|Interior scholia of British Library, Burney 86|British Library, Burney 86||true|grc"])
urlcatalog == filecatalog == stringcatalog == defaultcatalog
true
Filter a list of Block
s by type
The blocks
function can also be used to select blocks of a given type from a list of Block
s.
filteredcatalog = blocks(fileblocks, "ctscatalog")
1-element Vector{Block}:
Block("ctscatalog", SubString{String}["urn|citationScheme|groupName|workTitle|versionLabel|exemplarLabel|online|language", "urn:cts:greekLit:tlg5026.burney86.hmt:|book, scholion|Scholia to the Iliad|Main scholia to the Iliad of British Library, Burney 86|British Library, Burney 86||true|grc", "urn:cts:greekLit:tlg5026.burney86int.hmt:|book,scholion,section|Scholia to the Iliad|Interior scholia of British Library, Burney 86|British Library, Burney 86||true|grc"])
filteredcatalog == filecatalog
true