import torch
import torch.nn as nn
import torch.nn.functional as F
from torchvision import models

class X_ray_Classifier(nn.Module):
    def __init__(self):
        super(X_ray_Classifier, self).__init__()
        # Defining the convolution layers and the maxpooling structure
        self.c1 = nn.Conv2d(1, 32, kernel_size=3)
        self.mp1 = nn.MaxPool2d(kernel_size=2)
        self.c2 = nn.Conv2d(32, 32, kernel_size=3)
        self.mp2 = nn.MaxPool2d(kernel_size=2)
        self.c3 = nn.Conv2d(32, 32, kernel_size=3)
        self.mp3 = nn.MaxPool2d(kernel_size=2)
        self.c4 = nn.Conv2d(32, 64, kernel_size=3)
        self.mp4 = nn.MaxPool2d(kernel_size=2)
        self.f1 = nn.Linear(16384, 1280)
        self.f2 = nn.Linear(1280, 64)
        self.output = nn.Linear(64, 4)
        # Define the activation function
        self.act1 = nn.ReLU()

    def forward(self, x):
        x = self.act1(self.c1(x))
        x = self.act1(self.mp1(x))
        x = self.act1(self.c2(x))
        x = self.act1(self.mp2(x))
        x = self.act1(self.c3(x))
        x = self.act1(self.mp3(x))
        x = self.act1(self.c4(x))
        x = self.act1(self.mp4(x))
        x = x.view(-1, x.size(1)*x.size(2)*x.size(3))
        x = self.act1(self.f1(x))
        x = self.act1(self.f2(x))
        return self.output(x)

class RestNetBasicBlock(nn.Module):
    def __init__(self, in_channels, out_channels, stride):
        super(RestNetBasicBlock, self).__init__()
        self.conv1 = nn.Conv2d(in_channels, out_channels, kernel_size=3,
                               stride=stride, padding=1)
        self.bn1 = nn.BatchNorm2d(out_channels)
        self.conv2 = nn.Conv2d(out_channels, out_channels, kernel_size=3,
                               stride=stride, padding=1)
        self.bn2 = nn.BatchNorm2d(out_channels)

    def forward(self, x):
        output = self.conv1(x)
        output = F.relu(self.bn1(output))
        output = self.conv2(output)
        output = self.bn2(output)
        return F.relu(x + output)

class RestNetDownBlock(nn.Module):
    def __init__(self, in_channels, out_channels, stride):
        super(RestNetDownBlock, self).__init__()
        self.conv1 = nn.Conv2d(in_channels, out_channels, kernel_size=3,
                               stride=stride[0], padding=1)
        self.bn1 = nn.BatchNorm2d(out_channels)
        self.conv2 = nn.Conv2d(out_channels, out_channels, kernel_size=3,
                               stride=stride[1], padding=1)
        self.bn2 = nn.BatchNorm2d(out_channels)
        self.extra = nn.Sequential(
            nn.Conv2d(in_channels, out_channels, kernel_size=1,
                      stride=stride[0], padding=0),
            nn.BatchNorm2d(out_channels)
        )

    def forward(self, x):
        extra_x = self.extra(x)
        output = self.conv1(x)
        out = F.relu(self.bn1(output))

        out = self.conv2(out)
        out = self.bn2(out)
        return F.relu(extra_x + out)

class RestNet18(nn.Module):
    def __init__(self):
        super(RestNet18, self).__init__()
        self.conv1 = nn.Conv2d(1, 64, kernel_size=7, stride=2, padding=3)
        self.bn1 = nn.BatchNorm2d(64)
        self.maxpool = nn.MaxPool2d(kernel_size=3, stride=2, padding=1)

        self.layer1 = nn.Sequential(RestNetBasicBlock(64, 64, 1),
                                    RestNetBasicBlock(64, 64, 1))

        self.layer2 = nn.Sequential(RestNetDownBlock(64, 128, [2, 1]),
                                    RestNetBasicBlock(128, 128, 1))

        self.layer3 = nn.Sequential(RestNetDownBlock(128, 256, [2, 1]),
                                    RestNetBasicBlock(256, 256, 1))

        self.layer4 = nn.Sequential(RestNetDownBlock(256, 512, [2, 1]),
                                    RestNetBasicBlock(512, 512, 1))

        self.avgpool = nn.AdaptiveAvgPool2d(output_size=(1, 1))

        self.fc = nn.Linear(512, 4)

    def forward(self, x):
        out = self.conv1(x)
        out = self.layer1(out)
        out = self.layer2(out)
        out = self.layer3(out)
        out = self.layer4(out)
        out = self.avgpool(out)
        out = out.reshape(x.shape[0], -1)
        out = self.fc(out)
        return out

class CustomAlexnet(nn.Module):
    def __init__(self):
        super(CustomAlexnet, self).__init__()
        self.model = models.alexnet(pretrained=True)
        # Alter the final fully connected layer to output 4 classes
        self.model.classifier = \
            nn.Sequential(nn.Dropout(p=0.5, inplace=False),
                          nn.Linear(in_features=9216, out_features=4096,
                                    bias=True),
                          nn.ReLU(inplace=True),
                          nn.Dropout(p=0.5, inplace=False),
                          nn.Linear(in_features=4096, out_features=4096,
                                    bias=True),
                          nn.ReLU(inplace=True),
                          nn.Linear(in_features=4096, out_features=4,
                                    bias=True))

    def forward(self, x):
        x = self.model(x)
        return x

class CustomResnet(nn.Module):
    def __init__(self):
        super(CustomResnet, self).__init__()
        self.model = models.resnet18(pretrained=True)

        self.model.fc = nn.Sequential(
                            nn.Linear(512, 512, bias=True),
                            nn.ReLU(),
                            nn.Linear(512, 4, bias=True))

    def forward(self, x):
        x = self.model(x)
        return x

class CustomSqueezenet(nn.Module):
    def __init__(self):
        super(CustomSqueezenet, self).__init__()
        self.model = models.squeezenet1_1(pretrained=True)
        # Change final layer for our case
        self.model.classifier[1] = nn.Conv2d(512, 4,
                                             kernel_size=(1, 1),
                                             stride=(1, 1))

    def forward(self, x):
        x = self.model(x)
        return x

class CustomGooglenet(nn.Module):
    def __init__(self):
        super(CustomGooglenet, self).__init__()
        model = models.googlenet(pretrained=True)

        for param in model.parameters():
            param.requires_grad = False

        model.fc = nn.Linear(in_features=1024, out_features=4, bias=True)
        self.model = nn.Sequential(nn.Conv2d(1, 3, kernel_size=3, stride=1,
                                             padding=1, dilation=1, groups=1,
                                             bias=True), model)

    def forward(self, x):
        x = self.model(x)
        return x

class basic_block(nn.Module):
    expansion = 1

    def __init__(self, inplanes, planes, stride=1, downsample=None):
        super().__init__()
        self.conv1 = nn.Conv2d(inplanes, planes, kernel_size=3, stride=stride,
                               padding=1, bias=False)
        self.bn1 = nn.BatchNorm2d(planes)
        self.relu = nn.ReLU(inplace=True)
        self.conv2 = nn.Conv2d(planes, planes, kernel_size=3, stride=1,
                               padding=1, bias=False)
        self.bn2 = nn.BatchNorm2d(planes)
        self.downsample = downsample
        self.stride = stride

    def forward(self, x):
        identity = x

        out = self.conv1(x)
        out = self.bn1(out)
        out = self.relu(out)

        out = self.conv2(out)
        out = self.bn2(out)

        if self.downsample is not None:
            identity = self.downsample(x)

        out += identity
        out = self.relu(out)

        return out

# classes needed for the
class X_ray_RESnet(nn.Module):

    def __init__(self, block, layers, num_classes=4):
        super().__init__()

        self.inplanes = 64

        self.conv1 = nn.Conv2d(1, self.inplanes, kernel_size=7, stride=2,
                               padding=3, bias=False)
        self.bn1 = nn.BatchNorm2d(self.inplanes)
        self.relu = nn.ReLU(inplace=True)
        self.maxpool = nn.MaxPool2d(kernel_size=3, stride=2, padding=1)

        self.layer1 = self._make_layer(block, 64, layers[0])
        self.layer2 = self._make_layer(block, 128, layers[1], stride=2)
        self.layer3 = self._make_layer(block, 256, layers[2], stride=2)
        self.layer4 = self._make_layer(block, 512, layers[3], stride=2)

        self.avgpool = nn.AdaptiveAvgPool2d((1, 1))
        self.fc = nn.Linear(512, num_classes)

    def _make_layer(self, block, planes, blocks, stride=1):
        downsample = None

        if stride != 1 or self.inplanes != planes:
            downsample = nn.Sequential(
                nn.Conv2d(self.inplanes, planes, 1, stride, bias=False),
                nn.BatchNorm2d(planes),
            )

        layers = []
        layers.append(block(self.inplanes, planes, stride, downsample))

        self.inplanes = planes

        for _ in range(1, blocks):
            layers.append(block(self.inplanes, planes))

        return nn.Sequential(*layers)

    def forward(self, x):
        x = self.conv1(x)
        x = self.bn1(x)
        x = self.relu(x)
        x = self.maxpool(x)

        x = self.layer1(x)
        x = self.layer2(x)
        x = self.layer3(x)
        x = self.layer4(x)

        x = self.avgpool(x)
        x = torch.flatten(x, 1)
        x = self.fc(x)

        return x

def xray_RESNET():
    layers = [3, 4, 6, 3]
    model = X_ray_RESnet(basic_block, layers)
    return model


from tkinter import *
import random
from ready_templates import list
from questions import questions

random_photo = random.choice(list)
random_question = random.choice(questions)
BACKGROUND_COLOR = "white"

window = Tk()
window.title("Ποιος θα ήθελες")
window.config(padx=50, pady=50, bg=BACKGROUND_COLOR)

vs_photo = PhotoImage(file=random_photo)

def next_card():
    global random_photo, vs_photo
    random_question = random.choice(questions)
    canvas.itemconfig(card_question, text=random_question)
    canvas.itemconfig(card_background, image=vs_photo)

canvas = Canvas(width=800, height=400)
card_background = canvas.create_image(400, 263, image=vs_photo)
card_question = canvas.create_text(400, 30, text=random_question, font=("Ariel", 20))
canvas.config(bg=BACKGROUND_COLOR, highlightthickness=0)
canvas.grid(row=0, column=0, columnspan=2)

tick_image = PhotoImage(file="images/tick png.png")
left_button = Button(image=tick_image, highlightthickness=0, command=next_card)
left_button.grid(row=1, column=0)

right_button = Button(image=tick_image, highlightthickness=0, command=next_card)
right_button.grid(row=1, column=1)

next_card()

window.mainloop()


# ---------------------------------------------------------------------------------------------------------------------#
'''
This code is to pull random tickers from the SP500, Russell, or stock exchanges.
'''
# ---------------------------------------------------------------------------------------------------------------------#

import csv
import datetime as dt
import pickle
import random
from datetime import timedelta

import alpaca_trade_api as tradeapi
import bs4 as bs
import pandas as pd
import requests
'''
from Functions.Alpaca_Key_Store import initiate_API_keys
from Functions.Stock_Filter import sift_strategy
from Functions.Stock_Filter import ticker_selection
'''

from Alpaca_Key_Store import initiate_API_keys
from Stock_Filter import sift_strategy
from Stock_Filter import ticker_selection

# ---------------------------------------------------------------------------------------------------------------------#
ALPACA_API_KEY, ALPACA_SECRET_KEY, ALPACA_API_BASE_URL = initiate_API_keys()
ALPACA_PAPER = True
api = tradeapi.REST(ALPACA_API_KEY, ALPACA_SECRET_KEY, ALPACA_API_BASE_URL, 'v2')
# ---------------------------------------------------------------------------------------------------------------------#

pd.set_option('display.max_rows', None)
pd.set_option('display.max_columns', None)

class gen_tickers():
    def __init__(self, year, smonth, mrange):
        self.year = year
        self.smonth = smonth
        # Defining start and end dates
        weekend_test = dt.date(year=int(year), month=int(smonth), day=3).weekday()
        period_start = dt.date(year=int(year), month=int(smonth), day=3)
        # ---------------------------------------------------------------

        if (weekend_test == 5):
            self.simstart = period_start + timedelta(days=2)
            self.start = period_start - timedelta(days=22)
        elif (weekend_test == 6):
            self.simstart = period_start + timedelta(days=1)
            self.start = period_start - timedelta(days=22)
        else:
            self.simstart = period_start
            self.start = period_start - timedelta(days=22)

        weekend_test = dt.date(year=int(year), month=int(smonth + mrange), day=3).weekday()
        period_end = dt.date(year=int(year), month=int(smonth + mrange), day=3)

        if (weekend_test == 5):
            self.end = period_end + timedelta(days=2)
        elif (weekend_test == 6):
            self.end = period_end + timedelta(days=1)
        else:
            self.end = period_end

    def sp500_grab(self, size):
        resp = requests.get('https://en.wikipedia.org/wiki/List_of_S%26P_500_companies')
        soup = bs.BeautifulSoup(resp.text, "lxml")
        table = soup.find('table', {'class': 'wikitable sortable'})
        tickers_trial = []
        for row in table.findAll('tr')[1:]:
            ticker = row.findAll('td')[0].text.strip()
            mapping = str.maketrans(".", "-")
            ticker = ticker.translate(mapping)
            tickers_trial.append(ticker)

        with open("sp500tickers.pickle", "wb") as f:
            pickle.dump(tickers_trial, f)

        tickers = []
        while int(len(tickers)) < int(size):
            ticker = random.choices(tickers_trial, k=1)
            try:
                data = api.polygon.historic_agg_v2(str(ticker[0]), 1, timespan='day', _from=str(self.simstart), to=str(self.end)).df
                df = data.reset_index()
                tickers.append(str(ticker[0]))
            except:
                continue

        return tickers

    def russell_grab(self, sector, strat, period, z):
        tickers = ticker_selection(self.year, sector)
        tickers = sift_strategy(strat, self.year, self.smonth, period, z, tickers)

        return tickers

    def main_exchanges(self, size):

        with open('Stock_Exchange_Lists/NYSE.csv') as csv_file:
            data_1 = csv.reader(csv_file, delimiter=",")

            companies_1 = []
            tickers_1 = []
            sector_1 = []

            for row in data_1:
                tickers_1.append(row[0])
                sector_1.append(row[5])

                tickers_1 = [x.strip(' ') for x in tickers_1]
                sector_1 = [x.strip(' ') for x in sector_1]

            while ("" in tickers_1):
                tickers_1.remove("")

        del tickers_1[0]
        del sector_1[0]

        with open('Stock_Exchange_Lists/NASDAQ.csv') as csv_file:
            data_2 = csv.reader(csv_file, delimiter=",")

            companies_2 = []
            tickers_2 = []
            sector_2 = []

            for row in data_2:
                tickers_2.append(row[0])
                sector_2.append(row[5])

                tickers_2 = [x.strip(' ') for x in tickers_2]
                sector_2 = [x.strip(' ') for x in sector_2]

            while ("" in tickers_2):
                tickers_2.remove("")

        del tickers_2[0]
        del sector_2[0]

        # Compile all tickers from each stock exchange of interest.
        total_tickers = []
        total_tickers.extend(tickers_1)
        total_tickers.extend(tickers_2)

        # Deleting any duplicates from those exchanges. Successful.
        total_tickers = list(dict.fromkeys(total_tickers))

        tickers = []
        while int(len(tickers)) < int(size):
            ticker = random.choices(total_tickers, k=1)
            try:
                data = api.polygon.historic_agg_v2(str(ticker[0]), 1, timespan='day', _from=self.simstart, to=self.end).df
                df = data.reset_index()
                tickers.append(str(ticker[0]))
            except:
                continue

        return tickers


from typing import Union
from .abstracts import BaseDetector
from .wrappers import (
    MediapipeDetector,
    Ssd300x300Detector,
    RetinafaceDetector
)

class DetectorFactory:
    __detector_map = {
        "mediapipe": MediapipeDetector,
        "ssd": Ssd300x300Detector,
        "ssd300x300": Ssd300x300Detector,
        "retinaface": RetinafaceDetector,
    }
    @staticmethod
    def get_detector_class(detector_name: str):
        detector_name = detector_name.lower()
        if detector_name not in DetectorFactory.__detector_map:
            raise ValueError("Detector not found")
        return DetectorFactory.__detector_map[detector_name]
    @staticmethod
    def get_detector(detector_name: str) -> BaseDetector:
        return DetectorFactory.get_detector_class(detector_name)()
    @staticmethod
    def check_detector(detector: Union[str, BaseDetector]) -> BaseDetector:
        if not isinstance(detector, (str, BaseDetector)):
            raise ValueError("Detector must be string or simple-face detector instance")
        if isinstance(detector, str):
            detector = DetectorFactory.get_detector(detector)
        return detector


from itertools import izip_longest

from flask import url_for, request

from flask_cms.page.models import Page
from flask.ext.security import current_user

def get_breadcrumbs(page, breadcrumbs=None):
    if not breadcrumbs:
        breadcrumbs = []

    breadcrumbs.append(page.slug)
    if page.parent is None:
        breadcrumbs.reverse()
        return breadcrumbs
    breadcrumbs = get_breadcrumbs(page.parent, breadcrumbs)
    return breadcrumbs

def create_breadcrumbs_snippet():
    def add_breadcrumbs_snippet(page):
        snippet = ''
        breadcrumbs = get_breadcrumbs(page)
        if not breadcrumbs:
            return snippet
        snippet = "
"
        for breadcrumb in breadcrumbs:
            snippet += '
{camelized_slug}
'. \
                format(url=url_for('page.show', slug=breadcrumb),
                       camelized_slug=breadcrumb.title())
        snippet += '
'
        return snippet

    return dict(add_breadcrumbs_snippet=add_breadcrumbs_snippet)

def add_grouper():
    def grouper(iterable, n, fillvalue=None):
        "Collect data into fixed-length chunks or blocks"
        # grouper('ABCDEFG', 3, 'x') --> ABC DEF Gxx
        args = [iter(iterable)] * n
        return izip_longest(fillvalue=fillvalue, *args)

    return dict(grouper=grouper)

def add_navbar():
    def navbar():
        snippet = '
'
        if current_user.is_authenticated:
            pages_to_show = Page.query.filter_by(publish=True, show_in_nav=True, level=0)
        else:
            pages_to_show = Page.query.filter_by(publish=True, show_in_nav=True, level=0, login_required=False)

        for page in pages_to_show:
            if page.children.all():
                snippet += '
'
                snippet += '''
                {title}'''. \
                    format(title=page.title.title())
                snippet += '
'
                for child in page.children:
                    snippet += '
{title}
'. \
                        format(url=url_for("page.show", slug=child.slug),
                               title=child.title.title(), )
                snippet += '

'
            else:
                css_class = ""
                if request.path.split("/")[-1] == page.slug:
                    css_class = 'class="active"'
                snippet += '
{title}
'. \
                    format(css_class=css_class,
                           url=url_for("page.show", slug=page.slug),
                           title=page.title.title())
        snippet += '
'
        return snippet

    return dict(navbar=navbar)

def add_flash_form_errors():
    def flash_form_errors(form):
        snippet = ""
        for field, errors in form.errors.items():
            for error in errors:
                snippet += '
'
                snippet += ''
                snippet += '{}
'.format(error)
        return snippet

    return dict(flash_form_errors=flash_form_errors)


def gcd(a,b): #최대공약수
    while(b!=0):
        r=a%b
        a=b
        b=r
        if b==1:
            return 1

    return a

if __name__=='__main__':
    a,b=map(int,input().split(":"))

    result=gcd(a,b)

    print(str(int(a/result))+":"+str(int(b/result)))


import matplotlib.pyplot as plt

def PlotOriginalAndProcessed(filename, total_images, original_image, ego_lanes_image, image_number):
    plot_original_and_processed = plt.figure(171, figsize=(80, 25))
    plot_original_and_processed.add_subplot(2, total_images, image_number)
    plt.imshow(original_image)
    plt.title(
        filename), plt.xticks([]), plt.yticks([])
    plot_original_and_processed.add_subplot(
        2, total_images, image_number+total_images)
    plt.imshow(ego_lanes_image)
    plt.savefig('test_images_output/originalVsProcessed.jpg')

def PlotLaneFindingProcess(filename, gray_image, blur_image, canny_image, region_of_interest, lines_in_image, ego_lanes_image, image_number):
    fig_lane_finding_process = plt.figure(image_number, figsize=(25, 10))
    fig_lane_finding_process.add_subplot(2, 3, 1)
    plt.imshow(gray_image, cmap='gray')
    plt.title("Gray Scaled Image")
    fig_lane_finding_process.add_subplot(2, 3, 2)
    plt.imshow(blur_image, cmap='gray')
    plt.title("Blurred Image")
    fig_lane_finding_process.add_subplot(2, 3, 3)
    plt.imshow(canny_image, cmap='gray')
    plt.title("Edges in the Image"), plt.xticks([]), plt.yticks([])
    fig_lane_finding_process.add_subplot(2, 3, 4)
    plt.imshow(region_of_interest, cmap='gray')
    plt.title("Region Of Interest"), plt.xticks([]), plt.yticks([])
    fig_lane_finding_process.add_subplot(2, 3, 5)
    plt.imshow(lines_in_image, cmap='gray')
    plt.title("Lines in Image"), plt.xticks([]), plt.yticks([])
    fig_lane_finding_process.add_subplot(2, 3, 6)
    plt.imshow(ego_lanes_image, cmap="gray")
    plt.title("Ego Lanes Found"), plt.xticks([]), plt.yticks([])
    plt.savefig('test_images_output/process_'+filename)


import sys

# ======= configuration globals ======

# global vars changed by command line options

options={
  "debug_print_flag":False, # if True, print a lot of details of the parsing process (turn on by -debug)
  "prover_print_flag":False, # if True, print prover logic input and output
  "prover_nosolve_flag":False, # if True, attempt to solve the question, if False, just output logic
  "prover_postprocess_flag":False, # if True, apply post_process_logic_list to the logic created
  "prover_rawresult_flag":False, # if True, give a raw json result
  "prover_explain_flag":False, # if True, output nlp explanation
  "show_logic_flag":False, # if True, output also conventional logic for sentences and nlp explanation
  "show_prover_flag":False, # if True, show prover input and output
  "usekb_flag": False, #if True, use shared memory kb
  "forward_flag":False, # if True, use forward search
  "backward_flag":False, # if True, use backward search
  "nocontext_flag":False, # if True, do not insert context information (time, situation) into logic
  "noexceptions_flag":False, # if True, do not insert exception information (blockers) into logic
  "noproptypes_flag":False,  # if True, remove prop strength and type information
  "nokb_flag":True,  # if True, do not use the shared memory knowledge base
  "prover_axiomfiles":False,  # if not False, use these as axioms instead of the default prover_axiomfile below
  "prover_print":False,  # if not False, use the argument integer for gk printout level, instead of the default
  "prover_strategy":False,  # if not False, use the argument as a gk strategy file, instead of the default
  "prover_seconds":2  # give the prover this many seconds, instead of the default 1
}

# connecting to nlpserver.py
server_name="localhost"
server_port=8080
server_timeout=2

# solving logic with a prover
prover_fname="./gk"
memkb_name="1000"  # in-memory knowledge base name (number)
prover_infile="gk_infile.js"
prover_axiomfile="axioms_std.js"
prover_params=["-defaults","-confidence","0.1","-keepconfidence","0.1"] # additional prover params, always appended
usekb_prover_params=["-usekb","-confidence","0.1","-keepconfidence","0.1"] # additional prover params, always appended

#prover_params=["-usekb", "-confidence","0.1","-keepconfidence","0.1"] # additional prover params, always appended

#prover_params=["-strategy", "bigkb.txt"] #["-print","20"] #[] #["-print","20"] #[] # "knowledge.js","-print","15"]
#prover_params=["quasi_50k.js"]
#prover_params=["quasi_50k.js","-confidence","0.1","-keepconfidence","0.1"]
"""
[
    "-usekb","-mbsize","100","-seconds","1","-mbnr","1001",
    "-nonegative","-nocheck", "-strategy","strat_large_parts.js","-confidence","0"

]
"""

constant_prefix="c" # new constants start with this by default
det_constant_prefix="the_" # prefixed to determined (a, the, an, another) constants
skolem_constant_prefix="cs" # new skolem constants start with this
external_skolem_constant_prefix="sk" # external skolem constants are assumed to start with this (for answer printing)
typed_skolem_function_prefix="skt" # new typed skolem functions start with this
definition_prefix="$def" # new definitions start with this
var_prefix="?:X" # new vars start with this
confidence_function="$conf" # temporary encoding of confidence like ["$conf",0.9]
ctxt_function="$ctxt" # function name for the contextual data put into literals
theof_function="$theof"
measure_function="$measure"

generic_value="$generic"
min_prop_intensity=1
max_prop_intensity=3
default_prop_intensity=generic_value
default_prop_class=generic_value
unknown_value="$unknown"
fully_free_variable="$free_variable"
count_function="$count"
lambda_firstarg="$arg1"
set_function="$setof"

#date_function="$date"
time_function="$time"
year_type_argument="$year"

dummysubject="$dummysubject"
dummypredicate="$dummy"
unknownsubject="$unknown"
#propclass_var="?:PC"

dummy_name="Dummyname" # new vars start with this
question_var="?:Q"
frame_var_prefix="?:Fv"
unit_var_prefix="?:Unit"

question_words=["who","what","where","when"]
simple_question_words=["who","what"]
complex_question_words=["who","what","which","who?","what?","which?"]

logic_ops=["forall","exists","and","or","not","&","|","=>","<=","then","if","<=>","nor","xor"]

# ========= setting some globals from other files ======

def set_globals(g1,g2,g3,g4,g5,g6,g7,g8,g9,g10,g11):
  global debug_print_flag, prover_print_flag, prover_nosolve_flag,prover_rawresult_flag
  global prover_explain_flag,show_logic_flag,show_prover_flag,usekb_flag,forward_flag,backward_flag
  global nocontext_flag,noexceptions_flag #,noproptypes_flag
  debug_print_flag=g1
  prover_print_flag=g2
  prover_nosolve_flag=g3
  prover_rawresult_flag=g4
  prover_explain_flag=g5
  show_logic_flag=g6
  show_prover_flag=g7
  usekb_flag=g8
  forward_flag=g9
  backward_flag=g10
  nocontext_flag=g11
  noexceptions_flag=g12
  #options.noproptypes_flag=g12

def set_global_options(newoptions):
  global options
  for key in newoptions:
    if key in options:
      options[key]=newoptions[key]
    else:
      print("Error: option",key,"is not recognized.")
      sys.exit(0)

# ========= data globals ==========

end_punctuation_lemmas=[".","?","!"]

string_replacements=[

  [" something ", " an object "],
  [" somebody ", " a person "],
  [" someone ", " a person "],

  [" everything ", " every object "],
  [" everybody ", " every person "],
  [" everyone ", " every person "],

  [" cannot "," can not "],
  [" isnt "," is not "],
  [" wasnt "," was not "],
  [" doesnt "," does not "],
  [" hasnt "," has not "],

  [" isn't "," is not "],
  [" wasn't "," was not "],
  [" haven't "," has not "],
  [" hadn't "," had not "],
  [" doesn't "," does not "],
  [" can't "," can not "],
  [" won't "," will not "],
  [" wouldn't "," would not "],
  [" couldn't "," could not "],

  [" is unable to "," can not "],
  [" is unable of "," can not "],
  [" is inable to "," can not "],
  [" is inable of "," can not "],
  [" is incapable to "," can not "],
  [" is incapable of "," can not "],

  [" are unable to "," can not "],
  [" are unable of "," can not "],
  [" are inable to "," can not "],
  [" are inable of "," can not "],
  [" are incapable to "," can not "],
  [" are incapable of "," can not "],

  [" were unable to "," could not "],
  [" were unable of "," could not "],
  [" were inable to "," could not "],
  [" were inable of "," could not "],
  [" were incapable to "," could not "],
  [" were incapable of "," could not "],

  [" was unable to "," could not "],
  [" was unable of "," could not "],
  [" was inable to "," could not "],
  [" was inable of "," could not "],
  [" was incapable to "," could not "],
  [" was incapable of "," could not "],

  [" unable "," can not "],
  [" incapable "," can not "],

  [" is capable of "," can "],
  [" are capable of "," can "],
  [" was capable of "," could "],
  [" were capable of "," could "],
  [" have been capable of "," could "],
  [" had been capable of "," could "],

  [" is able to "," can "],
  [" are able to "," can "],
  [" was able to "," could "],
  [" were able to "," could "],
  [" have been able to "," could "],
  [" had been able to "," could "],

  [" has a capability to "," can "],
  [" have a capability to "," can "],
  [" had a capability to "," could "],
  [" have had a capability to "," could "],

  [" has an ability to "," can "],
  [" have an ability to  "," can "],
  [" had an ability to  "," could "],
  [" have had an ability to  "," could "],

  [" has a capacity to "," can "],
  [" have a capacity to "," can "],
  [" had a capacity to "," could "],
  [" have had a capacity to "," could "],

  [" has the capability to "," can "],
  [" have the capability to "," can "],
  [" had the capability to "," could "],
  [" have had the capability to "," could "],

  [" has the ability to "," can "],
  [" have the ability to "," can "],
  [" had the ability to "," could "],
  [" have had the ability to "," could "],

  [" has the capacity to "," can "],
  [" have the capacity to "," can "],
  [" had the capacity to "," could "],
  [" have had the capacity to "," could "],

  [" a large number of "," many "],
  [" a great number of "," many "],
  [" a lot of "," many "],
  [" a majority of "," most "]

]

have_type_verbs={"have":1} # used to determine whether to use forall or exists for an object: for these prefer exists

# used to determine whether to use forall or exists for an object: for these prefer forall
like_type_verbs={
  "like":1, "love":1, "prefer":1, "adore":1, "want":1, "respect":1, "envy":1,
  "hate":1, "detest":1, "abhor":1, "dislike":1, "resent":1, "loathe":1
}

probability_words=["confidence","probability","likelihood","plausibility","chance"]

measure_words={
  "weight": {"units": ["kilogram","kg","gram","ton","pound","ounze","oz"], "morenouns": ["heavy"], "lessnouns": ["light"]},
  "length": {"units": ["m","f","meter","millimeter","kilometer","centimeter","mile","foot","yard"],"morenouns": ["long"],"lessnouns": ["short"]},
  "height": {"units": ["meter","millimeter","kilometer","centimeter","mile","foot","yard"], "morenouns": ["tall"],"lessnouns": ["short"]},
  "width":  {"units": ["meter","millimeter","kilometer","centimeter","mile","foot","yard"], "morenouns": ["wide"],"lessnouns": ["narrow"]},
  "depth":  {"units": ["meter","millimeter","kilometer","centimeter","mile","foot","yard"], "morenouns": ["deep"], "lessnouns": ["shallow"]},
  "temperature": {"units": ["celsius","fahrenheit","c","f"], "morenouns":["warm","hot"],"lessnouns": ["cold"]},
  "price": {"units": ["eur","usd","euro","dollar"], "morenouns": ["cost"],"lessnouns": ["cheap"]},
  "duration": {"units":["s","m","h","second","minute","hour","day","week","month","year","century"]}
}

comparison_words={
  "less": {"less": True},
  "more": {"more": True},
  "equal": {"equal": True}
}

lemma_confidences={
  "doubtless": 0.98,
  "certainly": 0.98,
  "obviously": 0.98,
  "certain": 0.98,
  "surely": 0.97,

  "sure": 0.97,
  "typically": 0.95,
  "typical": 0.95,
  "normally": 0.95,
  "normal": 0.95,
  "usually": 0.9,
  "usual": 0.9,
  "apparently": 0.92,
  "apparent": 0.92,
  "probably": 0.9,
  "probable": 0.9,
  "almost": 0.9,
  "probs": 0.9,
  "prob": 0.9,
  "commonly": 0.9,
  "common": 0.9,
  "likely": 0.9,
  "often": 0.8,
  "plausibly": 0.8,
  "plausible": 0.8,
  "frequently": 0.8,
  "seemingly": 0.8,
  "hopefully": 0.8,
  "supposedly": 0.8,
  "perchance": 0.65,
  "possibly": 0.6,
  "possible": 0.6,
  "imaginably": 0.6,
  "imaginable": 0.6,
  "maybe": 0.5,
  "perhaps": 0.2,
  "sometimes": 0.2,
  "uncertain": -0.5,
  "doubtful": -0.8,
  "questionable": -0.8,
  "seldom": -0.8,
  "hardly": -0.8,
  "unfrequently": -0.8,
  "infrequently": -0.8,
  "infrequent": -0.8,
  "uncommonly": -0.9,
  "uncommon": -0.9,
  "unusually": -0.9,
  "unlikely": -0.9,
  "rarely": -0.9,
  "rare": -0.9,
  "improbably": -0.9,
  "improbable": -0.9,
  "inconceivably": -0.94,
  "inconceivable": -0.94,
  "unbelievable": -0.95,
  "unimaginable": -0.95
}

mistrust_confidences={
  "know": 1,
  "see": 0.99,
  "hear": 0.95,
  "believe": 0.85,
  "claim": 0.85,
  "think": 0.85,
  "say": 0.8,
  "assume": 0.8,
  "hope": 0.8,
  "suspect": 0.7
}

quantor_confidences={
  "most": 0.85,
  "many": 0.2,
  "several": -0.2,
  "few": -0.5,
}

maximize_prop_words={
  "super": True,
  "extremely": True,
  "incredibly": True,
  "massively": True,
  "hugely": True,
  "very": True,
  "really" : True,
  "totally": True
}

minimize_prop_words={
  "slightly": True,
  "somewhat": True,
  "little": True,
  "moderately": True,
  "partially": True,
  "marginally": True
}

no_prop_words={
  "never": True,
  #"hardly": True,
  "that": True,
  "also": True,
  "even": True,
  "additionally": True,
  "again": True,
  "besides": True,
  "further": True,
  "furthermore": True,
  "likewise": True
}

class_prop_words={
  "good": True,
  "bad": True,
  "poor": True,

  "competent": True,
  "incompetent": True,
  "substandard": True,

  "superior": True,
  "inferior": True,

  "capable": True,
  "incapable": True,

  "strong": True,
  "powerful": True,
  "weak": True,
  "feeble": True,
  "puny": True,

  "fast": True,
  "quick": True,
  "slow": True,

  "huge": True,
  "enormous": True,
  "colossal": True,
  "large": True,
  "big": True,
  "small": True,
  "little": True,
  "tiny": True,
  "mini": True,
  "minute": True,
  "miniscule": True,

  "massive": True,
  "heavy": True,
  "light": True,

  "long": True,
  "tall": True,
  "short": True,

  "high": True,
  "low": True,

  "deep": True,
  "shallow": True,

  "late": True,
  "early": True

  #"rich"
  #"poor"
}

#class_prop_words={}

"""
tense_words=["is","was","were"]
by_words=["by"]
uncertain_actions=["believed","suspected","thought","said","claimed","hoped","assumed"]
mistrust_words=["maybe","perhaps","possibly","supposedly","probably","hopefully"]
conditional_in_words=["if","unless"]
negative_conditional_in_words=["unless"]
cond_first_words=["in"]
cond_second_words=["case"]
nonconditional_in_words=["although","despite","before","after"]
useless_condition_phrases=["whether or not"]
"""

number_word_translate={
  "zero":0, "one":1, "two":2, "three": 3, "four": 4, "five": 5, "six": 6, "seven": 7, "eight": 8, "nine": 9,
  "ten": 10, "eleven": 11, "twelve": 12, "thirteen": 13, "fourteen": 14
}

relation_type_translate={
  "inside": "in",
  "outside": "out"
}

relation_type_reverse_translate={
  "contain": "in"
}

relation_type_negative_translate={
  "out": "in"
}

is_location_relations=[
  "in","on","at","near","above","under"
]

is_time_relations=[
  "in","at","on","during","before","after"
]

larger_words=[
  "more","over","above"
]

smaller_words=[
  "less","under","below"
]

"""
relation_type_translate={
  "is_inside": "is_in",
  "is_outside": "is_out"
}

relation_type_reverse_translate={
  "contain": "is_in"
}

relation_type_negative_translate={
  "is_out": "is_in",
}

is_location_relations=[
  "is_in","is_on","is_at","is_near","is_above","is_under"
]
"""

first_names={
"Liam":"m","Noah":"m","Oliver":"m","Elijah":"m","James":"m","William":"m",
"Benjamin":"m","Lucas":"m","Henry":"m","Theodore":"m","Jack":"m",
"Levi":"m","Alexander":"m","Jackson":"m","Mateo":"m","Daniel":"m",
"Michael":"m","Mason":"m","Sebastian":"m","Ethan":"m","Logan":"m",
"Owen":"m","Samuel":"m","Jacob":"m","Asher":"m","Aiden":"m",
"John":"m","Joseph":"m","Wyatt":"m","David":"m","Leo":"m",
"Luke":"m","Julian":"m","Hudson":"m","Grayson":"m","Matthew":"m",
"Ezra":"m","Gabriel":"m","Carter":"m","Isaac":"m","Jayden":"m",
"Luca":"m","Anthony":"m","Dylan":"m","Lincoln":"m","Thomas":"m",
"Maverick":"m","Elias":"m","Josiah":"m","Charles":"m","Caleb":"m",
"Christopher":"m","Ezekiel":"m","Miles":"m","Jaxon":"m","Isaiah":"m",
"Andrew":"m","Joshua":"m","Nathan":"m","Nolan":"m","Adrian":"m",
"Cameron":"m","Santiago":"m","Eli":"m","Aaron":"m","Ryan":"m",
"Angel":"m","Cooper":"m","Waylon":"m","Easton":"m","Kai":"m",
"Christian":"m","Landon":"m","Colton":"m","Roman":"m","Axel":"m",
"Brooks":"m","Jonathan":"m","Robert":"m","Jameson":"m","Ian":"m",
"Everett":"m","Greyson":"m","Wesley":"m","Jeremiah":"m","Hunter":"m",
"Leonardo":"m","Jordan":"m","Jose":"m","Bennett":"m","Silas":"m",
"Nicholas":"m","Parker":"m","Beau":"m","Weston":"m","Austin":"m",
"Connor":"m","Carson":"m","Dominic":"m","Xavier":"m","Jaxson":"m",
"Jace":"m","Emmett":"m","Adam":"m","Declan":"m","Rowan":"m",
"Micah":"m","Kayden":"m","Gael":"m","River":"m","Ryder":"m",
"Kingston":"m","Damian":"m","Sawyer":"m","Luka":"m","Evan":"m",
"Vincent":"m","Legend":"m","Myles":"m","Harrison":"m","August":"m",
"Bryson":"m","Amir":"m","Giovanni":"m","Chase":"m","Diego":"m",
"Milo":"m","Jasper":"m","Walker":"m","Jason":"m","Brayden":"m",
"Cole":"m","Nathaniel":"m","George":"m","Lorenzo":"m","Zion":"m",
"Luis":"m","Archer":"m","Enzo":"m","Jonah":"m","Thiago":"m",
"Theo":"m","Ayden":"m","Zachary":"m","Calvin":"m","Braxton":"m",
"Ashton":"m","Rhett":"m","Atlas":"m","Jude":"m","Bentley":"m",
"Carlos":"m","Ryker":"m","Adriel":"m","Arthur":"m","Ace":"m",
"Tyler":"m","Jayce":"m","Max":"m","Elliot":"m","Graham":"m",
"Kaiden":"m","Maxwell":"m","Juan":"m","Dean":"m","Matteo":"m",
"Malachi":"m","Ivan":"m","Elliott":"m","Jesus":"m","Emiliano":"m",
"Messiah":"m","Gavin":"m","Maddox":"m","Camden":"m","Hayden":"m",
"Leon":"m","Antonio":"m","Justin":"m","Tucker":"m","Brandon":"m",
"Kevin":"m","Judah":"m","Finn":"m","King":"m","Brody":"m",
"Xander":"m","Nicolas":"m","Charlie":"m","Arlo":"m","Emmanuel":"m",
"Barrett":"m","Felix":"m","Alex":"m","Miguel":"m","Abel":"m",
"Alan":"m","Beckett":"m","Amari":"m","Karter":"m","Timothy":"m",
"Abraham":"m","Jesse":"m","Zayden":"m","Blake":"m","Alejandro":"m",
"Dawson":"m","Tristan":"m","Victor":"m","Avery":"m","Joel":"m",
"Grant":"m","Eric":"m","Patrick":"m","Peter":"m","Richard":"m",
"Edward":"m","Andres":"m","Emilio":"m","Colt":"m","Knox":"m",
"Beckham":"m","Adonis":"m","Kyrie":"m","Matias":"m","Oscar":"m",
"Lukas":"m","Marcus":"m","Hayes":"m","Caden":"m","Remington":"m",
"Griffin":"m","Nash":"m","Israel":"m","Steven":"m","Holden":"m",
"Rafael":"m","Zane":"m","Jeremy":"m","Kash":"m","PrestonRowan":"m",
"Kyler":"m","Jax":"m","Jett":"m","Kaleb":"m","Riley":"m",
"Simon":"m","Phoenix":"m","Javier":"m","Bryce":"m","Louis":"m",
"Mark":"m","Cash":"m","Lennox":"m","Paxton":"m","Malakai":"m",
"Paul":"m","Kenneth":"m","Nico":"m","Kaden":"m","Lane":"m",
"Kairo":"m","Maximus":"m","Omar":"m","Finley":"m","Atticus":"m",
"Crew":"m","Brantley":"m","Colin":"m","Dallas":"m","Walter":"m",
"Brady":"m","Callum":"m","Ronan":"m","Hendrix":"m","Jorge":"m",
"Tobias":"m","Clayton":"m","Emerson":"m","Damien":"m","Zayn":"m",
"Malcolm":"m","Kayson":"m","Bodhi":"m","Bryan":"m","Aidan":"m",
"Cohen":"m","Brian":"m","Cayden":"m","Andre":"m","Niko":"m",
"Maximiliano":"m","Zander":"m","Khalil":"m","Rory":"m","Francisco":"m",
"Cruz":"m","Kobe":"m","Reid":"m","Daxton":"m","Derek":"m",
"Martin":"m","Jensen":"m","Karson":"m","Tate":"m","Muhammad":"m",
"Jaden":"m","Joaquin":"m","Josue":"m","Gideon":"m","Dante":"m",
"Cody":"m","Bradley":"m","Orion":"m","Spencer":"m","Angelo":"m",
"Erick":"m","Jaylen":"m","Julius":"m","Manuel":"m","Ellis":"m",
"Colson":"m","Cairo":"m","Gunner":"m","Wade":"m","Chance":"m",
"Odin":"m","Anderson":"m","Kane":"m","Raymond":"m","Cristian":"m",
"Aziel":"m","Prince":"m","Ezequiel":"m","Jake":"m","Otto":"m",
"Eduardo":"m","Rylan":"m","Ali":"m","Cade":"m","Stephen":"m",
"Ari":"m","Kameron":"m","Dakota":"m","Warren":"m","Ricardo":"m",
"Killian":"m","Mario":"m","Romeo":"m","Cyrus":"m","Ismael":"m",
"Russell":"m","Tyson":"m","Edwin":"m","Desmond":"m","Nasir":"m",
"Remy":"m","Tanner":"m","Fernando":"m","Hector":"m","Titus":"m",
"Lawson":"m","Sean":"m","Kyle":"m","Elian":"m","Corbin":"m",
"Bowen":"m","Wilder":"m","Armani":"m","Royal":"m","Stetson":"m",
"Briggs":"m","Sullivan":"m","Leonel":"m","Callan":"m","Finnegan":"m",
"Jay":"m","Zayne":"m","Marshall":"m","Kade":"m","Travis":"m",
"Sterling":"m","Raiden":"m","Sergio":"m","Tatum":"m","Cesar":"m",
"Zyaire":"m","Milan":"m","Devin":"m","Gianni":"m","Kamari":"m",
"Royce":"m","Malik":"m","Jared":"m","Franklin":"m","Clark":"m",
"Noel":"m","Marco":"m","Archie":"m","Apollo":"m","Pablo":"m",
"Garrett":"m","Oakley":"m","Memphis":"m","Quinn":"m","Onyx":"m",
"Alijah":"m","Baylor":"m","Edgar":"m","Nehemiah":"m","Winston":"m",
"Major":"m","Rhys":"m","Forrest":"m","Jaiden":"m","Reed":"m",
"Santino":"m","Troy":"m","Caiden":"m","Harvey":"m","Collin":"m",
"Solomon":"m","Donovan":"m","Damon":"m","Jeffrey":"m","Kason":"m",
"Sage":"m","Grady":"m","Kendrick":"m","Leland":"m","Luciano":"m",
"Pedro":"m","Hank":"m","Hugo":"m","Esteban":"m","Johnny":"m",
"Kashton":"m","Ronin":"m","Ford":"m","Mathias":"m","Porter":"m",
"Erik":"m","Johnathan":"m","Frank":"m","Tripp":"m","Casey":"m",
"Fabian":"m","Leonidas":"m","Baker":"m","Matthias":"m","Philip":"m",
"Jayceon":"m","Kian":"m","Saint":"m","Ibrahim":"m","Jaxton":"m",
"Augustus":"m","Callen":"m","Trevor":"m","Ruben":"m","Adan":"m",
"Conor":"m","Dax":"m","Braylen":"m","Kaison":"m","Francis":"m",
"Kyson":"m","Andy":"m","Lucca":"m","Mack":"m","Peyton":"m",
"Alexis":"m","Deacon":"m","Kasen":"m","Kamden":"m","Frederick":"m",
"Princeton":"m","Braylon":"m","Wells":"m","Nikolai":"m","Iker":"m",
"Bo":"m","Dominick":"m","Moshe":"m","Cassius":"m","Gregory":"m",
"Lewis":"m","Kieran":"m","Isaias":"m","Seth":"m","Marcos":"m",
"Omari":"m","Shane":"m","Keegan":"m","Jase":"m","Asa":"m",
"Sonny":"m","Uriel":"m","Pierce":"m","Jasiah":"m","Barack":"m",
"Mike":"m","Pete":"m","Ants":"m","Jaan":"m","Juhan":"m",
"Konstantin":"m","Aleksei":"m","Tanel":"m","Mihkel":"m","Ott":"m",
"Peeter":"m","Sander":"m","Aleksander":"m","Kristjan":"m","Kevin,":"m",
"Nikita":"m","Markus":"m","Artur":"m","Maksim":"m","Karl":"m",
"Dmitri":"m","Daniil":"m","Siim":"m","Rasmus":"m","Andrei":"m",
"Artjom":"m","Ilja":"m","Uku":"m","Jaanus":"m","Jan":"m",
"Mattias":"m","Joonas":"m","Jonas":"m","Anton":"m","Nils":"m",
"Svante":"m","Per":"m","Olle":"m","Gustav":"m","Hjalmar":"m",
"Carl":"m","Alfred":"m","Ben":"m","Jakob":"m","Maximilian":"m",
"Niklas":"m","Hannes":"m","Jules":"m","Mohamed":"m","Mohammed":"m",
"Marius":"m","Robin":"m","Bjorn":"m","Olivia":"f","Emma":"f",
"Charlotte":"f","Amelia":"f","Ava":"f","Sophia":"f","Isabella":"f",
"Mia":"f","Evelyn":"f","Harper":"f","Luna":"f","Camila":"f",
"Gianna":"f","Elizabeth":"f","Eleanor":"f","Ella":"f","Abigail":"f",
"Sofia":"f","Scarlett":"f","Emily":"f","Aria":"f","Penelope":"f",
"Chloe":"f","Layla":"f","Mila":"f","Nora":"f","Hazel":"f",
"Madison":"f","Ellie":"f","Lily":"f","Nova":"f","Isla":"f",
"Grace":"f","Violet":"f","Aurora":"f","Zoey":"f","Willow":"f",
"Emilia":"f","Stella":"f","Zoe":"f","Victoria":"f","Hannah":"f",
"Addison":"f","Leah":"f","Lucy":"f","Eliana":"f","Ivy":"f",
"Everly":"f","Lillian":"f","Paisley":"f","Elena":"f","Naomi":"f",
"Maya":"f","Natalie":"f","Kinsley":"f","Delilah":"f","Claire":"f",
"Audrey":"f","Aaliyah":"f","Ruby":"f","Brooklyn":"f","Alice":"f",
"Aubrey":"f","Autumn":"f","Leilani":"f","Savannah":"f","Valentina":"f",
"Kennedy":"f","Madelyn":"f","Josephine":"f","Bella":"f","Skylar":"f",
"Genesis":"f","Sophie":"f","Hailey":"f","Sadie":"f","Natalia":"f",
"Caroline":"f","Allison":"f","Gabriella":"f","Anna":"f","Serenity":"f",
"Nevaeh":"f","Cora":"f","Ariana":"f","Emery":"f","Lydia":"f",
"Jade":"f","Sarah":"f","Eva":"f","Adeline":"f","Madeline":"f",
"Piper":"f","Rylee":"f","Athena":"f","Everleigh":"f","Vivian":"f",
"Clara":"f","Raelynn":"f","Liliana":"f","Samantha":"f","Maria":"f",
"Iris":"f","Ayla":"f","Eloise":"f","Lyla":"f","Eliza":"f",
"Hadley":"f","Melody":"f","Julia":"f","Rose":"f","Isabelle":"f",
"Brielle":"f","Adalynn":"f","Arya":"f","Eden":"f","Remi":"f",
"Mackenzie":"f","Maeve":"f","Margaret":"f","Reagan":"f","Alaia":"f",
"Melanie":"f","Josie":"f","Elliana":"f","Cecilia":"f","Mary":"f",
"Daisy":"f","Alina":"f","Lucia":"f","Ximena":"f","Juniper":"f",
"Kaylee":"f","Magnolia":"f","Summer":"f","Adalyn":"f","Sloane":"f",
"Amara":"f","Arianna":"f","Isabel":"f","Reese":"f","Emersyn":"f",
"Sienna":"f","Kehlani":"f","Freya":"f","Valerie":"f","Blakely":"f",
"Genevieve":"f","Esther":"f","Valeria":"f","Katherine":"f","Kylie":"f",
"Norah":"f","Amaya":"f","Bailey":"f","Ember":"f","Ryleigh":"f",
"Georgia":"f","Catalina":"f","Alexandra":"f","Faith":"f","Jasmine":"f",
"Ariella":"f","Ashley":"f","Andrea":"f","Millie":"f","June":"f",
"Khloe":"f","Callie":"f","Juliette":"f","Ada":"f","Anastasia":"f",
"Olive":"f","Alani":"f","Brianna":"f","Rosalie":"f","Molly":"f",
"Brynlee":"f","Amy":"f","Ruth":"f","Aubree":"f","Gemma":"f",
"Taylor":"f","Margot":"f","Arabella":"f","Sara":"f","Journee":"f",
"Harmony":"f","Alaina":"f","Aspen":"f","Noelle":"f","Selena":"f",
"Oaklynn":"f","Morgan":"f","Londyn":"f","Zuri":"f","Aliyah":"f",
"Jordyn":"f","Juliana":"f","Presley":"f","Zara":"f","Leila":"f",
"Marley":"f","Amira":"f","Lilly":"f","London":"f","Kimberly":"f",
"Elsie":"f","Ariel":"f","Lila":"f","Alana":"f","Diana":"f",
"Kamila":"f","Nyla":"f","Vera":"f","Hope":"f","Annie":"f",
"Kaia":"f","Myla":"f","Alyssa":"f","Angela":"f","Ana":"f",
"Lennon":"f","Evangeline":"f","Harlow":"f","Rachel":"f","Gracie":"f",
"Laila":"f","Elise":"f","Sutton":"f","Lilah":"f","Adelyn":"f",
"Phoebe":"f","Octavia":"f","Sydney":"f","Mariana":"f","Wren":"f",
"Lainey":"f","Vanessa":"f","Teagan":"f","Kayla":"f","Malia":"f",
"Elaina":"f","Saylor":"f","Brooke":"f","Lola":"f","Miriam":"f",
"Alayna":"f","Adelaide":"f","Daniela":"f","Jane":"f","Payton":"f",
"Journey":"f","Lilith":"f","Delaney":"f","Mya":"f","Charlee":"f",
"Alivia":"f","Annabelle":"f","Kailani":"f","Lucille":"f","Trinity":"f",
"Gia":"f","Raegan":"f","Camille":"f","Kaylani":"f","Kali":"f",
"Stevie":"f","Maggie":"f","Haven":"f","Tessa":"f","Daphne":"f",
"Adaline":"f","Joanna":"f","Jocelyn":"f","Lena":"f","Evie":"f",
"Juliet":"f","Fiona":"f","Cataleya":"f","Angelina":"f","Leia":"f",
"Paige":"f","Julianna":"f","Milani":"f","Talia":"f","Rebecca":"f",
"Kendall":"f","Harley":"f","Lia":"f","Dahlia":"f","Camilla":"f",
"Thea":"f","Jayla":"f","Brooklynn":"f","Blair":"f","Vivienne":"f",
"Hallie":"f","Madilyn":"f","Mckenna":"f","Evelynn":"f","Ophelia":"f",
"Celeste":"f","Alayah":"f","Winter":"f","Catherine":"f","Collins":"f",
"Nina":"f","Briella":"f","Palmer":"f","Noa":"f","Mckenzie":"f",
"Kiara":"f","Adriana":"f","Gracelynn":"f","Lauren":"f","Cali":"f",
"Kalani":"f","Aniyah":"f","Nicole":"f","Mariah":"f","Gabriela":"f",
"Wynter":"f","Amina":"f","Ariyah":"f","Adelynn":"f","Reign":"f",
"Alaya":"f","Dream":"f","Alexandria":"f","Willa":"f","Avianna":"f",
"Makayla":"f","Gracelyn":"f","Elle":"f","Amiyah":"f","Arielle":"f",
"Elianna":"f","Giselle":"f","Brynn":"f","Ainsley":"f","Aitana":"f",
"Charli":"f","Demi":"f","Makenna":"f","Rosemary":"f","Danna":"f",
"Izabella":"f","Lilliana":"f","Melissa":"f","Samara":"f","Lana":"f",
"Mabel":"f","Everlee":"f","Fatima":"f","Leighton":"f","Esme":"f",
"Raelyn":"f","Madeleine":"f","Nayeli":"f","Camryn":"f","Kira":"f",
"Annalise":"f","Selah":"f","Serena":"f","Royalty":"f","Rylie":"f",
"Celine":"f","Laura":"f","Brinley":"f","Frances":"f","Michelle":"f",
"Heidi":"f","Sabrina":"f","Destiny":"f","Gwendolyn":"f","Alessandra":"f",
"Poppy":"f","Amora":"f","Nylah":"f","Luciana":"f","Maisie":"f",
"Miracle":"f","Joy":"f","Liana":"f","Raven":"f","Shiloh":"f",
"Allie":"f","Daleyza":"f","Kate":"f","Lyric":"f","Alicia":"f",
"Lexi":"f","Addilyn":"f","Anaya":"f","Malani":"f","Paislee":"f",
"Elisa":"f","Kayleigh":"f","Azalea":"f","Francesca":"f","Regina":"f",
"Viviana":"f","Aylin":"f","Skye":"f","Daniella":"f","Makenzie":"f",
"Veronica":"f","Legacy":"f","Maia":"f","Ariah":"f","Alessia":"f",
"Carmen":"f","Astrid":"f","Maren":"f","Helen":"f","Felicity":"f",
"Alexa":"f","Danielle":"f","Lorelei":"f","Paris":"f","Adelina":"f",
"Bianca":"f","Gabrielle":"f","Jazlyn":"f","Scarlet":"f","Bristol":"f",
"Navy":"f","Esmeralda":"f","Colette":"f","Stephanie":"f","Jolene":"f",
"Marlee":"f","Sarai":"f","Hattie":"f","Nadia":"f","Rosie":"f",
"Kamryn":"f","Kenzie":"f","Alora":"f","Holly":"f","Matilda":"f",
"Sylvia":"f","Emelia":"f","Keira":"f","Braelynn":"f","Jacqueline":"f",
"Alison":"f","Amanda":"f","Cassidy":"f","Emory":"f","Haisley":"f",
"Jimena":"f","Jessica":"f","Elaine":"f","Dorothy":"f","Mira":"f",
"Eve":"f","Oaklee":"f","Averie":"f","Charleigh":"f","Lyra":"f",
"Madelynn":"f","Edith":"f","Jennifer":"f","Raya":"f","Heaven":"f",
"Kyla":"f","Wrenley":"f","Meadow":"f","Pia":"f","Piia":"f",
"Mari":"f","Kristiina":"f","Kristi":"f","Liisi":"f","Liis":"f",
"Liisu":"f","Leena":"f","Kristina":"f","Sandra":"f","Anastassia":"f",
"Jekaterina":"f","Karina":"f","Aleksandra":"f","Viktoria":"f","Darja":"f",
"Triin":"f","Moa":"f","Ingrid":"f","Rutt":"f","Signe":"f",
"Elsa":"f","Brit":"f","Britta":"f","Alma":"f","Selma":"f",
"Elina":"f","Elin":"f","Lina":"f","Marie":"f","Leni":"f",
"Mathilda":"f","Frieda":"f","Frida":"f","Nele":"f","Marlene":"f",
"Merle":"f","Agathe":"f","Ambre":"f","Ines":"f",
"Harry":"m","Imelia":"f","Mickey":"m","Minnie":"f",
"Dave": "m","Colin": "m", "Bill":"m"}

pseudo_names={"Mr":"m","Mrs":"f","Ms":"f"}

person_names=z = {**first_names, **pseudo_names}

gendered_words={
"abbess":"f","abbot":"m","able_seaman":"m","actress":"f","adonis":"m","adulteress":"f",
"adventuress":"f","aircraftsman":"m","aircrewman":"m","alderman":"m","altar_boy":"m",
"amazon":"f","ambassadress":"f","ancestress":"f","ape-man":"m","apostle":"m",
"archbishop":"m","archdeacon":"m","archduchess":"f","archpriest":"m","armiger":"m",
"artilleryman":"m","assemblyman":"m","assemblywoman":"f","au_pair_girl":"f","augustinian":"m",
"aunt":"f","austin_friar":"m","authoress":"f","aviatrix":"f","ayah":"f",
"b-girl":"f","babu":"m","bacchant":"m","bacchante":"f","bachelor":"m",
"bachelor_girl":"f","backroom_boy":"m","bag":"f","bag_lady":"f","baggage":"f",
"baggageman":"m","bagman":"m","ball_boy":"m","ball-buster":"f","ballerina":"f",
"ballet_master":"m","ballet_mistress":"f","bandsman":"m","baritone":"m","barmaid":"f",
"baron":"m","baroness":"f","basileus":"m","bass":"m","bat_boy":"m",
"batman":"m","beadsman":"m","beard":"f","beggarman":"m","beggarwoman":"f",
"beguine":"f","begum":"f","beldam":"f","bellboy":"m","belle":"f",
"belly_dancer":"f","benedick":"m","benefactress":"f","best_man":"m","bey":"m",
"big_brother":"m","big_sister":"f","black_man":"m","black_woman":"f","blade":"m",
"blood_brother":"m","bluestocking":"f","boatman":"m","bobbysoxer":"f","bondman":"m",
"bondsman":"m","bondwoman":"f","border_patrolman":"m","boy":"m","boy_scout":"m",
"boy_wonder":"m","boyfriend":"m","brahman":"m","brakeman":"m","bride":"f",
"bridesmaid":"f","broad":"f","broth_of_a_boy":"m","brother":"m","brother-in-law":"m",
"brownie":"f","brunet":"m","buddy":"m","bull":"m","bullyboy":"m",
"burgrave":"m","busboy":"m","bushman":"m","businessman":"m","businesswoman":"f",
"butch":"f","butler":"m","cabin_boy":"m","call_girl":"f","cameraman":"m",
"campfire_girl":"f","canary":"f","capo":"m","career_girl":"f","career_man":"m",
"casanova":"m","castrato":"m","cat":"f","catamite":"m","cattleman":"m",
"cavalier":"m","cavalryman":"m","caveman":"m","centurion":"m","chachka":"f",
"chairman_of_the_board":"m","chambermaid":"f","chapman":"m","charon":"m","charwoman":"f",
"chatelaine":"f","check_girl":"f","choirboy":"m","chorus_girl":"f","church_father":"m",
"cinderella":"f","circe":"f","city_man":"m","clansman":"m","clergyman":"m",
"cleric":"m","closet_queen":"m","co-ed":"f","coachman":"m","coalman":"m",
"coastguardsman":"m","codger":"m","coiffeur":"m","coiffeuse":"f","colleen":"f",
"coloratura":"f","comedienne":"f","comfort_woman":"f","committeeman":"m","committeewoman":"f",
"company_man":"m","concubine":"f","conductress":"f","confidante":"f","confidence_man":"m",
"congressman":"m","contralto":"f","coquette":"f","cornishman":"m","cornishwoman":"f",
"councilman":"m","councilwoman":"f","count":"m","countertenor":"m","countess":"f",
"countryman":"m","countrywoman":"f","cover_girl":"f","cow":"f","cowboy":"m",
"cowgirl":"f","craftsman":"m","crewman":"m","crown_prince":"m","crown_princess":"f",
"cub":"m","cub_scout":"m","cuckold":"m","curandera":"f","curandero":"m",
"cyril":"m","czar":"m","czarina":"f","dad":"m","dairymaid":"f",
"dairyman":"m","dalesman":"m","dame":"f","damsel":"f","dandy":"m",
"danseur":"m","daughter":"f","daughter-in-law":"f","dauphin":"m","dayboy":"m",
"daygirl":"f","deacon":"m","deaconess":"f","deadbeat_dad":"m","dean":"m",
"debutante":"f","deliveryman":"m","demimondaine":"f","den_mother":"f","dirty_old_man":"m",
"divorcee":"f","dog":"m","doge":"m","domestic_prelate":"m","don":"m",
"don_juan":"m","donna":"f","doorkeeper":"m","doughboy":"m","doyenne":"f",
"draftsman":"m","dragoman":"m","dragon":"f","drum_majorette":"f","duchess":"f",
"duenna":"f","duke":"m","dutch_uncle":"m","eagle_scout":"m","earl":"m",
"earl_marshal":"m","ejaculator":"m","elder_statesman":"m","elector":"m","embroideress":"f",
"emir":"m","emperor":"m","empress":"f","enchantress":"f","end_man":"m",
"englishman":"m","englishwoman":"f","enlisted_man":"m","enlisted_woman":"f","ent_man":"m",
"eparch":"m","esquire":"m","ethnarch":"m","everyman":"m","ex-boyfriend":"m",
"ex-husband":"m","ex-wife":"f","exarch":"m","excavator":"m","executrix":"f",
"eyeful":"f","fairy_godmother":"f","family_man":"m","fancy_man":"m","farm_boy":"m",
"farm_girl":"f","farmerette":"f","fathead":"m","father":"m","father_figure":"m",
"father-figure":"m","father-in-law":"m","fauntleroy":"m","favorite_son":"m","fellow":"m",
"female":"f","female_aristocrat":"f","female_child":"f","female_offspring":"f","female_sibling":"f",
"ferryman":"m","feudal_lord":"m","fiancee":"f","fireman":"m","first_baseman":"m",
"first_lady":"f","fisherman":"m","flamen":"m","flapper":"f","flibbertigibbet":"f",
"flower_girl":"f","footman":"m","forefather":"m","foreman":"m","foremother":"f",
"forewoman":"f","foster-brother":"m","foster-daughter":"f","foster-father":"m","foster-mother":"f",
"foster-nurse":"f","foster-sister":"f","foster-son":"m","foundress":"f","four-minute_man":"m",
"franklin":"m","freedman":"m","freeman":"m","frenchman":"m","friar":"m",
"front_man":"m","frontiersman":"m","frontierswoman":"f","frump":"f","fugleman":"m",
"g-man":"m","gagman":"m","gal":"f","galoot":"m","gamine":"f",
"ganger":"m","garbage_man":"m","gasman":"m","gaucho":"m","gay_man":"m",
"geezer":"m","geisha":"f","gent":"m","gentleman":"m","gentlemen":"m",
"gibson_girl":"f","gillie":"m","girl":"f","girl_friday":"f","girl_scout":"f",
"girl_wonder":"f","girlfriend":"f","gitana":"f","gitano":"m","goddaughter":"f",
"godfather":"m","godmother":"f","godson":"m","gold_digger":"f","golf_widow":"f",
"goliard":"m","good_old_boy":"m","governess":"f","grand_duchess":"f","grand_duke":"m",
"granddaughter":"f","grande_dame":"f","grandee":"m","grandfather":"m","grandson":"m",
"granny":"f","grass_widower":"m","gravida":"f","great_granddaughter":"f","great_grandfather":"m",
"great_grandmother":"f","great_grandson":"m","great-aunt":"f","great-nephew":"m","great-niece":"f",
"great-uncle":"m","grocery_boy":"m","groom":"m","groomsman":"m","groundsman":"m",
"groupie":"f","guardsman":"m","gunman":"m","guy":"m","hag":"f",
"half_sister":"f","handmaid":"f","handyman":"m","hangman":"m","harridan":"f",
"hatchet_man":"m","he":"m","head_linesman":"m","headman":"m","headmistress":"f",
"headsman":"m","heidelberg_man":"m","heiress":"f","helmsman":"m","her":"f",
"heroine":"f","herr":"m","hers":"f","herself":"f","him":"m",
"himself":"m","his":"m","hobbledehoy":"m","holdup_man":"m","holy_roman_emperor":"m",
"homeboy":"m","homegirl":"f","honest_woman":"f","hooray_henry":"m","horseman":"m",
"horsewoman":"f","hostess":"f","housefather":"m","housemother":"f","housewife":"f",
"huntress":"f","husband":"m","iceman":"m","idolatress":"f","imam":"m",
"inamorata":"f","inamorato":"m","indiana":"m","infantryman":"m","ingenue":"f",
"instructress":"f","irishman":"m","irishwoman":"f","iron_man":"m","ironside":"m",
"jacob":"m","jane_doe":"f","jawan":"m","jewess":"f","jezebel":"f",
"jilt":"f","jimdandy":"m","john_doe":"m","jute":"m","kaiser":"m",
"kennan":"m","king":"m","king_of_england":"m","king_of_france":"m","king_of_the_germans":"m",
"kinsman":"m","kinswoman":"f","klansman":"m","knight_of_the_round_table":"m","knight_templar":"m",
"knight-errant":"m","lackey":"m","ladies":"f","lady":"f","lady's_maid":"f",
"ladylove":"f","landlady":"f","lass":"f","lawman":"m","layman":"m",
"leading_lady":"f","leading_man":"m","letterman":"m","libertine":"m","liege":"m",
"life_peer":"m","light-o'-love":"f","lighterman":"m","limey":"m","lineman":"m",
"linesman":"m","linkboy":"m","little_brother":"m","little_sister":"f","liveryman":"m",
"lobsterman":"m","lollipop_lady":"f","longbowman":"m","loon":"m","lord":"m",
"lord_chancellor":"m","lothario":"m","lounge_lizard":"m","lowerclassman":"m","lumberman":"m",
"ma":"f","ma'am":"f","macaroni":"m","macho":"m","madam":"f",
"madame":"f","madwoman":"f","maenad":"f","mafioso":"m","maharaja":"m",
"maharani":"f","maid":"f","maiden_aunt":"f","mailman":"m","male":"m",
"male_aristocrat":"m","male_chauvinist":"m","male_child":"m","male_offspring":"m","male_sibling":"m",
"malik":"m","mamma":"f","mammy":"f","man":"m","man_jack":"m",
"man_of_letters":"m","man_of_means":"m","man-at-arms":"m","manageress":"f","mannequin":"f",
"manservant":"m","marchioness":"f","margrave":"m","marksman":"m","marquess":"m",
"marquis":"m","masseur":"m","matriarch":"f","matron":"f","matron_of_honor":"f",
"may_queen":"f","mayoress":"f","mediatrix":"f","medicine_man":"m","memsahib":"f",
"men":"m","mesne_lord":"m","messenger_boy":"m","mestiza":"f","mestizo":"m",
"meter_maid":"f","middle-aged_man":"m","midshipman":"m","midwife":"f","mikado":"m",
"milady":"f","miles_gloriosus":"m","military_policeman":"m","militiaman":"m","milkman":"m",
"mill-girl":"f","millionairess":"f","milord":"m","minuteman":"m","miracle_man":"m",
"misogynist":"m","miss":"f","missus":"f","mistress":"f","mollycoddle":"m",
"monk":"m","monsieur":"m","monsignor":"m","mother":"f","mother_figure":"f",
"mother_hen":"f","mother-in-law":"f","mother's_boy":"m","mother's_daughter":"f","mother's_son":"m",
"mover":"m","mr.":"m","mrs.":"f","ms.":"f","muffin_man":"m",
"mullah":"m","murderess":"f","muscleman":"m","muslimah":"f","nabob":"m",
"nan":"f","nanny":"f","nautch_girl":"f","negotiatress":"f","negress":"f",
"nephew":"m","newswoman":"f","niece":"f","night_watchman":"m","niqaabi":"f",
"novillero":"m","nullipara":"f","nun":"f","nuncio":"m","nymph":"f",
"nymphet":"f","nymphomaniac":"f","oarsman":"m","oarswoman":"f","odalisque":"f",
"office_boy":"m","oilman":"m","oklahoman":"m","old_boy":"m","old_lady":"f",
"old_man":"m","old_woman":"f","one_of_the_boys":"m","orangeman":"m","ordinary":"m",
"organization_man":"m","ottoman":"m","outdoorsman":"m","outdoorswoman":"f","pachuco":"m",
"page":"m","palatine":"m","paperboy":"m","parisienne":"f","parlormaid":"f",
"party_girl":"f","party_man":"m","pater":"m","patriarch":"m","patroness":"f",
"pederast":"m","peer":"m","peer_of_the_realm":"m","pendragon":"m","peri":"f",
"peter_pan":"m","pharaoh":"m","pilate":"m","piltdown_man":"m","pitchman":"m",
"placeman":"m","plainclothesman":"m","plainsman":"m","plowboy":"m","plowman":"m",
"poetess":"f","point_man":"m","point_woman":"f","pointsman":"m","police_matron":"f",
"policeman":"m","polyandrist":"f","polycarp":"m","polygynist":"m","ponce":"m",
"ponce_de_leon":"m","pope":"m","popper":"m","poseuse":"f","posseman":"m",
"poster_boy":"m","poster_girl":"f","postmistress":"f","potboy":"m","poultryman":"m",
"praetor":"m","priest":"m","priestess":"f","prima_ballerina":"f","prima_donna":"f",
"primigravida":"f","primipara":"f","prince_consort":"f","prince_of_wales":"m","princeling":"m",
"princess":"f","princess_royal":"f","proconsul":"m","procuress":"f","property_man":"m",
"prophetess":"f","proprietress":"f","protegee":"f","puerpera":"f","quadripara":"f",
"quarryman":"m","queen":"f","queen_consort":"f","queen_dowager":"f","queen_mother":"f",
"queen_of_england":"f","queen_regent":"f","quintipara":"f","raftsman":"m","raja":"m",
"rake":"m","rani":"f","remittance_man":"m","renaissance_man":"m","repairman":"m",
"rhea_silvia":"f","rifleman":"m","right-hand_man":"m","ring_girl":"f","roadman":"m",
"roman":"m","roman_emperor":"m","romeo":"m","rosebud":"f","roundsman":"m",
"sadhu":"m","salesgirl":"f","salesman":"m","samurai":"m","sandboy":"m",
"sandwichman":"m","sannup":"m","satyr":"m","schoolboy":"m","schoolgirl":"f",
"schoolman":"m","schoolmarm":"f","scold":"f","scotswoman":"f","sculptress":"f",
"sea_scout":"m","second_baseman":"m","section_man":"m","secundigravida":"f","seducer":"m",
"seductress":"f","seedsman":"m","selectman":"m","selectwoman":"f","senhor":"m",
"servant_girl":"f","serviceman":"m","sex_kitten":"f","shah":"m","shaheed":"m",
"shaver":"m","she":"f","she-devil":"f","sheepman":"m","sheik":"m",
"sheika":"f","shepherdess":"f","shiksa":"f","shop_boy":"m","shop_girl":"f",
"showman":"m","shrew":"f","sibyl":"f","sidesman":"m","signalman":"m",
"signor":"m","signora":"f","signore":"m","signorina":"f","simeon":"m",
"sir":"m","sire":"m","sirrah":"m","sister":"f","sister-in-law":"f",
"skivvy":"f","slattern":"f","small_businessman":"m","smasher":"f","sod":"m",
"sodomite":"m","son":"m","son-in-law":"m","songstress":"f","soprano":"f",
"sorceress":"f","soubrette":"f","soul_brother":"m","soundman":"m","spinster":"f",
"spitfire":"f","spokesman":"m","spokeswoman":"f","sporting_man":"m","squaw":"f",
"squaw_man":"m","squire":"m","stableman":"m","starlet":"f","statesman":"m",
"stateswoman":"f","stepbrother":"m","stepdaughter":"f","stepfather":"m","stepmother":"f",
"stepson":"m","stewardess":"f","stiff":"m","stockman":"m","straight_man":"m",
"street_arab":"m","strongman":"m","stud":"m","stuffed_shirt":"m","subdeacon":"m",
"suffragette":"f","sugar_daddy":"m","suitor":"m","sultan":"m","sumo_wrestler":"m",
"supermom":"f","surrogate_mother":"f","swagman":"m","sweater_girl":"f","sylph":"f",
"t-man":"m","tallyman":"m","tarzan":"m","taskmistress":"f","taxi_dancer":"f",
"tenor":"m","tertigravida":"f","test-tube_baby":"f","testatrix":"f","thane":"m",
"third_baseman":"m","thrush":"f","timberman":"m","toast_mistress":"f","tom":"m",
"tomboy":"f","torch_singer":"f","town":"m","townee":"m","townes":"m",
"townsman":"m","trainbandsman":"m","trainman":"m","traitress":"f","trappist":"m",
"traveling_salesman":"m","tribesman":"m","trophy_wife":"f","uncle":"m","undoer":"f",
"unmarried_woman":"f","unpleasant_woman":"f","uriah":"m","usherette":"f","utility_man":"m",
"uxor":"f","uxoricide":"m","valley_girl":"f","vaquero":"m","vestal":"f",
"vestal_virgin":"f","vestryman":"m","vestrywoman":"f","vicar":"m","vicar_apostolic":"m",
"vicar-general":"m","vice_chairman":"m","villainess":"f","virago":"f","viscount":"m",
"viscountess":"f","visiting_fireman":"m","vizier":"m","wac":"f","waitress":"f",
"wanton":"f","war_bride":"f","war_widow":"f","wardress":"f","warlord":"m",
"washerman":"m","washwoman":"f","watchman":"m","water_boy":"m","weatherman":"m",
"welshman":"m","wencher":"m","wet_nurse":"f","white_man":"m","white_slave":"f",
"white_woman":"f","widow":"f","widower":"m","wife":"f","wild_man":"m",
"wingman":"m","wireman":"m","wittol":"m","wolf":"m","wolf_boy":"m",
"woman":"f","womanizer":"m","women":"f","wonder_boy":"m","wonder_woman":"f",
"woodsman":"m","working_girl":"f","workman":"m","yachtsman":"m","yardman":"m",
"yellow_man":"m","yellow_woman":"f","yenta":"f","yeoman":"m"}

preposition_words={
  "of":1,
	"with":1,
	"at":1,
	"from":1,
	"into":1,
	"during":1,
	"including":1,
	"until":1,
	"against":1,
	"among":1,
	"throughout":1,
	"despite":1,
	"towards":1,
	"upon":1,
	"concerning":1,
	"to":1,
	"in":1,
	"for":1,
	"on":1,
	"by":1,
	"about":1,
	"like":1,
	"through":1,
	"over":1,
	"before":1,
	"between":1,
	"after":1,
	"since":1,
	"without":1,
	"under":1,
	"within":1,
	"along":1,
	"following":1,
	"across":1,
	"behind":1,
	"beyond":1,
	"plus":1,
	"except":1,
	"but":1,
	"up":1,
	"out":1,
	"around":1,
	"down":1,
	"off":1,
	"above":1,
	"near":1
}

# =========== the end ==========
"""
verbnet

https://www.gingersoftware.com/content/grammar-rules/verbs/list-of-phrasal-verbs/

https://www.perfect-english-grammar.com/stative-verbs.html

https://www.englishwithashish.com/stative-verbs-guide/

https://engdic.org/list-of-stative-verbs-in-english/

https://engdic.org/contraction-grammar/

https://7esl.com/english-verbs/#List_of_Verbs_by_Grammatical_Functions

https://www.worldclasslearning.com/english/4000-most-common-english-words.html
"""


from .base import BaseModel, Entity
from .comment import Comment
from .direct import Direct, Message
from .feed import Feed
from .media import Media
from .resource import (
    Candidate,
    Image,
    Resource,
    Resources,
    Video,
)
from .story import Story
from .user import User

__all__ = [
    "BaseModel",
    "Direct",
    "Entity",
    "Feed",
    "Media",
    "Message",
    "Comment",
    "Candidate",
    "Resource",
    "Resources",
    "Image",
    "Video",
    "Story",
    "User",
]


# 列表、元组、集合、字典
# 可迭代对象 iterable
# 迭代器 iterator：
# 1)是对象 class
# 2)类中实现两个函数__iter__()、__next__()

# 浅拷贝、深拷贝

class BooksCollection():
    ''' 定义一个迭代器
    '''
    def __init__(self):
        self.data = ['《往事》', '《只能》', '《回味》']
        self.curor = 0

    def __iter__(self):
        return self

    def __next__(self):
        if self.curor >= len(self.data):
            raise StopIteration
        r = self.data[self.curor]
        self.curor += 1
        return r

books = BooksCollection()
import copy
# copy一个迭代器
books_copy = copy.copy(books)

# 可通过for循环访问迭代器
for i in books:
    print(i)

# 再次循环，将不输出
# 迭代器只能一次性访问
# for j in books:
#     print(j)

# 用next()访问
# print(next(books))
# print(next(books))
# print(next(books))

print('--------------')
for i in books_copy:
    print(i)


import pytest
play_menu = pytest.importorskip("play_menu")
from play_menu import *

def test_displayPlayMenu(monkeypatch, capsys):
    menu = "1. Build a HSE\n2. Build a BCH\n3. See remaining buildings\n4. See current score\n\n5. Save game\n0. Exit to main menu\n"
    monkeypatch.setattr('builtins.input', lambda _: "0")
    play_menu([],"HSE", "BCH",[["?","?","?","?"],["?","?","?","?"],["?","?","?","?"],["?","?","?","?"]], 1)
    out, err = capsys.readouterr()
    assert out[0:len(menu)] == menu

#lower boundary
def test_LowerBoundaryInvalidOptionEntered(monkeypatch, capsys):
    menu = "1. Build a HSE\n2. Build a BCH\n3. See remaining buildings\n4. See current score\n\n5. Save game\n0. Exit to main menu\n"
    monkeypatch.setattr('builtins.input', lambda _: "-1")
    play_menu([],"HSE", "BCH",[["?","?","?","?"],["?","?","?","?"],["?","?","?","?"],["?","?","?","?"]], 1)
    out, err = capsys.readouterr()
    assert out[len(menu):] == "Invalid option! Please try again!\n"

def test_Option0Selected(monkeypatch, capsys):
    monkeypatch.setattr('builtins.input', lambda _: "0")
    result = play_menu([],"HSE", "BCH",[["?","?","?","?"],["?","?","?","?"],["?","?","?","?"],["?","?","?","?"]], 1)

    assert result == True

def test_Option1Selected(monkeypatch):
    menu = "1. Build a HSE\n2. Build a BCH\n3. See remaining buildings\n4. See current score\n\n5. Save game\n0. Exit to main menu\n"
    responses = iter(["1", "a1"])
    monkeypatch.setattr('builtins.input', lambda msg: next(responses))
    option = play_menu([],"HSE", "BCH",[["?","?","?","?"],["?","?","?","?"],["?","?","?","?"],["?","?","?","?"]], 1)
    assert option == "1"

# upper boundary
def test_Option4Selected(monkeypatch, capsys):
    menu = "1. Build a HSE\n2. Build a BCH\n3. See remaining buildings\n4. See current score\n\n5. Save game\n0. Exit to main menu\n"
    expectedOutput = "\nHSE: 0\nFAC: 0\nSHP: 0\nHWY: 0\nBCH: 0\nTotal score: 0\n"
    monkeypatch.setattr('builtins.input', lambda _: "4")
    play_menu([],"HSE", "BCH",[["?","?","?","?"],["?","?","?","?"],["?","?","?","?"],["?","?","?","?"]], 1)
    out, err = capsys.readouterr()
    assert out[len(menu):] == expectedOutput

def test_Option5Selected(monkeypatch, capsys):
    menu = "1. Build a HSE\n2. Build a BCH\n3. See remaining buildings\n4. See current score\n\n5. Save game\n0. Exit to main menu\n"
    expectedOutput = "\nGame saved!\n"
    expectedBoard = [["?","?","?","?"],["?","?","?","?"],["?","?","?","?"],["?","?","?","?"]]
    monkeypatch.setattr('builtins.input', lambda _: "5")
    play_menu([],"HSE", "BCH",[["?","?","?","?"],["?","?","?","?"],["?","?","?","?"],["?","?","?","?"]], 1)

    board = []
    count = 0
    turn_num = 0
    # loops through each line in the .csv file
    for i in open("SimpCityBoard.csv"):
        i = i.strip("\n")

        # checks if the current line is first line
        # if is first line, retrieve the turn number, stored in the first line of the .csv file
        if count == 0:
            turn_num = int(i)
            count += 1
            continue
        # if not first line, split the line by ',' and append it to the board
        row = i.split(",")
        board.append(row)

    out, err = capsys.readouterr()
    assert out[len(menu):] == expectedOutput and board == expectedBoard and turn_num == 1

def test_UpperBoundaryInvalidOptionEntered(monkeypatch, capsys):
    menu = "1. Build a HSE\n2. Build a BCH\n3. See remaining buildings\n4. See current score\n\n5. Save game\n0. Exit to main menu\n"
    monkeypatch.setattr('builtins.input', lambda _: "6")
    play_menu([],"HSE", "BCH",[["?","?","?","?"],["?","?","?","?"],["?","?","?","?"],["?","?","?","?"]], 1)
    out, err = capsys.readouterr()
    assert out[len(menu):] == "Invalid option! Please try again!\n"


from pathlib import Path

from armory.data.utils import maybe_download_weights_from_s3
from armory.logs import log

PARENT_DIR = Path(__file__).parent

def get_path(filename) -> str:
    """
    Get the absolute path of the provided file name. Ordering priority is:
        1) Check directly for provided filepath
        2) Load from parent directory
        3) Attempt to download from s3 as a weights file
    """
    filename = Path(filename)
    if filename.is_file():
        return str(filename)
    filepath = PARENT_DIR / filename
    if filepath.is_file():
        return str(filepath)

    return maybe_download_weights_from_s3(filename)


# https://leetcode.com/problems/reverse-nodes-in-k-group/description/
# tags: linked list

# Definition for singly-linked list.
# class ListNode:
#     def __init__(self, val=0, next=None):
#         self.val = val
#         self.next = next
class Solution:
    def reverseKGroup(self, head: Optional[ListNode], k: int) -> Optional[ListNode]:
        node = head
        for _ in range(k):
            if not node:
                return head
            node = node.next

        prev, curr = None, head
        for _ in range(k):
            next = curr.next
            curr.next = prev

            prev = curr
            curr = next

        head.next = self.reverseKGroup(curr, k)
        return prev


__author__ = 'Brandon Funk'

from PIL import Image, ImageFilter, ImageOps
import os, sys
import subprocess

from tkinter.filedialog import askopenfilename, askdirectory

textures=[]
size_int=int(input("Target texture Size>"),10)
size=(size_int,size_int)
texture_type = ""
outputPath = askdirectory()

def getTexture():
    if len(textures) is 0:
        texture_type = "Metallic"
    elif len(textures) is 1:
        texture_type = "Ambient Occlusion"
    elif len(textures) is 2:
        texture_type = "Detail"
    elif len(textures) is 3:
        texture_type = "Smoothness"
    print("{0} map".format(texture_type))
    inputPath = askopenfilename(initialdir = outputPath, title = "Choose {0} Texture".format(texture_type), filetypes = (("PNG", "*.png"),("JPEG","*.jpg"),("TIFF", ".tif"),("all files", "*")))
    if texture_type == "Smoothness":
        cmd = int(input("1: Roughness  |  2: Smoothness >"),10)
        if cmd == 1:
            img = Image.open(inputPath)
            img = ImageOps.invert(img)
            img = img.convert("L")
            textures.append(img.resize(size))

        elif cmd == 2:
            textures.append(Image.open(inputPath).convert('L').resize(size))

        else:
            print("Try Again!")
    else:
        textures.append(Image.open(inputPath).convert('L').resize(size))

def getColor():
    if len(textures) is 0:
        texture_type = "Metallic"
    elif len(textures) is 1:
        texture_type = "Ambient Occlusion"
    elif len(textures) is 2:
        texture_type = "Detail"
    elif len(textures) is 3:
        texture_type = "Smoothness"
    color = int(input("Color (0-255) for {0} map>".format(texture_type)))
    textures.append(Image.new('L', size, color))

def make_texture():
    for texture in textures:
        texture.resize(size)
    Image.merge("RGBA",tuple(textures) ).save("{0}/MaskMap.png".format(outputPath))

def main():
    while True:
        if len(textures) > 3:
            make_texture()
            break
        try:
            cmd = int(input("1: Texture  |  2: Color >"),10)
            if cmd == 1:
                getTexture()
            elif cmd == 2:
                getColor()
            else:
                print ("Number must be one or two")
        except Exception:
            print ("Please enter a real number")

if __name__ == '__main__':
    main()


import torch
import torch.nn as nn
import torch.nn.functional as F
import numpy as np

from Pytorch.config import global_config

CFG = global_config.cfg

device = 'cuda' if torch.cuda.is_available() else 'cpu'

# 高通滤波器
class HPFNode(nn.Module):
    def __init__(self, image_channel=3):
        super(HPFNode, self).__init__()
        HPF = np.array([[[0, 0, 0, 0, 0],
                         [0, 0, 0, 0, 0],
                         [0, 0, -1, 1, 0],
                         [0, 0, 0, 0, 0],
                         [0, 0, 0, 0, 0]],
                        [[0, 0, 0, 0, 0],
                         [0, 0, 0, 0, 0],
                         [0, 0, -1, 0, 0],
                         [0, 0, 1, 0, 0],
                         [0, 0, 0, 0, 0]],
                        [[0, 0, 0, 0, 0],
                         [0, 0, 0, 0, 0],
                         [0, 1, -2, 1, 0],
                         [0, 0, 0, 0, 0],
                         [0, 0, 0, 0, 0]],
                        [[0, 0, 0, 0, 0],
                         [0, 0, 1, 0, 0],
                         [0, 0, -2, 0, 0],
                         [0, 0, 1, 0, 0],
                         [0, 0, 0, 0, 0]],
                        [[0, 0, 0, 0, 0],
                         [0, -1, 2, -1, 0],
                         [0, 2, -4, 2, 0],
                         [0, -1, 2, -1, 0],
                         [0, 0, 0, 0, 0]],
                        [[-1, 2, -2, 2, -1],
                         [2, -6, 8, -6, 2],
                         [-2, 8, -12, 8, -2],
                         [2, -6, 8, -6, 2],
                         [-1, 2, -2, 2, -1]]],
                       dtype=np.float32)
        self.HPF = torch.from_numpy(HPF).to(device)
        self.image_channel = image_channel

    def forward(self, input_image):
        output = []
        for i in range(6):
            kernel = self.HPF[i, :, :].unsqueeze(0).unsqueeze(0)
            kernel = kernel.repeat(1, self.image_channel, 1, 1)
            output_channel = F.conv2d(input_image, kernel, stride=1, padding=2)
            output.append(output_channel)
        output = torch.cat(output, dim=1)
        return output

class Discriminator(nn.Module):
    def __init__(self, image_size, image_channels=3):
        super(Discriminator, self).__init__()
        # 判别器特征层数量
        dis_filter = [8, 16, 32, 64, 128]
        # 高通滤波
        self.HPF = HPFNode()
        # Group 1
        self.conv_1 = nn.Conv2d(6, dis_filter[0], kernel_size=3, padding=1)
        self.bn_1 = nn.BatchNorm2d(dis_filter[0])
        self.pool_1 = nn.AvgPool2d(kernel_size=5, padding=2, stride=2)
        # Group 2
        self.conv_2 = nn.Conv2d(dis_filter[0], dis_filter[1], kernel_size=3, padding=1)
        self.bn_2 = nn.BatchNorm2d(dis_filter[1])
        self.pool_2 = nn.AvgPool2d(kernel_size=5, padding=2, stride=2)
        # Group 3
        self.conv_3 = nn.Conv2d(dis_filter[1], dis_filter[2], kernel_size=3, padding=1)
        self.bn_3 = nn.BatchNorm2d(dis_filter[2])
        self.pool_3 = nn.AvgPool2d(kernel_size=5, padding=2, stride=2)
        # Group 4
        self.conv_4 = nn.Conv2d(dis_filter[2], dis_filter[3], kernel_size=3, padding=1)
        self.bn_4 = nn.BatchNorm2d(dis_filter[3])
        self.pool_4 = nn.AvgPool2d(kernel_size=5, padding=2, stride=2)
        # Group 5
        self.conv_5 = nn.Conv2d(dis_filter[3], dis_filter[4], kernel_size=3, padding=1)
        self.bn_5 = nn.BatchNorm2d(dis_filter[4])
        self.pool_5 = torch.nn.AdaptiveAvgPool2d((1, 1))
        # Group 6 FullyConnect
        self.linear = nn.Linear(in_features=dis_filter[4], out_features=2, bias=True)

    def forward(self, input_image):
        x0 = self.HPF(input_image)
        # Group 1
        conv1 = self.conv_1(x0)
        bn1 = self.bn_1(torch.abs(conv1))
        pool1 = self.pool_1(F.tanh(bn1))
        # Group 2
        conv2 = self.conv_2(pool1)
        bn2 = self.bn_2(conv2)
        pool2 = self.pool_2(F.tanh(bn2))
        # Group 3
        conv3 = self.conv_3(pool2)
        bn3 = self.bn_3(conv3)
        pool3 = self.pool_3(F.relu(bn3))
        # Group 4
        conv4 = self.conv_4(pool3)
        bn4 = self.bn_4(conv4)
        pool4 = self.pool_4(F.relu(bn4))
        # Group 5
        conv5 = self.conv_5(pool4)
        bn5 = self.bn_5(conv5)
        pool5 = self.pool_5(F.relu(bn5))
        # Group 6 FullyConnect
        prob = pool5.squeeze()
        prob = self.linear(prob)
        prob = F.softmax(prob, dim=1)
        return prob


import json
import os
from glob import glob
from threading import Thread
from xml.dom.minidom import parseString

import yaml
from bs4 import BeautifulSoup as bs
from dicttoxml import dicttoxml

import smalianalysis

'''
# decompile apk (APKTool)
- get smali files
'''

def meta_constructor(loader, node):
    '''
    function to make yaml play nice
    '''
    value = loader.construct_mapping(node)
    return value

yaml.add_constructor(u'tag:yaml.org,2002:brut.androlib.meta.MetaInfo',
                     meta_constructor)  # This makes sure yaml doesn't break

def bulk_handler(path: str, num_threads: int):
    globpath = os.path.join(path, '*', '')
    dirs = glob(globpath)
    analyzers = []
    for i in range(num_threads):
        analyzer = Analysis(target_filepaths=dirs[i::num_threads])
        analyzer.thread.start()
        analyzers.append(analyzer)
    for analyzer in analyzers:
        if analyzer.thread.is_alive():
            analyzer.thread.join(60)
    print("All APKs analyzed.")

def manifest_name(soup: bs) -> list:
    '''
    analyzes a soup file to locate the manifest name
    '''
    manifest = soup.find('manifest')
    return manifest.get('package')

def analyze_permissions(soup: bs) -> list:
    '''
    Analyzes a soup file to locate app permissions
    '''
    permissions = []
    manifests = soup.find_all('manifest')  # Should be one, catching edges
    for manifest in manifests:
        for permission in manifest.find_all('uses-permission'):
            permissions.append(permission.get('android:name'))
    return permissions

def analyze_intents(soup: bs) -> list:
    intents = []
    manifests = soup.find_all('manifest')  # should only be one manifest
    for manifest in manifests:
        for intent_filter in manifest.find_all('intent-filter'):
            for action in intent_filter.find_all('action'):
                intents.append(action.get('android:name'))
    return intents

def analyze_services(soup: bs) -> list:
    services = []
    manifests = soup.find_all('manifest')  # should only be one manifest
    for manifest in manifests:
        for service in manifest.find_all('service'):
            services.append(service.get('android:name'))
    return services

def analyze_receivers(soup: bs) -> list:
    receivers = []
    manifests = soup.find_all('manifest')  # just in case there's > 1
    for manifest in manifests:
        for receiver in manifest.find_all('receiver'):
            receivers.append(receiver.get('android:name'))
    return receivers

def analysis(path: str, write_xml: bool) -> None:
    '''
    takes filepath and does analysis.
    '''
    dict = {}
    filepath = os.path.join(path, 'AndroidManifest.xml')
    apkt_yaml = os.path.join(path, 'apktool.yml')
    # print(f'Processing {filepath} and {apkt_yaml}, results to {results}.')
    with open(filepath, encoding='utf-8') as manifest:  # using UTF-8
        soup = bs(manifest, "lxml")
        dict['package'] = manifest_name(soup)
        analyzed_manifest = {
            'permissions': analyze_permissions(soup),
            'intents': analyze_intents(soup),
            'services': analyze_services(soup),
            'receivers': analyze_receivers(soup)
        }
        dict['manifest'] = analyzed_manifest
    with open(apkt_yaml, encoding='utf-8') as apktool_info:
        apkinfo = yaml.load(apktool_info, Loader=yaml.FullLoader)
        dict['sdkInfo'] = apkinfo['sdkInfo']  # no methods, a dict
    smali_results = smalianalysis.analyze(path)
    dict['urls'] = smali_results['urls']
    dict['dangerous_functions'] = smali_results['dangerous']
    dict['encryption_text'] = smali_results['encryption']
    if write_xml:
        results = os.path.join(path, 'result.xml')
        write_results_to_XML(results, dict)
    else:
        results = os.path.join(path, 'result.json')
        write_results_to_json(results, dict)

    # print(f'{path} processed.')

def write_results_to_XML(results, dict):
    with open(results, 'w', encoding='utf-8') as outfile:
        xml = dicttoxml(dict)
        dom = parseString(xml)
        outfile.write(dom.toprettyxml())

def write_results_to_json(results, dict):
    with open(results, "w", encoding='utf=8') as outfile:
        out = json.dumps(dict)
        outfile.write(out)

class Analysis:
    def __init__(self, target_filepaths, use_xml=False):
        self.write_xml = use_xml
        self.paths = target_filepaths
        self.total_paths = len(target_filepaths)
        self.thread = Thread(target=self.bulk_analyze)

    def bulk_analyze(self):
        current_file = 1
        for path in self.paths:
            print(f'{self.thread.name}: ' +
                  f'File {current_file} of {self.total_paths}: {path}')
            try:
                analysis(path, self.write_xml)
            except Exception as e:
                print(f'Error {e} on {path}, continuing.')
            current_file += 1
        print(f'{self.thread.name} analyzed assigned files.')


from scipy import signal
import numpy as np
import matplotlib.pyplot as plt

def axesCross(ax):
    ax.spines['left'].set_position('zero')
    ax.spines['bottom'].set_position('zero')
    ax.spines['right'].set_color('none')
    ax.spines['top'].set_color('none')
    ax.yaxis.set_ticks([])
    ax.set_xlim(-5, 5)
    ax.set_ylim(-.1, 2.2)
    ax.xaxis.set_ticks([-4, -2, 0, 2, 4])
    ax.xaxis.set_ticklabels([r"$-\frac{2\pi}{T}$", r"$-\frac{\pi}{T}$", r"$0$", r"$\frac{\pi}{T}$", r"$\frac{2\pi}{T}$"])

def periodization(f, T, times, ax=None, color='#999999', lstyle=':'):
    limit = np.floor(T*times/2)
    x = np.arange(-limit, limit, .02)
    sumY = 0
    for n in np.arange(times):
        y1 = f(x-T*n)
        sumY = sumY + y1
        if ax is not None:
            ax.plot(x, y1, color=color, linestyle=lstyle)
            ax.fill_between(x, 0, y1, facecolor=color, alpha=.3)

        if n != 0:
            y2 = f(x+T*n)
            sumY = sumY + y2
            if ax is not None:
                ax.plot(x, y2, color=color, linestyle=lstyle)
                ax.fill_between(x, 0, y2, facecolor=color, alpha=.3)
    return x, sumY

# the tick 2 is pi
f = lambda x: np.where(np.abs(x)<1, -np.abs(x)+1, 0)
f2 = lambda x: np.where(np.abs(x)<2, -.5*np.abs(x)+1, 0)
noise = lambda x: np.where(np.abs(x)<1, 0, np.where(np.abs(x)<4.2, .2, 0))
f2 = lambda x: .4*f(.5*x)
lowpass = lambda x: np.where(np.abs(x)<1, 1, 0)
prefilter = lambda x: np.where(np.abs(x)<1, 1, np.where(np.abs(x)<3, -.5*np.abs(x)+1.5, 0))
prefilterf = lambda x: .7*f(x)*prefilter(x)
prefilternoise = lambda x: .7*noise(x)*prefilter(x)

fig = plt.figure(figsize=(9,10), dpi=120)
ax1, ax2, ax3, ax4, ax5 = fig.subplots(5, 1)

x, y = periodization(f, 4, 10)
fx = np.arange(-10, 10, .02)
fy = f(fx)
ny = noise(fx)
py = prefilter(fx)

axesCross(ax1)
ax1.plot(fx, fy)
ax1.plot(fx, ny)
ax1.plot(fx, py, color='r', linestyle='--')
ax1.fill_between(fx, 0, fy, color='C0', alpha=.3)
ax1.fill_between(fx, 0, ny, color='C1', alpha=.3)
ax1.xaxis.set_ticks([-3, -1, 0, 1, 3])
ax1.xaxis.set_ticklabels([r"$-\Omega_c$", r"$-\Omega_N$", r"$0$", r"$\Omega_N$", r"$\Omega_c$"])
ax1.annotate("Simple antialiasing filter", xy=(1.2, .9), xytext=(2, 2), color='r', arrowprops=dict(arrowstyle='->', color='r'))
ax1.annotate("High-frequency noise", xy=(2, .2), xytext=(2, 1), color='C1', arrowprops=dict(arrowstyle='->', color='C1'))
ax1.annotate("Signal", xy=(-.5, .5), xytext=(-2.5, 1), color='C0', arrowprops=dict(arrowstyle='->',color='C0'))
ax1.annotate(r"$X_c(j\Omega)$", xy=(0, 0), xytext=(-5, 1.7), color='k')
ax1.annotate(r"$1$", xy=(0, 0), xytext=(-.2, 1.1), color='k')

axesCross(ax2)
ax2.plot(fx, fy)
ax2.plot(fx, ny*py)
ax2.fill_between(fx, 0, fy, color='C0', alpha=.3)
ax2.fill_between(fx, 0, ny*py, color='C1', alpha=.3)
ax2.xaxis.set_ticks([-3, -1, 0, 1, 3])
ax2.xaxis.set_ticklabels([r"$-\Omega_c$", r"$-\Omega_N$", r"$0$", r"$\Omega_N$", r"$\Omega_c$"])
ax2.annotate(r"$X_a(j\Omega) = X_c(j\Omega)H_{aa}(j\Omega)$", xy=(0, 0), xytext=(-5, 1.7), color='k')
ax2.annotate("Signal", xy=(-.5, .5), xytext=(-2.5, 1), color='C0', arrowprops=dict(arrowstyle='->',color='C0'))
ax2.annotate("Filtered noise", xy=(2, .1), xytext=(2, 1), color='C1', arrowprops=dict(arrowstyle='->', color='C1'))
ax2.annotate(r"$1$", xy=(0, 0), xytext=(-.2, 1.1), color='k')

axesCross(ax3)
lpfx, lpfy = periodization(prefilterf, 4, 10, ax3, 'C0', '-')
lpnx, lpny = periodization(prefilternoise, 4, 10, ax3, 'C1', '-')
#ax3.plot(lpfx, lpfy)
#ax3.fill_between(lpfx, 0, lpfy, color='C0', alpha=.3)
ax3.annotate(r"$X_{as}(j\Omega) = \frac{1}{T}\sum_{k=-\infty}^{\infty}X_a\left[j\left(\Omega-\frac{2\pi k}{T}\right)\right]$", xy=(0, 0), xytext=(-5, 1.7), color='k')
ax3.annotate(r"$T =\frac{\pi}{M\Omega_N}\qquad M\Omega_N\geqslant \frac{\Omega_N+\Omega_c}{2}$", xy=(0, 0), xytext=(1, 1.3), color='k')
ax3.annotate(r"$\frac{1}{T}$", xy=(0, 0), xytext=(-.2, .8), color='k')

axesCross(ax4)
ax4.xaxis.set_ticks([-4, -2, 0, 2, 4])
ax4.xaxis.set_ticklabels([r"$-2\pi$", r"$-\pi$", r"$0$", r"$\pi$", r"$2\pi$"])
lpfx, lpfy = periodization(prefilterf, 4, 10, ax4, 'C0', '-')
lpnx, lpny = periodization(prefilternoise, 4, 10, ax4, 'C1', '-')
lx, ly = periodization(lowpass, 4, 10)
ax4.plot(lx, ly, color='r', linestyle='--')
ax4.annotate(r"$\hat{X}(e^{j\omega}) = X_{as}(j\Omega)|_{\omega=T\Omega}$", xy=(0, 0), xytext=(-5, 1.7), color='k')
ax4.annotate("Sharp cutoff decimation filter", xy=(-1, .9), xytext=(-3, 1.3), color='r', arrowprops=dict(arrowstyle='->', color='r'))
ax4.annotate(r"$1$", xy=(0, 0), xytext=(-.2, 1.1), color='k')
ax4.annotate(r"$\frac{1}{T}$", xy=(0, 0), xytext=(-.2, .7), color='k')

axesCross(ax5)
ax5.xaxis.set_ticks([-4, -2, 0, 2, 4])
ax5.xaxis.set_ticklabels([r"$-2\pi$", r"$-\pi$", r"$0$", r"$\pi$", r"$2\pi$"])
f2x, f2y = periodization(f2, 4, 10)
ax5.plot(f2x, f2y)
ax5.fill_between(f2x, 0, f2y, color='C0', alpha=.3)
ax5.annotate(r"$X_d(e^{j\omega}) = Downsampling\ \hat{X}(e^{j\omega})\ with\ M$", xy=(0, 0), xytext=(-5, 1.7), color='k')
ax5.annotate(r"$T_d = MT$", xy=(0, 0), xytext=(1, 1), color='k')
ax5.annotate(r"$\frac{1}{T_d}$", xy=(0, 0), xytext=(-.2, .6), color='k')

plt.show()
fig.savefig("SimpleAntiAliasing.png", format='png')