Пример #1
0
def get_contributor(data, name):
    name = HumanName(name.strip())
    id_ = slug(name.last + name.first)
    res = data['Contributor'].get(id_)
    if not res:
        res = data.add(common.Contributor, id_, id=id_, name=name.original)
    return res
Пример #2
0
def get_authors(p):
    doc = nlp(p.getText())
    authors_list = except_auth(p)
    for tok in doc.ents:
        if tok.label_ == 'PERSON':
            if 'KB' not in tok.text:
                author = HumanName(tok.text)
                author = author.last + ", " + author.first + " " + author.middle
                author = author.strip()
                authors_list += [author]
    return " and ".join(authors_list)
def namify(line):
    line = re.split(', | and|,and|,|&', line)
    line = list(filter(None, line))
    authors_list = []
    for name in line:
        if 'KB' not in name:
            author = HumanName(name)
            author = author.last + ", " + author.first + " " + author.middle
            author = author.strip()
            authors_list += [author]
    return " and ".join(authors_list)
Пример #4
0
def namify(line):
    line = remove_digit(line).replace("…", "").strip().strip(".")
    line = line.strip()
    line = re.split(', | and|,and|,|&', line)
    line = list(filter(None, line))  # remove empty
    authors_list = []
    for name in line:
        if 'KB' not in name:
            author = HumanName(name)
            author = author.last + ", " + author.first + " " + author.middle
            author = author.strip()
            authors_list += [author]
    return " and ".join(authors_list)
Пример #5
0
def GetNameLink(name):
    # Finds and returns formatted name and wikilinks for given name.
    if name == "":
        return ["", ""]
    name = HumanName(name)
    name.capitalize(force=True)
    name = str(name)
    global name_links
    lower = name.strip().lower().replace("-", "").replace(" ", "").replace(
        ".", "")  # key for name in dict
    if lower in name_links:
        return name_links[lower]
    soup = GetSoup("https://en.wikipedia.org/wiki/" + name.replace(" ", "_"),
                   False).text
    wikitext = name
    tennis = [
        "International Tennis Federation", "Prize money", "Grand Slam",
        "tennis career", "Wikipedia does not have", "WTA", "ITF", "ATP"
    ]
    pipe = False
    if soup != None:
        if any(
            [f in soup for f in tennis]
        ) and not "may refer to" in soup:  # player article exists, or no article exists
            if "Redirected from" in soup:
                soup = GetSoup(soup, True)
                title = str(soup.title.string).replace(" - Wikipedia",
                                                       "").strip()
                wikitext = title
                pipe = False  # if name is redirect, pipes wikilink to avoid anachronist names, e.g. using "Margaret Court" instead of "Margaret Smith" before she married.
        else:  # article exists for name but for different person, or disambugation page
            wikitext = name + " (tennis)"
            pipe = True
    wikilink = "[[" + wikitext + ("|" + name if pipe else "") + "]]"
    split_name = name.split(" ")
    abbr_name = "-".join(
        f[0] for f in split_name[0].split("-")) + " " + " ".join(
            split_name[1:]
        )  # reduce name to first name initials + last name, e.g. "J-L Struff"
    abbr_wikilink = "[[" + wikitext + "|" + abbr_name + "]]"
    name_links[lower] = [wikilink, abbr_wikilink]
    return name_links[lower]
Пример #6
0


Author: Marie Dubremetz
"""

from nameparser import HumanName #'pip install nameparser' if import error occures
import sys

def invert_name(line):
	"""(String)->String
		
		given a string containing names separated by " and " returns the names with first name last name reverted
		
		>>>'John B. Smith and Pablo Ramirez-Gonzalez and Bob Doe'
		'Smith, John B. and Ramirez-Gonzalez, Pablo and Doe, Bob'
		"""
    line=line.replace(" And ", " and ")
    name_list=line.split(' and ')
    authors_list=[]
    for name in name_list:
        author = HumanName(name)
        author = author.last+", "+author.first+" "+author.middle
        author = author.strip()
        authors_list += [author]
    return " and ".join(authors_list)

if __name__ == "__invert_name__":
    line=sys.argv[1]
    invert_name(line)
    print(invert_name(line))