使用 biblatex 和 biber 检查 urldate

使用 biblatex 和 biber 检查 urldate

我尝试进行设置,以便如果url使用该字段,则也必须使用 urldate。以下是我目前所拥有的。似乎有一个错误,因为biber -V它抱怨所有三个条目都缺少一个urldate字段。理想的解决方案不会抱怨 acl85 条目,因为它是完整的。它也不会抱怨 CP85a-irgendwo,因为它从 acl85 继承了两个字段,但它应该抱怨 CP85a-nirgendwo 项,因为它覆盖了 url 但有一个继承的 urldate 字段。我不知道是否有可能捕捉到最后一种情况。但让其他两个工作起来,就已经很棒了。

\documentclass{article}

\begin{filecontents}{\jobname.bib}

@inproceedings{CP85a-irgendwo,
        Author = {Lewis G. Creary and Carl J. Pollard},
        Crossref = {acl85},
        Pages = {172--179},
        Title = {A Computational Semantics for Natural Language}}

@inproceedings{CP85a-nirgendwo,
        Author = {Lewis G. Creary and Carl J. Pollard},
        Crossref = {acl85},
        url = {http://nirgendwo.de},
        Pages = {172--179},
        Title = {A Computational Semantics for Natural Language}}

@proceedings{acl85,
        Address = {Chicago, IL},
        Editor = {Mann, William C.},
        Publisher = {acl},
        Title = {Proceedings of the {Twenty-Third Annual Meeting of the Association for
Computational Linguistics}},
        url = {http://irgendwo.de},
        urldate = {2021-02-15},
        Year = {1985}}


\end{filecontents}
\begin{filecontents}{bookparent.dbx}
\DeclareDatamodelEntryfields[book]{
  booktitle}

\DeclareDatamodelFields[type=field,datatype=date]{
   urldate}
\DeclareDatamodelEntryfields{urldate}

\ResetDatamodelConstraints

\DeclareDatamodelConstraints[
  article,
  book,
  inbook,
  bookinbook,
  suppbook,
  booklet,
  collection,
  incollection,
  suppcollection,
  manual,
  misc,
  mvbook,
  mvcollection,
  online,
  patent,
  periodical,
  suppperiodical,
  proceedings,
  inproceedings,
  reference,
  inreference,
  report,
  set,
  thesis,
  unpublished]{
    \constraint[type=mandatory]{
      \constraintfieldsxor{
        \constraintfield{date}
        \constraintfield{year}
      }
    }
    % if there is an URL then there should be a urldate field.
    \constraint[type=conditional]{
      \antecedent[quantifier=one]{
        \constraintfield{url}
      }
      \consequent[quantifier=all]{
          \constraintfield{urldate}
      }
    }
  }


\end{filecontents}


\usepackage[
  natbib=true,
  backend=biber,
  datamodel=bookparent,
]{biblatex}
\addbibresource{\jobname.bib}

\begin{document}
\autocite{CP85a-nirgendwo,CP85a-irgendwo}

\printbibliography
\end{document}

答案1

date字段有点特殊biblatex,因为它们在 Biber 运行期间被解析并分成biblatex日期部分。

显然,数据模型约束验证发生在非常晚的阶段,此时日期解析和拆分已经发生,因此您不想测试字段是否存在urldate,而是想检查urlyear和。urlmonthurlday

\documentclass{article}

\begin{filecontents}{\jobname.bib}
@inproceedings{CP85a-irgendwo,
  author   = {Lewis G. Creary and Carl J. Pollard},
  crossref = {acl85},
  pages    = {172--179},
  title    = {A Computational Semantics for Natural Language},
}
@inproceedings{CP85a-nirgendwo,
  author   = {Lewis G. Creary and Carl J. Pollard},
  crossref = {acl85},
  url      = {http://nirgendwo.de},
  pages    = {172--179},
  title    = {A Computational Semantics for Natural Language},
}
@proceedings{acl85,
  address   = {Chicago, IL},
  editor    = {Mann, William C.},
  publisher = {acl},
  title     = {Proceedings of the {Twenty-Third Annual Meeting
               of the Association for Computational Linguistics}},
  url       = {http://irgendwo.de},
  urldate   = {2021-02-15},
  year      = {1985},
}
\end{filecontents}
\begin{filecontents}{bookparent.dbx}
\DeclareDatamodelEntryfields[book]{
  booktitle}

\DeclareDatamodelFields[type=field,datatype=date]{
   urldate}
\DeclareDatamodelEntryfields{urldate}

\ResetDatamodelConstraints

\DeclareDatamodelConstraints[
  article,
  book,
  inbook,
  bookinbook,
  suppbook,
  booklet,
  collection,
  incollection,
  suppcollection,
  manual,
  misc,
  mvbook,
  mvcollection,
  online,
  patent,
  periodical,
  suppperiodical,
  proceedings,
  inproceedings,
  reference,
  inreference,
  report,
  set,
  thesis,
  unpublished]{
    \constraint[type=mandatory]{
      \constraintfieldsxor{
        \constraintfield{date}
        \constraintfield{year}
      }
    }
    % if there is an URL then there should be a urldate field.
    \constraint[type=conditional]{
      \antecedent[quantifier=one]{
        \constraintfield{url}
      }
      \consequent[quantifier=all]{
        \constraintfield{urlyear}
        \constraintfield{urlmonth}
        \constraintfield{urlday}
      }
    }
  }
\end{filecontents}

\usepackage[
  natbib=true,
  backend=biber,
  datamodel=bookparent,
]{biblatex}
\addbibresource{\jobname.bib}

\begin{document}
\autocite{CP85a-nirgendwo,CP85a-irgendwo}

\printbibliography
\end{document}

运行时不会给出任何警告biber -V,因为所有条目都有urlurldate

特别CP85a-nirgendwo是不会生成警告,即使您希望看到该条目的警告。由于数据模型验证发生在继承数据已经解析的位置,因此无法发出警告,CP85a-nirgendwo因为它确实有一个urland urldate(数据模型验证不知道一个是继承的,另一个是在条目本身中给出的)。如果您需要能够将继承的字段与直接在条目中给出的字段区别对待,您可能需要在以下位置打开功能请求:https://github.com/plk/biber/issues

相关内容