예제 #1
0
 def get_address(self, data):
     conference = ConferenceReader(data)
     pubinfo_city = latex_encode(conference.city)
     pubinfo_country_code = latex_encode(conference.country)
     if pubinfo_city and pubinfo_country_code:
         return f"{pubinfo_city}, {pubinfo_country_code}"
     return latex_encode(get_value(data, "imprints[0].place"))
예제 #2
0
def test_latex_encode_escapes_special_chars():
    text = r" # $ % & \ { } _ ~ ^"
    expected = (
        r" \# \$ \% \& \textbackslash{} \{ \} \_ \textasciitilde{} \textasciicircum{}"
    )

    assert expected == latex_encode(text)
예제 #3
0
 def encode_author_name(name):
     name = name.replace(".", ". ").replace("  ", " ")
     parts = [p.strip() for p in name.split(", ")]
     has_suffix = len(parts) > 2
     if has_suffix:
         parts = [parts[0], parts[-1]] + parts[1:-1]
     return latex_encode(", ".join(parts))
예제 #4
0
 def get_school(self, data):
     schools = [
         school["name"]
         for school in get_value(data, "thesis_info.institutions", [])
     ]
     if schools:
         return latex_encode(", ".join(schools))
예제 #5
0
    def get_note(self, data):
        notices = ("erratum", "addendum")
        entries = [
            entry for entry in get_value(data, "publication_info", [])
            if entry.get("material") in notices
        ]

        if not entries:
            return None

        note_strings = [
            text_type("{field}: {journal} {volume}, {pages} {year}").format(
                field=entry["material"].title(),
                journal=entry.get("journal_title"),
                volume=entry.get("journal_volume"),
                pages=LiteratureReader.get_page_artid_for_publication_info(
                    entry, "--"),
                year="({})".format(entry["year"]) if "year" in entry else "",
            ).strip() for entry in entries
        ]

        note_string = "[" + ", ".join(note_strings) + "]"
        note_string = re.sub(" +", " ", note_string)
        return latex_encode(re.sub(",,", ",", note_string))
예제 #6
0
 def get_report_number(self, data):
     report_number = ", ".join(report["value"]
                               for report in data.get("report_numbers", [])
                               if not report.get("hidden", False))
     return latex_encode(report_number)
예제 #7
0
 def get_collaboration(self, data):
     collaboration = ", ".join(
         get_value(data, "collaborations.value", default=[]))
     return latex_encode(collaboration)
def test_latex_encode_do_not_escape_curly_brakcets():
    text = r"Search for Axion Like Particle Production in 400-{GeV} Proton - Copper Interactions"
    expected = r"Search for Axion Like Particle Production in 400-{GeV} Proton - Copper Interactions"
    assert expected == latex_encode(text)
예제 #9
0
 def get_series(self, data):
     return latex_encode(get_value(data, "book_series.title[0]"))
예제 #10
0
def test_latex_encode_encodes_the_right_parts_when_contains_math_is_true_and_starts_with_math():
    text = r"$\alpha$ to ω"
    expected = r"$\alpha$ to \ensuremath{\omega}"

    assert expected == latex_encode(text, contains_math=True)
예제 #11
0
def test_latex_encode_preserves_math_when_contains_math_is_true():
    text = r"Paper on $\gamma$-ray bursts and \(\mu\)-neutrinos \o/"
    expected = r"Paper on $\gamma$-ray bursts and \(\mu\)-neutrinos \textbackslash{}o/"

    assert expected == latex_encode(text, contains_math=True)
예제 #12
0
def test_latex_encode_escapes_math_by_default():
    text = r"Paper on $\gamma$-ray bursts and \(\mu\)-neutrinos \o/"
    expected = r"Paper on \$\textbackslash{}gamma\$-ray bursts and \textbackslash{}(\textbackslash{}mu\textbackslash{})-neutrinos \textbackslash{}o/"

    assert expected == latex_encode(text)
예제 #13
0
def test_latex_encode_escapes_non_ascii():
    text = "Rapčák"
    expected = r"Rap\v{c}\'ak"

    assert expected == latex_encode(text)
예제 #14
0
def test_latex_encode_returns_none_when_input_is_none():
    assert None == latex_encode(None)
예제 #15
0
def test_latex_encode_is_correct_when_contains_math_is_true_and_no_math():
    text = r"Paper on γ-ray bursts and μ-neutrinos \o/"
    expected = r"Paper on \ensuremath{\gamma}-ray bursts and \ensuremath{\mu}-neutrinos \textbackslash{}o/"

    assert expected == latex_encode(text, contains_math=True)
예제 #16
0
 def get_publisher(self, data):
     return latex_encode(get_value(data, "imprints.publisher[0]"))
예제 #17
0
def test_latex_encodes_understands_escaped_math_delimiters():
    text = r"How to make $\$ 10^100$ from $\alpha$ to Ω"
    expected = r"How to make $\$ 10^100$ from $\alpha$ to \ensuremath{\Omega}"

    assert expected == latex_encode(text, contains_math=True)
예제 #18
0
 def get_journal(self, data):
     return latex_encode(
         BibTexCommonSchema.get_best_publication_info(data).get(
             "journal_title").replace(".", ". ").rstrip(" "))
예제 #19
0
파일: bibtex.py 프로젝트: tsgit/inspirehep
 def get_authors_with_role(authors, role):
     return [
         latex_encode(author["full_name"]) for author in authors
         if role in author.get("inspire_roles", ["author"])
     ]