忽略 biber 中的特定 URL 字段?

忽略 biber 中的特定 URL 字段?

我使用 Biber 来阅读我的文献。通常应该打印出 URL,但有些条目的 URL 很“丑陋”,例如“http://dx.doi.org/...”等等。如果 URL 字段包含特定字符串,是否可以不打印 URL?我不想清理我的 bib 文件,因为也许我想稍后使用所有 URL。

我尝试了 karlkoeller 的建议,但仍然不起作用。为什么以下代码不起作用?

\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map{
      \step[fieldsource=url,
        match=\regexp{dx.doi.org|dl.acm.org(.+)}, null=true
        ]
    }
  }
}

答案1

您的解决方案是使用biblatexbibersourcemap功能。

将以下代码片段添加到您的序言中。

\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map{
      \step[fieldsource=url, match=\regexp{http://(dx.doi.org/|dl.acm.org/)}, final]
      \step[fieldset=url, null]
      \step[fieldset=urldate, null]
    }
  }
}

您可以通过在 中指定 URL 来扩展要删除的 URL 列表match=\regexp{http://(dx.doi.org/|dl.acm.org/)}。要进行过滤example.com,请编写该行match=\regexp{http://(dx.doi.org/|dl.acm.org/|example.com)},但您可能match=\regexp{http://(www.)?(dx.doi.org/|dl.acm.org/|example.com)}还应该使用 来捕获www.example.com

biber使用 Perl 的正则表达式,你可以阅读更多关于它们的内容这里

如果biber找到匹配项,则urlurldate被清除,否则什么也不会发生。

数学家协会

\documentclass{article}
\usepackage[style=authoryear,backend=biber]{biblatex}

\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map{
      \step[fieldsource=url, match=\regexp{http://(dx.doi.org/|dl.acm.org/)}, final]
      \step[fieldset=url, null]
      \step[fieldset=urldate, null]
    }
  }
}

\begin{filecontents}{\jobname.bib}
@article{testarto,
  author        = {Arnold Uthor},
  title         = {L'Article},
  date          = {2013},
  journal       = {Journal of Interesting Articles},
  volume        = {42},
  url           = {http://dx.doi.org/10.234/56789},
  urldate       = {2013-09-18},
}
@article{testartt,
  author        = {William Riter},
  title         = {Research},
  date          = {2012},
  journal       = {Journal of Interesting Articles},
  volume        = {12},
  url           = {http://dx.doi.org/10.234/56789},
  urldate       = {2013-09-18},
}
@article{testartf,
  author        = {Steve C. Ientist},
  title         = {Some Paper},
  date          = {2012},
  journal       = {Journal of the ACM},
  volume        = {12},
  url           = {http://dl.acm.org/citation.cfm?id=2487241&picked=prox&CFID=362895712&CFTOKEN=85933440},
  urldate       = {2013-09-19},
}
@online{blog,
  author        = {Bernie Logger},
  title         = {A Very Opinionated Blogpost},
  date          = {2013-09-12},
  url           = {http://www.example.com/blog/2013/09/12/opinion},
  urldate       = {2013-09-19},
}
\end{filecontents}
\addbibresource{\jobname.bib}

\begin{document}
\nocite{*}
\printbibliography
\end{document}

产量 在此处输入图片描述


编辑

biber的功能使我们能够对这些 URL 实施更复杂的处理。

以下 MWE 将映射 DOI、稳定的 JSTOR 标识符和 arXiv 链接至适当的doieprintfields。如果您不想显示这些内容,只需将doi=false和添加eprint=falsebiblatex的选项即可。

\documentclass{article}
\usepackage{hyperref}
\usepackage[style=authoryear,backend=biber]{biblatex}

\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map{% JSTOR stable
      \step[fieldsource=url, match=\regexp{https?://(www.)?jstor.org/stable/}, final]
      \step[fieldset=eprint, origfieldval]
      \step[fieldsource=eprint, match=\regexp{https?://(www.)?jstor.org/stable/}, replace={}]
      \step[fieldset=eprinttype, fieldvalue={jstor}]
      \step[fieldset=url, null]
      \step[fieldset=urldate, null]
    }
    \map{% arXiv
      \step[fieldsource=url, match=\regexp{https?://arxiv.org/(abs|pdf|ps|format)/}, final]
      \step[fieldset=eprint, origfieldval]
      \step[fieldsource=eprint, match=\regexp{https?://arxiv.org/(abs|pdf|ps|format)/}, replace={}]
      \step[fieldset=eprinttype, fieldvalue={arxiv}]
      \step[fieldset=url, null]
      \step[fieldset=urldate, null]
    }
    \map{% DOIs
      \step[fieldsource=url, match=\regexp{https?://dx.doi.org/}, final]
      \step[fieldset=doi, origfieldval]
      \step[fieldsource=doi, match=\regexp{https?://dx.doi.org/}, replace={}]
      \step[fieldset=url, null]
      \step[fieldset=urldate, null]
    }
    \map{% get rid of
      \step[fieldsource=url, match=\regexp{https?://(dl.acm.org/)}, final]
      \step[fieldset=url, null]
      \step[fieldset=urldate, null]
    }
  }
}

\begin{filecontents}{\jobname.bib}
@article{testarto,
  author        = {Arnold Uthor},
  title         = {L'Article},
  date          = {2013},
  journal       = {Journal of Interesting Articles},
  volume        = {42},
  url           = {http://dx.doi.org/10.234/56789},
  urldate       = {2013-09-18},
}
@article{testartt,
  author        = {William Riter},
  title         = {Research},
  date          = {2012},
  journal       = {Journal of Interesting Articles},
  volume        = {12},
  url           = {http://dx.doi.org/10.234/56789},
  urldate       = {2013-09-18},
}
@article{testartf,
  author        = {Steve C. Ientist},
  title         = {Some Paper},
  date          = {2012},
  journal       = {Journal of the ACM},
  volume        = {12},
  url           = {http://dl.acm.org/citation.cfm?id=2487241&picked=prox&CFID=362895712&CFTOKEN=85933440},
  urldate       = {2013-09-19},
}
@online{blog,
  author        = {Bernie Logger},
  title         = {A Very Opinionated Blogpost},
  date          = {2013-09-12},
  url           = {http://www.example.com/blog/2013/09/12/opinion/},
  urldate       = {2013-09-19},
}
@online{HawSpT,
  author        = {S. W. Hawking},
  title         = {The Nature of Space and Time},
  date          = {1994-09-30},
  url           = {http://arxiv.org/abs/hep-th/9409195},
  urldate       = {2013-09-19},
}
@online{HelfGold,
  author        = {H. A. Helfgott},
  title         = {Major arcs for Goldbach's theorem},
  date          = {2013-06-14},
  url           = {http://arxiv.org/abs/1305.2897v2},
  urldate       = {2013-09-19},
}
@article{FregeNumber,
  author        = {G. Frege},
  title         = {The Whole Number},
  journal       = {Mind},
  series        = {newseries},
  volume        = {79},
  number        = {316},
  pages         = {481-486},
  date          = {1970-10},
  url           = {http://www.jstor.org/stable/2252434},
  urldate       = {2013-09-19},
}
\end{filecontents}
\addbibresource{\jobname.bib}

\begin{document}
\nocite{*}
\printbibliography
\end{document}

在此处输入图片描述

答案2

上述内容无法正确使用 https 链接。如果replace={}使用 而不是 , 则会出现所需的行为replace=\regexp{$1},如下所示:

\documentclass{article}
\usepackage{hyperref}
\usepackage[style=authoryear,backend=biber]{biblatex}

\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map{% JSTOR stable
      \step[fieldsource=url, match=\regexp{http(s)?://(www.)?jstor.org/stable/}, final]
      \step[fieldset=eprint, origfieldval]
      \step[fieldsource=eprint, match=\regexp{http(s)?://(www.)?jstor.org/stable/}, replace={}]
      \step[fieldset=eprinttype, fieldvalue={jstor}]
      \step[fieldset=url, null]
      \step[fieldset=urldate, null]
    }
    \map{% arXiv
      \step[fieldsource=url, match=\regexp{http(s)?://arxiv.org/(abs|pdf|ps|format)/}, final]
      \step[fieldset=eprint, origfieldval]
      \step[fieldsource=eprint, match=\regexp{http(s)?://arxiv.org/(abs|pdf|ps|format)/}, replace={}]
      \step[fieldset=eprinttype, fieldvalue={arxiv}]
      \step[fieldset=url, null]
      \step[fieldset=urldate, null]
    }
    \map{% DOIs
      \step[fieldsource=url, match=\regexp{http(s)?://dx.doi.org/}, final]
      \step[fieldset=doi, origfieldval]
      \step[fieldsource=doi, match=\regexp{http(s)?://dx.doi.org/}, replace={}]
      \step[fieldset=url, null]
      \step[fieldset=urldate, null]
    }
    \map{% get rid of
      \step[fieldsource=url, match=\regexp{http(s)?://(dl.acm.org/)}, final]
      \step[fieldset=url, null]
      \step[fieldset=urldate, null]
    }
  }
}    

\begin{filecontents}{\jobname.bib}
@article{testarto,
  author        = {Arnold Uthor},
  title         = {L'Article},
  date          = {2013},
  journal       = {Journal of Interesting Articles},
  volume        = {42},
  url           = {http://dx.doi.org/10.234/56789},
  urldate       = {2013-09-18},
}
@article{testartt,
  author        = {William Riter},
  title         = {Research},
  date          = {2012},
  journal       = {Journal of Interesting Articles},
  volume        = {12},
  url           = {http://dx.doi.org/10.234/56789},
  urldate       = {2013-09-18},
}
@article{testartf,
  author        = {Steve C. Ientist},
  title         = {Some Paper},
  date          = {2012},
  journal       = {Journal of the ACM},
  volume        = {12},
  url           = {http://dl.acm.org/citation.cfm?id=2487241&picked=prox&CFID=362895712&CFTOKEN=85933440},
  urldate       = {2013-09-19},
}
@online{blog,
  author        = {Bernie Logger},
  title         = {A Very Opinionated Blogpost},
  date          = {2013-09-12},
  url           = {http://www.example.com/blog/2013/09/12/opinion/},
  urldate       = {2013-09-19},
}
@online{HawSpT,
  author        = {S. W. Hawking},
  title         = {The Nature of Space and Time},
  date          = {1994-09-30},
  url           = {http://arxiv.org/abs/hep-th/9409195},
  urldate       = {2013-09-19},
}
@online{HelfGold,
  author        = {H. A. Helfgott},
  title         = {Major arcs for Goldbach's theorem},
  date          = {2013-06-14},
  url           = {http://arxiv.org/abs/1305.2897v2},
  urldate       = {2013-09-19},
}
@article{FregeNumber,
  author        = {G. Frege},
  title         = {The Whole Number},
  journal       = {Mind},
  series        = {newseries},
  volume        = {79},
  number        = {316},
  pages         = {481-486},
  date          = {1970-10},
  url           = {http://www.jstor.org/stable/2252434},
  urldate       = {2013-09-19},
}
\end{filecontents}
\addbibresource{\jobname.bib}

\begin{document}
\nocite{*}

相关内容