コード例 #1
0
def load_token_weights():
    global token_weights
    with open("data/token_weights.json", "rb") as f:
        w = json.loads(f.read())
        w = list(w.items())
        w.sort(key=lambda x: x[1]["male"] + x[1]["female"])
        w = helper.chunk(w, SECTIONS)
        for i in range(len(w)):
            w[i] = {co[0]: co[1] for co in w[i]}
        token_weights = w
コード例 #2
0
def part_2():
    ball_x = paddle_x = None
    computer = IntCodeComputer(instructions, lambda: (ball_x > paddle_x) - (ball_x < paddle_x))
    computer.memory[0] = 2

    points = 0
    while not computer.done:
        for x, y, tile in chunk(computer.compute(return_on_output=True), 3):
            paddle_x = x if tile == 3 else paddle_x
            ball_x = x if tile == 4 else ball_x
            points = tile if (x, y) == (-1, 0) else points
        return points
コード例 #3
0
    f = open(speech_filename, "r", encoding="utf8", errors='ignore')
    whole_text = f.read()
    print(whole_text)
    print(
        '=========================================================================='
    )
    print(
        '=========================================================================='
    )
    print(
        '=========================================================================='
    )
    print(
        '=========================================================================='
    )
    text = helper.chunk(whole_text)
    print(text)

    sentiments = []

    for document in text:
        for item in document['documents']:
            p = item['text']
            print('------------------------------')
            print(item['text'])
            payload = "text=" + p

            response = requests.request("POST",
                                        url,
                                        data=payload.encode('utf-8'),
                                        headers=headers)
コード例 #4
0
                remove = True

            if text[c:c+1] == '<':
                remove = False

            if not remove:
                if not text[c:c+1] == '<':
                    out = out + (text[c:c+1])

        out = out[::-1]          
        package = package + " " + out
    years.append(package)

text = []
for year in years:
    text.append(helper.chunk(year))

sentiments_list = []
for index in range(len(text)):
    documents = text[index][0]
    
    headers = {"ocp-apim-subscription-key": subscription_key}
    response = requests.post(sentiment_url, headers=headers, json=documents)
    sentiments = response.json()

    pprint(sentiments)
    sentiments_list.append(sentiments)

with open ('wiki_sentiments2.csv', 'w', newline ='', encoding="utf8", errors='ignore') as csvfile:
    writer = csv.writer(csvfile)
    counter = 0
コード例 #5
0
def part_1():
    computer = IntCodeComputer(instructions)
    total = sum(1 for _, _, tile in chunk(computer.compute(return_on_output=True), 3) if tile == 2)
    return total