BatchMarc在Go + JS上处理Marc文件

所有的海狸!
今天是星期五,这意味着时间要盘点!

继续我们图书馆俱乐部的主题,我让所有参与其中的人都感到高兴:我做到了!

在大量的神经细胞枯竭之后,经过了关于marc格式的文档编写工作,再加上一堆拐杖之后,我仍然为marc格式整理了一个相对比较理智(但仍然带有一个糟糕的代码:)的转换器(+处理程序+足以满足幻想的一切)。

https://github.com/HerzenLibRu/BatchMarc(处理程序,规则用js编写)

https://github.com/t0pep0/marc21(Go语言库,用于处理marc格式)



您可以这样运行:
go main.go inputFile.ldb outputFile.ldb rules.js

规则适用于文件中的每个marc条目。
文档尚未编写,但是一切都摆在我们面前吗?=)

库(以及相应的转换器)的一些细微差别:
  • 子字段存储在链接列表中,添加后进行排序(同事的特定请求不允许使用哈希图)
  • 命名领导者标记您可能不喜欢


编写规则的功能:
开始执行规则时,已经有两个对象:orig和res-orig-原始记录,res-最终将写入输出文件中的内容,并且当规则开始时,res是一个空对象,刚刚被初始化,在当orig充满数据时

  function VariableSubField(name, data){
      this.Name = name;
      this.Data = data;
    }

    function VariableField(tag, indicatorOne, indicatorTwo) {
      this.Tag = tag;
      this.IndicatorOne = indicatorOne;
      this.IndicatorTwo = indicatorTwo;
      this.RawData = [];
      this.SubField = [];
    }

    function Leader() {
        this.Status = "";
        this.Type = "";
        this.BibLevel = "";
        this.ControlType = "";
        this.CharacterEncoding = "";
        this.IndicatorCount = "";
        this.SubfieldCodeCount = "";
        this.EncodingLevel = "";
        this.CatalogingForm = "";
        this.MultipartLevel = "";
        this.LengthOFFieldPort = "";
        this.StartCharPos = "";
        this.LengthImplemenDefine = "";
        this.Undefine = "";
    }

    function MarcRecord(){
      this.Leader = new Leader()
      this.VariableField = []
    };

    orig = new MarcRecord();
    res = new MarcRecord();


制定规则后,Go将从res中获取数据,并将其写入文件。

注意!该代码未经过优化,请认为它是最小的可行产品。

可以在BatchMarc存储库中找到规则的示例。

PullRequest,IssueRequest-被

UPD 接受:用于编写规则的js被选为分布最广泛的语言(包括在库环境中)

Source: https://habr.com/ru/post/zh-CN395377/


All Articles