예제 #1
0
def winner_text(factsys, data, win):
    factsys.grammar.embed("G")
    import G

    name = G.pnameName(pname(win))
    priz = factsys.str2exp("Prize", win.prize)
    cit = cname(factsys, win.city)
    countr = cname(factsys, win.country)

    doc = G.OneSentenceDoc(
        G.ContinuousPastFactSentence(  ## for Ger
            G.ActFact(G.NameObject(name),
                      G.winPrizeDateAct(priz, string_year(win.year)))))
    doc = G.AddSentenceDoc(
        doc,
        G.ContinuousPastFactSentence(
            G.ActFact(G.PronObject(name),
                      G.bornAct(string_year(win.born), cit, countr))))
    if len(win) > 7 and win.dead:
        try:
            fname = G.pnameName(pname(win, just_family=True))
            doc = G.AddSentenceDoc(
                doc,
                G.PunctualPastFactSentence(
                    G.ActFact(G.NameObject(fname),
                              G.dieAct(string_year(win.dead)))))
        except:
            pass


##    print(doc)

    return doc, name, priz
예제 #2
0
def country_texts_embedded(factsys, data):
    factsys.grammar.embed("G")
    import G

    fields = factsys.fieldnames.split()

    facts = []

    for tuple in data:

        countr = factsys.str2exp("Name", tuple[0])
        cap = factsys.str2exp('Name', tuple.capital)
        cont = factsys.str2exp('Name', tuple.continent).unpack()[1][0]  #CDNAME
        curr = factsys.str2exp('Name', tuple.currency)
        pop = pgf.readExpr(str(tuple.population))
        are = pgf.readExpr(str(tuple.area))

        doc = G.OneSentenceDoc(
            G.FactSentence(
                G.KindFact(
                    G.NameObject(countr),
                    G.ModifierKind(
                        G.PropertyKind(G.cdProperty(cont), G.country_Kind),
                        G.NumericKindModifier(G.IntNumeric(pop),
                                              G.inhabitant_Kind)))))
        doc = G.AddSentenceDoc(
            doc,
            G.FactSentence(
                G.AttributeFact(G.area_Attribute, G.PronObject(countr),
                                G.NumericValue(G.IntNumeric(are)))))
        doc = G.AddSentenceDoc(
            doc,
            G.ConjSentence(
                G.FactSentence(
                    G.AttributeFact(G.capital_Attribute, G.NameObject(countr),
                                    G.NameValue(cap))),
                G.FactSentence(
                    G.AttributeFact(G.currency_Attribute, G.PronObject(countr),
                                    G.NameValue(curr)))))
        facts.append(doc)
    return facts
예제 #3
0
def continent_text(factsys, data, cont):
    factsys.grammar.embed("G")
    import G

    facts = []

    cont_data = [d for d in data if cont in [d.continent, the_world]]
    ncountries = len(cont_data)
    largestpop = max(cont_data, key=lambda c: int(c.population)).country
    largestarea = max(cont_data, key=lambda c: int(c.area)).country
    totalpop = sum([int(c.population) for c in cont_data]) // 1000000

    doc = factsys.str2exp("Doc", ("there are {} countries in {}.").format(
        ncountries, cont))
    doc = G.AddSentenceDoc(
        doc,
        factsys.str2exp("Sentence",
                        ("the total population of {} is {} million").format(
                            cont, totalpop)))
    doc = G.AddSentenceDoc(
        doc,
        factsys.str2exp(
            "Sentence",
            ("{} has the largest population and {} has the largest area"
             ).format(largestpop, largestarea)))

    billions = [c.country for c in cont_data if int(c.population) > 1000000000]
    if len(billions) == 1:
        subject = billions[0]
        property = ' is the only country '
    elif len(billions) > 1:
        subject = ', '.join(billions[:-1]) + ' and ' + billions[-1]
        property = ' are the only countries '
    if billions:
        doc = G.AddSentenceDoc(
            doc,
            factsys.str2exp(
                'Sentence',
                subject + property + 'with over a billion inhabitants'))

    return doc
예제 #4
0
def nobel_texts(factsys, data):
    factsys.grammar.embed("G")
    import G

    def first_woman(p):
        return min(filter(lambda w: w.sex == 'female' and w.prize == p, data),
                   key=lambda d: int(d.year[:4])).winner

    def youngest(p):
        return min(filter(lambda w: w.prize == p, data),
                   key=lambda d: int(d.year[:4]) - int(d.born[:4])).winner

    docs = []
    for win in data:
        doc, name, priz = winner_text(factsys, data, win)
        if win.winner == first_woman(win.prize):
            doc = G.AddSentenceDoc(
                doc,
                G.ContinuousPastFactSentence(
                    G.FirstInKindFact(
                        G.NameObject(name),
                        G.ModifierKind(
                            G.woman_Kind,
                            G.PunctualPastActModifier(G.winPrizeAct(priz))))))
        if win.winner == youngest(win.prize):
            if win.sex == 'female':
                winnerOf = G.femaleWinnerOfPrizeKind
            else:
                winnerOf = G.maleWinnerOfPrizeKind
            doc = G.AddSentenceDoc(
                doc,
                G.ContinuousPastFactSentence(
                    G.YoungestInKindFact(G.PronObject(name), winnerOf(priz))))

        docs.append(doc)

    return docs