Exemple #1
0
def get_problem_statement(a, b, problem_phrase, event):
    if event['prev']:
        again = 'again '
    else:
        again = ''
    rules = {
        'origin': [
            '#problem_statement#. #anger# #reaction#.',
            '#problem_statement#. #anger# #reaction#. #texture#',
        ],
        'problem_statement': [
            f'#a# {again}was #upset# because #a_they# felt that #b# #problem#',
            f'#a# {again}told #b# that #b# #problem#',
        ],
        'anger': util.rank([
            "#it_seemd# just the smallest difference in expectations. ",
            "#it_seemd# a modest gap in expectations",
            "#it_seemd# some difference in this regard.",
            "#it_seemd# a gap in expectations.",
            "#it_seemd# a serious gap.",
            "#it_seemd# a chasm in understanding.",
            "#it_seemd# an insurmountable gulf of incompatibility.",
        ], event['target']),
        'it_seemd': [
            'It seemed like there was',
            'There was',
            "It seemed like",
            '#b# had to admit that #b_they# and #a# had ',
        ],
        'upset': ['upset', 'frustrated', 'mad', 'angry'],
        'a': a['name'],
        'a_they': a['they'],
        'b': b['name'],
        'b_they': b['they'],
        'problem': problem_phrase,
        'pushing': ['pushing', 'telling', 'convincing', 'nagging', 'dragging'],
        'reaction': util.rank([
            '#a#\'s voice was gentle, but firm',
            '#a#\'s voice was soft, but firm',
            '#a# asked #b# if there was anything they could do to help.',
            '#a# looked at #b# silently, waiting for a response',
            '#a# folded their arms, glaring at #b#',
            '#a#\'s voice was harsh',
            '#a#\'s voice was cold',
            '#a#\'s tones were accusing',
        ], event['neuro_roll']),
        'texture': util.rank([
            '#b# sighed.',
            '#b# blinked slowly.',
            '#b# rubbed their eyes.',
            '#b# took a deep breath.',
            '#b# gasped anxiously.',
            '#b# was shocked.',
            '#b# was mortified.',
            '#b# was incensed.',
        ], random.gauss(b['neuro'], 0.1))
    }
    grammar = tracery.Grammar(rules)
    return grammar.flatten('#origin#')
Exemple #2
0
def get_name(topics_json, topic):
    p = inflect.engine()
    if topics_json[topic]["size"] == 0:
        return ""
    # Sort by the second value in the tuple which is the float representation
    # of the weight
    top_cw = sorted(topics_json[topic]["common_words"],
                    key=lambda k: float(k[1]),
                    reverse=True)[0][0].split("_")
    top_rw = sorted(topics_json[topic]["relevant_words"],
                    key=lambda k: float(k[1]),
                    reverse=True)[0][0].split("_")
    # Some simple heuristics:
    # Put the shorter one first
    # Only use one if it's a triple

    # Multiplex by node degree, elevation, and alliteration
    if topics_json[topic]["degree"] == 0:
        land_names = ISLANDS
    elif topics_json[topic]["degree"] == 1:
        land_names = PENINSULA
    else:
        land_names = LAND_NAMES
    land_names = [w.capitalize() for w in land_names]
    size = util.scale(topics_json[topic]["size"],
                      0,
                      4000,
                      0,
                      1,
                      use_clamp=True)

    words = [
        "#w#/#r#", "#r#/#w#", "#r#-#w#", "#w#-#r#", "#w#", "#w#", "#w#", "#w#"
    ]
    if top_cw == top_rw:
        words = ["#w#"]
    elif set(top_cw).issubset(set(top_rw)) or len(top_rw) >= 3:
        words = ["#r#"]
    elif set(top_rw).issubset(set(top_cw)) or len(top_cw) >= 3 or size > 0.75:
        words = ["#w#"]
    rules = {
        "origin": ["#land# of #words#", "#words# #land#"],
        "words": words,
        "r": " ".join([w.capitalize() for w in top_rw]),
        "w": " ".join([w.capitalize() for w in top_cw]),
        "land": ["#l#", "#ls#"],
        "l": util.rank(land_names, size),
        "ls": p.plural(util.rank(land_names, size)),
    }
    grammar = tracery.Grammar(rules)
    grammar.add_modifiers(base_english)
    return grammar.flatten("#origin#")
Exemple #3
0
def narrate_ran(a, b):
    rules = {
        'origin': [
            'They texted #b# once#response#.', '', '', '',
            f'They considered getting more interested in {random.choice(list(INTERESTS))}.'
        ],
        'a':
        a['name'],
        'a_they':
        a['they'],
        'a_their':
        a['their'],
        'b':
        b['name'],
        'b_their':
        b['their'],
        'b_they':
        b['they'],
        'response':
        rank([
            ', but #b_they# didn\'t respond',
            ' but #b_they# politely asked for space',
            ' and #a_they# got a few messages back, but #b_they# were clearly uninterested',
            ' and #b_they# chatted with them, but it did little for #a#'
        ], b['agree'])
    }
    print(tracery.Grammar(rules).flatten('#origin#'))
Exemple #4
0
def narrate_interests(event, events):

    # check whether previous events contain a non-rejected experience
    # if none found, this is the first d    ate
    # and we want to trigger the interests narration
    prev_experiences = [
        e for e in events if e['type'] == EventType.EXPERIENCE
        and e['phase'] == Phase.COURTING and e['rejected'] == False
    ]

    a, b = util.get_ab(event)

    person = event["person"]

    rules = {
        'origin': [
            f"#{event['target_property']}#, {person['name']} #shared# #interests#."
        ],
        'interests':
        f"{util.oxford_comma(person['interests'], conj = 'and')}",
        'libido':
        util.rank([
            "As they held hands", "While cuddling", "Later",
            "After they cooled down", "Later", "While laying in bed",
            "With their faces pressed together"
        ], event["threshold"]),
        'extra':
        util.rank(
            ["While they hung out", "Throughout the evening", "All night"],
            event["threshold"]),
        'open': ["While on their date"],
        'shared': [
            "was excited to tell Alex about", "talked a lot about",
            "gushed about", f"shared {person['their']} interest in"
        ]
    }

    if len(prev_experiences) == 0 and event['phase'] == Phase.COURTING:
        grammar = tracery.Grammar(rules)
        grammar.add_modifiers(base_english)
        print(grammar.flatten('#origin#'))
        print(f"""<p class='system'>{event['phase']}</p>""")

    if len(prev_experiences) == 3:
        get_first_impressions(person)
Exemple #5
0
def narrate_reflection(a, b, reflection):
    # memory = reflection['memory']
    ref_statement = get_reflection(a, b, reflection)

    rules = {
        'a_they':
        a['they'],
        'origin':
        '#breakup#. #afterward# #realized# that #they# #change##intent#.',
        'breakup':
        rank([
            '#a# took the break up hard',
            '#a# had a hard time when #b# stopped talking to them',
            '#a# struggled to cut #b# out of #their# life',
            '#a# knew the break up was for the best, but it didn\'t feel that way',
            '#a# felt like a great weight lifted off #their# shoulders after the relationship ended',
            '#a# was happy to be out of that relationship'
        ], a['commit']),
        'afterward': [
            'Immediately after the break up,', 'Later,',
            'After the relationship ended,',
            'While the relationship fell apart,'
        ],
        'realized':
        ['#a# realized', '#b# told #a#', '#a# had the dawning realization'],
        'change':
        ref_statement,
        'intent':
        rank([
            ', and #a_they# journaled about #their# intent to change',
            '. It hurt to realize', '. #a# would have to work on it',
            ', and #they# resolved to improve', '. #a# decided to change'
        ], a['confidence']),
        'a':
        a['name'],
        'they':
        a['they'],
        'their':
        a['their'],
        'b':
        b['name'],
        # 'them': a['them']
    }
    print(tracery.Grammar(rules).flatten('#origin#'))
Exemple #6
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("-n", dest="n", type=int, required=True)
    parser.add_argument("-f",
                        dest="f",
                        type=create_lambda_with_globals,
                        required=True)
    args = parser.parse_args()

    start = time.time()

    # Special corner case for n = 1
    if args.n == 1:
        if args.f(0) == args.f(1):
            s = 1
        else:
            s = 0
        end = time.time()
        print("s: ", s)
        print("Execution time: ", end - start)
        return

    # Choose qubits to use.
    measure_qubits = [cirq.GridQubit(i, 0) for i in range(args.n)]
    aux_qubits = [cirq.GridQubit(i, 0) for i in range(args.n, 2 * args.n)]

    # Create Bf
    Bf = Cirq_Custom(2 * args.n, create_Bf_matrix(args.f, args.n), name="Bf")

    # Create DJ circuit
    circuit = make_simon_circuit(measure_qubits, aux_qubits, Bf)
    print('Circuit:')
    print(circuit)

    # Sample from the circuit a couple times until we have the proper
    # number of results to calculate "s".
    simulator = cirq.Simulator()
    M = []
    while rank(M) < args.n - 1:
        result = simulator.run(circuit, repetitions=1)
        frequencies = result.histogram(key='result', fold_func=bitstring)
        r = list(frequencies.keys())[0]
        y = [int(i) for i in r]
        y.append(0)
        M = new_sample(M, y)
    s = solve_reduced_row_echelon_form(M)
    # Test s = all zeros, because that is the only other option other than our result.
    if args.f("".join(['0' for i in range(args.n)])) != args.f("".join(
        [str(i) for i in s])):
        print("s: ", [0 for i in range(args.n)])
    else:
        print("s: ", s)

    end = time.time()
    print("Execution time: ", end - start)
Exemple #7
0
def get_outcome(a, b, event):
    rules = {
        'origin': util.rank([
            'Talking things out drastically improved their relationship.',
            'Things were shaky for a bit, but the relationship soon returned to normal.',
            'Things felt awkward for awhile.',
            'The two walked on eggshells for awhile.',
            'Things seemed tenuous for a long while after.',
            'The fight spelled disaster for their relationship.'
        ], pow(1-event['delta'], 2))
    }
    grammar = tracery.Grammar(rules)
    return grammar.flatten('#origin#')
Exemple #8
0
def narrate_minor_conflict(a, b, event, problem_phrase):
    problem_statement = tracery.Grammar(
        {
            'origin': "#a# #asked# #b# to #a# felt that #b# was #problem#. ",
            # Alex asked Tracy to be more hot
            'problem': problem_phrase,
            'pushing': 'pushing',
            'sometimes': util.rank(['occasionally', 'sometimes', 'often', 'frequently', 'always'], util.scale(event['delta'], -1, 0.5, 1, 0)),
            'fought': ['fought', 'argued', 'clashed', 'scuffled'],
            'They': ['They', 'The couple'],
            'a': a['name'],
            'b': b['name'],
        }).flatten('#origin#')
    print(problem_statement)
Exemple #9
0
def narrate_conflict_zoomout(a, b, event, problem_phrase):
    response = get_response(a, b, event)
    problem_statement = tracery.Grammar(
        {
            'origin': "#They# #sometimes# #fought# because #a# felt that #b# #problem#.\n",
            'problem': problem_phrase,
            'pushing': 'pushing',
            'sometimes': util.rank(['occasionally', 'sometimes', 'often', 'frequently', 'always'], util.scale(event['delta'], -1, 0.5, 1, 0)),
            'fought': ['fought', 'argued', 'clashed', 'scuffled'],
            'They': ['They', 'The couple'],
            'a': a['name'],
            'b': b['name'],
        }).flatten('#origin#')
    print(problem_statement)
Exemple #10
0
def test_truncated_lyapunov():
    d = 100
    n = 1000
    shared_rank = 2
    independent_rank = 1
    A, C = u.random_cov_pair(shared_rank=shared_rank,
                             independent_rank=independent_rank,
                             strength=0.1,
                             d=d,
                             n=n)
    X = u.lyapunov_truncated(A, C)

    # effective rank of X captures dimensionality of shared subspace
    u.check_close(u.rank(X), shared_rank + independent_rank, rtol=1e-4)
    u.check_close(u.erank(X), shared_rank, rtol=1e-2)
Exemple #11
0
def get_first_impressions(person):
    rules = {
        'origin':
        "#status#",
        'communication':
        "#before# #medium# #frequently#.",
        'before': [
            "Before meeting up, #they#",
            "Leading up to their first date, #they#", "#they.capitalize#"
        ],
        'they': ["the two", "they", f"Alex and {person['name']}"],
        'medium':
        ["texted", "exchanged messages", "chatted", "called", "video-called"],
        'frequently': ["a lot", "a few times", "incessantly", "once"],
        'status':
        f"#over_time#, Alex #gathered# that {person['name']} was #exp# romantic relationships. With Alex, {person['they']} seemed to #commit#.",
        'over_time': [
            "After a couple dates", "The more they talked",
            "As they got to know each other better"
        ],
        'gathered': ["could gather", "sensed", "realized", "felt"],
        'commit':
        util.rank([
            'want something casual', 'be up for anything',
            'be ready for something serious'
        ], person['commit']),
        'exp':
        util.rank([
            'insecure about', 'nervous about', 'timid in', 'unsure of',
            'open to', 'relaxed about', 'secure in', 'well-versed in',
            'experienced in'
        ], person['exp']),
    }
    grammar = tracery.Grammar(rules)
    grammar.add_modifiers(base_english)
    print(grammar.flatten('<p>#origin#</p>'))
def export_markdown(modeldesc, sourcedesc, topics):
    analysisfilename = report_file('ldaanl-%s.md' % modeldesc)

    with open(analysisfilename, 'w', encoding='utf-8') as analysisfile:
        analysisfile.write('# Topic Model Analysis\n\n')
        analysisfile.write('- Model description: %s\n' % modeldesc)
        analysisfile.write('- Source description: %s\n' % sourcedesc)

        for index, topic in enumerate(topics):
            analysisfile.write('\n## %s Topic\n\n' % rank(index + 1))
            analysisfile.write('ID: %d\n\n' % topic['topic_id'])
            analysisfile.write('Words: %s\n\n' % topic['words'])

            for text in topic['documents']:
                text = text.strip()
                analysisfile.write('- %s\n' % text)

    cl.success('Analysis file saved as: %s' % analysisfilename)
Exemple #13
0
def get_sprite_name(id):
    suit = util.suit(id)
    if suit == 0:
        suitName = 'spades'
    elif suit == 1:
        suitName = 'diamonds'
    elif suit == 2:
        suitName = 'hearts'
    else:
        suitName = 'clubs'

    rank = util.rank(id)
    if rank == 14:
        rankName = 'ace'
    elif rank == 11:
        rankName = 'jack'
    elif rank == 12:
        rankName = 'queen'
    elif rank == 13:
        rankName = 'king'
    else:
        rankName = rank

    return str(rankName) + '_of_' + suitName
def narrate_experience(event, events):
    a, b = get_ab(event)

    if event['rejected'] and event['target_property'] not in ['con', 'exp', 'neuro']:
        narrate_rejection(event, events)
        narrate_experience_system(event)
        return

    detail = False

    artifact = False
    if event.get('phase') == Phase.COURTING and random.random() < 0.6:
        artifact = True
        # 50% chance to show the detail of the experience in the artifact
        detail = random.random() < 0.5
        print(artifacts.get_date_artifact(event, events, detail))

    # compare the target_properties of the characters
    # create boolean that asks if b > a
    b_greaterthan_a = b[event['target_property']] > a[event['target_property']]

    # openness activities can fall 3 different ways
    # <.33 proposer suggests activity they like
    # <.66 proposer suggest an activity that their partner likes
    # < 1 proposer suggests any activity

    if event['target_property'] == 'open':
        rules = {
            'origin': '<p>#hobby_proposal# #reply# #outcome# </p>',
            'mood': util.rank([
                "Having a strong preference for what #they# wanted to do for date night,",
                f"Having been obsessed with {event['interest']} more than ever lately,",
                "Wanting to have a nice evening together,",
                "Wanting to surprise #b#,",
                "In effort to mix up what they usually do,",
                "In the mood for adventure,"
            ], event['threshold']),
            'proposed': [
                "asked #b# to", "begged #b# to", "proposed that they",
                "wondered if it would be fun to", "suggested that they",
                "wanted to", "invited #b# to"
            ],
            'hobby_proposal': [
                f"#mood# #a# #proposed# go to {random.choice(INTERESTS[event['interest']]['location'])} together.",
                f"#mood# #a# #proposed# {random.choice(INTERESTS[event['interest']]['verb'])} together."
            ],
            'response': util.rank([
                "I'd love to!", "Sounds like fun!", "Yes, let's do it,",
                "Sure!", "Okay,", "Oh, okay,", "I guess so...",
                "Do we have to?", "You know I don't like that,"
            ], 1-event['delta']),
            'reply': ['"#response#" #b# replied.'],
            'quality': util.rank([
                'terrible', 'pretty bad', 'okay',
                'decent', 'good',
                'joyous', 'fantastic', 'outstanding'
            ], event['delta']),
            'verdict': util.rank([
                '#b# would rather not spend their time like this in the future.',
                'Perhaps, they could try something else next time.',
                '#b# would consider doing a similar activity again.',
                f'#b# enjoyed {b["themself"]}.',
                '#b# could see the two of them doing this often.',
                '#b# loved the date.'
            ], 1 - event['concession_roll']),
            'match': f"#b# loved {event['interest']}",
            'outcome': "The two had a #quality# time. #verdict#"
        }
        rules.update(getInterestRules(a, b, event['interest']))
        grammar = tracery.Grammar(rules)
        if not detail:
            print(grammar.flatten('<p>#origin#</p>'))
        else:
            print(grammar.flatten('<p>#outcome#</p>'))
        # logging.debug(
        #    f"OPEN EXPERIENCE {event['interest']} {event['threshold']} a: {a['open']} b: {b['open']}")
    elif event['target_property'] in ['extra', 'libido']:
        rules = {
            'origin':
            f"#Onday# #{event['target_property']}#. #{event['target_property']}_{b_greaterthan_a}_response#.",
            'day': ['day', 'morning', 'afternoon', 'evening'],
            'Onday': '#artifact#' if artifact else '#later#',
            'artifact': [
                f"On {event['date'].strftime('%A')}, #they#",
                f"{event['date'].strftime('%A')} came around. #they.capitalize#",
                f"{event['date'].strftime('%A')} arrived. #they.capitalize#",
            ],
            'later': [
                '#artifact#',
                '#artifact#',
                "Later that week, #they#"
            ],
            'extra':
            util.rank([
                '#enjoyed# a tranquil #day# watching Netflix',
                '#enjoyed# a tranquil #day# watching Youtube videos',
                '#enjoyed# a tranquil #day# watching a movie',
                '#enjoyed# a quiet #day# reading together',
                '#enjoyed# a #day# of people-watching',
                '#enjoyed# a #day# hanging out with friends',
                '#enjoyed# a night out together at the bar',
                '#enjoyed# a night out at the club',
            ], event['threshold']),
            'libido':
            util.rank([
                'held hands',
                'cuddled on the couch',
                'shared a kiss',
                'made out #vigorously# #location# upon seeing each other',
                'sneakily groped each other #in_public#',
                '#enjoyed# a steamy evening together',
                '#enjoyed# an intensely passionate evening together',
            ], event['threshold']),
            'they': [
                'they', 'the couple', '#a# and #b#', 'the two of them',
                'the pair'
            ],
            'enjoyed': util.rank([
                'spent', 'happily spent', 'enjoyed',
                'excitedly spent', 'savored',
                'reveled in', 'relished'
            ], event['delta']),
            'vigorously': util.rank([
                'awkwardly', 'briefly', '', 'passionately', 'vigorously'
            ], event['delta']),
            'location': [
                "on the street", "outside #a#'s apartment", "on #b#'s doorstep", "in the back of the rideshare",
                "outside the subway",
            ],
            'in_public': [
                "while walking down the street", "while waiting in line at checkout"
            ],
            # if B has higher libido than A:
            'libido_True_response': util.rank([
                '#b# was enraptured',
                '#b# sighed with pleasure',
                '#b# smiled coyly',
                f'"How nice", #b# thought to {b["themself"]}',
                '#b# was left wanting more',
                '#b# wanted to go further, but #a# pulled away',
                '#b# excitedly attempted to push things further, but #a# pulled away',
                '#b# was left to take care of their needs alone',
            ], event['concession']),
            'libido_False_response': util.rank([
                '#b# gasped with excitement',
                '#b# sighed with pleasure',
                '#b# smiled coyly',
                f'"How nice", #b# thought to {b["themself"]}',
                '#b# felt a little uncomfortable with how fast things were moving',
                '#b# felt that #a# was pushing things further than #b# would have liked',
                '#a# sure loved getting it on! #b# sighed',
                f'#b# wanted to pushed #a# away. "There\'s more to me than my body," #b# thought to {b["themself"]}'
            ], event['concession']),
            # b has higher extra
            'extra_True_response': util.rank([
                '#b# loved hanging out with #a# this way',
                '#b# was happy to hang out with #a# this way',
                'While #b# enjoyed #a#\'s company, #b# yearned for a more lively social experience',
                '#b# felt that it was a little bit boring',
                '#b# felt the urge to fill the silence with conversation',
                '#b# wished they had gone out to a more lively environment',
            ], event['concession']),
            'extra_False_response': util.rank([
                '#b# loved hanging out with #a# this way',
                '#b# was quiet, but happy to hang out with #a# this way',
                'while #b# enjoyed #a#\'s company, #b# yearned for a quieter social experience',
                f'#b# felt a bit awkward. "What should I be doing with my hands?" #b# thought to {b["themself"]}',
                'After a few hours, #b# was spent and made excuses to head home',
                '#b# collapsed on arriving home. How exhausting',
            ], event['concession']),
            'a': a['name'],
            'b': b['name'],
        }
        grammar = tracery.Grammar(rules)
        grammar.add_modifiers(base_english)
        print(grammar.flatten("#origin#"))
    else:
        rules = {
            'origin': [
                f"#Onday# #{event['target_property']}# #next#",
            ],
            'Onday': [
                f"On {event['date'].strftime('%A')}, ",
                f"{event['date'].strftime('%A')} came around. ",
                "Later that week, "
            ],
            'hot': util.rank([
                '#b# noticed that #a# sometimes gave off a mildly unpleasant odor.',
                f'#a# bragged to #b# about how infrequently {a["their"]} hair needed to be washed.',
                '#a# met #b# wearing an old college sweatshirt and an ill-fitting pair of jeans.',
                '#b# noticed #a# went to sleep without washing up first.',
                '#a# bought more skincare products.',
                '#a# went shopping for the latest trendy fashions.',
                '#a# went shopping for organic groceries. That figure didn\'t keep itself in shape!',
                '#a# spent the #day# at the gym. That body didn\'t keep itself in shape!',
            ], event['threshold']),
            'con': util.rank([
                '#b# noticed #a# had a lot of dishes piled up in the sink.',
                '#a# decided to call in sick to work. After all, you only live once.',
                f'#a# forgot to do {a["their"]} laundry.',
                '#a# left a couple of dishes piled up in the sink.',
                f'#a# noticed {a["they"]} needed to vacuum the carpet.',
                '#a# decided to start keeping a daily todo list.',
                f'#a# spent the #day# arranging {a["their"]} books by color and subject.',
                '#a# went shopping and purchased a daily planner.',
                '#a# stayed late at work.',
                '#a# spent the #day# #cleaning# the apartment.',
                '#a# spent the #day# #cleaning# the apartment. It was moderately dusty.',
                '#a# spent the #day# #cleaning# the bathroom. It certainly was in need of some attention.',
            ], event['threshold']),
            'exp': util.rank([
                '#a# was upset with #b#, but said nothing.',
                '#a# was jealous of #b#\'s moderately attractive co-worker.',
                f'#a# asked #b# how {b["they"]} felt about the relationship. The couple had an earnest conversation about where things were going.',
                f'#a# suggested that they enact weekly relationship check-ins. #b# agreed happily.'
            ], event['threshold']),
            'neuro': util.rank([
                '#b# had a night out with friends planned. #a# was happy to pass the evening doing other things.',
                '#b# had not responded to #a#\'s text messages for a few hours. #a# sent a followup.',
                '#a# fretted. #a# had not heard from #b# for a couple days.',
                f'#a# worried when #b# said that {b["they"]} sometimes preferred to be alone.',
                '#a# worried that #b# did not actually find them to be attractive.'
                '#b# kept a journal of how long it took for #a# to text them back.',
                '#a# worried that #b# would leave them some day soon.',
            ], event['threshold']),
            'cleaning': ['tidying', 'cleaning', 'organizing'],
            'day': ['day', 'morning', 'afternoon', 'evening'],
            'a': a['name'],
            'b': b['name'],
            'response': util.rank([
                '#b# was happy that the two of them shared similar habits.',
                '#b# was perfectly willing to support #a# when this happened.',
                '#b# didn\'t always understand #a#\'s actions.',
                '#b# did not appreciate #a# when things like this happened.',
            ], event['concession']),
            'rejection':
                '#b# refused to participate in this kind of behavior.',
            'next': '#rejection#' if event['rejected'] else '#response#'
        }
        print(tracery.Grammar(rules).flatten('#origin#'))
        # logging.debug(f"Event: {event}")
    prologue.narrate_interests(event, events)
    narrate_experience_system(event)
Exemple #15
0
def get_outlook(a):
    if a['confidence'] > .5:
        rules = {
            'origin':
            '#confident_statement#, #yet# #longing#.',
            'a':
            a['name'],
            'a_they':
            a['they'],
            'a_their':
            a['their'],
            'yet': ['yet', 'but', 'though', 'and still'],
            'confident_statement':
            rank([
                '#a# invested time in #a_their# #nonromantic#',
                '#a# felt #chill# regarding the encounter'
                'Overall, things had been going quite well for #a#',
            ], a['confidence'] / 2),
            'chill': [
                'undeterred', 'unbothered', 'at ease', 'aloof', 'untroubled',
                'nonchalant'
            ],
            'nonromantic':
            ['friendships', 'career', 'hobbies', 'stack of unread books'],
            'longing':
            rank([
                '#a_they# checked their phone often, expecting texts from no one',
                ' when #a# went to social events, #a_they# desperately wished they had a partner',
                '#a_they# kept re-downloading dating apps and browsing for hours',
                '#a#\'s friends teased them for constantly going on dates'
            ], a['commit'])
        }
    else:
        rules = {
            'origin':
            '#insecure_statement#, and #longing#.',
            'a':
            a['name'],
            'a_they':
            a['they'],
            'a_their':
            a['their'],
            'insecure_statement':
            rank([
                '#a# #felt# #a_they# were #unlovable#',
                '#Things# felt #hard# for a while',
                '#a# did not feel #great# after that', '#a# #avoid#'
            ], a['confidence'] / 2),
            'longing':
            rank([
                '#a_they# longed for touch, affection and companionship',
                '#a_they# couldn\'t deny the lonely ache in #a_their# chest',
                '#a_they# scrolled endlessly on #a_their# phone, searching for someone',
                '#a_they# were overcome with the absence of a best friend and partner'
            ], a['commit']),
            'Things': ['Everything', 'Life', 'Getting up', 'Dating'],
            'great': [
                'great', 'good', 'well', 'excited', 'confident', 'encouraged',
                'enthusiastic'
            ],
            'felt': [
                'felt as if', 'was sure that', 'felt certain that',
                'wondered if'
            ],
            'hard': [
                'hard', 'grey', 'difficult', 'lonely', 'like a struggle',
                'impossible', 'boring', 'uneventful'
            ],
            'unlovable': [
                'unlovable', 'unattractive', 'not fun to be around',
                'repellant', 'too desperate'
            ],
            'avoid': [
                '#tried# to get #their# mind off of things',
                '#tried# not to be #bugged# by it'
            ],
            'tried': ['tried', 'attempted'],
            'bugged':
            ['annoyed', 'bothered', 'annoyed', 'troubled', 'discouraged']
        }
    print(tracery.Grammar(rules).flatten('#origin#'))
Exemple #16
0
def get_partner_description(person):
    rules = {
        'origin': [
            "#time#, Alex #realized# that #name# was a #hot# person with #extra#. #they.capitalize# was #con# and #open#. When it came to their relationship, #name# was #neuro# #joiner# #agree#."
        ],
        'joiner':
        f"{util.joiner(pow(1-abs(1-person['neuro']-person['agree']), 2))}",
        'time': [
            "Over time", "As their relationship progressed",
            "As the two got to know each other", "The more they saw #name#"
        ],
        'realized':
        ["realized", "noticed", "discovered", "found", "saw", "learned"],
        'name':
        f"{person['name']}",
        'they':
        f"{person['they']}",
        'hot':
        util.rank([
            "unremarkable", "typical", "plain-looking", "homely", "kind-eyed",
            "sweet-faced", "attractive", "charming", "beautiful", "gorgeous",
            "stunning"
        ], person['hot']),
        'extra':
        util.rank([
            "a reserved manner", "a quiet demeanor", "a cat-like personality",
            "a laid-back demeanor", "a relaxed-personality", "an easy smile",
            "an enthusiastic charm", "a boisterous laugh",
            "a gregarious personality"
        ], person['extra']),
        'open':
        util.rank([
            "could not be convinced to try new food when they ate out together",
            "cautious in nature, hating surprises",
            "a creature of habit, inflexible but reliable",
            "usually stuck to what felt comfortable",
            "enjoyed trying new things occasionally",
            "constantly sought new hobbies and experiences",
            "impulsive in ways, always sensation-seeking"
        ], person['open']),
        'neuro':
        util.rank([
            "emotionally attuned",
            "emotionally stable",
            "stoic",
            "grounded",
            "composed",
            "well-adjusted",
            "easygoing",
            "nonchalant",
            "jittery",
            "anxious",
            "high strung",
            "emotionally volatile",
            "emotionally unpredictable",
            "prone to severe mood swings",
        ], person['neuro']),
        'con':
        util.rank([
            "disorganized", "careless", "meandering", "scattered",
            "working on being more organized", "a bit messy", "mostly tidy",
            "clean", "keen", "detail-oriented", "diligent", "dutiful",
            "a neat freak", "exacting"
        ], person['con']),
        'agree':
        util.rank([
            "callous",
            "combative",
            "argumentative",
            "rude",
            "stubborn",
            "independent",
            "apathetic",
            "cooperative",
            "empathetic",
            "deferential",
            "altruistic",
        ], person['agree']),
    }
    grammar = tracery.Grammar(rules)
    grammar.add_modifiers(base_english)
    print(grammar.flatten('<p>#origin#</p>'))
def narrate_meeting(event, events):
    a, b = get_ab(event)
    if event['delta'] == -1:

        narrate_meeting_system(event)
        return

    text = "<p>"
    if event['protagonist_initiated']:
        text += get_interest_sentence(event['protagonist'], event['person'],
                                      event['protagonist']['interest'])
    else:
        text += get_interest_sentence(event['person'], event['protagonist'],
                                      event['person']['interest'])
    adverb = util.rank(
        ['nervously', 'shyly', 'quietly', 'gently', 'intently', 'boldly'],
        a['interest'])

    if event['delta'] <= 0:
        REJECTIONS = [
            f", but {b['name']} averted {b['their']} eyes.",
            f", but {b['name']} did not respond.",
            f", but {b['name']} quickly turned away.",
        ]
        followup = random.choice(REJECTIONS)
    else:
        follow2 = random.choice([
            f'Soon, they got to talking and found themselves engaged in animated conversation. ',
            f"They exchanged several friendly words, before agreeing to meet again sometime soon. "
        ])
        contact = random.choice([
            'phone number', 'email', 'contact',
            'phone number scrawled onto a crumpled piece of paper',
            'phone number hastily scribbled on a napkin',
            'email address dashed onto a post-it note',
            'Discord server invite', 'laughter echoing in their ears',
            'smile etched into their memory', 'Instagram handle'
        ])
        follow3 = random.choice([
            f"{a['name']} left with {b['name']}'s {contact}. ",
            f"{b['name']} left with {a['name']}'s {contact}. ",
        ])
        ACCEPTS = [
            f". {b['name']} returned a flirtatious glance. {follow2}{follow3}",
            f". {b['name']} waved in return. {follow2}{follow3}",
            f". {b['name']} smiled back. {follow2}{follow3}"
        ]
        followup = random.choice(ACCEPTS)
    time = random.choice([
        'After a few moments, ',
        '',
        'After several minutes, ',
        'Eventually, ',
    ])
    APPROACHES = [
        f"{time}{a['name']} waved {adverb}{followup}",
        f"{time}{a['name']} smiled {adverb}{followup}",
        f"{time}{a['name']} began to gaze {adverb} at {b['name']}{followup}",
        f"{time}{a['name']} giggled {adverb}{followup}",
        f"{time}{a['name']} walked {adverb} toward {b['name']}{followup}"
    ]
    print(text + random.choice(APPROACHES) + "" + "</p>")

    narrate_meeting_system(event)
Exemple #18
0
def narrate_memory(a, b, reflection, interest):
    if reflection['memory']:
        rules = {
            'memory_sentence':
            [f"#time# #remembered# #{reflection['memory']}#. #reaction#."],
            'a':
            a['name'],
            'a_they':
            a['they'],
            'a_their':
            a['their'],
            'b':
            b['name'],
            'b_their':
            b['their'],
            'b_they':
            b['they'],
            'time': [
                'Every now and then when #a# was #action#',
                'Some mornings, in those tender moments between sleep and wake,',
                'One night, while #a# was #action#',
                'Randomly when #a# was #action#', 'When #a# was #action#',
                'One evening while #a# was #action#'
            ],
            'action': [
                'going to bed', 'getting groceries',
                f"going to {random.choice(INTERESTS[interest]['location'])}",
                'daydreaming', 'getting ready for work',
                'making plans for a vacation', f"reading about {interest}"
            ],
            'remembered': [
                '#a_they# couldn\'t help but think about',
                '#a_they# remembered', '#a# recalled', '#a_they# imagined',
                '#a_they# thought about'
            ],
            'open': [
                '#b#\'s enthusiastic charm',
                '#b#\'s gentle hand on #a_their#\'s, beckoning',
                '#b#\'s open and excited response when trying something new together'
            ],
            'extra': [
                '#b#\'s melodic laughter',
                'watching #b# at a party while #b_they# charmed the whole room'
            ],
            'libido': [
                'the curve #b#\'s neck as #b_they# undressed',
                'the smell of #b#\'s skin as they held each other',
                '#b#\'s electric touch against #a_their# skin',
                '#b#\'s body silhouetted against the moonlight'
            ],
            'con': [
                'one of #b#\'s intellectual ramblings',
                'watching #b#\'s back as #b_they# did the dishes',
                'what #b# would say about the state of #a_their# home'
            ],
            'agree': [
                '#b#\'s comforting presence',
                f"going to {random.choice(INTERESTS[interest]['location'])} and teaching #b# everything #a_they# knew",
                'the ease and enjoyment of sitting on #b#\'s floor, talking for hours'
            ],
            'exp': [
                '#b#\'s kind yet discerning expression as #b_they# would evaluate #a#',
                'one of #b#\'s stories about #b_their# ex. #a# wondered what #a_their# story would sound like when #b# told it.'
            ],
            'hot': [
                'the way #b# would turn heads as #b_they# walked down the street',
                'admiring #b#\'s face as #b_they# got ready for work',
                'staring into #b#\'s eyes for hours'
            ],
            'neuro': [
                'one of #b#\'s emotional breakdowns',
                'brushing #a_their# hands through #b#\'s hair as #b_they# endured another mood swing',
                '#b#\'s constant refrain: "thank you for staying being with me"'
            ],
            'commit': [
                'meeting #b#\'s parents', 'talking about moving in with #b#',
                'long discussions about #a_their# future with #b#'
            ],
            'reaction':
            rank([
                '#a# sighed and dismissed the thought',
                '#a# tried to push #b# out of #a_their# mind',
                '#a# bit #a_their# lip and moved on with #a_their# day',
                'In that moment #a# felt overcome with affection, and loss',
                '#a# wondered, surprised by #a_their# own desperation, if anyone other than #b# would do',
                '#a# took in a deep breath as tears welled up in #a_their# eyes. There was no one like #b#'
            ], a['interest'])
        }
        rules.update(getInterestRules(a, b, interest))
        print(tracery.Grammar(rules).flatten('#memory_sentence#'))
Exemple #19
0
 def compute_day(self, di, alpha):
     # Should return alpha as a list
     util.rank(alpha)
     return alpha
Exemple #20
0
def get_conflict_thought(a, b, event, problem_phrase):
    logging.debug("FIGHT ABORTED")
    conflicts = [e for e in event['prev'] if e['initiated']]
    ago = ''
    if conflicts:
        # There were previous fights about it.
        # One morning, the fight they had in December about Susan's laziness floated into ALex's mind.
        main = '#time#, the #fight# they had #ago# about how #b# #problem# #floated#.'
        ago = humanize.naturaldelta(
            event['date'] - conflicts[len(conflicts) - 1]['date']) + ' ago'
    elif event['prev']:
        # THere were previous aborted fights.
        main = 'The idea that #b# #problem# came back to #a#\'s #mind#.'
    else:
        main = '#time#, #a# #thought# that #perhaps# #b# #problem#.'
    but = '#resolve#' if event['initiated'] else '#but#'

    rules = {
        'origin': f"{main} {but}",
        'a': a['name'],
        'a_they': a['they'],
        'a_their': a['their'],
        'b': b['name'],
        'b_their': b['their'],
        'time': ['One morning', 'One day', f'On {event["date"].strftime("%A")}'],
        'mind': ['mind', 'head'],
        'ago': ago,
        'floated': ['floated back into #a#\'s #mind#', 'drifted into #a#\'s #mind#'],
        'perhaps': ['perhaps', 'maybe', '', '', 'compared to previous partners,'],
        'thought': ['thought', 'considered', 'felt bothered', 'felt concerned', 'had the thought', 'was discussing #b# with a friend and realized'],
        'problem': problem_phrase,
        'pushing': ['pushing', 'telling', 'convincing', 'nagging', 'dragging'],
        'but': [
            '#pushed_back#, and #return#',
            '#pushed_back#. '
        ],
        'pushed_back': [
            '#a# pushed the thought the the back of #a_their# mind',
            '#a# let the thought fade away',
        ],
        'return': [
            '#returned# to #a_their# coffee.',
            '#returned# to #a_their# breakfast.',
            '#returned# to #a_their# work.',
            f"#returned# to reading about {random.choice(a['hobbies'])}." if a[
                'hobbies'] else 'returned to reading.',
            f"#returned# to watching Youtube videos about {random.choice(a['hobbies'])}." if a[
                'hobbies'] else 'returned to surfing the Internet.',
        ],
        'returned': ['returned', 'went back'],
        'resolve': [
            '#texture# #a# resolved to bring it up to #b# next time they saw each other.'
        ],
        'texture': util.rank([
            '#a# #return#. It wasn\'t a big deal, but nonetheless,',
            '#a# exhaled slowly. Perhaps it could be resolved with a simple conversation. ',
            '#a# bit #a_their# lip. It was becoming more and more bothersome the more #a_they# thought about it.',
            '#a# clenched #a_their# fist. It was really not something #a# valued in a partner. ',
            '#a# felt themselves shaking with anger.',
        ], (event['target'])),
        'fight': ['fight', 'argument', 'dispute', 'spat']
    }
    return tracery.Grammar(rules).flatten('<p>#origin#</p>')
Exemple #21
0
def get_date_artifact(event, events, detail):
    a, b = get_ab(event)
    a_nick = event['protagonist']['nickname']
    b_nick = event['person']['nickname']
    a_interest = event['protagonist']['interest']
    b_interest = event['protagonist']['interest']

    # Look for the most recent event and use it to
    # determine the first message sent
    experiences = [e for e in events if e['type'] != EventType.NOTHING]
    recent_experience = experiences[-1]

    if recent_experience['type'] == EventType.CONFLICT and recent_experience[
            'initiated']:
        # This means there was a conflict recently
        message = [
            "Hey, can I cheer you up?",
            "Sorry about the other day. I wanna make it up to you! ",
        ]
    elif recent_experience.get('rejected'):
        # There was a previous rejection
        if recent_experience['protagonist_initiated'] == event[
                'protagonist_initiated']:
            message = ["Hey, uh, ", "are you around? ", "Mm, ", "hello? "]
        else:
            message = [
                "#hello# sorry again I was busy earlier! "
                "Ok I'm free now. ",
                "hey, sorry about that. ",
            ]
    elif recent_experience['type'] == EventType.COMMIT and recent_experience[
            'initiated']:
        if recent_experience['success_ratio'] > 1:
            # we only do these texts in COURTING, this is just a placeholder for now
            message = [';)']
        else:
            message = [
                "Well let's keep hanging out still!",
                "I still enjoy spending time with you",
                "I still really like you",
                "I'm still interested in hanging out more!"
            ]
    else:
        message = util.rank([
            '#hello# ',
            f'#hello# it was really nice to see you the other day!',
            f'i had fun! ',
            f'i had a lot of fun the other day! ',
            "You're cute. ",
            f"i had a #great# time! ",
            "You're a cutie. ",
            f"you are #great#. ",
            f"can’t stop thinking about you. ",
        ], random.gauss(a['interest'], 0.3))

    # Create the messages array
    # Initial message asks for the date
    messageA = '#start##punc# #ask#'

    # Always provide detail if rejecting
    if event['rejected']:
        detail = True

    # Set the response appropriately...
    messageB = '#resp#'
    if detail:
        messageB = '#rej#' if event['rejected'] else '#response#'

    messages = [{
        'text': messageA,
        'time': event['date'],
        'nickname': a_nick if event['protagonist_initiated'] else b_nick,
        'a': 'a' if event['protagonist_initiated'] else 'b'
    }, {
        'text': messageB,
        'time': event['date'],
        'nickname': b_nick if event['protagonist_initiated'] else a_nick,
        'a': 'b' if event['protagonist_initiated'] else 'a'
    }]

    if detail:
        # Splice in another message
        messages.insert(
            1, {
                'text': '#date_suggest#',
                'time': event['date'],
                'nickname': messages[0]['nickname'],
                'a': messages[0]['a']
            })

    rules = {
        'origin': ['#preface# #msg#', '#msg#', '#msg#'],
        'preface':
        get_message_intro(a, b),
        'msg':
        get_message_html(messages),
        'punc': ['', '#e#'],
        'e':
        HEART_EMOJIS,
        'start':
        message,
        'ask': [
            'can i see you again?',
            'when can i see you again?',
            'when can i see u next?',
            'when r u free?',
            'when are u free next?',
            'See me again soon?',
            'Want to hang out #day#?',
            'Want to hang out again?',
            'When are you free next?',
            'When are you free?',
            "I'd love to see you again!",
        ],
        'hello': [
            'hey',
            'heyy',
            'heya',
            'hi',
            'hello!',
            'yo',
            'sup',
            'Hey!',
            'Heya!',
            'Yo!',
            'Hello!',
            'Whats up!',
            '',
        ],
        'great':
        ['great', 'wonderful', 'fantastic', 'awesome', 'unforgettable'],
        'rej': [
            'uhhh let me take a look at my calendar', 'let me get back to you',
            'im kinda busy rn but ill text u',
            'Hm, my week is looking pretty busy', 'Let me get back to you...',
            'I have a upcoming deadline, can I let you know?'
        ],
        'resp':
        util.rank([
            '#suggest#',
            "#suggest# :)",
            "#suggest# #e#",
            'yea, #suggest#',
            "yes, #suggest#",
            "yes! #suggest#",
            "yeah id love to! #suggest#",
            'Looking forward to it #suggest#',
            'I\'d love to, #suggest#',
            'Of course! #suggest#',
            'Absolutely! #suggest#',
            'For sure! #suggest#',
        ], random.gauss(b['interest'], 0.3)),
        'suggest': [
            'what about #day#?', 'im free on #day#!', 'i can do #day#.',
            'i could do #day#.', '#day#?'
        ],
        'day': [
            'tomorrow', 'the day after tomorrow', 'some time next week',
            event['date'].strftime('%A')
        ],
        'date_suggest':
        f"#{event['target_property']}#",
        'open': [
            'Wanna go #hobby_verb#?', 'We could #hobby_verb#?',
            'Wanna go to #hobby_location#?',
            'We could check out #hobby_location#?'
        ],
        'extra':
        util.rank([
            'We could do something quiet at my place?',
            'We could do something chill',
            'Lets go out somewhere?',
            'We could go out!!',
        ], event['threshold']),
        'libido':
        util.rank([
            'But lets not jump right into bed?',
            'I cant stay over tonight though',
            "Id be interested in getting to know you better! #e#",
            '#e##e##e#',
            'wanna get freaky? #e##e##e#',
        ], event['threshold']),
        'hobby_location':
        INTERESTS[event['interest']]['location']
        if 'interest' in event else '',
        'hobby_verb':
        INTERESTS[event['interest']]['verb'] if 'interest' in event else '',
        'response':
        util.rank([
            "I'd love to! #suggest#", "Sounds like fun! #suggest#",
            "Yes, let's do it, #suggest#", "Sure! #suggest#", "Okay",
            "Oh, okay", "I guess so...", "Do we have to?",
            "You know I don't like that"
        ], event['concession']),
    }
    if 'interest' in event:
        rules.update(getInterestRules(a, b, event['interest'], pov=1))
    grammar = tracery.Grammar(rules)
    return grammar.flatten("#origin#\n")
def narrate_commit(event, events):
    a, b = get_ab(event)
    if event['initiated']:
        enthusiasm = util.scale(event['success_ratio'], 1, 3, 0, 1)
        rules = {
            'courting_phase': ['<p>#dating#</p>'],
            'dating_phase': ['<p>#iloveyou#</p>'],
            'dating': ['#dating_challenge# #dating_result#'],
            'iloveyou': ['#ily_challenge# #ily_result#'],
            'dating_challenge': [
                "#a# asked to start dating.",
                "#a# asked if #b# would be interested in dating.",
            ],
            'dating_result':
            f"#b# agreed {util.enthusiastically(enthusiasm)}. "
            if event['success_ratio'] >= 1 else
            f'#b# said that {b["they"]} needed more time. ',
            'ily_challenge':
            f"#a# said \"I love you,\"",
            'ily_result': [
                'but #b# could not say it back. #a# was #hurt#'
                if event['success_ratio'] < 1 else
                f'and #b# returned the words {util.enthusiastically(enthusiasm)}.'
            ],
            'hurt': util.rank(
                [
                    'hurt, but said #a_they# understood.',
                    'wounded. A tear fell from #a#\'s left eye. ',
                    'devasted. #a_they.capitalize# had hoped #b#\'s response might have been different this time.',
                    'mortified. #a# shouted that #b# was wasting #a#\'s time. #b# shrugged. '
                ],
                util.scale(event.get('prev', 0), 0, 3, 0, 1)
            ),
            'a': a['name'],
            'b': b['name'],
            'a_they': a['they']
        }

    elif event['initiate_ratio'] > 1:
        # Narrate a failed commit event held back by confidence
        rules = {
            'courting_phase': '#origin#',
            'dating_phase': '#origin#',
            'origin': [
                '#a# felt nervous, but excited. ',
                '#a# sighed. #b# seemed so amazing. But would #b_they# return #a#\'s feelings?',
                '#a# smiled quietly to themselves. Perhaps the right time to talk to #b# would come some day. ',
                "#a# had the urge to ask #b# about how they felt about the relationship, but wasn't quite confident enough to ask. ",
            ],
            'a': a['name'],
            'b': b['name'],
            'b_they': b['they'],
        }
    else:
        # Not interested enough.
        rules = {
            'courting_phase': [
                "#a# continued to use dating apps from time to time. ",
                "#a# considered sending #b# a message, but decided not to. ",
                "#a# noticed a message from #b#. #a# ignored it. ",
                "#b# had yet to meet most of #a#'s friends. ",
            ],
            'dating_phase': [
                "#a#'s Facebook relationship status still read 'Single'. ",
                "#a# had yet to mention #b# to their parents. ",
                "#a# told #b# they were busy, but in fact #a# had no concrete plans that day. ",
                "#a# lay awake at night, mulling over exes from previous relationships. ",
            ],
            'a': a['name'],
            'b': b['name'],
            'interest': a['interests'],
        }
    grammar = tracery.Grammar(rules)
    grammar.add_modifiers(base_english)
    if event['phase'] == Phase.COURTING:
        print(grammar.flatten('<p>#courting_phase#</p>'))
    elif event['phase'] == Phase.DATING:
        print(grammar.flatten('<p>#dating_phase#</p>'))
    print('\n')
    narrate_commit_system(event)