Example #1
0
def levelSelectionMenu():
    """
    Fait fonctionner le menu de sélection d'un niveau enregistré.
    """
    goInBlack()
    levels = IO.getLevels("level")
    levelSelected = 0
    level = IO.loadLevel(level=levels[0])
    game.initSelectionLevel(level)
    moveRender(levels, levelSelected, IO.loadLevel)
    while not evenement.event["game"] == 'return':
        evenement.compute()
        ui.logic(evenement.event["tk"])
        if evenement.event["game"] == "right":
            levelSelected = move(levelSelected, levels, 1, IO.loadLevel)
        elif evenement.event["game"] == "left":
            levelSelected = move(levelSelected, levels, -1, IO.loadLevel)
        elif evenement.event["game"] == "play":
            goInBlack()
            game.play(levels[levelSelected], "s")
            backInBlack(game.initSelectionLevel, [levels[levelSelected]])
            moveRender(levels, levelSelected, IO.loadLevel)
        elif evenement.event["game"] == "edit":
            goInBlack()
            editor.editor(levels[levelSelected])
            backInBlack(game.initSelectionLevel, [levels[levelSelected]])
            moveRender(levels, levelSelected, IO.loadLevel)
        game.updateTime()
        animation.update()
        ui.render(game.getFps())
        mise_a_jour()
    backInBlack(game.initPlayMenu)
Example #2
0
File: fabfile.py Project: F3DS/f3ds
def begin(arg):
    print arg
    with cd('socialscan'):
        ipaddress,personality=str(arg).split(':')
        print ipaddress, personality
        path=str(ipaddress)+'socialscan.config'
        get('socialscan.config',path)
        print 'Transferred socialscan.config file from server to localhost for editing'
        sharing=editor.getInfo(path)
        shandler=scanname.getName(ipaddress)
        print sharing
        print shandler
        editor.editor(shandler,personality,sharing,path)
        put(path,'socialscan.config')
Example #3
0
def interroplot(path, query):
    import corpkit
    """Interrogates path with Tregex query, gets relative frequencies, and plots the top seven results"""
    from corpkit import interrogator, editor, plotter
    quickstart = interrogator(path, 'words', query)
    edited = editor(quickstart.results, '%', quickstart.totals, print_info = False)
    plotter(str(path), edited.results)
    def __init__(self, name, is_old_project, old_project_file):
        self.name = name

        self.is_old_project = is_old_project
        self.old_project_file = old_project_file

        self.editor = editor(self, self.is_old_project, self.old_project_file)
Example #5
0
    def edit(self, *args, **kwargs):
        """Delete or keep rows by subcorpus or by middle column text.

        >>> skipped = conc.edit(skip_entries = r'to_?match')"""

        from editor import editor
        return editor(self, *args, **kwargs)
Example #6
0
    def edit(self, *args, **kwargs):
        """Delete or keep rows by subcorpus or by middle column text.

        >>> skipped = conc.edit(skip_entries = r'to_?match')"""

        from editor import editor
        return editor(self, *args, **kwargs)
Example #7
0
def default(mapeditor):
#   general things

    m=editor(mapeditor)

# a wall around the world, suitable for all games.

    m.make('wall',type='wall',pos=(-151,-101,village_height),bbox=[1,102,2.5])
    m.make('wall',type='wall',pos=(-151,-101,village_height),bbox=[152,1,2.5])
    m.make('wall',type='wall',pos=(-151,100,village_height),bbox=[152,1,2.5])
    m.make('wall',type='wall',pos=(100,-101,village_height),bbox=[1,102,2.5])

    m.make('weather',type='weather',desc='object that describes the weather',
           pos=(0,1,0), rain=0.0)

#   the gallows
    gallows = m.make('gallows', type='gallows', pos=gallows_pos)

#   the mayor, who runs the game
    mayor=m.make('mayor', type='mayor', pos=(1, 1, village_height))

#   the hangman, who lynches the villagers
    hangman=m.make('hangman', type='hangman', pos=(5, 5, village_height))
    m.learn(hangman,execute)
    m.know(hangman,knowledge)
    m.own(hangman,gallows)
Example #8
0
    def edit(self, *args, **kwargs):
        """Edit each value with :func:`~corpkit.interrogation.Interrogation.edit`.

        See :func:`~corpkit.interrogation.Interrogation.edit` for possible arguments.

        :returns: :class:`corpkit.interrogation.Interrodict`
        """

        from editor import editor
        return editor(self, *args, **kwargs)
Example #9
0
    def edit(self, *args, **kwargs):
        """Edit each value with :func:`~corpkit.interrogation.Interrogation.edit`.

        See :func:`~corpkit.interrogation.Interrogation.edit` for possible arguments.

        :returns: A :class:`corpkit.interrogation.Interrodict`
        """

        from editor import editor
        return editor(self, *args, **kwargs)
def create_town_buildings(mapeditor):

    m = editor(mapeditor)

    cfire=m.make('campfire',type='campfire',xyz=(3,9,10))
    m.make('fire',type='fire',xyz=(0,0,0),parent=cfire.id)
    m.make('mausoleum', type='mausoleum', xyz=(40,40,10))
    m.make('mausoleum', type='mausoleum', xyz=(40,-40,10))
    m.make('tavern',type='house3',xyz=(-80,-20,town_height),orientation=directions[2])
    # tower for the keep
    m.make('tower',type='tower',xyz=(-200,-120,30))
Example #11
0
def MENU():  # first Menu

    import os

    from ascci import rabbit
    from editor import editor
    from keydetect import keydetect
    from lwsystem import osuser
    from creds import creds

    os.system("clear")
    print "\x1b[0;31m" + "ducky converter/encoder " + "\x1b[0m" + "by"
    CSI = "\x1B["
    print " " + CSI + "\x1b[31;5m" + "		  ------------\n                  |DuckyTools|\n                  ------------" + CSI + "0m"
    print "(python2.7)"
    print("\n")

    userChoice = raw_input(
        "\nMENU :\n\nWhat do you want ?\n\n1) editor for translat many ducky/P4wnP1 keyboard keys \n2) generate payloads for P4wnP1 A.L.O.A with web client interface \n3) test P4wnP1 with a simple keyboard detect key pressed\n4) Creds\n\n99) exit \n\n>>> "
    )

    if userChoice == "1":
        editor()

    elif userChoice == "2":
        print "\n"
        os.system("clear")
        osuser()

    elif userChoice == "3":
        keydetect()

    elif userChoice == "4":
        creds()

    elif userChoice == "99":
        rabbit()
        exit()
    else:
        print "\nan error occurred, please try again\n"
        MENU()
Example #12
0
def plain(mapeditor):
#   general things

    m=editor(mapeditor)

    world=m.look()
    points = { }
    for i in range(-6, 7):
        for j in range(-6, 7):
            points['%ix%i'%(i,j)] = [i, j, 8]

    m.set(world.id, terrain={'points' : points})
Example #13
0
def plain(mapeditor):
    #   general things

    m = editor(mapeditor)

    world = m.look()
    points = {}
    for i in range(-6, 7):
        for j in range(-6, 7):
            points['%ix%i' % (i, j)] = [i, j, 8]

    m.set(world.id, terrain={'points': points})
Example #14
0
    def __init__(self, parent=None):
        QtGui.QMainWindow.__init__(self, parent)
        self.__Dir = os.path.dirname(sys.argv[0])
        self.icons =  os.path.join(self.__Dir, 'icons/')

        self.resize(640, 480)
        self.setWindowTitle('PyTe v3')
        self.setWindowIcon(QtGui.QIcon(self.icons+'pyte.png'))


        self.mainTabWidget = QtGui.QTabWidget(self)
        self.mainTabWidget.setTabsClosable(True)
        self.mainTabWidget.setMovable(True)
        self.setCentralWidget(self.mainTabWidget)

        newEditor = editor(self, self)
        newTab = self.mainTabWidget.addTab(newEditor, QtGui.QIcon(self.icons+'pyte.png'), "Pyte v3")
        self.mainTabWidget.setCurrentIndex(newTab)

        self.statusBar()

        closeTab = QtGui.QAction(QtGui.QIcon(self.icons+'exit.png'), 'Close Tab', self)
        closeTab.setStatusTip('Close Tab')
        self.connect(closeTab, QtCore.SIGNAL('triggered()'), self.closetab)

        newtab = QtGui.QAction(QtGui.QIcon(self.icons+'add.png'), 'Add Tab', self)
        newtab.setStatusTip('Add Tab')
        self.connect(newtab,QtCore.SIGNAL('triggered()'), self.codetab)

        self.connect(self.mainTabWidget, QtCore.SIGNAL("tabCloseRequested (int)"), self.on_close_tab_requested)
        self.connect(self.mainTabWidget, QtCore.SIGNAL("currentChanged (int)"), self.on_tab_change)

        menubar = self.menuBar()
        file = menubar.addMenu('&File')
        file.addAction(newtab)
        file.addAction(closeTab)

        #if there is a argument passed then try to open it as a file
        if (len(sys.argv) > 1):
            fn = sys.argv[1]

            fileName = str(fn)

            try:
                self.editor.openArg(fileName)
                self.editor.title(fileName)
            except:
                return

            self.setWindowTitle(fileName+" - PyTe v3")
        else:
            pass
def create_town_buildings(mapeditor):

    m = editor(mapeditor)

    cfire = m.make('campfire', type='campfire', xyz=(3, 9, 10))
    m.make('fire', type='fire', xyz=(0, 0, 0), parent=cfire.id)
    m.make('mausoleum', type='mausoleum', xyz=(40, 40, 10))
    m.make('mausoleum', type='mausoleum', xyz=(40, -40, 10))
    m.make('tavern',
           type='house3',
           xyz=(-80, -20, town_height),
           orientation=directions[2])
    # tower for the keep
    m.make('tower', type='tower', xyz=(-200, -120, 30))
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(402, 496)
        self.centralwidget = QtGui.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.verticalLayout = QtGui.QVBoxLayout(self.centralwidget)
        self.verticalLayout.setObjectName("verticalLayout")
        self.splitter = QtGui.QSplitter(self.centralwidget)
        self.splitter.setOrientation(QtCore.Qt.Vertical)
        self.splitter.setObjectName("splitter")
        self.list = QtGui.QTreeWidget(self.splitter)
        self.list.setTabKeyNavigation(True)
        self.list.setAlternatingRowColors(True)
        self.list.setItemsExpandable(False)
        self.list.setExpandsOnDoubleClick(False)
        self.list.setObjectName("list")
        self.editor = editor(self.splitter)
        self.editor.setObjectName("editor")
        self.verticalLayout.addWidget(self.splitter)
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtGui.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 402, 25))
        self.menubar.setObjectName("menubar")
        self.menuMenu = QtGui.QMenu(self.menubar)
        self.menuMenu.setObjectName("menuMenu")
        MainWindow.setMenuBar(self.menubar)
        self.toolBar = QtGui.QToolBar(MainWindow)
        self.toolBar.setObjectName("toolBar")
        MainWindow.addToolBar(QtCore.Qt.ToolBarArea(QtCore.Qt.TopToolBarArea), self.toolBar)
        self.actionDelete_Provider = QtGui.QAction(MainWindow)
        self.actionDelete_Provider.setObjectName("actionDelete_Provider")
        self.actionNew_Provider = QtGui.QAction(MainWindow)
        self.actionNew_Provider.setObjectName("actionNew_Provider")
        self.actionEdit_Provider = QtGui.QAction(MainWindow)
        self.actionEdit_Provider.setObjectName("actionEdit_Provider")
        self.menuMenu.addAction(self.actionNew_Provider)
        self.menuMenu.addAction(self.actionDelete_Provider)
        self.menuMenu.addAction(self.actionEdit_Provider)
        self.menubar.addAction(self.menuMenu.menuAction())
        self.toolBar.addAction(self.actionNew_Provider)
        self.toolBar.addAction(self.actionDelete_Provider)
        self.toolBar.addAction(self.actionEdit_Provider)

        self.retranslateUi(MainWindow)
        QtCore.QObject.connect(self.list, QtCore.SIGNAL("itemSelectionChanged()"), self.editor.hide)
        QtCore.QObject.connect(self.list, QtCore.SIGNAL("itemDoubleClicked(QTreeWidgetItem*,int)"), self.editor.edit)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)
Example #17
0
def modify_terrain(mapeditor):
    #   general things

    m = editor(mapeditor)

    world = m.look()
    points = {}
    for i in range(-6, 7):
        for j in range(-6, 7):
            if i >= 5 or j >= 5:
                points['%ix%i' % (i, j)] = [i, j, uniform(100, 150)]
            elif i <= -5 or j <= -5:
                points['%ix%i' % (i, j)] = [i, j, uniform(-30, -10)]
            elif (i == 2 or i == 3) and (j == 2 or j == 3):
                points['%ix%i' % (i, j)] = [i, j, uniform(20, 25)]
            elif i == 4 or j == 4:
                points['%ix%i' % (i, j)] = [i, j, uniform(30, 80)]
            elif i == -4 or j == -4:
                points['%ix%i' % (i, j)] = [i, j, uniform(-5, 5)]
            else:
                points['%ix%i' % (i, j)] = [
                    i, j, 1 + uniform(3, 11) * (abs(i) + abs(j))
                ]

    points['-4x-1'] = [-4, -1, 12.4]
    points['-4x-2'] = [-4, -2, -8.3]
    points['-3x-2'] = [-3, -2, -6.2]
    points['-3x-1'] = [-3, -1, -5.3]
    points['-2x-1'] = [-2, -1, -4.1]
    points['-1x-1'] = [-1, -1, -16.8]
    points['0x-1'] = [0, -1, -3.8]
    points['-1x0'] = [-1, 0, -2.8]
    points['-1x1'] = [-1, 1, -1.8]
    points['-1x2'] = [-1, 2, -1.7]
    points['0x2'] = [0, 2, -1.6]
    points['1x2'] = [1, 2, -1.3]
    points['1x3'] = [1, 3, -1.1]
    points['1x4'] = [1, 4, -0.6]
    points['1x-1'] = [1, -1, 15.8]
    points['0x0'] = [0, 0, 12.8]
    points['1x0'] = [1, 0, 23.1]
    points['0x1'] = [0, 1, 14.2]
    points['1x1'] = [1, 1, 19.7]

    m.set(world.id, terrain={'points': points})
Example #18
0
def modify_terrain(mapeditor):
#   general things

    m=editor(mapeditor)

    world=m.look()
    points = { }
    for i in range(-6, 7):
        for j in range(-6, 7):
            if i>=5 or j>=5:
                points['%ix%i'%(i,j)] = [i, j, uniform(100, 150)]
            elif i<=-5 or j <= -5:
                points['%ix%i'%(i,j)] = [i, j, uniform(-30, -10)]
            elif (i==2 or i==3) and (j==2 or j==3):
                points['%ix%i'%(i,j)] = [i, j, uniform(20, 25)]
            elif i==4 or j==4:
                points['%ix%i'%(i,j)] = [i, j, uniform(30, 80)]
            elif i==-4 or j==-4:
                points['%ix%i'%(i,j)] = [i, j, uniform(-5, 5)]
            else:
                points['%ix%i'%(i,j)] = [i, j, 1+uniform(3, 11)*(abs(i)+abs(j))]

    points['-4x-1'] = [-4, -1, 12.4]
    points['-4x-2'] = [-4, -2, -8.3]
    points['-3x-2'] = [-3, -2, -6.2]
    points['-3x-1'] = [-3, -1, -5.3]
    points['-2x-1'] = [-2, -1, -4.1]
    points['-1x-1'] = [-1, -1, -16.8]
    points['0x-1'] = [0, -1, -3.8]
    points['-1x0'] = [-1, 0, -2.8]
    points['-1x1'] = [-1, 1, -1.8]
    points['-1x2'] = [-1, 2, -1.7]
    points['0x2'] = [0, 2, -1.6]
    points['1x2'] = [1, 2, -1.3]
    points['1x3'] = [1, 3, -1.1]
    points['1x4'] = [1, 4, -0.6]
    points['1x-1'] = [1, -1, 15.8]
    points['0x0'] = [0, 0, 12.8]
    points['1x0'] = [1, 0, 23.1]
    points['0x1'] = [0, 1, 14.2]
    points['1x1'] = [1, 1, 19.7]

    m.set(world.id, terrain={'points' : points})
Example #19
0
def default(mapeditor):
    #   general things

    m = editor(mapeditor)

    # a wall around the world, suitable for all games.

    m.make('wall',
           type='wall',
           pos=(-151, -101, village_height),
           bbox=[1, 102, 2.5])
    m.make('wall',
           type='wall',
           pos=(-151, -101, village_height),
           bbox=[152, 1, 2.5])
    m.make('wall',
           type='wall',
           pos=(-151, 100, village_height),
           bbox=[152, 1, 2.5])
    m.make('wall',
           type='wall',
           pos=(100, -101, village_height),
           bbox=[1, 102, 2.5])

    m.make('weather',
           type='weather',
           desc='object that describes the weather',
           pos=(0, 1, 0),
           rain=0.0)

    #   the gallows
    gallows = m.make('gallows', type='gallows', pos=gallows_pos)

    #   the mayor, who runs the game
    mayor = m.make('mayor', type='mayor', pos=(1, 1, village_height))

    #   the hangman, who lynches the villagers
    hangman = m.make('hangman', type='hangman', pos=(5, 5, village_height))
    m.learn(hangman, execute)
    m.know(hangman, knowledge)
    m.own(hangman, gallows)
Example #20
0
def multiquery(corpus, query, sort_by = 'total', quicksave = False):
    import corpkit
    """Creates a named tuple for a list of named queries to count.

    Pass in something like:

    [[u'NPs in corpus', r'NP'], [u'VPs in corpus', r'VP']]"""

    import collections
    import os
    import pandas
    import pandas as pd
    from time import strftime, localtime
    from interrogator import interrogator
    from editor import editor

    if quicksave:
        savedir = 'saved_interrogations'
        if not quicksave.endswith('.p'):
            quicksave = quicksave + '.p'
        fullpath = os.path.join(savedir, quicksave)
        while os.path.isfile(fullpath):
            selection = raw_input("\nSave error: %s already exists in %s.\n\nPick a new name: " % (savename, savedir))
            if not selection.endswith('.p'):
                selection = selection + '.p'
                fullpath = os.path.join(savedir, selection)

    results = []
    for name, pattern in query:
        result = interrogator(corpus, 'count', pattern)
        result.totals.name = name # rename count
        results.append(result.totals)
    results = pd.concat(results, axis = 1)

    results = editor(results, sort_by = sort_by, print_info = False, keep_stats = False)
    time = strftime("%H:%M:%S", localtime())
    print '%s: Finished! %d unique results, %d total.' % (time, len(results.results.columns), results.totals.sum())
    if quicksave:
        from other import save_result
        save_result(results, quicksave)
    return results
Example #21
0
 def edit(self, *args, **kwargs):
     """calls corpkit.editor.editor()"""
     from editor import editor
     return editor(self, *args, **kwargs)
Example #22
0
def main():
    from fhbgui import coprscreen, titlescreen, level_select
    from editor import editor

    G.display.set_caption("Loading")
    joycfg.dump_joysticks(verbose=False)
    wndicon = G.image.load('tilesets/wndicon32.png')
    G.display.set_icon(wndicon)
    view = FHBGView()
    game = FHBGGame(view)
    view.bindings = joycfg.load_bindings(keybindings_filename)
    G.display.set_caption("Forehead Block Guy")
    quitting = False

    if view.bindings == 'reconfigure':
        got_preset = joycfg_get_preset()
        if got_preset:
            from textwrap import TextWrapper
            tw = TextWrapper(width=28)
            try:
                jname = joycfg.joysticks[0].get_name()
            except IndexError:
                jname = "Keyboard"
            bindingsNotice = '\n'.join([
                "\nRecommended settings for",
                tw.fill(jname),
                format_bindings(got_preset), "\nPress Tab to change"
            ])
            view.bindings = got_preset
            e = coprscreen(view, bindingsNotice, with_tab=True)
            if e & VK_SELECT:
                got_preset = None
        view.bindings = (got_preset
                         or joycfg.get_bindings(view.display.get_surface(),
                                                view.font,
                                                action_names,
                                                flipper=view.display))
        if not view.bindings:
            return
        joycfg.save_bindings(keybindings_filename, view.bindings, action_names)
    elif not isinstance(view.bindings, list):
        view.bindings = [('key', b) for b in default_bindings]

    if todoNotice:
        e = coprscreen(view, todoNotice)
    while not quitting:
        selected = titlescreen(view)
        if selected < 0:
            break
        if selected == 1:
            bindingsNotice = '\n'.join([
                "\nControls:",
                format_bindings(view.bindings),
                "\nTo change the controls,\npress Tab or Select"
            ])
            e = coprscreen(view, bindingsNotice, with_tab=True)
            if e & VK_SELECT:
                newbindings = joycfg.get_bindings(view.display.get_surface(),
                                                  view.font,
                                                  action_names,
                                                  flipper=view.display)
                view.bindings = newbindings or view.bindings
                joycfg.save_bindings(keybindings_filename, view.bindings,
                                     action_names)
            read_pads(view)  # clear out fire button
            continue
        elif selected == 2:  # practice
            ls_level = 0
            while True:
                e, ls_level = level_select(view, game, ls_level)
                if ls_level < 0:
                    break
                game.new_game()
                game.pf.sheet = view.metatile_sheet
                result = play_level(view, game, game.levels[ls_level])
                if result == 'q':
                    quitting = True
            continue
        elif selected == 3:  # edit
            editor(view, game, play_level)
            continue
        elif selected == 4:  # help
            e = coprscreen(view, helpScreenText)
            continue
        result = play_game(view, game)
        if result == 'q':
            quitting = True

    view.close()
Example #23
0
    def edit(self, *args, **kwargs):
        """Manipulate results of interrogations.

        There are a few overall kinds of edit, most of which can be combined into a single function call. It's useful to keep in mind that many are basic wrappers around `pandas` operations---if you're comfortable with `pandas` syntax, it may be faster at times to use its syntax instead.

        :Basic mathematical operations:

        First, you can do basic maths on results, optionally passing in some data to serve as the denominator. Very commonly, you'll want to get relative frequencies:

        :Example: 

        >>> data = corpus.interrogate({W: r'^t'})
        >>> rel = data.edit('%', SELF)
        >>> rel.results
            ..    to  that   the  then ...   toilet  tolerant  tolerate  ton
            01 18.50 14.65 14.44  6.20 ...     0.00      0.00      0.11 0.00
            02 24.10 14.34 13.73  8.80 ...     0.00      0.00      0.00 0.00
            03 17.31 18.01  9.97  7.62 ...     0.00      0.00      0.00 0.00

        For the operation, there are a number of possible values, each of which is to be passed in as a `str`:

           `+`, `-`, `/`, `*`, `%`: self explanatory

           `k`: log likelihood (keywords)

           `a`: get distance metric

           `d`: get percent difference (alternative approach to keywording)
        
        `SELF` is a very useful shorthand denominator. When used, all editing is performed on the data. The totals are then extracted from the edited data, and used as denominator. If this is not the desired behaviour, however, a more specific `interrogation.results` or `interrogation.totals` branch can be used.

        In the example above, `SELF` (or `'self'`) is equivalent to:

        :Example:

        >>> rel = data.edit('%', data.totals)

        :Keeping and skipping data:

        There are four keyword arguments that can be used to keep or skip rows or columns in the data:

        * `just_entries`
        * `just_subcorpora`
        * `skip_entries`
        * `skip_subcorpora`

        Each can accept different input types:

        * str: treated as regular expression to match
        * list: 

          * of integers: indices to match
          * of strings: entries/subcorpora to match

        :Example:

        >>> data.edit(just_entries = r'^fr', 
        ...           skip_entries = ['free', 'freedom'],
        ...           skip_subcorpora = r'[0-9]')

        :Merging data:

        There are also keyword arguments for merging entries and subcorpora.

        * `merge_entries`
        * `merge_subcorpora`

        These take a `dict`, with the new name as key and the criteria as value. The criteria can be a str (regex) or wordlist.

        :Example:
        
        >>> from dictionaries.wordlists import wordlists
        >>> mer = {'Articles': ['the', 'an', 'a'], 'Modals': wordlists.modals}
        >>> data.edit(merge_entries = mer)

        :Sorting:

        The `sort_by` keyword argument takes a `str`, which represents the way the result columns should be ordered.

        * `increase`: highest to lowest slope value
        * `decrease`: lowest to highest slope value
        * `turbulent`: most change in y axis values
        * `static`: least change in y axis values
        * `total/most`: largest number first
        * `infreq/least`: smallest number first
        * `name`: alphabetically

        :Example:

        >>> data.edit(sort_by = 'increase')

        :Editing entry text:
        
        Column labels, corresponding to individual interrogation results, can also be edited with `replace_names`.

        :param replace_names: Edit result names, then merge duplicate entries
        :type replace_names: str/dict

        If `replace_names` is a string, it is treated as a regex to delete from each name. If `replace_names` is a dict, the value is the regex, and the key is the replacement text:

        :Example:

        >>> data.edit(replace_names = {r'object': r'[di]obj'})

        :Other options:

        There are many other miscellaneous options.

        :param keep_stats: Keep/drop stats values from dataframe after sorting
        :type keep_stats: bool
        
        :param keep_top: After sorting, remove all but the top *keep_top* results
        :type keep_top: int
        
        :param just_totals: Sum each column and work with sums
        :type just_totals: bool
        
        :param threshold: When using results list as dataframe 2, drop values occurring fewer than n times. If not keywording, you can use:
                                
           `'high'`: `denominator total / 2500`
           
           `'medium'`: `denominator total / 5000`
           
           `'low'`: `denominator total / 10000`
                            
           If keywording, there are smaller default thresholds

        :type threshold: int/bool

        :param span_subcorpora: If subcorpora are numerically named, span all from *int* to *int2*, inclusive
        :type span_subcorpora: tuple -- `(int, int2)`

        :param projection:         a  to multiply results in subcorpus by n
        :type projection: tuple -- `(subcorpus_name, n)`
        :param remove_above_p: Delete any result over `p`
        :type remove_above_p: bool
        :param p:                  set the p value
        :type p: float
        
        :param revert_year: When doing linear regression on years, turn annual subcorpora into 1, 2 ...
        :type revert_year: bool
        
        :param print_info: Print stuff to console showing what's being edited
        :type print_info: bool
        
        :param spelling: Convert/normalise spelling:
        :type spelling: str -- `'US'`/`'UK'`
        
        :param selfdrop: When keywording, try to remove target corpus from reference corpus
        :type selfdrop: bool
        
        :param calc_all: When keywording, calculate words that appear in either corpus
        :type calc_all: bool

        :returns: :class:`corpkit.interrogation.Interrogation`
        """
        from editor import editor
        return editor(self, *args, **kwargs)
Example #24
0
    def edit(self, *args, **kwargs):
        """Manipulate results of interrogations.

        There are a few overall kinds of edit, most of which can be combined into a single function call. It's useful to keep in mind that many are basic wrappers around `pandas` operations---if you're comfortable with `pandas` syntax, it may be faster at times to use its syntax instead.

        :Basic mathematical operations:

        First, you can do basic maths on results, optionally passing in some data to serve as the denominator. Very commonly, you'll want to get relative frequencies:

        :Example: 

        >>> data = corpus.interrogate({W: r'^t'})
        >>> rel = data.edit('%', SELF)
        >>> rel.results
            ..    to  that   the  then ...   toilet  tolerant  tolerate  ton
            01 18.50 14.65 14.44  6.20 ...     0.00      0.00      0.11 0.00
            02 24.10 14.34 13.73  8.80 ...     0.00      0.00      0.00 0.00
            03 17.31 18.01  9.97  7.62 ...     0.00      0.00      0.00 0.00

        For the operation, there are a number of possible values, each of which is to be passed in as a `str`:

           `+`, `-`, `/`, `*`, `%`: self explanatory

           `k`: log likelihood (keywords)

           `a`: get distance metric

           `d`: get percent difference (alternative approach to keywording)
        
        `SELF` is a very useful shorthand denominator. When used, all editing is performed on the data. The totals are then extracted from the edited data, and used as denominator. If this is not the desired behaviour, however, a more specific `interrogation.results` or `interrogation.totals` branch can be used.

        In the example above, `SELF` (or `'self'`) is equivalent to:

        :Example:

        >>> rel = data.edit('%', data.totals)

        :Keeping and skipping data:

        There are four keyword arguments that can be used to keep or skip rows or columns in the data:

        * `just_entries`
        * `just_subcorpora`
        * `skip_entries`
        * `skip_subcorpora`

        Each can accept different input types:

        * str: treated as regular expression to match
        * list: 

          * of integers: indices to match
          * of strings: entries/subcorpora to match

        :Example:

        >>> data.edit(just_entries = r'^fr', 
        ...           skip_entries = ['free', 'freedom'],
        ...           skip_subcorpora = r'[0-9]')

        :Merging data:

        There are also keyword arguments for merging entries and subcorpora.

        * `merge_entries`
        * `merge_subcorpora`

        These take a `dict`, with the new name as key and the criteria as value. The criteria can be a str (regex) or wordlist.

        :Example:
        
        >>> from dictionaries.wordlists import wordlists
        >>> mer = {'Articles': ['the', 'an', 'a'], 'Modals': wordlists.modals}
        >>> data.edit(merge_entries = mer)

        :Sorting:

        The `sort_by` keyword argument takes a `str`, which represents the way the result columns should be ordered.

        * `increase`: highest to lowest slope value
        * `decrease`: lowest to highest slope value
        * `turbulent`: most change in y axis values
        * `static`: least change in y axis values
        * `total/most`: largest number first
        * `infreq/least`: smallest number first
        * `name`: alphabetically

        :Example:

        >>> data.edit(sort_by = 'increase')

        :Editing entry text:
        
        Column labels, corresponding to individual interrogation results, can also be edited with `replace_names`.

        :param replace_names: Edit result names, then merge duplicate entries
        :type replace_names: str/dict

        If `replace_names` is a string, it is treated as a regex to delete from each name. If `replace_names` is a dict, the value is the regex, and the key is the replacement text:

        :Example:

        >>> data.edit(replace_names = {r'object': r'[di]obj'})

        :Other options:

        There are many other miscellaneous options.

        :param keep_stats: Keep/drop stats values from dataframe after sorting
        :type keep_stats: bool
        
        :param keep_top: After sorting, remove all but the top *keep_top* results
        :type keep_top: int
        
        :param just_totals: Sum each column and work with sums
        :type just_totals: bool
        
        :param threshold: When using results list as dataframe 2, drop values occurring fewer than n times. If not keywording, you can use:
                                
           `'high'`: `denominator total / 2500`
           
           `'medium'`: `denominator total / 5000`
           
           `'low'`: `denominator total / 10000`
                            
           If keywording, there are smaller default thresholds

        :type threshold: int/bool

        :param span_subcorpora: If subcorpora are numerically named, span all from *int* to *int2*, inclusive
        :type span_subcorpora: tuple -- `(int, int2)`

        :param projection:         a  to multiply results in subcorpus by n
        :type projection: tuple -- `(subcorpus_name, n)`
        :param remove_above_p: Delete any result over `p`
        :type remove_above_p: bool
        :param p:                  set the p value
        :type p: float
        
        :param revert_year: When doing linear regression on years, turn annual subcorpora into 1, 2 ...
        :type revert_year: bool
        
        :param print_info: Print stuff to console showing what's being edited
        :type print_info: bool
        
        :param spelling: Convert/normalise spelling:
        :type spelling: str -- `'US'`/`'UK'`
        
        :param selfdrop: When keywording, try to remove target corpus from reference corpus
        :type selfdrop: bool
        
        :param calc_all: When keywording, calculate words that appear in either corpus
        :type calc_all: bool

        :returns: :class:`corpkit.interrogation.Interrogation`
        """
        from editor import editor
        return editor(self, *args, **kwargs)
Example #25
0
    game.initMenuUI()
    while not evenement.event["game"] == 'return':
        # ev=donne_evenement()
        # if ev[0]!='RAS':
        #     print(ev)
        evenement.compute()
        ui.logic(evenement.event["tk"])
        # home:play
        if evenement.event["game"] == 'play':
            goInBlack(game.initPlayMenu)
            choicePlaystyleMenu()
            backInBlack(game.initMenuUI)
        # home:editor
        elif evenement.event["game"] == 'editor':
            goInBlack()
            editor.editor()
            backInBlack(game.initMenuUI)
        elif evenement.event["game"] == 'score':
            goInBlack()
            scoresMenu()
            backInBlack(game.initMenuUI)

        game.updateTime()
        animation.update()  # /!\ render.updateAnimations before ui.render
        ui.render(game.getFps())
        mise_a_jour()

###############################################################################

###############################################################################
def default(mapeditor):
    #   general things

    m = editor(mapeditor)

    world = m.look()

    points = {}

    # terrain
    points['-6x-6'] = [-6, -6, 65]
    points['-5x-6'] = [-5, -6, 60]
    points['-4x-6'] = [-4, -6, -2]
    points['-3x-6'] = [-3, -6, -3]
    points['-2x-6'] = [-2, -6, -4]
    points['-1x-6'] = [-1, -6, -6]
    points['0x-6'] = [0, -6, -7]
    points['1x-6'] = [1, -6, -8]
    points['2x-6'] = [2, -6, -9]
    points['3x-6'] = [3, -6, -10]
    points['4x-6'] = [4, -6, -12]
    points['5x-6'] = [5, -6, -14]
    points['6x-6'] = [6, -6, -20]

    points['-6x-5'] = [-6, -5, 65.4]
    points['-5x-5'] = [-5, -5, 62.1]
    points['-4x-5'] = [-4, -5, 4]
    points['-3x-5'] = [-3, -5, 3.9]
    points['-2x-5'] = [-2, -5, 3.7]
    points['-1x-5'] = [-1, -5, 3.8]
    points['0x-5'] = [0, -5, 3.6]
    points['1x-5'] = [1, -5, 3.2]
    points['2x-5'] = [2, -5, 2.5]
    points['3x-5'] = [3, -5, 1]
    points['4x-5'] = [4, -5, 0]
    points['5x-5'] = [5, -5, -3]
    points['6x-5'] = [6, -5, -5]

    points['-6x-4'] = [-6, -4, 67]
    points['-5x-4'] = [-5, -4, 61]
    points['-4x-4'] = [-4, -4, 5]
    points['-3x-4'] = [-3, -4, 4.9]
    points['-2x-4'] = [-2, -4, 4.7]
    points['-1x-4'] = [-1, -4, 4.8]
    points['0x-4'] = [0, -4, 4.6]
    points['1x-4'] = [1, -4, 4.2]
    points['2x-4'] = [2, -4, 3.5]
    points['3x-4'] = [3, -4, 2]
    points['4x-4'] = [4, -4, 1]
    points['5x-4'] = [5, -4, 0]
    points['6x-4'] = [6, -4, -5]

    points['-6x-3'] = [-6, -3, 69]
    points['-5x-3'] = [-5, -3, 65]
    points['-4x-3'] = [-4, -3, 6]
    points['-3x-3'] = [-3, -3, 5.7]
    points['-2x-3'] = [-2, -3, 5.6]
    points['-1x-3'] = [-1, -3, 5.8]
    points['0x-3'] = [0, -3, 5.6]
    points['1x-3'] = [1, -3, 5.2]
    points['2x-3'] = [2, -3, 4.5]
    points['3x-3'] = [3, -3, 4.9]
    points['4x-3'] = [4, -3, 4.5]
    points['5x-3'] = [5, -3, 3]
    points['6x-3'] = [6, -3, 0]

    points['-6x-2'] = [-6, -2, 71]
    points['-5x-2'] = [-5, -2, 30]  # keep
    points['-4x-2'] = [-4, -2, 30]  # keep
    points['-3x-2'] = [-3, -2, 30]  # keep
    points['-2x-2'] = [-2, -2, -16.8]  # center of the lake
    points['-1x-2'] = [-1, -2, -3.8]  # east side of the lake
    points['0x-2'] = [0, -2, 15.8]  # east border of the lake
    points['1x-2'] = [1, -2, 13]
    points['2x-2'] = [2, -2, 10.5]
    points['3x-2'] = [3, -2, 7.9]
    points['4x-2'] = [4, -2, 6.5]
    points['5x-2'] = [5, -2, 5]
    points['6x-2'] = [6, -2, -4]

    points['-6x-1'] = [-6, -1, 70]
    points['-5x-1'] = [-5, -1, 64.6]
    points['-4x-1'] = [-4, -1, 30]  # keep
    points['-3x-1'] = [-3, -1, 30]  # keep
    points['-2x-1'] = [-2, -1, -2.8]  # north part of the lake
    points['-1x-1'] = [-1, -1, 12.7]  # town
    points['0x-1'] = [0, -1, 12.7]  # town
    points['1x-1'] = [1, -1, 12.5]  # town
    points['2x-1'] = [2, -1, 14.7]
    points['3x-1'] = [3, -1, 15.8]
    points['4x-1'] = [4, -1, 11]
    points['5x-1'] = [5, -1, 2]
    points['6x-1'] = [6, -1, -10]

    points['-6x0'] = [-6, 0, 72.4]
    points['-5x0'] = [-5, 0, 65.7]
    points['-4x0'] = [-4, 0, 30]  # keep
    points['-3x0'] = [-3, 0, 30]  #keep
    points['-2x0'] = [-2, 0, 20]  # road to the keep (north border of the lake)
    points['-1x0'] = [-1, 0, 13.2]  # town
    points['0x0'] = [0, 0, 12.8]  # town
    points['1x0'] = [1, 0, 12.5]  # town
    points['2x0'] = [2, 0, 12]
    points['3x0'] = [3, 0, 10.5]
    points['4x0'] = [4, 0, 5]
    points['5x0'] = [5, 0, 0]
    points['6x0'] = [6, 0, -15]

    points['-6x1'] = [-6, 1, 75]
    points['-5x1'] = [-5, 1, 67.5]
    points['-4x1'] = [-4, 1, 15.2]
    points['-3x1'] = [-3, 1, 14.6]
    points['-2x1'] = [-2, 1, 14.5]
    points['-1x1'] = [-1, 1, 13.1]  # town
    points['0x1'] = [0, 1, 12.9]  # town
    points['1x1'] = [1, 1, 12.7]  # town
    points['2x1'] = [2, 1, 12.5]
    points['3x1'] = [3, 1, 10.2]
    points['4x1'] = [4, 1, 8.9]
    points['5x1'] = [5, 1, 4]
    points['6x1'] = [6, 1, -9]

    points['-6x2'] = [-6, 2, 77]
    points['-5x2'] = [-5, 2, 68]
    points['-4x2'] = [-4, 2, 13]  # mine road
    points['-3x2'] = [-3, 2, 55]
    points['-2x2'] = [-2, 2, 57.6]
    points['-1x2'] = [-1, 2, 14]
    points['0x2'] = [0, 2, 20]
    points['1x2'] = [1, 2, 14]
    points['2x2'] = [2, 2, 22.4]
    points['3x2'] = [3, 2, 18]
    points['4x2'] = [4, 2, 10.7]
    points['5x2'] = [5, 2, 6.4]
    points['6x2'] = [6, 2, -4]

    points['-6x3'] = [-6, 3, 81.2]
    points['-5x3'] = [-5, 3, 66]
    points['-4x3'] = [-4, 3, 13.2]  # mine road
    points['-3x3'] = [-3, 3, 56.4]
    points['-2x3'] = [-2, 3, 60]
    points['-1x3'] = [-1, 3, 51.1]
    points['0x3'] = [0, 3, 19]
    points['1x3'] = [1, 3, 25.6]
    points['2x3'] = [2, 3, 10]
    points['3x3'] = [3, 3, 19.5]
    points['4x3'] = [4, 3, 11.3]
    points['5x3'] = [5, 3, 7]
    points['6x3'] = [6, 3, 0]

    points['-6x4'] = [-6, 4, 85]
    points['-5x4'] = [-5, 4, 66.7]
    points['-4x4'] = [-4, 4, 14.2]  # mine road
    points['-3x4'] = [-3, 4, 56.4]
    points['-2x4'] = [-2, 4, 57]
    points['-1x4'] = [-1, 4, 52.5]
    points['0x4'] = [0, 4, 31]
    points['1x4'] = [1, 4, 15]
    points['2x4'] = [2, 4, 26.2]
    points['3x4'] = [3, 4, 22.7]
    points['4x4'] = [4, 4, 15]
    points['5x4'] = [5, 4, 10]
    points['6x4'] = [6, 4, -3.5]

    points['-6x5'] = [-6, 5, 91]
    points['-5x5'] = [-5, 5, 68]
    points['-4x5'] = [-4, 5, 65.5]
    points['-3x5'] = [-3, 5, 62.2]
    points['-2x5'] = [-2, 5, 58]
    points['-1x5'] = [-1, 5, 54]
    points['0x5'] = [0, 5, 50]
    points['1x5'] = [1, 5, 44.4]
    points['2x5'] = [2, 5, 45]
    points['3x5'] = [3, 5, 38.6]
    points['4x5'] = [4, 5, 12]
    points['5x5'] = [5, 5, 0]
    points['6x5'] = [6, 5, -8.7]

    points['-6x6'] = [-6, 6, 100]
    points['-5x6'] = [-5, 6, 85]
    points['-4x6'] = [-4, 6, 75]
    points['-3x6'] = [-3, 6, 70]
    points['-2x6'] = [-2, 6, 65]
    points['-1x6'] = [-1, 6, 66.7]
    points['0x6'] = [0, 6, 65]
    points['1x6'] = [1, 6, 64.3]
    points['2x6'] = [2, 6, 59.7]
    points['3x6'] = [3, 6, 55.3]
    points['4x6'] = [4, 6, 46.7]
    points['5x6'] = [5, 6, 12]
    points['6x6'] = [6, 6, -5.8]

    m.set(world.id, terrain={'points': points}, name="moraf")

    # a wall around the world

    m.make('boundary',
           type='boundary',
           xyz=(-384, -384, town_height),
           bbox=[2, 514, 256])
    m.make('boundary',
           type='boundary',
           xyz=(-384, -384, town_height),
           bbox=[514, 2, 256])
    m.make('boundary',
           type='boundary',
           xyz=(-384, 384, town_height),
           bbox=[514, 2, 256])
    m.make('boundary',
           type='boundary',
           xyz=(384, -384, town_height),
           bbox=[2, 514, 256])

    # paths

    statue_path_area = {
        'points': [[5, 0], [4.33, 2.5], [2.5, 4.33], [0, 5], [-2.5, 4.33],
                   [-4.33, 2.5], [-5, 0], [-4.33, -2.5], [-2.5, -4.33],
                   [0, -5.0], [2.5, -4.33], [4.33, -2.5], [5.0, 0]],
        'layer':
        7
    }
    m.make('statue path',
           type='path',
           xyz=(0, 0, town_height),
           area=statue_path_area,
           bbox=[-5, -5, 0, 5, 5, 1])

    town_path_area = {
        'points': [[50, 0], [43.30, 25], [25, 43.30], [0, 50], [-25, 43.30],
                   [-43.30, 25], [-50, 0], [-43.30, -25], [-25, -43.30],
                   [0, -50], [25, -43.30], [43.30, -25], [50, -0.01],
                   [60, -0.01], [51.96, -30], [30, -51.96], [0, -60],
                   [-30, -51.96], [-51.96, -30], [-60, 0], [-51.96, 30],
                   [-30, 51.96], [0, 60], [30, 51.96], [51.96, 30], [60, 0]],
        'layer':
        7
    }
    m.make('town path',
           type='path',
           xyz=(0, 0, town_height),
           area=town_path_area,
           bbox=[-38, -62, 0, 169, 154, 1])

    m.make('fir', type='fir', xyz=(0, 0, town_height))

    m.make('fir', type='fir', xyz=(64, 0, 10))
    m.make('fir', type='fir', xyz=(128, 0, 10))
    m.make('fir', type='fir', xyz=(192, 0, 10))
    m.make('fir', type='fir', xyz=(256, 0, 10))
    m.make('fir', type='fir', xyz=(320, 0, 10))

    # animals

    chickens = []
    xbase = 0
    ybase = 0
    for i in range(0, 10):
        xpos = xbase + uniform(-10, 10)
        ypos = ybase + uniform(-10, 10)
        d = m.make('chicken', type='chicken', xyz=(xpos, ypos, town_height))
        chickens.append(d)
    m.learn(chickens, chicken_goals)

    dog = m.make('toby', type='dog', xyz=(5, 5, town_height))
    m.learn(dog, dog_goals)
    m.know(dog, tr_knowledge)
    m.tell_importance(dog, il.hunt, '>', il.patrol)
    m.tell_importance(dog, il.hunt, '>', il.forage)
    m.tell_importance(dog, il.forage, '>', il.patrol)

    # TEST: calling sub.methods
    create_town_buildings(mapeditor)
Example #27
0
if ('simulation' in sys.argv): modules.append('simulation')
if ('analysis' in sys.argv): modules.append('analysis')
if ('editor' in sys.argv): modules.append('editor')
if ('speed' in sys.argv): modules.append('speed')

ut.logo()

if len(modules) == 0:
    modules = (input(
        ' Please enter desired modules to run (SIMULATION and/or ANALYSIS or EDITOR): '
    ).lower()).split()

if ('-input' in sys.argv):
    input_file_name = current_dir + '/' + sys.argv[sys.argv.index('-input') +
                                                   1]
else:
    input_file_name = False

if ('simulation' in modules):
    from simulation import simulation
    simulation(current_dir, input_file_name)
if ('analysis' in modules):
    from analysis import analysis
    analysis(current_dir, input_file_name)
if ('editor' in modules):
    from editor import editor
    editor(current_dir, input_file_name)
if ('speed' in modules):
    from simulation import speed_test
    speed_test(current_dir, input_file_name)
Example #28
0
#! /usr/bin/env python

import sys
import os


try:
    __file__
except NameError:
    pass
else:
    libdir = os.path.abspath(os.path.join(os.path.dirname(__file__), 'lib'))
    sys.path.insert(0, libdir)

import editor
editor.editor()
Example #29
0
 def initeditor(self):
     self.editor = editor.editor()
Example #30
0
    def setupUi(self, MainWindow):
        MainWindow.setObjectName(_fromUtf8("MainWindow"))
        MainWindow.resize(989, 449)
        MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", "Shot Manager", None, QtGui.QApplication.UnicodeUTF8))
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap(_fromUtf8(":/todo.svg")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        MainWindow.setWindowIcon(icon)
        MainWindow.setDocumentMode(False)
        self.centralwidget = QtGui.QWidget(MainWindow)
        self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
        self.verticalLayout_2 = QtGui.QVBoxLayout(self.centralwidget)
        self.verticalLayout_2.setMargin(3)
        self.verticalLayout_2.setObjectName(_fromUtf8("verticalLayout_2"))
        self.splitter = QtGui.QSplitter(self.centralwidget)
        self.splitter.setFrameShape(QtGui.QFrame.StyledPanel)
        self.splitter.setLineWidth(4)
        self.splitter.setOrientation(QtCore.Qt.Horizontal)
        self.splitter.setOpaqueResize(False)
        self.splitter.setHandleWidth(10)
        self.splitter.setChildrenCollapsible(True)
        self.splitter.setObjectName(_fromUtf8("splitter"))
        self.widget = QtGui.QWidget(self.splitter)
        self.widget.setObjectName(_fromUtf8("widget"))
        self.verticalLayout_3 = QtGui.QVBoxLayout(self.widget)
        self.verticalLayout_3.setMargin(2)
        self.verticalLayout_3.setMargin(0)
        self.verticalLayout_3.setObjectName(_fromUtf8("verticalLayout_3"))
        self.frame = QtGui.QFrame(self.widget)
        self.frame.setMaximumSize(QtCore.QSize(16777215, 30))
        self.frame.setFrameShape(QtGui.QFrame.Panel)
        self.frame.setFrameShadow(QtGui.QFrame.Raised)
        self.frame.setLineWidth(1)
        self.frame.setMidLineWidth(1)
        self.frame.setObjectName(_fromUtf8("frame"))
        self.verticalLayout_4 = QtGui.QVBoxLayout(self.frame)
        self.verticalLayout_4.setSpacing(1)
        self.verticalLayout_4.setMargin(1)
        self.verticalLayout_4.setObjectName(_fromUtf8("verticalLayout_4"))
        self.gridLayout = QtGui.QGridLayout()
        self.gridLayout.setSizeConstraint(QtGui.QLayout.SetDefaultConstraint)
        self.gridLayout.setVerticalSpacing(5)
        self.gridLayout.setObjectName(_fromUtf8("gridLayout"))
        self.ProjectComboBox = QtGui.QComboBox(self.frame)
        self.ProjectComboBox.setEditable(False)
        self.ProjectComboBox.setFrame(False)
        self.ProjectComboBox.setObjectName(_fromUtf8("ProjectComboBox"))
        self.gridLayout.addWidget(self.ProjectComboBox, 0, 1, 1, 1)
        self.SequComboBox = QtGui.QComboBox(self.frame)
        self.SequComboBox.setMaximumSize(QtCore.QSize(748, 16777215))
        self.SequComboBox.setObjectName(_fromUtf8("SequComboBox"))
        self.gridLayout.addWidget(self.SequComboBox, 0, 4, 1, 1)
        self.label = QtGui.QLabel(self.frame)
        self.label.setText(QtGui.QApplication.translate("MainWindow", "Select Project", None, QtGui.QApplication.UnicodeUTF8))
        self.label.setObjectName(_fromUtf8("label"))
        self.gridLayout.addWidget(self.label, 0, 0, 1, 1)
        self.label_2 = QtGui.QLabel(self.frame)
        self.label_2.setText(QtGui.QApplication.translate("MainWindow", "Select Sequence", None, QtGui.QApplication.UnicodeUTF8))
        self.label_2.setObjectName(_fromUtf8("label_2"))
        self.gridLayout.addWidget(self.label_2, 0, 3, 1, 1)
        self.frame_2 = QtGui.QFrame(self.frame)
        self.frame_2.setFrameShape(QtGui.QFrame.StyledPanel)
        self.frame_2.setFrameShadow(QtGui.QFrame.Raised)
        self.frame_2.setObjectName(_fromUtf8("frame_2"))
        self.gridLayout.addWidget(self.frame_2, 0, 5, 1, 1)
        spacerItem = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)
        self.gridLayout.addItem(spacerItem, 0, 2, 1, 1)
        self.gridLayout.setColumnMinimumWidth(1, 50)
        self.gridLayout.setColumnMinimumWidth(4, 50)
        self.gridLayout.setColumnMinimumWidth(5, 300)
        self.verticalLayout_4.addLayout(self.gridLayout)
        self.verticalLayout_3.addWidget(self.frame)
        self.list = QtGui.QTreeWidget(self.widget)
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.list.sizePolicy().hasHeightForWidth())
        self.list.setSizePolicy(sizePolicy)
        self.list.setMinimumSize(QtCore.QSize(400, 0))
        self.list.setFrameShape(QtGui.QFrame.StyledPanel)
        self.list.setFrameShadow(QtGui.QFrame.Plain)
        self.list.setLineWidth(0)
        self.list.setAutoScroll(False)
        self.list.setTabKeyNavigation(False)
        self.list.setAlternatingRowColors(True)
        self.list.setRootIsDecorated(True)
        self.list.setUniformRowHeights(True)
        self.list.setAnimated(True)
        self.list.setAllColumnsShowFocus(False)
        self.list.setWordWrap(True)
        self.list.setExpandsOnDoubleClick(False)
        self.list.setObjectName(_fromUtf8("list"))
        self.list.headerItem().setText(0, QtGui.QApplication.translate("MainWindow", "Shot", None, QtGui.QApplication.UnicodeUTF8))
        self.list.headerItem().setText(1, QtGui.QApplication.translate("MainWindow", "In", None, QtGui.QApplication.UnicodeUTF8))
        self.list.headerItem().setText(2, QtGui.QApplication.translate("MainWindow", "Out", None, QtGui.QApplication.UnicodeUTF8))
        self.list.headerItem().setText(3, QtGui.QApplication.translate("MainWindow", "CutIn", None, QtGui.QApplication.UnicodeUTF8))
        self.list.headerItem().setText(4, QtGui.QApplication.translate("MainWindow", "CutOut", None, QtGui.QApplication.UnicodeUTF8))
        self.list.headerItem().setText(5, QtGui.QApplication.translate("MainWindow", "Status", None, QtGui.QApplication.UnicodeUTF8))
        self.list.header().setCascadingSectionResizes(False)
        self.list.header().setDefaultSectionSize(50)
        self.list.header().setHighlightSections(True)
        self.list.header().setMinimumSectionSize(40)
        self.list.header().setStretchLastSection(True)
        self.verticalLayout_3.addWidget(self.list)
        self.editor = editor(self.splitter)
        self.editor.setEnabled(False)
        self.editor.setMaximumSize(QtCore.QSize(500, 16777215))
        self.editor.setObjectName(_fromUtf8("editor"))
        self.verticalLayout_2.addWidget(self.splitter)
        MainWindow.setCentralWidget(self.centralwidget)
        self.toolBar = QtGui.QToolBar(MainWindow)
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Minimum)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.toolBar.sizePolicy().hasHeightForWidth())
        self.toolBar.setSizePolicy(sizePolicy)
        self.toolBar.setMinimumSize(QtCore.QSize(0, 30))
        self.toolBar.setWindowTitle(QtGui.QApplication.translate("MainWindow", "toolBar", None, QtGui.QApplication.UnicodeUTF8))
        self.toolBar.setObjectName(_fromUtf8("toolBar"))
        MainWindow.addToolBar(QtCore.Qt.TopToolBarArea, self.toolBar)
        self.actionDelete_Task = QtGui.QAction(MainWindow)
        self.actionDelete_Task.setEnabled(False)
        self.actionDelete_Task.setText(QtGui.QApplication.translate("MainWindow", "Delete Shot", None, QtGui.QApplication.UnicodeUTF8))
        self.actionDelete_Task.setShortcut(QtGui.QApplication.translate("MainWindow", "Del", None, QtGui.QApplication.UnicodeUTF8))
        self.actionDelete_Task.setObjectName(_fromUtf8("actionDelete_Task"))
        self.actionNew_Task = QtGui.QAction(MainWindow)
        self.actionNew_Task.setEnabled(False)
        self.actionNew_Task.setText(QtGui.QApplication.translate("MainWindow", "New Shot", None, QtGui.QApplication.UnicodeUTF8))
        self.actionNew_Task.setObjectName(_fromUtf8("actionNew_Task"))
        self.actionUpdate_database = QtGui.QAction(MainWindow)
        self.actionUpdate_database.setEnabled(False)
        self.actionUpdate_database.setText(QtGui.QApplication.translate("MainWindow", "Update Database", None, QtGui.QApplication.UnicodeUTF8))
        self.actionUpdate_database.setObjectName(_fromUtf8("actionUpdate_database"))
        self.actionEdit = QtGui.QAction(MainWindow)
        self.actionEdit.setCheckable(True)
        self.actionEdit.setText(QtGui.QApplication.translate("MainWindow", "Edit", None, QtGui.QApplication.UnicodeUTF8))
        self.actionEdit.setObjectName(_fromUtf8("actionEdit"))
        self.actionNew_Sequence = QtGui.QAction(MainWindow)
        self.actionNew_Sequence.setEnabled(False)
        self.actionNew_Sequence.setText(QtGui.QApplication.translate("MainWindow", "New Sequence", None, QtGui.QApplication.UnicodeUTF8))
        self.actionNew_Sequence.setObjectName(_fromUtf8("actionNew_Sequence"))
        self.actionSet_project = QtGui.QAction(MainWindow)
        self.actionSet_project.setText(QtGui.QApplication.translate("MainWindow", "set Environment", None, QtGui.QApplication.UnicodeUTF8))
        self.actionSet_project.setObjectName(_fromUtf8("actionSet_project"))
        self.toolBar.addSeparator()
        self.toolBar.addAction(self.actionSet_project)
        self.toolBar.addAction(self.actionEdit)
        self.toolBar.addSeparator()
        self.toolBar.addSeparator()
        self.toolBar.addAction(self.actionNew_Sequence)
        self.toolBar.addAction(self.actionNew_Task)
        self.toolBar.addAction(self.actionUpdate_database)
        self.toolBar.addAction(self.actionDelete_Task)
        self.toolBar.addSeparator()

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)
Example #31
0
 def edit(self, *args, **kwargs):
     from editor import editor
     return editor(self, *args, **kwargs)
def default(mapeditor):
#   general things

    m=editor(mapeditor)

    world=m.look()

    points = { }

# terrain
    points['-6x-6'] = [-6, -6, 65]
    points['-5x-6'] = [-5, -6, 60]
    points['-4x-6'] = [-4, -6, -2]
    points['-3x-6'] = [-3, -6, -3]
    points['-2x-6'] = [-2, -6, -4]
    points['-1x-6'] = [-1, -6, -6]
    points['0x-6'] = [0, -6, -7]
    points['1x-6'] = [1, -6, -8]
    points['2x-6'] = [2, -6, -9]
    points['3x-6'] = [3, -6, -10]
    points['4x-6'] = [4, -6, -12]
    points['5x-6'] = [5, -6, -14]
    points['6x-6'] = [6, -6, -20]

    points['-6x-5'] = [-6, -5, 65.4]
    points['-5x-5'] = [-5, -5, 62.1]
    points['-4x-5'] = [-4, -5, 4]
    points['-3x-5'] = [-3, -5, 3.9]
    points['-2x-5'] = [-2, -5, 3.7]
    points['-1x-5'] = [-1, -5, 3.8]
    points['0x-5'] = [0, -5, 3.6]
    points['1x-5'] = [1, -5, 3.2]
    points['2x-5'] = [2, -5, 2.5]
    points['3x-5'] = [3, -5, 1]
    points['4x-5'] = [4, -5, 0]
    points['5x-5'] = [5, -5, -3]
    points['6x-5'] = [6, -5, -5]

    points['-6x-4'] = [-6, -4, 67]
    points['-5x-4'] = [-5, -4, 61]
    points['-4x-4'] = [-4, -4, 5]
    points['-3x-4'] = [-3, -4, 4.9]
    points['-2x-4'] = [-2, -4, 4.7]
    points['-1x-4'] = [-1, -4, 4.8]
    points['0x-4'] = [0, -4, 4.6]
    points['1x-4'] = [1, -4, 4.2]
    points['2x-4'] = [2, -4, 3.5]
    points['3x-4'] = [3, -4, 2]
    points['4x-4'] = [4, -4, 1]
    points['5x-4'] = [5, -4, 0]
    points['6x-4'] = [6, -4, -5]

    points['-6x-3'] = [-6, -3, 69]
    points['-5x-3'] = [-5, -3, 65]
    points['-4x-3'] = [-4, -3, 6]
    points['-3x-3'] = [-3, -3, 5.7]
    points['-2x-3'] = [-2, -3, 5.6]
    points['-1x-3'] = [-1, -3, 5.8]
    points['0x-3'] = [0, -3, 5.6]
    points['1x-3'] = [1, -3, 5.2]
    points['2x-3'] = [2, -3, 4.5]
    points['3x-3'] = [3, -3, 4.9]
    points['4x-3'] = [4, -3, 4.5]
    points['5x-3'] = [5, -3, 3]
    points['6x-3'] = [6, -3, 0]

    points['-6x-2'] = [-6, -2, 71]
    points['-5x-2'] = [-5, -2, 30] # keep
    points['-4x-2'] = [-4, -2, 30] # keep
    points['-3x-2'] = [-3, -2, 30] # keep
    points['-2x-2'] = [-2, -2, -16.8] # center of the lake
    points['-1x-2'] = [-1, -2, -3.8] # east side of the lake
    points['0x-2'] = [0, -2, 15.8] # east border of the lake
    points['1x-2'] = [1, -2, 13]
    points['2x-2'] = [2, -2, 10.5]
    points['3x-2'] = [3, -2, 7.9]
    points['4x-2'] = [4, -2, 6.5]
    points['5x-2'] = [5, -2, 5]
    points['6x-2'] = [6, -2, -4]

    points['-6x-1'] = [-6, -1, 70]
    points['-5x-1'] = [-5, -1, 64.6]
    points['-4x-1'] = [-4, -1, 30] # keep
    points['-3x-1'] = [-3, -1, 30] # keep
    points['-2x-1'] = [-2, -1, -2.8] # north part of the lake
    points['-1x-1'] = [-1, -1, 12.7] # town
    points['0x-1'] = [0, -1, 12.7] # town
    points['1x-1'] = [1, -1, 12.5] # town
    points['2x-1'] = [2, -1, 14.7]
    points['3x-1'] = [3, -1, 15.8]
    points['4x-1'] = [4, -1, 11]
    points['5x-1'] = [5, -1, 2]
    points['6x-1'] = [6, -1, -10]

    points['-6x0'] = [-6, 0, 72.4]
    points['-5x0'] = [-5, 0, 65.7]
    points['-4x0'] = [-4, 0, 30] # keep
    points['-3x0'] = [-3, 0, 30] #keep
    points['-2x0'] = [-2, 0, 20] # road to the keep (north border of the lake)
    points['-1x0'] = [-1, 0, 13.2] # town 
    points['0x0'] = [0, 0, 12.8] # town
    points['1x0'] = [1, 0, 12.5] # town
    points['2x0'] = [2, 0, 12]
    points['3x0'] = [3, 0, 10.5]
    points['4x0'] = [4, 0, 5]
    points['5x0'] = [5, 0, 0]
    points['6x0'] = [6, 0, -15]

    points['-6x1'] = [-6, 1, 75]
    points['-5x1'] = [-5, 1, 67.5]
    points['-4x1'] = [-4, 1, 15.2]
    points['-3x1'] = [-3, 1, 14.6]
    points['-2x1'] = [-2, 1, 14.5]
    points['-1x1'] = [-1, 1, 13.1] # town
    points['0x1'] = [0, 1, 12.9] # town
    points['1x1'] = [1, 1, 12.7] # town
    points['2x1'] = [2, 1, 12.5]
    points['3x1'] = [3, 1, 10.2]
    points['4x1'] = [4, 1, 8.9]
    points['5x1'] = [5, 1, 4]
    points['6x1'] = [6, 1, -9]

    points['-6x2'] = [-6, 2, 77]
    points['-5x2'] = [-5, 2, 68]
    points['-4x2'] = [-4, 2, 13] # mine road
    points['-3x2'] = [-3, 2, 55]
    points['-2x2'] = [-2, 2, 57.6]
    points['-1x2'] = [-1, 2, 14]
    points['0x2'] = [0, 2, 20]
    points['1x2'] = [1, 2, 14]
    points['2x2'] = [2, 2, 22.4]
    points['3x2'] = [3, 2, 18]
    points['4x2'] = [4, 2, 10.7]
    points['5x2'] = [5, 2, 6.4]
    points['6x2'] = [6, 2, -4]

    points['-6x3'] = [-6, 3, 81.2]
    points['-5x3'] = [-5, 3, 66]
    points['-4x3'] = [-4, 3, 13.2] # mine road
    points['-3x3'] = [-3, 3, 56.4]
    points['-2x3'] = [-2, 3, 60]
    points['-1x3'] = [-1, 3, 51.1]
    points['0x3'] = [0, 3, 19]
    points['1x3'] = [1, 3, 25.6]
    points['2x3'] = [2, 3, 10]
    points['3x3'] = [3, 3, 19.5]
    points['4x3'] = [4, 3, 11.3]
    points['5x3'] = [5, 3, 7]
    points['6x3'] = [6, 3, 0]

    points['-6x4'] = [-6, 4, 85]
    points['-5x4'] = [-5, 4, 66.7]
    points['-4x4'] = [-4, 4, 14.2] # mine road
    points['-3x4'] = [-3, 4, 56.4]
    points['-2x4'] = [-2, 4, 57]
    points['-1x4'] = [-1, 4, 52.5]
    points['0x4'] = [0, 4, 31]
    points['1x4'] = [1, 4, 15]
    points['2x4'] = [2, 4, 26.2]
    points['3x4'] = [3, 4, 22.7]
    points['4x4'] = [4, 4, 15]
    points['5x4'] = [5, 4, 10]
    points['6x4'] = [6, 4, -3.5]

    points['-6x5'] = [-6, 5, 91]
    points['-5x5'] = [-5, 5, 68]
    points['-4x5'] = [-4, 5, 65.5]
    points['-3x5'] = [-3, 5, 62.2]
    points['-2x5'] = [-2, 5, 58]
    points['-1x5'] = [-1, 5, 54]
    points['0x5'] = [0, 5, 50]
    points['1x5'] = [1, 5, 44.4]
    points['2x5'] = [2, 5, 45]
    points['3x5'] = [3, 5, 38.6]
    points['4x5'] = [4, 5, 12]
    points['5x5'] = [5, 5, 0]
    points['6x5'] = [6, 5, -8.7]

    points['-6x6'] = [-6, 6, 100]
    points['-5x6'] = [-5, 6, 85]
    points['-4x6'] = [-4, 6, 75]
    points['-3x6'] = [-3, 6, 70]
    points['-2x6'] = [-2, 6, 65]
    points['-1x6'] = [-1, 6, 66.7]
    points['0x6'] = [0, 6, 65]
    points['1x6'] = [1, 6, 64.3]
    points['2x6'] = [2, 6, 59.7]
    points['3x6'] = [3, 6, 55.3]
    points['4x6'] = [4, 6, 46.7]
    points['5x6'] = [5, 6, 12]
    points['6x6'] = [6, 6, -5.8]

    m.set(world.id, terrain={'points' : points}, name="moraf")

# a wall around the world

    m.make('boundary',type='boundary',xyz=(-384,-384,town_height),bbox=[2,514,256])
    m.make('boundary',type='boundary',xyz=(-384,-384,town_height),bbox=[514,2,256])
    m.make('boundary',type='boundary',xyz=(-384, 384,town_height),bbox=[514,2,256])
    m.make('boundary',type='boundary',xyz=(384,-384,town_height),bbox=[2,514,256])

# paths

    statue_path_area={'points' : [ [5,0], [4.33,2.5], [2.5,4.33], [0,5], [-2.5, 4.33], [-4.33,2.5], [-5,0], [-4.33,-2.5], [-2.5,-4.33], [0,-5.0], [2.5,-4.33], [4.33,-2.5], [5.0,0] ], 'layer' : 7}
    m.make('statue path',type='path',xyz=(0, 0, town_height), area=statue_path_area,bbox=[-5,-5,0,5,5,1])

    town_path_area={'points' : [ [50,0], [43.30,25], [25,43.30], [0,50], [-25, 43.30], [-43.30,25], [-50,0], [-43.30,-25], [-25, -43.30], [0, -50], [25,-43.30], [43.30,-25], [50,-0.01], [60,-0.01], [51.96,-30], [30,-51.96], [0, -60], [-30,-51.96], [-51.96,-30], [-60,0], [-51.96,30], [-30,51.96], [0,60], [30,51.96], [51.96,30], [60,0] ], 'layer' : 7}
    m.make('town path',type='path',xyz=(0, 0, town_height), area=town_path_area,bbox=[-38,-62,0,169,154,1])

    m.make('fir',type='fir',xyz=(0,0,town_height))

    m.make('fir',type='fir',xyz=(64,0,10))
    m.make('fir',type='fir',xyz=(128,0,10))
    m.make('fir',type='fir',xyz=(192,0,10))
    m.make('fir',type='fir',xyz=(256,0,10))
    m.make('fir',type='fir',xyz=(320,0,10))

# animals

    chickens=[]
    xbase = 0;
    ybase = 0;
    for i in range(0,10):
        xpos = xbase + uniform(-10,10)
        ypos = ybase + uniform(-10,10)
        d=m.make('chicken', type='chicken', xyz=(xpos, ypos, town_height))
        chickens.append(d)
    m.learn(chickens,chicken_goals)

    dog = m.make('toby',type='dog',xyz=(5,5,town_height))
    m.learn(dog,dog_goals)
    m.know(dog,tr_knowledge)
    m.tell_importance(dog,il.hunt,'>',il.patrol)
    m.tell_importance(dog,il.hunt,'>',il.forage)
    m.tell_importance(dog,il.forage,'>',il.patrol)

# TEST: calling sub.methods
    create_town_buildings(mapeditor)
Example #33
0
import os
import sys

cwd = os.getcwd()
sys.path.append( cwd + "/lib" )

import dbclient
import crypto
import editor


count = 1
def test( test, result ) :
    global count
    print( "Test %d : \t%s\t\t - %s" %( count, test, "passed" if result else "failed" ) )
    count = count + 1

dbc = dbclient.dbclient( os.getcwd() + "/my_test_database.db" )
cryptographer = crypto.crypto( "baby steps" )
text = "Mary had a little lamb"
cyphertext = cryptographer.encrypt( text )
edit = editor.editor()

test( "database connectivity test", dbc != None )
test( "encryption test", text == cryptographer.decrypt( cyphertext ) )
test( "editor test", "abc\ndef\n" == edit.edit( "abc" ) )
Example #34
0
def editor(): # tool editor function

    from ascci import rabbit
    from editor import editor
    from keydetect import keydetect
    from lwsystem import osuser
    from creds import creds
    from menu import MENU

    liste = []
    os.system("clear")
    print ("translate a ducky script keyboard keys into a keyboard keys adapted to the web interface of P4wnP1 A.L.O.A.\n\nput a ducky script keyboard keys and press enter to add another ducky script,\npress" +"\x1b[0;31m" + " CTRL c " + "\x1b[0m" + "when you are finish\n\nESC, GUI r, ENTER, STRING, REM, ALT, CTRL, TAB, LEFT, RIGHT, UP, DOWN, F1, F2, DELETE, CAPSLOCK, NUMLOCK, HOME, END, BREAK \n") #\n\n========================\npress ENTER for continue\n========================\n")

    while 1== 1:
        try:
	    liste.append(raw_input("\x1b[0m"+""))
        except KeyboardInterrupt:
            print("\n")
            for l in liste:
                if l == "GUI r": 		# GUI r
                    print('press(\"GUI r\")')	# press("GUI r")

                elif l[:3] == "REM":		# REM
                    print "//"+str(l[3:]) 	# //

	        elif  l[:5] == "DELAY":			# DELAY
	    	    print "delay("+str(l[6:])+str(")")  # delay()

	        elif l[:6] == "STRING":			  	# STRING
		    print "type(\""+str(l[7:])+str("\")") 	# type("")

	        elif l == "ENTER":		# ENTER
		    print "press(\"ENTER\")"	# type("\n") or press("ENTER")

                elif l == "SHIFT":		# SHIFT
                    print "press(\"SHIFT\")"	# press("SHIFT")

	        elif l == "ALT":		# ALT
	       	    print "press(\"ALT\")"	# press("ALT")

                elif l == "CAPSLOCK":			# CAPSLOCK
                    print "press(\"CAPSLOCK\")"		# press("CAPSLOCK")

                elif l == "NUMLOCK":		# NUMLOCK
                    print "press(\"NUMLOCK\")"	# press("NUMLOCK")

                elif l == "HOME":		# HOME
                    print "press(\"HOME\")"	# press("HOME")

                elif l == "END":	# END
                    print "press(\"END\")"	# press("END")

	        elif l == "CTRL":		# CTRL
	       	    print "press(\"CTRL\")"	# press("CTRL")

                elif l == "ESC": 		# ESC or ESCAPE
                    print "press(\"ESC\")"	# press("ESC")

                elif l == "ESCAPE":                # ESC or ESCAPE
                    print "press(\"ESC\")"      # press("ESC")

                elif l == "TAB":		# TAB
                    print "press(\"TAB\")"	# press("TAB")

                elif l == "BREAK":		# BREAK
                    print "press(\"BREAK\")"	# press("BREAK")

		elif l == "DELETE":		# DELETE
		    print "press(\"DELETE\")"	# press("DELETE")

	        elif l == "UP":		 	# UP
		    print "press(\"UP\")"	#press("UP")

	        elif l == "UPARROW":		# UPARROW
		    print "press(\"UP\")"	# press("UP")

	        elif l == "DOWN":		#DOWN
		    print "press(\"DOWN\")"	#press("DOWN")

                elif l == "DOWNARROW":		# DOWNARROW
                    print "press(\"DOWN\")"	# press("DOWN")

                elif l == "RIGHT":		# RIGHT
                    print "press(\"RIGHT\")"	# press("RIGHT")

                elif l == "RIGHTARROW":		# RIGHTARROW
                    print "press(\"RIGHT\")"	# press("RIGHT")

                elif l == "LEFTARROW": 		# LEFTARROW
                    print "press(\"LEFT\")"	# press("LEFT")

                elif l == "LEFT":          	# LEFT
                    print "press(\"LEFT\")"     # press("LEFT")

                elif l == "F1":			# F1
                    print "press(\"F1\")"	# press("F1")

                elif l == "F2":			# F2
                    print "press(\"F2\")"

                elif l == "F3":			# F3
                    print "press(\"F3\")"

                elif l == "F4":			# F4
                    print "press(\"F4\")"

                elif l == "F5":			# F5
                    print "press(\"F5\")"

                elif l == "F6":			# F6
                    print "press(\"F6\")"

                elif l == "F7":			# F7
                    print "press(\"F7\")"

                elif l == "F8":			# F8
                    print "press(\"F8\")"

                elif l == "F9":			# F9
                    print "press(\"F9\")"

                elif l == "F10":		# F10
                    print "press(\"F10\")"

                elif l == "F11":		# F11
                    print "press(\"F11\")"

                elif l == "F12":		# F12
                    print "press(\"F12\")"

            menu = raw_input("\n\n\nWhat do you want now ?\n\n1) convert another\n2) back to menu\n3) exit\n\n> ") # second menu
	    if menu == "1":
		editor()

            elif menu == "2":
		os.system("clear")
		MENU()
	    elif menu == "3":
		rabbit()
		exit()
            break
Example #35
0
    def setupUi(self, MainWindow):
        MainWindow.setObjectName(_fromUtf8("MainWindow"))
        MainWindow.resize(340, 464)
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap(_fromUtf8(":/todo.svg")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        MainWindow.setWindowIcon(icon)
        self.centralwidget = QtGui.QWidget(MainWindow)
        self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
        self.verticalLayout = QtGui.QVBoxLayout(self.centralwidget)
        self.verticalLayout.setObjectName(_fromUtf8("verticalLayout"))
        self.splitter = QtGui.QSplitter(self.centralwidget)
        self.splitter.setOrientation(QtCore.Qt.Vertical)
        self.splitter.setObjectName(_fromUtf8("splitter"))
        self.list = QtGui.QTreeWidget(self.splitter)
        self.list.setAlternatingRowColors(True)
        self.list.setRootIsDecorated(False)
        self.list.setUniformRowHeights(True)
        self.list.setAllColumnsShowFocus(True)
        self.list.setObjectName(_fromUtf8("list"))
        self.editor = editor(self.splitter)
        self.editor.setEnabled(True)
        self.editor.setObjectName(_fromUtf8("editor"))
        self.verticalLayout.addWidget(self.splitter)
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtGui.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 340, 27))
        self.menubar.setObjectName(_fromUtf8("menubar"))
        self.menuTask = QtGui.QMenu(self.menubar)
        self.menuTask.setObjectName(_fromUtf8("menuTask"))
        MainWindow.setMenuBar(self.menubar)
        self.toolBar = QtGui.QToolBar(MainWindow)
        self.toolBar.setObjectName(_fromUtf8("toolBar"))
        MainWindow.addToolBar(QtCore.Qt.TopToolBarArea, self.toolBar)
        self.actionDelete_Task = QtGui.QAction(MainWindow)
        self.actionDelete_Task.setEnabled(False)
        icon1 = QtGui.QIcon()
        icon1.addPixmap(QtGui.QPixmap(_fromUtf8(":/delete.svg")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.actionDelete_Task.setIcon(icon1)
        self.actionDelete_Task.setObjectName(_fromUtf8("actionDelete_Task"))
        self.actionNew_Task = QtGui.QAction(MainWindow)
        icon2 = QtGui.QIcon()
        icon2.addPixmap(QtGui.QPixmap(_fromUtf8(":/filenew.svg")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.actionNew_Task.setIcon(icon2)
        self.actionNew_Task.setObjectName(_fromUtf8("actionNew_Task"))
        self.actionEdit_Task = QtGui.QAction(MainWindow)
        self.actionEdit_Task.setChecked(False)
        self.actionEdit_Task.setEnabled(False)
        icon3 = QtGui.QIcon()
        icon3.addPixmap(QtGui.QPixmap(_fromUtf8(":/edit.svg")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.actionEdit_Task.setIcon(icon3)
        self.actionEdit_Task.setObjectName(_fromUtf8("actionEdit_Task"))
        self.menuTask.addAction(self.actionNew_Task)
        self.menuTask.addAction(self.actionEdit_Task)
        self.menuTask.addSeparator()
        self.menuTask.addAction(self.actionDelete_Task)
        self.menubar.addAction(self.menuTask.menuAction())
        self.toolBar.addAction(self.actionNew_Task)
        self.toolBar.addAction(self.actionEdit_Task)
        self.toolBar.addSeparator()
        self.toolBar.addAction(self.actionDelete_Task)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)
Example #36
0
def editor(interrogation, 
            operation = None,
            denominator = False,
            sort_by = False,
            keep_stats = False,
            keep_top = False,
            just_totals = False,
            threshold = 'medium',
            just_entries = False,
            skip_entries = False,
            merge_entries = False,
            newname = 'combine',
            multiple_merge = False,
            just_subcorpora = False,
            skip_subcorpora = False,
            span_subcorpora = False,
            merge_subcorpora = False,
            new_subcorpus_name = False,
            replace_names = False,
            projection = False,
            remove_above_p = False,
            p = 0.05, 
            revert_year = True,
            print_info = True,
            spelling = False,
            selfdrop = True,
            calc_all = True,
            **kwargs
            ):
    """Edit results of interrogations, do keywording, sort, etc.

    ``just/skip_entries`` and ``just/skip_subcorpora`` can take a few different kinds of input:

    * str: treated as regular expression to match
    * list: 

      * of integers: indices to match
      * of strings: entries/subcorpora to match

    ``merge_entries`` and ``merge_subcorpora``, however, are best entered as dicts:

    ``{newname: criteria, newname2: criteria2}```

    where criteria is a string, list, etc.

    :param interrogation: Results to edit
    :type interrogation: pandas.core.frame.DataFrame
    
    :param operation: Kind of maths to do on inputted lists:

        '+', '-', '/', '*', '%': self explanatory
        'k': log likelihood (keywords)
        'a': get distance metric (for use with interrogator 'a' option)
        'd': get percent difference (alternative approach to keywording)

    :type operation: str
    
    :param denominator: List of results or totals.

        If list of results, for each entry in dataframe 1, locate
        entry with same name in dataframe 2, and do maths there
        if 'self', do all merging/keeping operations, then use
        edited interrogation as denominator

    :type denominator: pandas.core.series.Series/pandas.core.frame.DataFrame/dict/'self'
    
    :param sort_by: Calculate slope, stderr, r, p values, then sort by:

        increase: highest to lowest slope value
        decrease: lowest to highest slope value
        turbulent: most change in y axis values
        static: least change in y axis values
        total/most: largest number first
        infreq/least: smallest number first
        name: alphabetically
        
    :type sort_by: str

    :param keep_stats: Keep/drop stats values from dataframe after sorting
    :type keep_stats: bool
    
    :param keep_top: After sorting, remove all but the top *keep_top* results
    :type keep_top: int
    
    :param just_totals: Sum each column and work with sums
    :type just_totals: bool
    
    :param threshold: When using results list as denominator, drop values occurring
                        fewer than n times. If not keywording, you can use:
                            ``'high'``: denominator total / 2500
                            ``'medium'``: denominator total / 5000
                            ``'low'``: denominator total / 10000
                        Note: if keywording, there are smaller default thresholds
    :type threshold: int/bool
    :param just_entries: Keep matching entries
    :type just_entries: see above
    :param skip_entries: Skip matching entries
    :type skip_entries: see above
    :param merge_entries: Merge matching entries
    :type merge_entries: see above
    :param newname: New name for merged entries
    :type newname: str/'combine'
    :param just_subcorpora: Keep matching subcorpora
    :type just_subcorpora: see above
    :param skip_subcorpora: Skip matching subcorpora
    :type skip_subcorpora: see above
    :param span_subcorpora: If subcorpora are numerically named, span all from *int* to *int2*, inclusive
    :type span_subcorpora: tuple -- ``(int, int2)``
    :param merge_subcorpora: Merge matching subcorpora
    :type merge_subcorpora: see above
    :param new_subcorpus_name: Name for merged subcorpora
    :type new_subcorpus_name: str/``'combine'``

    :param replace_names: Edit result names and then merge duplicate names.
    :type replace_names: dict -- ``{criteria: replacement_text}``; str -- a regex to delete from names
    :param projection:         a  to multiply results in subcorpus by n
    :type projection: tuple -- ``(subcorpus_name, n)``
    :param remove_above_p: Delete any result over p
    :type remove_above_p: bool
    :param p:                  set the p value
    :type p: float
    
    :param revert_year:        when doing linear regression on years, turn annual subcorpora into 1, 2 ...
    :type revert_year: bool
    
    :param print_info: Print stuff to console showing what's being edited
    :type print_info: bool
    
    :param spelling: Convert/normalise spelling:
    :type spelling: str -- ``'US'``/``'UK'``
    
    :param selfdrop: When keywording, try to remove target corpus from reference corpus
    :type selfdrop: bool
    
    :param calc_all: When keywording, calculate words that appear in either corpus
    :type calc_all: bool

    :returns: corpkit.interrogation.Interrogation
    """

    # grab arguments, in case we get dict input and have to iterate
    locs = locals()

    import corpkit
    import pandas
    import signal
    import re
    import collections
    import pandas as pd
    import numpy as np

    from pandas import DataFrame, Series
    from time import localtime, strftime
    
    try:
        get_ipython().getoutput()
    except TypeError:
        have_ipython = True
    except NameError:
        have_ipython = False
    try:
        from IPython.display import display, clear_output
    except ImportError:
        pass

    return_conc = False
    from interrogation import Interrodict, Interrogation, Concordance
    if interrogation.__class__ == Interrodict:
        locs.pop('interrogation', None)
        from collections import OrderedDict
        outdict = OrderedDict()
        from editor import editor
        for i, (k, v) in enumerate(interrogation.items()):
            # only print the first time around
            if i != 0:
                locs['print_info'] = False
            # if df2 is also a dict, get the relevant entry
            if type(denominator) == dict or denominator.__class__ == Interrodict:
                #if sorted(set([i.lower() for i in list(dataframe1.keys())])) == \
                #   sorted(set([i.lower() for i in list(denominator.keys())])):
                #   locs['denominator'] = denominator[k]
                    if kwargs.get('denominator_totals'):
                        locs['denominator'] = denominator[k].totals
                    else:
                        locs['denominator'] = denominator[k].results

            outdict[k] = editor(v.results, **locs)
        if print_info:
            from time import localtime, strftime
            thetime = strftime("%H:%M:%S", localtime())
            print("\n%s: Finished! Output is a dictionary with keys:\n\n         '%s'\n" % (thetime, "'\n         '".join(sorted(outdict.keys()))))
        return Interrodict(outdict)

    elif type(interrogation) in [pandas.core.frame.DataFrame, pandas.core.series.Series]:
        dataframe1 = interrogation
    elif interrogation.__class__ == Interrogation:
        #if interrogation.__dict__.get('concordance', None) is not None:
        #    concordances = interrogation.concordance
        branch = kwargs.pop('branch', 'results')
        if branch.lower().startswith('r') :
            dataframe1 = interrogation.results
        elif branch.lower().startswith('t'):
            dataframe1 = interrogation.totals
        elif branch.lower().startswith('c'):
            dataframe1 = interrogation.concordance
            return_conc = True
        else:
            dataframe1 = interrogation.results
    
    elif interrogation.__class__ == Concordance or \
                        all(x in list(dataframe1.columns) for x in ['l', 'm', 'r']):
            return_conc = True
            dataframe1 = interrogation
    # hope for the best
    else:
        dataframe1 = interrogation

    the_time_started = strftime("%Y-%m-%d %H:%M:%S")

    pd.options.mode.chained_assignment = None
    pd.set_option('display.float_format', lambda x: '%.2f' % x)

    try:
        from tests import check_pytex
    except ImportError:
        from corpkit.tests import check_pytex
        
    if check_pytex():
        print_info = False

    def combiney(df, df2, operation = '%', threshold = 'medium', prinf = True):
        """mash df and df2 together in appropriate way"""
        totals = False
        # delete under threshold
        if just_totals:
            if using_totals:
                if not single_totals:
                    to_drop = list(df2[df2['Combined total'] < threshold].index)
                    df = df.drop([e for e in to_drop if e in list(df.index)])
                    if prinf:
                        to_show = []
                        [to_show.append(w) for w in to_drop[:5]]
                        if len(to_drop) > 10:
                            to_show.append('...')
                            [to_show.append(w) for w in to_drop[-5:]]
                        if len(to_drop) > 0:
                            print('Removing %d entries below threshold:\n    %s' % (len(to_drop), '\n    '.join(to_show)))
                        if len(to_drop) > 10:
                            print('... and %d more ... \n' % (len(to_drop) - len(to_show) + 1))
                        else:
                            print('')
                else:
                    denom = df2
        else:
            denom = list(df2)
        if single_totals:
            if operation == '%':
                totals = df.sum() * 100.0 / float(df.sum().sum())
                df = df * 100.0
                try:
                    df = df.div(denom, axis = 0)
                except ValueError:
                    from time import localtime, strftime
                    thetime = strftime("%H:%M:%S", localtime())
                    print('%s: cannot combine DataFrame 1 and 2: different shapes' % thetime)
            elif operation == '+':
                try:
                    df = df.add(denom, axis = 0)
                except ValueError:
                    from time import localtime, strftime
                    thetime = strftime("%H:%M:%S", localtime())
                    print('%s: cannot combine DataFrame 1 and 2: different shapes' % thetime)
            elif operation == '-':
                try:
                    df = df.sub(denom, axis = 0)
                except ValueError:
                    from time import localtime, strftime
                    thetime = strftime("%H:%M:%S", localtime())
                    print('%s: cannot combine DataFrame 1 and 2: different shapes' % thetime)
            elif operation == '*':
                totals = df.sum() * float(df.sum().sum())
                try:
                    df = df.mul(denom, axis = 0)
                except ValueError:
                    from time import localtime, strftime
                    thetime = strftime("%H:%M:%S", localtime())
                    print('%s: cannot combine DataFrame 1 and 2: different shapes' % thetime)
            elif operation == '/':
                try:
                    totals = df.sum() / float(df.sum().sum())
                    df = df.div(denom, axis = 0)
                except ValueError:
                    from time import localtime, strftime
                    thetime = strftime("%H:%M:%S", localtime())
                    print('%s: cannot combine DataFrame 1 and 2: different shapes' % thetime)
            elif operation == 'd':
                #df.ix['Combined total'] = df.sum()
                #to_drop = to_drop = list(df.T[df.T['Combined total'] < threshold].index)
                to_drop = [n for n in list(df.columns) if df[n].sum() < threshold]
                df = df.drop([e for e in to_drop if e in list(df.columns)], axis = 1)
                #df.drop('Combined total')
                if prinf:
                    to_show = []
                    [to_show.append(w) for w in to_drop[:5]]
                    if len(to_drop) > 10:
                        to_show.append('...')
                        [to_show.append(w) for w in to_drop[-5:]]
                    if len(to_drop) > 0:
                        print('Removing %d entries below threshold:\n    %s' % (len(to_drop), '\n    '.join(to_show)))
                    if len(to_drop) > 10:
                        print('... and %d more ... \n' % (len(to_drop) - len(to_show) + 1))
                    else:
                        print('')

                # get normalised num in target corpus
                norm_in_target = df.div(denom, axis = 0)
                # get normalised num in reference corpus, with or without selfdrop
                tot_in_ref = df.copy()
                for c in list(tot_in_ref.index):
                    if selfdrop:
                        tot_in_ref.ix[c] = df.sum() - tot_in_ref.ix[c]
                    else:
                        tot_in_ref.ix[c] = df.sum()
                norm_in_ref = tot_in_ref.div(df.sum().sum())
                df = (norm_in_target - norm_in_ref) / norm_in_ref * 100.0
                df = df.replace(float(-100.00), np.nan)

            elif operation == 'a':
                for c in [c for c in list(df.columns) if int(c) > 1]:
                    df[c] = df[c] * (1.0 / int(c))
                df = df.sum(axis = 1) / df2
            
            elif operation.startswith('c'):
                import warnings
                with warnings.catch_warnings():
                    warnings.simplefilter("ignore")
                    df = pandas.concat([df, df2], axis = 1)
            return df, totals

        elif not single_totals:
            if not operation.startswith('a'):
                # generate totals
                if operation == '%':
                    totals = df.sum() * 100.0 / float(df2.sum().sum())
                if operation == '*':
                    totals = df.sum() * float(df2.sum().sum())
                if operation == '/':
                    totals = df.sum() / float(df2.sum().sum())
                if operation.startswith('c'):
                    # add here the info that merging will not work 
                    # with identical colnames
                    import warnings
                    with warnings.catch_warnings():
                        warnings.simplefilter("ignore")
                        d = pd.concat([df.T, df2.T])
                        # make index nums
                        d = d.reset_index()
                        # sum and remove duplicates
                        d = d.groupby('index').sum()
                        dx = d.reset_index('index')
                        dx.index = list(dx['index'])
                        df = dx.drop('index', axis = 1).T

                for index, entry in enumerate(list(df.columns)):
                    #p.animate(index)
                    if operation == '%':
                        try:
                            df[entry] = df[entry] * 100.0 / df2[entry]
                        except:
                            continue
                        #df.drop(entry, axis = 1, inplace = True)
                        #df[entry] = maths_done
                    elif operation == '+':
                        try:
                            df[entry] = df[entry] + df2[entry]
                        except:
                            continue
                    elif operation == '-':
                        try:
                            df[entry] = df[entry] - df2[entry]
                        except:
                            continue
                    elif operation == '*':
                        try:
                            df[entry] = df[entry] * df2[entry]
                        except:
                            continue
                    elif operation == '/':
                        try:
                            df[entry] = df[entry] / df2[entry]
                        except:
                            continue

            else:
                for c in [c for c in list(df.columns) if int(c) > 1]:
                    df[c] = df[c] * (1.0 / int(c))
                df = df.sum(axis = 1) / df2.T.sum()

        return df, totals

    def parse_input(df, the_input):
        """turn whatever has been passed in into list of words that can 
           be used as pandas indices---maybe a bad way to go about it"""
        parsed_input = False
        import re
        if the_input == 'all':
            the_input = r'.*'
        if type(the_input) == int:
            try:
                the_input = str(the_input)
            except:
                pass
            the_input = [the_input]
        elif type(the_input) == str or type(the_input) == str:
            try:
                regex = re.compile(the_input)
                parsed_input = [w for w in list(df) if re.search(regex, w)]
                return parsed_input
            except:
                the_input = [the_input]
        if type(the_input) == list:
            if type(the_input[0]) == int:
                parsed_input = [word for index, word in enumerate(list(df)) if index in the_input]
            elif type(the_input[0]) == str or type(the_input[0]) == unicode:
                try:
                    parsed_input = [word for word in the_input if word in df.columns]
                except AttributeError: # if series
                    parsed_input = [word for word in the_input if word in df.index]
        return parsed_input

    def synonymise(df, pos = 'n'):
        """pass a df and a pos and convert df columns to most common synonyms"""
        from nltk.corpus import wordnet as wn
        #from dictionaries.taxonomies import taxonomies
        from collections import Counter
        fixed = []
        for w in list(df.columns):
            try:
                syns = []
                for syns in wn.synsets(w, pos = pos):
                    for w in syns:
                        synonyms.append(w)
                top_syn = Counter(syns).most_common(1)[0][0]
                fixed.append(top_syn)
            except:
                fixed.append(w)
        df.columns = fixed
        return df

    def convert_spell(df, convert_to = 'US', print_info = print_info):
        """turn dataframes into us/uk spelling"""
        from dictionaries.word_transforms import usa_convert
        if print_info:
            print('Converting spelling ... \n')
        if convert_to == 'UK':
            usa_convert = {v: k for k, v in list(usa_convert.items())}
        fixed = []
        for val in list(df.columns):
            try:
                fixed.append(usa_convert[val])
            except:
                fixed.append(val)
        df.columns = fixed
        return df

    def merge_duplicates(df, print_info = print_info):
        if print_info:
            print('Merging duplicate entries ... \n')
        # now we have to merge all duplicates
        for dup in df.columns.get_duplicates():
            #num_dupes = len(list(df[dup].columns))
            temp = df[dup].sum(axis = 1)
            #df = df.drop([dup for d in range(num_dupes)], axis = 1)
            df = df.drop(dup, axis = 1)
            df[dup] = temp
        return df

    def name_replacer(df, replace_names, print_info = print_info):
        """replace entry names and merge"""
        import re        
        # double or single nest if need be
        if type(replace_names) == str:
            replace_names = [(replace_names, '')]
        if type(replace_names) != dict:
            if type(replace_names[0]) == str:
                replace_names = [replace_names]
        if type(replace_names) == dict:
            replace_names = [(v, k) for k, v in list(replace_names.items())]
        for to_find, replacement in replace_names:
            if print_info:
                try:
                    print('Replacing "%s" with "%s" ...\n' % (to_find, replacement))
                except:
                    print('Deleting "%s" from entry names ...\n' % (to_find))
            to_find = re.compile(to_find)
            try:
                replacement = replacement
            except:
                replacement = ''
            df.columns = [re.sub(to_find, replacement, l) for l in list(df.columns)]
        df = merge_duplicates(df, print_info = False)
        return df

    def just_these_entries(df, parsed_input, prinf = True):
        entries = [word for word in list(df) if word not in parsed_input]
        if prinf:
            print('Keeping %d entries:\n    %s' % (len(parsed_input), '\n    '.join(parsed_input[:10])))
            if len(parsed_input) > 10:
                print('... and %d more ... \n' % (len(parsed_input) - 10))
            else:
                print('')
        df = df.drop(entries, axis = 1)
        return df

    def skip_these_entries(df, parsed_input, prinf = True):
        if prinf:     
            print('Skipping %d entries:\n    %s' % (len(parsed_input), '\n    '.join(parsed_input[:10])))
            if len(parsed_input) > 10:
                print('... and %d more ... \n' % (len(parsed_input) - 10))
            else:
                print('')
        df = df.drop(parsed_input, axis = 1)
        return df

    def newname_getter(df, parsed_input, newname = 'combine', prinf = True, merging_subcorpora = False):
        """makes appropriate name for merged entries"""
        if merging_subcorpora:
            if newname is False:
                newname = 'combine'
        if type(newname) == int:
            the_newname = list(df.columns)[newname]
        elif type(newname) == str:
            if newname == 'combine':
                if len(parsed_input) <= 3:
                    the_newname = '/'.join(parsed_input)
                elif len(parsed_input) > 3:
                    the_newname = '/'.join(parsed_input[:3]) + '...'
            else:
                the_newname = newname
        if newname is False:
            # revise this code
            import operator
            sumdict = {}
            for item in parsed_input:
                summed = sum(list(df[item]))
                sumdict[item] = summed
            the_newname = max(iter(sumdict.items()), key=operator.itemgetter(1))[0]
        if type(the_newname) != str:
            the_newname = str(the_newname, errors = 'ignore')
        return the_newname

    def merge_these_entries(df, parsed_input, the_newname, prinf = True, merging = 'entries'):
        # make new entry with sum of parsed input
        if len(parsed_input) == 0:
            import warnings
            warnings.warn('No %s could be automatically merged.\n' % merging)
        else:
            if prinf:
                print('Merging %d %s as "%s":\n    %s' % (len(parsed_input), merging, the_newname, '\n    '.join(parsed_input[:10])))
                if len(parsed_input) > 10:
                    print('... and %d more ... \n' % (len(parsed_input) - 10))
                else:
                    print('')
        # remove old entries
        temp = sum([df[i] for i in parsed_input])
        if not multiple_merge:
            if type(df) == pandas.core.series.Series:
                df = df.drop(parsed_input)
            else:
                df = df.drop(parsed_input, axis = 1)
        df[the_newname] = temp
        return df

    def just_these_subcorpora(df, lst_of_subcorpora, prinf = True):        
        if type(lst_of_subcorpora[0]) == int:
            lst_of_subcorpora = [str(l) for l in lst_of_subcorpora]
        good_years = [subcorpus for subcorpus in list(df.index) if subcorpus in lst_of_subcorpora]
        if prinf:
            print('Keeping %d subcorpora:\n    %s' % (len(good_years), '\n    '.join(good_years[:10])))
            if len(good_years) > 10:
                print('... and %d more ... \n' % (len(good_years) - 10))
            else:
                print('')
        df = df.drop([subcorpus for subcorpus in list(df.index) if subcorpus not in good_years], axis = 0)
        return df

    def skip_these_subcorpora(df, lst_of_subcorpora, prinf = True):
        if type(lst_of_subcorpora) == int:
            lst_of_subcorpora = [lst_of_subcorpora]
        if type(lst_of_subcorpora[0]) == int:
            lst_of_subcorpora = [str(l) for l in lst_of_subcorpora]
        bad_years = [subcorpus for subcorpus in list(df.index) if subcorpus in lst_of_subcorpora]
        if len(bad_years) == 0:
            import warnings
            warnings.warn('No subcorpora skipped.\n')
        else:
            if prinf:       
                print('Skipping %d subcorpora:\n    %s' % (len(bad_years), '\n    '.join([str(i) for i in bad_years[:10]])))
                if len(bad_years) > 10:
                    print('... and %d more ... \n' % (len(bad_years) - 10))
                else:
                    print('')
        df = df.drop([subcorpus for subcorpus in list(df.index) if subcorpus in bad_years], axis = 0)
        return df

    def span_these_subcorpora(df, lst_of_subcorpora, prinf = True):
        """select only a span of numerical suborpora (first, last)"""
        non_totals = [subcorpus for subcorpus in list(df.index)]
        good_years = [subcorpus for subcorpus in non_totals if int(subcorpus) >= int(lst_of_subcorpora[0]) and int(subcorpus) <= int(lst_of_subcorpora[-1])]
        if len(lst_of_subcorpora) == 0:
            import warnings
            warnings.warn('Span not identified.\n')
        else:        
            if prinf:        
                print('Keeping subcorpora:\n    %d--%d\n' % (int(lst_of_subcorpora[0]), int(lst_of_subcorpora[-1])))
        df = df.drop([subcorpus for subcorpus in list(df.index) if subcorpus not in good_years], axis = 0)
        # retotal needed here
        return df

    def projector(df, list_of_tuples, prinf = True):
        """project abs values"""
        if type(list_of_tuples) == list:
            tdict = {}
            for a, b in list_of_tuples:
                tdict[a] = b
            list_of_tuples = tdict
        for subcorpus, projection_value in list(list_of_tuples.items()):
            if type(subcorpus) == int:
                subcorpus = str(subcorpus)
            df.ix[subcorpus] = df.ix[subcorpus] * projection_value
            if prinf:
                if type(projection_value) == float:
                    print('Projection: %s * %s' % (subcorpus, projection_value))
                if type(projection_value) == int:
                    print('Projection: %s * %d' % (subcorpus, projection_value))
        if prinf:
            print('')
        return df

    def do_stats(df):
        """do linregress and add to df"""
        try: 
            from scipy.stats import linregress
        except ImportError:
            from time import localtime, strftime
            thetime = strftime("%H:%M:%S", localtime())
            print('%s: sort type not available in this verion of corpkit.' % thetime)
            return False
        #from stats.stats import linregress

        entries = []
        slopes = []
        intercepts = []
        rs = []
        ps = []
        stderrs = []
        indices = list(df.index)
        first_year = list(df.index)[0]
        try:
            x = [int(y) - int(first_year) for y in indices]
        except ValueError:
            x = list(range(len(indices)))
        statfields = ['slope', 'intercept', 'r', 'p', 'stderr']
        for entry in list(df.columns):
            entries.append(entry)
            y = list(df[entry])
            slope, intercept, r, p, stderr = linregress(x, y)
            slopes.append(slope)
            intercepts.append(intercept)
            rs.append(r)
            ps.append(p)
            stderrs.append(stderr)
        sl = pd.DataFrame([slopes, intercepts, rs, ps, stderrs], 
                           index = statfields, 
                           columns = list(df.columns))
        df = df.append(sl)
        # drop infinites and nans
        if operation != 'd':
            df = df.replace([np.inf, -np.inf], np.nan)
            df = df.fillna(0.0)
        return df

    def recalc(df, operation = '%'):
        statfields = ['slope', 'intercept', 'r', 'p', 'stderr']
        """Add totals to the dataframe1"""

        #df.drop('Total', axis = 0, inplace = True)
        #df.drop('Total', axis = 1, inplace = True)
        try:
            df['temp-Total'] = df.drop(statfields).sum(axis = 1)
        except:
            df['temp-Total'] = df.sum(axis = 1)
        df = df.T
        try:
            df['temp-Total'] = df.drop(statfields).sum(axis = 1)
        except:
            df['temp-Total'] = df.sum(axis = 1)
        df = df.T
        return df

    def resort(df, sort_by = False, keep_stats = False):
        """sort results, potentially using scipy's linregress"""
        
        # translate options and make sure they are parseable
        options = ['total', 'name', 'infreq', 'increase', 'turbulent',
                   'decrease', 'static', 'most', 'least', 'none', 'p']

        if sort_by is True:
            sort_by = 'total'
        if sort_by == 'most':
            sort_by = 'total'
        if sort_by == 'least':
            sort_by = 'infreq'
        if sort_by not in options and sort_by:
            raise ValueError("sort_by parameter error: '%s' not recognised. Must be True, False, %s" % (sort_by, ', '.join(options)))

        if operation.startswith('k'):
            if type(df) == pandas.core.series.Series:
                if sort_by == 'total':
                    df = df.order(ascending = False)

                elif sort_by == 'infreq':
                    df = df.order(ascending = True)

                elif sort_by == 'name':
                    df = df.sort_index()
                return df

        if just_totals:
            if sort_by == 'infreq':
                df = df.sort_values(by = 'Combined total', ascending = True, axis = 1)
            elif sort_by == 'total':
                df = df.sort_values(by = 'Combined total', ascending = False, axis = 1)
            elif sort_by == 'name':
                df = df.sort_index()
            return df

        # this is really shitty now that i know how to sort, like in the above
        if keep_stats:
            df = do_stats(df)
            if type(df) == bool:
                if df is False:
                    return False
        if sort_by == 'total':
            if df1_istotals:
                df = df.T
            df = recalc(df, operation = operation)
            tot = df.ix['temp-Total']
            df = df[tot.argsort()[::-1]]
            df = df.drop('temp-Total', axis = 0)
            df = df.drop('temp-Total', axis = 1)
            if df1_istotals:
                df = df.T
        elif sort_by == 'infreq':
            if df1_istotals:
                df = df.T
            df = recalc(df, operation = operation)
            tot = df.ix['temp-Total']
            df = df[tot.argsort()]
            df = df.drop('temp-Total', axis = 0)
            df = df.drop('temp-Total', axis = 1)
            if df1_istotals:
                df = df.T
        elif sort_by == 'name':
            # currently case sensitive...
            df = df.reindex_axis(sorted(df.columns), axis=1)
        elif sort_by == 'p':
            df = df.T.sort_values(by='p').T
        else:
            statfields = ['slope', 'intercept', 'r', 'p', 'stderr']
            
            if not keep_stats:
                df = do_stats(df)
                if type(df) == bool:
                    if df is False:
                        return False

            slopes = df.ix['slope']
            if sort_by == 'increase':
                df = df[slopes.argsort()[::-1]]
            elif sort_by == 'decrease':
                df = df[slopes.argsort()]
            elif sort_by == 'static':
                df = df[slopes.abs().argsort()]
            elif sort_by == 'turbulent':
                df = df[slopes.abs().argsort()[::-1]]
            if remove_above_p:
                # the easy way to do it!
                df = df.T
                df = df[df['p'] <= p]
                df = df.T

            # remove stats field by default
            if not keep_stats:
                df = df.drop(statfields, axis = 0)

        return df

    def set_threshold(big_list, threshold, prinf = True, for_keywords = False):
        if type(threshold) == str:
            if threshold.startswith('l'):
                denominator = 10000
            if threshold.startswith('m'):
                denominator = 5000
            if threshold.startswith('h'):
                denominator = 2500

            if type(big_list) == pandas.core.frame.DataFrame:
                tot = big_list.sum().sum()

            if type(big_list) == pandas.core.series.Series:
                tot = big_list.sum()
            the_threshold = float(tot) / float(denominator)
            #if for_keywords:
                #the_threshold = the_threshold / 2
        else:
            the_threshold = threshold
        if prinf:
            print('Threshold: %d\n' % the_threshold)
        return the_threshold

    # copy dataframe to be very safe
    df = dataframe1.copy()
    # make cols into strings
    try:
        df.columns = [str(c) for c in list(df.columns)]
    except:
        pass

    if operation is None:
        operation = 'None'

    # do concordance work
    if return_conc:
        if just_entries:
            if type(just_entries) == int:
                just_entries = [just_entries]
            if type(just_entries) == str:
                df = df[df['m'].str.contains(just_entries)]
            if type(just_entries) == list:
                if all(type(e) == str for e in just_entries):
                    mp = df['m'].map(lambda x: x in just_entries)
                    df = df[mp]
                else:
                    df = df.ix[just_entries]

        if skip_entries:
            if type(skip_entries) == int:
                skip_entries = [skip_entries]
            if type(skip_entries) == str:
                df = df[~df['m'].str.contains(skip_entries)]
            if type(skip_entries) == list:
                if all(type(e) == str for e in skip_entries):
                    mp = df['m'].map(lambda x: x not in skip_entries)
                    df = df[mp]
                else:
                    df = df.drop(skip_entries, axis = 0)

        if just_subcorpora:
            if type(just_subcorpora) == int:
                just_subcorpora = [just_subcorpora]
            if type(just_subcorpora) == str:
                df = df[df['c'].str.contains(just_subcorpora)]
            if type(just_subcorpora) == list:
                if all(type(e) == str for e in just_subcorpora):
                    mp = df['c'].map(lambda x: x in just_subcorpora)
                    df = df[mp]
                else:
                    df = df.ix[just_subcorpora]

        if skip_subcorpora:
            if type(skip_subcorpora) == int:
                skip_subcorpora = [skip_subcorpora]
            if type(skip_subcorpora) == str:
                df = df[~df['c'].str.contains(skip_subcorpora)]
            if type(skip_subcorpora) == list:
                if all(type(e) == str for e in skip_subcorpora):
                    mp = df['c'].map(lambda x: x not in skip_subcorpora)
                    df = df[mp]
                else:
                    df = df.drop(skip_subcorpora, axis = 0)

        return Concordance(df)

    if print_info:
        print('\n***Processing results***\n========================\n')

    df1_istotals = False
    if type(df) == pandas.core.series.Series:
        df1_istotals = True
        df = pandas.DataFrame(df)
        # if just a single result
    else:
        df = pandas.DataFrame(df)
    if operation.startswith('k'):
        if sort_by is False:
            if not df1_istotals:
                sort_by = 'turbulent'
        if df1_istotals:
            df = df.T
    
    # figure out if there's a second list
    # copy and remove totals if there is
    single_totals = True
    using_totals = False
    outputmode = False

    if denominator.__class__ == Interrogation:
        try:
            denominator = denominator.results
        except AttributeError:
            denominator = denominator.totals

    if denominator is not False and type(denominator) != str:
        df2 = denominator.copy()
        using_totals = True
        if type(df2) == pandas.core.frame.DataFrame:
            if len(df2.columns) > 1:
                single_totals = False
            else:
                df2 = pandas.Series(df2)
            if operation == 'd':
                df2 = df2.sum(axis = 1)
                single_totals = True
        elif type(df2) == pandas.core.series.Series:
            single_totals = True
            #if operation == 'k':
                #raise ValueError('Keywording requires a DataFrame for denominator. Use "self"?')
        else:
            raise ValueError('Denominator not recognised.')
    else:
        if operation in ['k', 'd', 'a', '%', '/', '*', '-', '+']:
            denominator = 'self'         
        if denominator == 'self':
            outputmode = True

    if operation.startswith('a') or operation.startswith('A'):
        if list(df.columns)[0] != '0' and list(df.columns)[0] != 0:
            df = df.T
        if using_totals:
            if not single_totals:
                df2 = df2.T

    if projection:
        # projection shouldn't do anything when working with '%', remember.
        df = projector(df, projection)
        if using_totals:
            df2 = projector(df2, projection)

    if spelling:
        df = convert_spell(df, convert_to = spelling)
        df = merge_duplicates(df, print_info = False)

        if not single_totals:
            df2 = convert_spell(df2, convert_to = spelling, print_info = False)
            df2 = merge_duplicates(df2, print_info = False)
        if not df1_istotals:
            sort_by = 'total'

    if replace_names:
        df = name_replacer(df, replace_names)
        df = merge_duplicates(df)
        if not single_totals:
            df2 = name_replacer(df2, print_info = False)
            df2 = merge_duplicates(df2, print_info = False)
        if not sort_by:
            sort_by = 'total'

    # remove old stats if they're there:
    statfields = ['slope', 'intercept', 'r', 'p', 'stderr']
    try:
        df = df.drop(statfields, axis = 0)
    except:
        pass
    if using_totals:
        try:
            df2 = df2.drop(statfields, axis = 0)
        except:
            pass

    # remove totals and tkinter order
    for name, ax in zip(['Total'] * 2 + ['tkintertable-order'] * 2, [0, 1, 0, 1]):
        if name == 'Total' and df1_istotals:
            continue
        try:
            df = df.drop(name, axis = ax, errors = 'ignore')
        except:
            pass
    for name, ax in zip(['Total'] * 2 + ['tkintertable-order'] * 2, [0, 1, 0, 1]):
        if name == 'Total' and single_totals:
            continue

        try:

            df2 = df2.drop(name, axis = ax, errors = 'ignore')
        except:
            pass

    # merging: make dicts if they aren't already, so we can iterate
    if merge_entries:
        if type(merge_entries) != list:
            if type(merge_entries) == str or type(merge_entries) == str:
                merge_entries = {newname: merge_entries}
            # for newname, criteria    
            for name, the_input in sorted(merge_entries.items()):
                the_newname = newname_getter(df, parse_input(df, the_input), newname = name, prinf = print_info)
                df = merge_these_entries(df, parse_input(df, the_input), the_newname, prinf = print_info)
                if not single_totals:
                    df2 = merge_these_entries(df2, parse_input(df2, the_input), the_newname, prinf = False)
        else:
            for i in merge_entries:
                the_newname = newname_getter(df, parse_input(df, merge_entries), newname = newname, prinf = print_info)
                df = merge_these_entries(df, parse_input(df, merge_entries), the_newname, prinf = print_info)
                if not single_totals:
                    df2 = merge_these_entries(df2, parse_input(df2, merge_entries), the_newname, prinf = False)
    
    if merge_subcorpora:
        if type(merge_subcorpora) != dict:
            if type(merge_subcorpora) == list:
                if type(merge_subcorpora[0]) == tuple:
                    merge_subcorpora = {x: y for x, y in merge_subcorpora}
                elif type(merge_subcorpora[0]) == str or type(merge_subcorpora[0]) == str:
                    merge_subcorpora = {new_subcorpus_name: [x for x in merge_subcorpora]}
                elif type(merge_subcorpora[0]) == int:
                    merge_subcorpora = {new_subcorpus_name: [str(x) for x in merge_subcorpora]}
            else:
                merge_subcorpora = {new_subcorpus_name: merge_subcorpora}
        for name, the_input in sorted(merge_subcorpora.items()):
            the_newname = newname_getter(df.T, parse_input(df.T, the_input), 
                                     newname = name, 
                                     merging_subcorpora = True,
                                     prinf = print_info)
            df = merge_these_entries(df.T, parse_input(df.T, the_input), the_newname, merging = 'subcorpora', prinf = print_info).T
            if using_totals:
                df2 = merge_these_entries(df2.T, parse_input(df2.T, the_input), the_newname, merging = 'subcorpora', prinf = False).T
    
    if just_subcorpora:
        df = just_these_subcorpora(df, just_subcorpora, prinf = print_info)
        if using_totals:
            df2 = just_these_subcorpora(df2, just_subcorpora, prinf = False)
    
    if skip_subcorpora:
        df = skip_these_subcorpora(df, skip_subcorpora, prinf = print_info)
        if using_totals:
            df2 = skip_these_subcorpora(df2, skip_subcorpora, prinf = False)
    
    if span_subcorpora:
        df = span_these_subcorpora(df, span_subcorpora, prinf = print_info)
        if using_totals:
            df2 = span_these_subcorpora(df2, span_subcorpora, prinf = False)

    if just_entries:
        df = just_these_entries(df, parse_input(df, just_entries), prinf = print_info)
        if not single_totals:
            df2 = just_these_entries(df2, parse_input(df2, just_entries), prinf = False)
    
    if skip_entries:
        df = skip_these_entries(df, parse_input(df, skip_entries), prinf = print_info)
        if not single_totals:
            df2 = skip_these_entries(df2, parse_input(df2, skip_entries), prinf = False)

    # drop infinites and nans
    if operation != 'd':
        df = df.replace([np.inf, -np.inf], np.nan)
        df = df.fillna(0.0)

    # make just_totals as dataframe
    just_one_total_number = False
    if just_totals:
        df = pd.DataFrame(df.sum(), columns = ['Combined total'])
        if using_totals:
            if not single_totals:
                df2 = pd.DataFrame(df2.sum(), columns = ['Combined total'])
            else:
                just_one_total_number = True
                df2 = df2.sum()

    tots = df.sum(axis = 1)

    if using_totals or outputmode:
        if not operation.startswith('k'):
            the_threshold = 0
            # set a threshold if just_totals
            if outputmode is True:
                df2 = df.T.sum()
                if not just_totals:
                    df2.name = 'Total'
                else:
                    df2.name = 'Combined total'
                using_totals = True
                single_totals = True
            if just_totals:
                if not single_totals:
                    the_threshold = set_threshold(df2, threshold, prinf = print_info)
            if operation == 'd':
                the_threshold = set_threshold(df2, threshold, prinf = print_info) 
            df, tots = combiney(df, df2, operation = operation, threshold = the_threshold, prinf = print_info)
    
    # if doing keywording...
    if operation.startswith('k'):
        from keys import keywords

        # allow saved dicts to be df2, etc
        try:
            if denominator == 'self':
                df2 = df.copy()
        except TypeError:
            pass
        if type(denominator) == str:
            if denominator != 'self':
                df2 = denominator
    
        else:
            the_threshold = False

        df = keywords(df, df2, 
                      selfdrop = selfdrop, 
                      threshold = threshold, 
                      printstatus = print_info,
                      editing = True,
                      calc_all = calc_all,
                      **kwargs)

        # eh?
        df = df.T
    
    # drop infinites and nans
    if operation != 'd':
        df = df.replace([np.inf, -np.inf], np.nan)
        df = df.fillna(0.0)

    # resort data
    if sort_by or keep_stats:
        df = resort(df, keep_stats = keep_stats, sort_by = sort_by)
        if type(df) == bool:
            if df is False:
                return 'linregress'

    if keep_top:
        if not just_totals:
            df = df[list(df.columns)[:keep_top]]
        else:
            df = df.head(keep_top)

    if just_totals:
        # turn just_totals into series:
        df = pd.Series(df['Combined total'], name = 'Combined total')

    if df1_istotals:
        if operation.startswith('k'):
            try:
                df = pd.Series(df.ix[dataframe1.name])
                df.name = '%s: keyness' % df.name
            except:
                df = df.iloc[0,:]
                df.name = 'keyness' % df.name

    # generate totals branch if not percentage results:
    # fix me
    if df1_istotals or operation.startswith('k'):
        if not just_totals:
            try:
                total = pd.Series(df['Total'], name = 'Total')
            except:
                pass
                total = 'none'
            #total = df.copy()
        else:
            total = 'none'
    else:
        # might be wrong if using division or something...
        try:
            total = df.T.sum(axis = 1)
        except:
            total = 'none'
    
    if type(tots) != pandas.core.frame.DataFrame and type(tots) != pandas.core.series.Series:
        total = df.sum(axis = 1)
    else:
        total = tots

    if type(df) == pandas.core.frame.DataFrame:
        datatype = df.ix[0].dtype
    else:
        datatype = df.dtype

    # TURN INT COL NAMES INTO STR
    try:
        df.results.columns = [str(d) for d in list(df.results.columns)]
    except:
        pass

    def add_tkt_index(df):
        if type(df) != pandas.core.series.Series:
            df = df.T
            df = df.drop('tkintertable-order', errors = 'ignore', axis = 0)
            df = df.drop('tkintertable-order', errors = 'ignore', axis = 1)
            df['tkintertable-order'] = pd.Series([index for index, data in enumerate(list(df.index))], index = list(df.index))
            df = df.T
        return df

    # while tkintertable can't sort rows
    try:
        from tests import check_t_kinter
    except ImportError:
        from corpkit.tests import check_t_kinter
    tk = check_t_kinter()
    if tk:
        df = add_tkt_index(df)

    if kwargs.get('df1_always_df'):
        if type(df) == pandas.core.series.Series:
            df = pandas.DataFrame(df)

    #outputnames = collections.namedtuple('edited_interrogation', ['query', 'results', 'totals'])
    #output = outputnames(the_options, df, total)

    # delete non-appearing conc lines
    if interrogation.__dict__.get('concordance', None) is None:
        lns = None
    else:
        col_crit = interrogation.concordance['m'].map(lambda x: x in list(df.columns))
        ind_crit = interrogation.concordance['c'].map(lambda x: x in list(df.index))
        lns = interrogation.concordance[col_crit]
        lns = lns.loc[ind_crit]
        lns = Concordance(lns)
    
    output = Interrogation(results = df, totals = total, query = locs, concordance = lns)

    #print '\nResult (sample)\n'
    if print_info:
        #if merge_entries or merge_subcorpora or span_subcorpora or just_subcorpora or \
           #just_entries or skip_entries or skip_subcorpora or printed_th or projection:
        print('***Done!***\n========================\n')
    #print df.head().T
    #print ''
    if operation.startswith('k') or just_totals or df1_istotals:
        pd.set_option('display.max_rows', 30)
    else:
        pd.set_option('display.max_rows', 15)
    pd.set_option('display.max_columns', 8)
    pd.set_option('max_colwidth',70)
    pd.set_option('display.width', 800)
    pd.set_option('expand_frame_repr', False)
    pd.set_option('display.float_format', lambda x: '%.2f' % x)

    return output
Example #37
0
def editor(
    interrogation,
    operation=None,
    denominator=False,
    sort_by=False,
    keep_stats=False,
    keep_top=False,
    just_totals=False,
    threshold="medium",
    just_entries=False,
    skip_entries=False,
    merge_entries=False,
    newname="combine",
    multiple_merge=False,
    just_subcorpora=False,
    skip_subcorpora=False,
    span_subcorpora=False,
    merge_subcorpora=False,
    new_subcorpus_name=False,
    replace_names=False,
    projection=False,
    remove_above_p=False,
    p=0.05,
    revert_year=True,
    print_info=True,
    spelling=False,
    selfdrop=True,
    calc_all=True,
    **kwargs
):
    """Edit results of interrogations, do keywording, sort, etc.

    ``just/skip_entries`` and ``just/skip_subcorpora`` can take a few different kinds of input:

    * str: treated as regular expression to match
    * list: 

      * of integers: indices to match
      * of strings: entries/subcorpora to match

    ``merge_entries`` and ``merge_subcorpora``, however, are best entered as dicts:

    ``{newname: criteria, newname2: criteria2}```

    where criteria is a string, list, etc.

    :param interrogation: Results to edit
    :type interrogation: pandas.core.frame.DataFrame
    
    :param operation: Kind of maths to do on inputted lists:

        '+', '-', '/', '*', '%': self explanatory
        'k': log likelihood (keywords)
        'a': get distance metric (for use with interrogator 'a' option)
        'd': get percent difference (alternative approach to keywording)

    :type operation: str
    
    :param denominator: List of results or totals.

        If list of results, for each entry in dataframe 1, locate
        entry with same name in dataframe 2, and do maths there
        if 'self', do all merging/keeping operations, then use
        edited interrogation as denominator

    :type denominator: pandas.core.series.Series/pandas.core.frame.DataFrame/dict/'self'
    
    :param sort_by: Calculate slope, stderr, r, p values, then sort by:

        increase: highest to lowest slope value
        decrease: lowest to highest slope value
        turbulent: most change in y axis values
        static: least change in y axis values
        total/most: largest number first
        infreq/least: smallest number first
        name: alphabetically
        
    :type sort_by: str

    :param keep_stats: Keep/drop stats values from dataframe after sorting
    :type keep_stats: bool
    
    :param keep_top: After sorting, remove all but the top *keep_top* results
    :type keep_top: int
    
    :param just_totals: Sum each column and work with sums
    :type just_totals: bool
    
    :param threshold: When using results list as denominator, drop values occurring
                        fewer than n times. If not keywording, you can use:
                            ``'high'``: denominator total / 2500
                            ``'medium'``: denominator total / 5000
                            ``'low'``: denominator total / 10000
                        Note: if keywording, there are smaller default thresholds
    :type threshold: int/bool
    :param just_entries: Keep matching entries
    :type just_entries: see above
    :param skip_entries: Skip matching entries
    :type skip_entries: see above
    :param merge_entries: Merge matching entries
    :type merge_entries: see above
    :param newname: New name for merged entries
    :type newname: str/'combine'
    :param just_subcorpora: Keep matching subcorpora
    :type just_subcorpora: see above
    :param skip_subcorpora: Skip matching subcorpora
    :type skip_subcorpora: see above
    :param span_subcorpora: If subcorpora are numerically named, span all from *int* to *int2*, inclusive
    :type span_subcorpora: tuple -- ``(int, int2)``
    :param merge_subcorpora: Merge matching subcorpora
    :type merge_subcorpora: see above
    :param new_subcorpus_name: Name for merged subcorpora
    :type new_subcorpus_name: str/``'combine'``

    :param replace_names: Edit result names and then merge duplicate names.
    :type replace_names: dict -- ``{criteria: replacement_text}``; str -- a regex to delete from names
    :param projection:         a  to multiply results in subcorpus by n
    :type projection: tuple -- ``(subcorpus_name, n)``
    :param remove_above_p: Delete any result over p
    :type remove_above_p: bool
    :param p:                  set the p value
    :type p: float
    
    :param revert_year:        when doing linear regression on years, turn annual subcorpora into 1, 2 ...
    :type revert_year: bool
    
    :param print_info: Print stuff to console showing what's being edited
    :type print_info: bool
    
    :param spelling: Convert/normalise spelling:
    :type spelling: str -- ``'US'``/``'UK'``
    
    :param selfdrop: When keywording, try to remove target corpus from reference corpus
    :type selfdrop: bool
    
    :param calc_all: When keywording, calculate words that appear in either corpus
    :type calc_all: bool

    :returns: corpkit.interrogation.Interrogation
    """

    # grab arguments, in case we get dict input and have to iterate
    locs = locals()

    import corpkit
    import pandas
    import signal
    import re
    import collections
    import pandas as pd
    import numpy as np

    from pandas import DataFrame, Series
    from time import localtime, strftime

    try:
        get_ipython().getoutput()
    except TypeError:
        have_ipython = True
    except NameError:
        have_ipython = False
    try:
        from IPython.display import display, clear_output
    except ImportError:
        pass

    return_conc = False
    from interrogation import Interrodict, Interrogation, Concordance

    if interrogation.__class__ == Interrodict:
        from collections import OrderedDict

        outdict = OrderedDict()
        from editor import editor

        for i, (k, v) in enumerate(interrogation.items()):
            # only print the first time around
            if i == 0:
                pass
                # saved_args['print_info'] = True
            else:
                locs["print_info"] = False
            # if df2 is also a dict, get the relevant entry
            if type(denominator) == dict:
                if sorted(set([i.lower() for i in list(dataframe1.keys())])) == sorted(
                    set([i.lower() for i in list(denominator.keys())])
                ):
                    locs["denominator"] = denominator[k]

                    if kwargs.get("use_df2_totals"):
                        saved_args["denominator"] = denominator[k].totals
            outdict[k] = editor(v.results, **saved_args)
        if print_info:
            from time import localtime, strftime

            thetime = strftime("%H:%M:%S", localtime())
            print(
                "\n%s: Finished! Output is a dictionary with keys:\n\n         '%s'\n"
                % (thetime, "'\n         '".join(sorted(outdict.keys())))
            )
        return Interrodict(outdict)

    elif type(interrogation) in [pandas.core.frame.DataFrame, pandas.core.series.Series]:
        dataframe1 = interrogation
    elif interrogation.__class__ == Interrogation:
        # if interrogation.__dict__.get('concordance', None) is not None:
        #    concordances = interrogation.concordance
        branch = kwargs.pop("branch", "results")
        if branch.lower().startswith("r"):
            dataframe1 = interrogation.results
        elif branch.lower().startswith("t"):
            dataframe1 = interrogation.totals
        elif branch.lower().startswith("c"):
            dataframe1 = interrogation.concordance
            return_conc = True
        else:
            dataframe1 = interrogation.results

    elif interrogation.__class__ == Concordance or all(x in list(dataframe1.columns) for x in ["l", "m", "r"]):
        return_conc = True
        dataframe1 = interrogation
    # hope for the best
    else:
        dataframe1 = interrogation

    the_time_started = strftime("%Y-%m-%d %H:%M:%S")

    pd.options.mode.chained_assignment = None
    pd.set_option("display.float_format", lambda x: "%.2f" % x)

    from tests import check_pytex

    if check_pytex():
        print_info = False

    def combiney(df, df2, operation="%", threshold="medium", prinf=True):
        """mash df and df2 together in appropriate way"""
        totals = False
        # delete under threshold
        if just_totals:
            if using_totals:
                if not single_totals:
                    to_drop = list(df2[df2["Combined total"] < threshold].index)
                    df = df.drop([e for e in to_drop if e in list(df.index)])
                    if prinf:
                        to_show = []
                        [to_show.append(w) for w in to_drop[:5]]
                        if len(to_drop) > 10:
                            to_show.append("...")
                            [to_show.append(w) for w in to_drop[-5:]]
                        if len(to_drop) > 0:
                            print(
                                "Removing %d entries below threshold:\n    %s" % (len(to_drop), "\n    ".join(to_show))
                            )
                        if len(to_drop) > 10:
                            print("... and %d more ... \n" % (len(to_drop) - len(to_show) + 1))
                        else:
                            print("")
                else:
                    denom = df2
        else:
            denom = list(df2)
        if single_totals:
            if operation == "%":
                totals = df.sum() * 100.0 / float(df.sum().sum())
                df = df * 100.0
                try:
                    df = df.div(denom, axis=0)
                except ValueError:
                    from time import localtime, strftime

                    thetime = strftime("%H:%M:%S", localtime())
                    print("%s: cannot combine DataFrame 1 and 2: different shapes" % thetime)
            elif operation == "+":
                try:
                    df = df.add(denom, axis=0)
                except ValueError:
                    from time import localtime, strftime

                    thetime = strftime("%H:%M:%S", localtime())
                    print("%s: cannot combine DataFrame 1 and 2: different shapes" % thetime)
            elif operation == "-":
                try:
                    df = df.sub(denom, axis=0)
                except ValueError:
                    from time import localtime, strftime

                    thetime = strftime("%H:%M:%S", localtime())
                    print("%s: cannot combine DataFrame 1 and 2: different shapes" % thetime)
            elif operation == "*":
                totals = df.sum() * float(df.sum().sum())
                try:
                    df = df.mul(denom, axis=0)
                except ValueError:
                    from time import localtime, strftime

                    thetime = strftime("%H:%M:%S", localtime())
                    print("%s: cannot combine DataFrame 1 and 2: different shapes" % thetime)
            elif operation == "/":
                try:
                    totals = df.sum() / float(df.sum().sum())
                    df = df.div(denom, axis=0)
                except ValueError:
                    from time import localtime, strftime

                    thetime = strftime("%H:%M:%S", localtime())
                    print("%s: cannot combine DataFrame 1 and 2: different shapes" % thetime)
            elif operation == "d":
                # df.ix['Combined total'] = df.sum()
                # to_drop = to_drop = list(df.T[df.T['Combined total'] < threshold].index)
                to_drop = [n for n in list(df.columns) if df[n].sum() < threshold]
                df = df.drop([e for e in to_drop if e in list(df.columns)], axis=1)
                # df.drop('Combined total')
                if prinf:
                    to_show = []
                    [to_show.append(w) for w in to_drop[:5]]
                    if len(to_drop) > 10:
                        to_show.append("...")
                        [to_show.append(w) for w in to_drop[-5:]]
                    if len(to_drop) > 0:
                        print("Removing %d entries below threshold:\n    %s" % (len(to_drop), "\n    ".join(to_show)))
                    if len(to_drop) > 10:
                        print("... and %d more ... \n" % (len(to_drop) - len(to_show) + 1))
                    else:
                        print("")

                # get normalised num in target corpus
                norm_in_target = df.div(denom, axis=0)
                # get normalised num in reference corpus, with or without selfdrop
                tot_in_ref = df.copy()
                for c in list(tot_in_ref.index):
                    if selfdrop:
                        tot_in_ref.ix[c] = df.sum() - tot_in_ref.ix[c]
                    else:
                        tot_in_ref.ix[c] = df.sum()
                norm_in_ref = tot_in_ref.div(df.sum().sum())
                df = (norm_in_target - norm_in_ref) / norm_in_ref * 100.0
                df = df.replace(float(-100.00), np.nan)

            elif operation == "a":
                for c in [c for c in list(df.columns) if int(c) > 1]:
                    df[c] = df[c] * (1.0 / int(c))
                df = df.sum(axis=1) / df2

            elif operation.startswith("c"):
                import warnings

                with warnings.catch_warnings():
                    warnings.simplefilter("ignore")
                    df = pandas.concat([df, df2], axis=1)
            return df, totals

        elif not single_totals:
            if not operation.startswith("a"):
                # generate totals
                if operation == "%":
                    totals = df.sum() * 100.0 / float(df2.sum().sum())
                if operation == "*":
                    totals = df.sum() * float(df2.sum().sum())
                if operation == "/":
                    totals = df.sum() / float(df2.sum().sum())
                if operation.startswith("c"):
                    # add here the info that merging will not work
                    # with identical colnames
                    import warnings

                    with warnings.catch_warnings():
                        warnings.simplefilter("ignore")
                        d = pd.concat([df.T, df2.T])
                        # make index nums
                        d = d.reset_index()
                        # sum and remove duplicates
                        d = d.groupby("index").sum()
                        dx = d.reset_index("index")
                        dx.index = list(dx["index"])
                        df = dx.drop("index", axis=1).T

                for index, entry in enumerate(list(df.columns)):
                    # p.animate(index)
                    if operation == "%":
                        try:
                            df[entry] = df[entry] * 100.0 / df2[entry]
                        except:
                            continue
                        # df.drop(entry, axis = 1, inplace = True)
                        # df[entry] = maths_done
                    elif operation == "+":
                        try:
                            df[entry] = df[entry] + df2[entry]
                        except:
                            continue
                    elif operation == "-":
                        try:
                            df[entry] = df[entry] - df2[entry]
                        except:
                            continue
                    elif operation == "*":
                        try:
                            df[entry] = df[entry] * df2[entry]
                        except:
                            continue
                    elif operation == "/":
                        try:
                            df[entry] = df[entry] / df2[entry]
                        except:
                            continue

            else:
                for c in [c for c in list(df.columns) if int(c) > 1]:
                    df[c] = df[c] * (1.0 / int(c))
                df = df.sum(axis=1) / df2.T.sum()

        return df, totals

    def parse_input(df, the_input):
        """turn whatever has been passed in into list of words that can 
           be used as pandas indices---maybe a bad way to go about it"""

        # FIX MERGE ERROR HERE
        parsed_input = False

        import re

        if the_input == "all":
            the_input = r".*"
        if type(the_input) == int:
            try:
                the_input = str(the_input)
            except:
                pass
            the_input = [the_input]
        elif type(the_input) == str or type(the_input) == str:
            try:
                regex = re.compile(the_input)
                parsed_input = [w for w in list(df) if re.search(regex, w)]
                return parsed_input
            except:
                the_input = [the_input]
        if type(the_input) == list:
            if type(the_input[0]) == int:
                parsed_input = [word for index, word in enumerate(list(df)) if index in the_input]
            elif type(the_input[0]) == str or type(the_input[0]) == str:
                try:
                    parsed_input = [word for word in the_input if word in df.columns]
                except AttributeError:  # if series
                    parsed_input = [word for word in the_input if word in df.index]

        return parsed_input

    def synonymise(df, pos="n"):
        """pass a df and a pos and convert df columns to most common synonyms"""
        from nltk.corpus import wordnet as wn

        # from dictionaries.taxonomies import taxonomies
        from collections import Counter

        fixed = []
        for w in list(df.columns):
            try:
                syns = []
                for syns in wn.synsets(w, pos=pos):
                    for w in syns:
                        synonyms.append(w)
                top_syn = Counter(syns).most_common(1)[0][0]
                fixed.append(top_syn)
            except:
                fixed.append(w)
        df.columns = fixed
        return df

    def convert_spell(df, convert_to="US", print_info=print_info):
        """turn dataframes into us/uk spelling"""
        from dictionaries.word_transforms import usa_convert

        if print_info:
            print("Converting spelling ... \n")
        if convert_to == "UK":
            usa_convert = {v: k for k, v in list(usa_convert.items())}
        fixed = []
        for val in list(df.columns):
            try:
                fixed.append(usa_convert[val])
            except:
                fixed.append(val)
        df.columns = fixed
        return df

    def merge_duplicates(df, print_info=print_info):
        if print_info:
            print("Merging duplicate entries ... \n")
        # now we have to merge all duplicates
        for dup in df.columns.get_duplicates():
            # num_dupes = len(list(df[dup].columns))
            temp = df[dup].sum(axis=1)
            # df = df.drop([dup for d in range(num_dupes)], axis = 1)
            df = df.drop(dup, axis=1)
            df[dup] = temp
        return df

    def name_replacer(df, replace_names, print_info=print_info):
        """replace entry names and merge"""
        import re

        # double or single nest if need be
        if type(replace_names) == str:
            replace_names = [(replace_names, "")]
        if type(replace_names) != dict:
            if type(replace_names[0]) == str:
                replace_names = [replace_names]
        if type(replace_names) == dict:
            replace_names = [(v, k) for k, v in list(replace_names.items())]
        for to_find, replacement in replace_names:
            if print_info:
                try:
                    print('Replacing "%s" with "%s" ...\n' % (to_find, replacement))
                except:
                    print('Deleting "%s" from entry names ...\n' % (to_find))
            to_find = re.compile(to_find)
            try:
                replacement = replacement
            except:
                replacement = ""
            df.columns = [re.sub(to_find, replacement, l) for l in list(df.columns)]
        df = merge_duplicates(df, print_info=False)
        return df

    def just_these_entries(df, parsed_input, prinf=True):
        entries = [word for word in list(df) if word not in parsed_input]
        if prinf:
            print("Keeping %d entries:\n    %s" % (len(parsed_input), "\n    ".join(parsed_input[:10])))
            if len(parsed_input) > 10:
                print("... and %d more ... \n" % (len(parsed_input) - 10))
            else:
                print("")
        df = df.drop(entries, axis=1)
        return df

    def skip_these_entries(df, parsed_input, prinf=True):
        if prinf:
            print("Skipping %d entries:\n    %s" % (len(parsed_input), "\n    ".join(parsed_input[:10])))
            if len(parsed_input) > 10:
                print("... and %d more ... \n" % (len(parsed_input) - 10))
            else:
                print("")
        df = df.drop(parsed_input, axis=1)
        return df

    def newname_getter(df, parsed_input, newname="combine", prinf=True, merging_subcorpora=False):
        """makes appropriate name for merged entries"""
        if merging_subcorpora:
            if newname is False:
                newname = "combine"
        if type(newname) == int:
            the_newname = list(df.columns)[newname]
        elif type(newname) == str:
            if newname == "combine":
                if len(parsed_input) <= 3:
                    the_newname = "/".join(parsed_input)
                elif len(parsed_input) > 3:
                    the_newname = "/".join(parsed_input[:3]) + "..."
            else:
                the_newname = newname
        if newname is False:
            # revise this code
            import operator

            sumdict = {}
            for item in parsed_input:
                summed = sum(list(df[item]))
                sumdict[item] = summed
            the_newname = max(iter(sumdict.items()), key=operator.itemgetter(1))[0]
        if type(the_newname) != str:
            the_newname = str(the_newname, errors="ignore")
        return the_newname

    def merge_these_entries(df, parsed_input, the_newname, prinf=True, merging="entries"):
        # make new entry with sum of parsed input
        if len(parsed_input) == 0:
            import warnings

            warnings.warn("No %s could be automatically merged.\n" % merging)
        else:
            if prinf:
                print(
                    'Merging %d %s as "%s":\n    %s'
                    % (len(parsed_input), merging, the_newname, "\n    ".join(parsed_input[:10]))
                )
                if len(parsed_input) > 10:
                    print("... and %d more ... \n" % (len(parsed_input) - 10))
                else:
                    print("")
        # remove old entries
        temp = sum([df[i] for i in parsed_input])
        if not multiple_merge:
            if type(df) == pandas.core.series.Series:
                df = df.drop(parsed_input)
            else:
                df = df.drop(parsed_input, axis=1)
        df[the_newname] = temp
        return df

    def just_these_subcorpora(df, lst_of_subcorpora, prinf=True):
        if type(lst_of_subcorpora[0]) == int:
            lst_of_subcorpora = [str(l) for l in lst_of_subcorpora]
        good_years = [subcorpus for subcorpus in list(df.index) if subcorpus in lst_of_subcorpora]
        if prinf:
            print("Keeping %d subcorpora:\n    %s" % (len(good_years), "\n    ".join(good_years[:10])))
            if len(good_years) > 10:
                print("... and %d more ... \n" % (len(good_years) - 10))
            else:
                print("")
        df = df.drop([subcorpus for subcorpus in list(df.index) if subcorpus not in good_years], axis=0)
        return df

    def skip_these_subcorpora(df, lst_of_subcorpora, prinf=True):
        if type(lst_of_subcorpora) == int:
            lst_of_subcorpora = [lst_of_subcorpora]
        if type(lst_of_subcorpora[0]) == int:
            lst_of_subcorpora = [str(l) for l in lst_of_subcorpora]
        bad_years = [subcorpus for subcorpus in list(df.index) if subcorpus in lst_of_subcorpora]
        if len(bad_years) == 0:
            import warnings

            warnings.warn("No subcorpora skipped.\n")
        else:
            if prinf:
                print(
                    "Skipping %d subcorpora:\n    %s"
                    % (len(bad_years), "\n    ".join([str(i) for i in bad_years[:10]]))
                )
                if len(bad_years) > 10:
                    print("... and %d more ... \n" % (len(bad_years) - 10))
                else:
                    print("")
        df = df.drop([subcorpus for subcorpus in list(df.index) if subcorpus in bad_years], axis=0)
        return df

    def span_these_subcorpora(df, lst_of_subcorpora, prinf=True):
        """select only a span of numerical suborpora (first, last)"""
        non_totals = [subcorpus for subcorpus in list(df.index)]
        good_years = [
            subcorpus
            for subcorpus in non_totals
            if int(subcorpus) >= int(lst_of_subcorpora[0]) and int(subcorpus) <= int(lst_of_subcorpora[-1])
        ]
        if len(lst_of_subcorpora) == 0:
            import warnings

            warnings.warn("Span not identified.\n")
        else:
            if prinf:
                print("Keeping subcorpora:\n    %d--%d\n" % (int(lst_of_subcorpora[0]), int(lst_of_subcorpora[-1])))
        df = df.drop([subcorpus for subcorpus in list(df.index) if subcorpus not in good_years], axis=0)
        # retotal needed here
        return df

    def projector(df, list_of_tuples, prinf=True):
        """project abs values"""
        if type(list_of_tuples) == list:
            tdict = {}
            for a, b in list_of_tuples:
                tdict[a] = b
            list_of_tuples = tdict
        for subcorpus, projection_value in list(list_of_tuples.items()):
            if type(subcorpus) == int:
                subcorpus = str(subcorpus)
            df.ix[subcorpus] = df.ix[subcorpus] * projection_value
            if prinf:
                if type(projection_value) == float:
                    print("Projection: %s * %s" % (subcorpus, projection_value))
                if type(projection_value) == int:
                    print("Projection: %s * %d" % (subcorpus, projection_value))
        if prinf:
            print("")
        return df

    def do_stats(df):
        """do linregress and add to df"""
        try:
            from scipy.stats import linregress
        except ImportError:
            from time import localtime, strftime

            thetime = strftime("%H:%M:%S", localtime())
            print("%s: sort type not available in this verion of corpkit." % thetime)
            return False
        # from stats.stats import linregress

        entries = []
        slopes = []
        intercepts = []
        rs = []
        ps = []
        stderrs = []
        indices = list(df.index)
        first_year = list(df.index)[0]
        try:
            x = [int(y) - int(first_year) for y in indices]
        except ValueError:
            x = list(range(len(indices)))
        statfields = ["slope", "intercept", "r", "p", "stderr"]
        for entry in list(df.columns):
            entries.append(entry)
            y = list(df[entry])
            slope, intercept, r, p, stderr = linregress(x, y)
            slopes.append(slope)
            intercepts.append(intercept)
            rs.append(r)
            ps.append(p)
            stderrs.append(stderr)
        sl = pd.DataFrame([slopes, intercepts, rs, ps, stderrs], index=statfields, columns=list(df.columns))
        df = df.append(sl)
        # drop infinites and nans
        if operation != "d":
            df = df.replace([np.inf, -np.inf], np.nan)
            df = df.fillna(0.0)
        return df

    def recalc(df, operation="%"):
        statfields = ["slope", "intercept", "r", "p", "stderr"]
        """Add totals to the dataframe1"""

        # df.drop('Total', axis = 0, inplace = True)
        # df.drop('Total', axis = 1, inplace = True)
        try:
            df["temp-Total"] = df.drop(statfields).sum(axis=1)
        except:
            df["temp-Total"] = df.sum(axis=1)
        df = df.T
        try:
            df["temp-Total"] = df.drop(statfields).sum(axis=1)
        except:
            df["temp-Total"] = df.sum(axis=1)
        df = df.T
        return df

    def resort(df, sort_by=False, keep_stats=False):
        """sort results, potentially using scipy's linregress"""

        # translate options and make sure they are parseable
        options = [
            "total",
            "name",
            "infreq",
            "increase",
            "turbulent",
            "decrease",
            "static",
            "most",
            "least",
            "none",
            "p",
        ]

        if sort_by is True:
            sort_by = "total"
        if sort_by == "most":
            sort_by = "total"
        if sort_by == "least":
            sort_by = "infreq"
        if sort_by not in options and sort_by:
            raise ValueError(
                "sort_by parameter error: '%s' not recognised. Must be True, False, %s" % (sort_by, ", ".join(options))
            )

        if operation.startswith("k"):
            if type(df) == pandas.core.series.Series:
                if sort_by == "total":
                    df = df.order(ascending=False)

                elif sort_by == "infreq":
                    df = df.order(ascending=True)

                elif sort_by == "name":
                    df = df.sort_index()
                return df

        if just_totals:
            if sort_by == "infreq":
                df = df.sort_values(by="Combined total", ascending=True, axis=1)
            elif sort_by == "total":
                df = df.sort_values(by="Combined total", ascending=False, axis=1)
            elif sort_by == "name":
                df = df.sort_index()
            return df

        # this is really shitty now that i know how to sort, like in the above
        if keep_stats:
            df = do_stats(df)
            if type(df) == bool:
                if df is False:
                    return False
        if sort_by == "total":
            if df1_istotals:
                df = df.T
            df = recalc(df, operation=operation)
            tot = df.ix["temp-Total"]
            df = df[tot.argsort()[::-1]]
            df = df.drop("temp-Total", axis=0)
            df = df.drop("temp-Total", axis=1)
            if df1_istotals:
                df = df.T
        elif sort_by == "infreq":
            if df1_istotals:
                df = df.T
            df = recalc(df, operation=operation)
            tot = df.ix["temp-Total"]
            df = df[tot.argsort()]
            df = df.drop("temp-Total", axis=0)
            df = df.drop("temp-Total", axis=1)
            if df1_istotals:
                df = df.T
        elif sort_by == "name":
            # currently case sensitive...
            df = df.reindex_axis(sorted(df.columns), axis=1)
        elif sort_by == "p":
            df = df.T.sort_values(by="p").T
        else:
            statfields = ["slope", "intercept", "r", "p", "stderr"]

            if not keep_stats:
                df = do_stats(df)
                if type(df) == bool:
                    if df is False:
                        return False

            slopes = df.ix["slope"]
            if sort_by == "increase":
                df = df[slopes.argsort()[::-1]]
            elif sort_by == "decrease":
                df = df[slopes.argsort()]
            elif sort_by == "static":
                df = df[slopes.abs().argsort()]
            elif sort_by == "turbulent":
                df = df[slopes.abs().argsort()[::-1]]
            if remove_above_p:
                # the easy way to do it!
                df = df.T
                df = df[df["p"] <= p]
                df = df.T

            # remove stats field by default
            if not keep_stats:
                df = df.drop(statfields, axis=0)

        return df

    def set_threshold(big_list, threshold, prinf=True, for_keywords=False):
        if type(threshold) == str:
            if threshold.startswith("l"):
                denominator = 10000
            if threshold.startswith("m"):
                denominator = 5000
            if threshold.startswith("h"):
                denominator = 2500

            if type(big_list) == pandas.core.frame.DataFrame:
                tot = big_list.sum().sum()

            if type(big_list) == pandas.core.series.Series:
                tot = big_list.sum()
            the_threshold = float(tot) / float(denominator)
            # if for_keywords:
            # the_threshold = the_threshold / 2
        else:
            the_threshold = threshold
        if prinf:
            print("Threshold: %d\n" % the_threshold)
        return the_threshold

    # copy dataframe to be very safe
    df = dataframe1.copy()
    # make cols into strings
    try:
        df.columns = [str(c) for c in list(df.columns)]
    except:
        pass

    if operation is None:
        operation = "None"

    # do concordance work
    if return_conc:
        if just_entries:
            if type(just_entries) == int:
                just_entries = [just_entries]
            if type(just_entries) == str:
                df = df[df["m"].str.contains(just_entries)]
            if type(just_entries) == list:
                if all(type(e) == str for e in just_entries):
                    mp = df["m"].map(lambda x: x in just_entries)
                    df = df[mp]
                else:
                    df = df.ix[just_entries]

        if skip_entries:
            if type(skip_entries) == int:
                skip_entries = [skip_entries]
            if type(skip_entries) == str:
                df = df[~df["m"].str.contains(skip_entries)]
            if type(skip_entries) == list:
                if all(type(e) == str for e in skip_entries):
                    mp = df["m"].map(lambda x: x not in skip_entries)
                    df = df[mp]
                else:
                    df = df.drop(skip_entries, axis=0)

        if just_subcorpora:
            if type(just_subcorpora) == int:
                just_subcorpora = [just_subcorpora]
            if type(just_subcorpora) == str:
                df = df[df["c"].str.contains(just_subcorpora)]
            if type(just_subcorpora) == list:
                if all(type(e) == str for e in just_subcorpora):
                    mp = df["c"].map(lambda x: x in just_subcorpora)
                    df = df[mp]
                else:
                    df = df.ix[just_subcorpora]

        if skip_subcorpora:
            if type(skip_subcorpora) == int:
                skip_subcorpora = [skip_subcorpora]
            if type(skip_subcorpora) == str:
                df = df[~df["c"].str.contains(skip_subcorpora)]
            if type(skip_subcorpora) == list:
                if all(type(e) == str for e in skip_subcorpora):
                    mp = df["c"].map(lambda x: x not in skip_subcorpora)
                    df = df[mp]
                else:
                    df = df.drop(skip_subcorpora, axis=0)

        return Concordance(df)

    if print_info:
        print("\n***Processing results***\n========================\n")

    df1_istotals = False
    if type(df) == pandas.core.series.Series:
        df1_istotals = True
        df = pandas.DataFrame(df)
        # if just a single result
    else:
        df = pandas.DataFrame(df)
    if operation.startswith("k"):
        if sort_by is False:
            if not df1_istotals:
                sort_by = "turbulent"
        if df1_istotals:
            df = df.T

    # figure out if there's a second list
    # copy and remove totals if there is
    single_totals = True
    using_totals = False
    outputmode = False

    if denominator is not False and type(denominator) != str:
        df2 = denominator.copy()
        using_totals = True
        if type(df2) == pandas.core.frame.DataFrame:
            if len(df2.columns) > 1:
                single_totals = False
            else:
                df2 = pandas.Series(df2)
            if operation == "d":
                df2 = df2.sum(axis=1)
                single_totals = True
        elif type(df2) == pandas.core.series.Series:
            single_totals = True
            # if operation == 'k':
            # raise ValueError('Keywording requires a DataFrame for denominator. Use "self"?')
        else:
            raise ValueError("Denominator not recognised.")
    else:
        if operation in ["k", "d", "a", "%", "/", "*", "-", "+"]:
            denominator = "self"
        if denominator == "self":
            outputmode = True

    if operation.startswith("a") or operation.startswith("A"):
        if list(df.columns)[0] != "0" and list(df.columns)[0] != 0:
            df = df.T
        if using_totals:
            if not single_totals:
                df2 = df2.T

    if projection:
        # projection shouldn't do anything when working with '%', remember.
        df = projector(df, projection)
        if using_totals:
            df2 = projector(df2, projection)

    if spelling:
        df = convert_spell(df, convert_to=spelling)
        df = merge_duplicates(df, print_info=False)

        if not single_totals:
            df2 = convert_spell(df2, convert_to=spelling, print_info=False)
            df2 = merge_duplicates(df2, print_info=False)
        if not df1_istotals:
            sort_by = "total"

    if replace_names:
        df = name_replacer(df, replace_names)
        df = merge_duplicates(df)
        if not single_totals:
            df2 = name_replacer(df2, print_info=False)
            df2 = merge_duplicates(df2, print_info=False)
        if not sort_by:
            sort_by = "total"

    # remove old stats if they're there:
    statfields = ["slope", "intercept", "r", "p", "stderr"]
    try:
        df = df.drop(statfields, axis=0)
    except:
        pass
    if using_totals:
        try:
            df2 = df2.drop(statfields, axis=0)
        except:
            pass

    # remove totals and tkinter order
    for name, ax in zip(["Total"] * 2 + ["tkintertable-order"] * 2, [0, 1, 0, 1]):
        if name == "Total" and df1_istotals:
            continue
        try:
            df = df.drop(name, axis=ax, errors="ignore")
        except:
            pass
    for name, ax in zip(["Total"] * 2 + ["tkintertable-order"] * 2, [0, 1, 0, 1]):
        if name == "Total" and single_totals:
            continue

        try:

            df2 = df2.drop(name, axis=ax, errors="ignore")
        except:
            pass

    # merging: make dicts if they aren't already, so we can iterate
    if merge_entries:
        if type(merge_entries) != list:
            if type(merge_entries) == str or type(merge_entries) == str:
                merge_entries = {newname: merge_entries}
            # for newname, criteria
            for name, the_input in sorted(merge_entries.items()):
                the_newname = newname_getter(df, parse_input(df, the_input), newname=name, prinf=print_info)
                df = merge_these_entries(df, parse_input(df, the_input), the_newname, prinf=print_info)
                if not single_totals:
                    df2 = merge_these_entries(df2, parse_input(df2, the_input), the_newname, prinf=False)
        else:
            for i in merge_entries:
                the_newname = newname_getter(df, parse_input(df, merge_entries), newname=newname, prinf=print_info)
                df = merge_these_entries(df, parse_input(df, merge_entries), the_newname, prinf=print_info)
                if not single_totals:
                    df2 = merge_these_entries(df2, parse_input(df2, merge_entries), the_newname, prinf=False)

    if merge_subcorpora:
        if type(merge_subcorpora) != dict:
            if type(merge_subcorpora) == list:
                if type(merge_subcorpora[0]) == tuple:
                    merge_subcorpora = {x: y for x, y in merge_subcorpora}
                elif type(merge_subcorpora[0]) == str or type(merge_subcorpora[0]) == str:
                    merge_subcorpora = {new_subcorpus_name: [x for x in merge_subcorpora]}
                elif type(merge_subcorpora[0]) == int:
                    merge_subcorpora = {new_subcorpus_name: [str(x) for x in merge_subcorpora]}
            else:
                merge_subcorpora = {new_subcorpus_name: merge_subcorpora}
        for name, the_input in sorted(merge_subcorpora.items()):
            the_newname = newname_getter(
                df.T, parse_input(df.T, the_input), newname=name, merging_subcorpora=True, prinf=print_info
            )
            df = merge_these_entries(
                df.T, parse_input(df.T, the_input), the_newname, merging="subcorpora", prinf=print_info
            ).T
            if using_totals:
                df2 = merge_these_entries(
                    df2.T, parse_input(df2.T, the_input), the_newname, merging="subcorpora", prinf=False
                ).T

    if just_subcorpora:
        df = just_these_subcorpora(df, just_subcorpora, prinf=print_info)
        if using_totals:
            df2 = just_these_subcorpora(df2, just_subcorpora, prinf=False)

    if skip_subcorpora:
        df = skip_these_subcorpora(df, skip_subcorpora, prinf=print_info)
        if using_totals:
            df2 = skip_these_subcorpora(df2, skip_subcorpora, prinf=False)

    if span_subcorpora:
        df = span_these_subcorpora(df, span_subcorpora, prinf=print_info)
        if using_totals:
            df2 = span_these_subcorpora(df2, span_subcorpora, prinf=False)

    if just_entries:
        df = just_these_entries(df, parse_input(df, just_entries), prinf=print_info)
        if not single_totals:
            df2 = just_these_entries(df2, parse_input(df2, just_entries), prinf=False)
    if skip_entries:
        df = skip_these_entries(df, parse_input(df, skip_entries), prinf=print_info)
        if not single_totals:
            df2 = skip_these_entries(df2, parse_input(df2, skip_entries), prinf=False)

    # drop infinites and nans
    if operation != "d":
        df = df.replace([np.inf, -np.inf], np.nan)
        df = df.fillna(0.0)

    # make just_totals as dataframe
    just_one_total_number = False
    if just_totals:
        df = pd.DataFrame(df.sum(), columns=["Combined total"])
        if using_totals:
            if not single_totals:
                df2 = pd.DataFrame(df2.sum(), columns=["Combined total"])
            else:
                just_one_total_number = True
                df2 = df2.sum()

    tots = df.sum(axis=1)

    if using_totals or outputmode:
        if not operation.startswith("k"):
            the_threshold = 0
            # set a threshold if just_totals
            if outputmode is True:
                df2 = df.T.sum()
                if not just_totals:
                    df2.name = "Total"
                else:
                    df2.name = "Combined total"
                using_totals = True
                single_totals = True
            if just_totals:
                if not single_totals:
                    the_threshold = set_threshold(df2, threshold, prinf=print_info)
            if operation == "d":
                the_threshold = set_threshold(df2, threshold, prinf=print_info)
            df, tots = combiney(df, df2, operation=operation, threshold=the_threshold, prinf=print_info)

    # if doing keywording...
    if operation.startswith("k"):
        from keys import keywords

        # allow saved dicts to be df2, etc
        try:
            if denominator == "self":
                df2 = df.copy()
        except TypeError:
            pass
        if type(denominator) == str:
            if denominator != "self":
                df2 = denominator

        else:
            the_threshold = False

        df = keywords(
            df,
            df2,
            selfdrop=selfdrop,
            threshold=threshold,
            printstatus=print_info,
            editing=True,
            calc_all=calc_all,
            **kwargs
        )

        # eh?
        df = df.T

    # drop infinites and nans
    if operation != "d":
        df = df.replace([np.inf, -np.inf], np.nan)
        df = df.fillna(0.0)

    # resort data
    if sort_by or keep_stats:
        df = resort(df, keep_stats=keep_stats, sort_by=sort_by)
        if type(df) == bool:
            if df is False:
                return "linregress"

    if keep_top:
        if not just_totals:
            df = df[list(df.columns)[:keep_top]]
        else:
            df = df.head(keep_top)

    if just_totals:
        # turn just_totals into series:
        df = pd.Series(df["Combined total"], name="Combined total")

    if df1_istotals:
        if operation.startswith("k"):
            try:
                df = pd.Series(df.ix[dataframe1.name])
                df.name = "%s: keyness" % df.name
            except:
                df = df.iloc[0, :]
                df.name = "keyness" % df.name

    # generate totals branch if not percentage results:
    # fix me
    if df1_istotals or operation.startswith("k"):
        if not just_totals:
            try:
                total = pd.Series(df["Total"], name="Total")
            except:
                pass
                total = "none"
            # total = df.copy()
        else:
            total = "none"
    else:
        # might be wrong if using division or something...
        try:
            total = df.T.sum(axis=1)
        except:
            total = "none"

    if type(tots) != pandas.core.frame.DataFrame and type(tots) != pandas.core.series.Series:
        total = df.sum(axis=1)
    else:
        total = tots

    if type(df) == pandas.core.frame.DataFrame:
        datatype = df.ix[0].dtype
    else:
        datatype = df.dtype

    # TURN INT COL NAMES INTO STR
    try:
        df.results.columns = [str(d) for d in list(df.results.columns)]
    except:
        pass

    def add_tkt_index(df):
        if type(df) != pandas.core.series.Series:
            df = df.T
            df = df.drop("tkintertable-order", errors="ignore", axis=0)
            df = df.drop("tkintertable-order", errors="ignore", axis=1)
            df["tkintertable-order"] = pd.Series(
                [index for index, data in enumerate(list(df.index))], index=list(df.index)
            )
            df = df.T
        return df

    # while tkintertable can't sort rows
    from tests import check_t_kinter

    tk = check_t_kinter()
    if tk:
        df = add_tkt_index(df)

    if kwargs.get("df1_always_df"):
        if type(df) == pandas.core.series.Series:
            df = pandas.DataFrame(df)

    # outputnames = collections.namedtuple('edited_interrogation', ['query', 'results', 'totals'])
    # output = outputnames(the_options, df, total)

    # delete non-appearing conc lines
    if interrogation.__dict__.get("concordance", None) is None:
        lns = None
    else:
        col_crit = interrogation.concordance["m"].map(lambda x: x in list(df.columns))
        ind_crit = interrogation.concordance["c"].map(lambda x: x in list(df.index))
        lns = interrogation.concordance[col_crit]
        lns = lns.loc[ind_crit]
        lns = Concordance(lns)

    output = Interrogation(results=df, totals=total, query=locs, concordance=lns)

    # print '\nResult (sample)\n'
    if print_info:
        # if merge_entries or merge_subcorpora or span_subcorpora or just_subcorpora or \
        # just_entries or skip_entries or skip_subcorpora or printed_th or projection:
        print("***Done!***\n========================\n")
    # print df.head().T
    # print ''
    if operation.startswith("k") or just_totals or df1_istotals:
        pd.set_option("display.max_rows", 30)
    else:
        pd.set_option("display.max_rows", 15)
    pd.set_option("display.max_columns", 8)
    pd.set_option("max_colwidth", 70)
    pd.set_option("display.width", 800)
    pd.set_option("expand_frame_repr", False)
    pd.set_option("display.float_format", lambda x: "%.2f" % x)

    return output
Example #38
0
 def codetab(self):
     newEditor = editor(self, self)
     newTab = self.mainTabWidget.addTab(newEditor, QtGui.QIcon(self.icons+'tex.png'), "Code Editor")
     self.mainTabWidget.setCurrentIndex(newTab)
     self.printChildren(self.mainTabWidget, "")
Example #39
0
def default(mapeditor):
#   general things

    m=editor(mapeditor)

# a wall around the world

    m.make('wall',type='wall',xyz=(-151,-101,village_height),bbox=[2,204,5])
    m.make('wall',type='wall',xyz=(-151,-101,village_height),bbox=[304,2,5])
    m.make('wall',type='wall',xyz=(-151,100,village_height),bbox=[304,2,5])
    m.make('wall',type='wall',xyz=(100,-101,village_height),bbox=[2,204,5])

# a camp near the origin

    #cfire=m.make('campfire',type='campfire',xyz=(0,4,village_height))
    #m.make('fire',type='fire',xyz=(0.7,0.7,0),parent=cfire.id)
    #m.make('tent',type='tent',xyz=(-1,8,village_height),bbox=[2.5,2.5,3])
    #m.make('lumber',type='lumber',xyz=(-1,3,village_height))
    #m.make('lumber',type='lumber',xyz=(-1,2.5,village_height))

    cfire=m.make('campfire',type='campfire',xyz=(35,54,village_height))
    m.make('fire',type='fire',xyz=(0.7,0.7,0),parent=cfire.id)

    cfire=m.make('campfire',type='campfire',xyz=(42,51,village_height))
    m.make('fire',type='fire',xyz=(0.7,0.7,0),parent=cfire.id)

    cfire=m.make('campfire',type='campfire',xyz=(43,39,village_height))
    m.make('fire',type='fire',xyz=(0.7,0.7,0),parent=cfire.id)

    m.make('sign_market_w',type='sign_market_w',xyz=(-8.7,-21.2,village_height))

    for i in range(0, 20):
        m.make('lumber',type='lumber',xyz=(uniform(-100,0),uniform(-100,-80),village_height))

#   general
    m.make('oak',type='oak',xyz=(-70,-86,village_height), bbox=[1,1,6])
    m.make('oak',type='oak',xyz=(-6,-77,village_height), bbox=[1,1,6])
    m.make('oak',type='oak',xyz=(-24,-90,village_height), bbox=[1,1,6])
    m.make('oak',type='oak',xyz=(-49,-90,village_height), bbox=[1,1,6])
    m.make('oak',type='oak',xyz=(-86,-81,village_height), bbox=[1,1,6])
    m.make('oak',type='oak',xyz=(-12,-98,village_height), bbox=[1,1,6])
    m.make('oak',type='oak',xyz=(-35,-73,village_height), bbox=[1,1,6])
    m.make('oak',type='oak',xyz=(-83,-66,village_height), bbox=[1,1,6])
    m.make('oak',type='oak',xyz=(-87,-34,village_height), bbox=[1,1,6])
    m.make('oak',type='oak',xyz=(-98,-28,village_height), bbox=[1,1,6])
    m.make('oak',type='oak',xyz=(-75,31,village_height), bbox=[1,1,6])

    m.make('weather',type='weather',desc='object that describes the weather',
           xyz=(0,1,0), rain=0.0)

#   bones all over the place
    for i in range(0, 10):
        xpos = uniform(-150,100)
        ypos = uniform(-100,100)
        m.make('skull', type='skull', xyz=(xpos+uniform(-2,2),ypos+uniform(-2,2),village_height))
        m.make('pelvis', type='pelvis', xyz=(xpos+uniform(-2,2),ypos+uniform(-2,2),village_height))
        m.make('arm', type='arm', xyz=(xpos+uniform(-2,2),ypos+uniform(-2,2),village_height))
        m.make('thigh', type='thigh', xyz=(xpos+uniform(-2,2),ypos+uniform(-2,2),village_height))
        m.make('shin', type='shin', xyz=(xpos+uniform(-2,2),ypos+uniform(-2,2),village_height))
        m.make('ribcage', type='ribcage', xyz=(xpos+uniform(-2,2),ypos+uniform(-2,2),village_height))

#   the lych, who makes bones into skeletons
    lych=m.make('lych', type='lych', xyz=(-21, -89, village_height))
    m.learn(lych,lych_goals)
    m.know(lych,lych_knowledge)
    m.tell_importance(lych,il.assemble,'>',il.patrol)

#   animals
    piglet = m.make('pig', type='pig', xyz=(-31,-16,village_height))
    m.learn(piglet,pig_goals)

    wolf = m.make('wolf', type='wolf', xyz=(90,-90,village_height))
    m.learn(wolf,wolf_goals)
    m.know(wolf,wolf_knowledge)
    m.tell_importance(wolf,il.forage,'>',il.hunt)
    m.tell_importance(wolf,il.forage,'>',il.patrol)
    m.tell_importance(wolf,il.hunt,'>',il.patrol)

    crab = m.make('crab', type='crab', xyz=(-90,90,village_height))
    m.learn(crab,crab_goals)

    skeleton = m.make('skeleton', type='skeleton', xyz=(-38,-25,village_height))

    #squirrel = m.make('squirrel', type='squirrel', desc='test squirrel',
                    #xyz=(-32,-115,village_height))
    #m.know(squirrel,sknowledge)
    #m.learn(squirrel,(il.transport,"transport_something(self,'acorn','forest','stash')"))

#   villagers

    # Some generic market traders, to operate the market stalls
    stall_list = ['mstall_bakery_2_se', 'mstall_beer_1_se',
                  'mstall_blacksmith_1_sw', 'mstall_blue_1_us',
                  'mstall_books_2_sw', 'mstall_cheese_2_se',
                  'mstall_fish_1_se', 'mstall_freshmeat_1_se',
                  'mstall_fruits_2_se', 'mstall_healer_1_sw',
                  'mstall_household_1_sw', 'mstall_jewels_1_sw',
                  'mstall_magic_items_1_sw', 'mstall_milk_2_se',
                  'mstall_seamstress_1_sw', 'mstall_vegetables_1_se',
                  'mstall_wine_1_se']
    directions = [[0,1,0],[1,0,0],[0,-1,0],[-1,0,0],
                  [0.7,0.7,0],[0.7,-0.7,0],[-0.7,-0.7,0],[-0.7,0.7,0]]
    trader_list = ['merchant', 'maid_brown', 'maid_blond', 'maid_red']
    for stall in stall_list:
        trader=m.make('trader',type=trader_list[randint(0,3)],
                 xyz=(uniform(-36,-56),uniform(-7,-17),village_height),
                 age=probability.fertility_age,face=directions[randint(0,7)])
        m.learn(trader,(il.market,"run_shop('"+stall+"','open','dawn')"))
        m.learn(trader,(il.market,"run_shop('"+stall+"','closed','evening')"))

    #m.make('bstall',type='bstall',xyz=(-41,-5,village_height))

    home1_xyz=(90,-90,village_height)

    butcher=m.make('Ulad Bargan',type='butcher',desc='the butcher',
                 xyz=butcher_stall_xyz,age=probability.fertility_age,sex='male')
    m.learn(butcher,(il.trade,"trade(self, 'pig', 'cleaver', 'cut', 'ham', 'market','day')"))
    m.learn(butcher,(il.buy_livestock,"buy_livestock('pig', 1)"))
    m.learn(butcher,(il.market,"run_shop('mstall_freshmeat_1_se','open','dawn')"))
    m.learn(butcher,(il.market,"run_shop('mstall_freshmeat_1_se','closed','evening')"))
    m.know(butcher,bknowledge)
    m.price(butcher,bprices)
    cleaver=m.make('cleaver', type='cleaver', desc='cleaver for cutting meat',
                   place='market', xyz=(-41,-5,village_height))
    m.own(butcher,cleaver)
    m.learn(butcher,(il.sell,"sell_trade('ham', 'market')"))
    coins=[]
    for i in range(0, 60):
        coins.append(m.make('coin',type='coin',xyz=(0,0,0),parent=butcher.id))
    m.own(butcher,coins)
    

    home2_xyz=(80,80,village_height)
    merchant=m.make('Dyfed Searae',type='merchant',desc='the pig merchant',
         xyz=pig_stall_xyz,age=probability.fertility_age,sex='male',face=[-1,0,0])
    merchant2=m.make('Dylan Searae',type='merchant',desc='the pig merchant',
         xyz=(-28,2,village_height),age=probability.fertility_age,sex='male',face=[0,-1,0])
    merchants=[merchant, merchant2]
    sty=m.make('sty',type='sty',xyz=pig_sty_xyz,status=1.0,bbox=[5,5,3])
    m.know(merchants,mknowledge)
    m.know(merchants,village)
    m.price(merchant,mprices)
    m.price(merchant2,m2prices)
    m.own(merchant,sty)
    m.learn(merchant,(il.keep,"keep('pig', 'sty')"))
    m.learn(merchant, (il.sell,"sell_trade('pig', 'market', 'morning')"))
    m.learn(merchant2,(il.sell,"sell_trade('pig', 'market', 'afternoon')"))
    m.learn(merchants,(il.lunch,"meal(self, 'ham','midday', 'inn')"))
    m.learn(merchants,(il.sup,"meal(self, 'beer', 'evening', 'inn')"))
    piglets=[]
    for i in range(0, 6):
        piglets.append(m.make('pig',type='pig',xyz=(uniform(0,4),uniform(0,4),village_height),parent=sty.id,face=directions[randint(0,7)]))
    m.learn(piglets,pig_goals)
    m.own(merchants,piglets)

    # Warriors - the more adventurous types

    warriors=[]
    warrior=m.make('Tom Harrowe', type='guard',xyz=(uniform(-1,14),uniform(-18,-27),village_height),sex='male',face=directions[randint(0,7)])
    sword=m.make('sword',type='sword',xyz=(0,0,0), parent=warrior.id)
    m.own(warrior,sword)
    warriors.append(warrior)

    warrior=m.make('Mae Dollor', type='guard',xyz=(uniform(-1,14),uniform(-18,-27),village_height),sex='female',face=directions[randint(0,7)])
    sword=m.make('sword',type='sword',xyz=(0,0,0), parent=warrior.id)
    m.own(warrior,sword)
    warriors.append(warrior)

    warrior=m.make('Covan Dubneal',type='guard',xyz=(uniform(-1,14),uniform(-18,-27),village_height),sex='male',face=directions[randint(0,7)])
    sword=m.make('sword',type='sword',xyz=(0,0,0), parent=warrior.id)
    m.own(warrior,sword)
    warriors.append(warrior)

    warrior=m.make('Roal Guddon', type='guard',xyz=(uniform(-1,14),uniform(-18,-27),village_height),sex='male',face=directions[randint(0,7)])
    sword=m.make('sword',type='sword',xyz=(0,0,0), parent=warrior.id)
    m.own(warrior,sword)
    warriors.append(warrior)

    m.learn(warriors,(il.defend,"defend(self, 'sword', 'skeleton', 10)"))

    warrior=m.make('Vonaa Barile',type='archer',xyz=(uniform(-1,14),uniform(-18,-27),village_height),sex='female',face=directions[randint(0,7)])
    m.learn(warrior,(il.hunt,"hunt(self, 'bow', 'deer', 10)"))
    bow=m.make('bow',type='bow',xyz=(0,0,0), parent=warrior.id)
    m.own(warrior,bow)
    warriors.append(warrior)

    warrior=m.make('Lile Birloc', type='archer',xyz=(-2,-2,village_height),sex='female',face=directions[randint(0,7)])
    m.learn(warrior,(il.hunt,"hunt(self, 'bow', 'deer', 10)"))
    bow=m.make('bow',type='bow',xyz=(0,0,0), parent=warrior.id)
    m.own(warrior,bow)
    for i in range(0, 6):
        arrow=m.make('arrow',type='arrow',xyz=(0,0,0), parent=warrior.id)
        m.own(warrior,arrow)
    warriors.append(warrior)

    # Warriors all know where stuff is in the village
    m.know(warriors,village)

    # Warriors enjoy their food and drink
    m.learn(warriors,(il.lunch,"meal(self, 'ham','midday', 'inn')"))
    m.learn(warriors,(il.sup,"meal(self, 'beer', 'evening', 'inn')"))

    m.make('deer',type='deer',xyz=(2,2,village_height))
Example #40
0
def _edit(self, *args, **kwargs):
    from corpkit import editor
    return editor(self, *args, **kwargs)
Example #41
0
def textEditor(init=''):
    return editor.editor(box=True, inittext=init, win_location=(0, 0))
Example #42
0
def default(mapeditor):
#   general things

    m=editor(mapeditor)

#   general
    m.make('oak',type='oak',desc='oak tree',
           xyz=(-16,-8,forest_height),status=1.0)
    m.make('oak',type='oak',desc='oak tree',
           xyz=(-7,19,forest_height),status=1.0)
    m.make('oak',type='oak',desc='oak tree',
           xyz=(3,14,forest_height),status=1.0)
    m.make('oak',type='oak',desc='oak tree',
           xyz=(12,36,forest_height),status=1.0)

#    m.make('oak',type='oak',desc='oak tree',xyz=(-15,-166,forest_height),status=1.0)
#    m.make('oak',type='oak',desc='oak tree',xyz=(-16,-190,forest_height),status=1.0)
#    m.make('oak',type='oak',desc='oak tree',xyz=(-18,-176,forest_height),status=1.0)
#    m.make('oak',type='oak',desc='oak tree',xyz=(-23,-155,forest_height),status=1.0)
#    m.make('oak',type='oak',desc='oak tree',xyz=(-25,-170,forest_height),status=1.0)
#    m.make('oak',type='oak',desc='oak tree',xyz=(-24,-185,forest_height),status=1.0)
#    m.make('oak',type='oak',desc='oak tree',xyz=(-30,-158,forest_height),status=1.0)
#    m.make('oak',type='oak',desc='oak tree',xyz=(-33,-179,forest_height),status=1.0)
#    m.make('oak',type='oak',desc='oak tree',xyz=(-32,-192,forest_height),status=1.0)
#    m.make('oak',type='oak',desc='oak tree',xyz=(-38,-159,forest_height),status=1.0)
#    m.make('oak',type='oak',desc='oak tree',xyz=(-50,-169,forest_height),status=1.0)
#    m.make('oak',type='oak',desc='oak tree',xyz=(-43,-182,forest_height),status=1.0)

#   animals
    for i in range(0, 5):
        m.make('skull',  type='skull', desc='test skull', xyz=(uniform(-2,2),uniform(-2,2),village_height))
        m.make('pelvis', type='pelvis', desc='test pelvis', xyz=(uniform(-2,2),uniform(-2,2),village_height))
        m.make('arm',    type='arm', desc='test arm', xyz=(uniform(-2,2),uniform(-2,2),village_height))
        m.make('thigh',  type='thigh', desc='test thigh', xyz=(uniform(-2,2),uniform(-2,2),village_height))
        m.make('shin',   type='shin', desc='test shin', xyz=(uniform(-2,2),uniform(-2,2),village_height))
        m.make('ribcage',type='ribcage',desc='test ribcage',xyz=(uniform(-2,2),uniform(-2,2),village_height))



    lych=m.make('lych', type='lych', desc='Source of all evil',
                    xyz=(2, 3, village_height))
    m.learn(lych,(il.assemble,
"assemble(self, 'skeleton', ['skull', 'ribcage', 'arm', 'pelvis', 'thigh', 'shin'])"))

    piglet = m.make('pig', type='pig', desc='test piglet',
                    xyz=(-16,13,village_height))
    m.learn(piglet,(il.avoid,"avoid('wolf',10.0)"))
    m.learn(piglet,(il.forage,"forage(self, 'acorn')"))

    piglet = m.make('pig', type='pig', desc='test piglet',
                    xyz=(-18,15,village_height))
    m.learn(piglet,(il.avoid,"avoid('wolf',10.0)"))
    m.learn(piglet,(il.forage,"forage(self, 'acorn')"))

    piglet = m.make('pig', type='pig', desc='test piglet',
                    xyz=(-16,15,village_height))
    m.learn(piglet,(il.avoid,"avoid('wolf',10.0)"))
    m.learn(piglet,(il.forage,"forage(self, 'acorn')"))
     
#    wolf = m.make('wolf', type='wolf', desc='test wolf',
#                  xyz=(-10,-10,village_height))
#    m.learn(wolf,(il.hunt,"predate(self,'pig',50.0)"))
#    m.learn(wolf,wander)

    #crab = m.make('crab', type='crab', desc='test crab',
    #                xyz=(-40,-125,village_height))
    #m.learn(crab,wander)

#    skeleton = m.make('skeleton', type='skeleton', desc='test skeleton',
#                    xyz=(-38,-125,village_height))

    #squirrel = m.make('squirrel', type='squirrel', desc='test squirrel',
                    #xyz=(-32,-115,village_height))
    #m.know(squirrel,sknowledge)
    #m.learn(squirrel,(il.transport,"transport_something(self,'acorn','forest','stash')"))

#   farmers

    #home1_xyz=(100,-130,village_height)

    #butcher=m.make('Bill Brondmore',type='farmer',desc='the butcher',
                   #xyz=home1_xyz,age=probability.fertility_age,sex='male')
    #m.learn(butcher,(il.trade,"trade(self, 'pig', 'cleaver', 'cut', 'sausage', 'market')"))
    #m.know(butcher,bknowledge)
    #cleaver=m.make('cleaver',desc='cleaver for cutting meat',place='market',
                   #xyz=home1_xyz,status=1.0)
    #m.own(butcher,cleaver)

    #home2_xyz=(80,-130,village_height)
    #merchant=m.make('Indor Fergman',type='farmer',desc='the pig merchant',
                   #xyz=home2_xyz,age=probability.fertility_age,sex='female')
    #m.know(merchant,bknowledge)

#    sty=m.make('sty',desc='A pig sty',xyz=(-27,-2,village_height),status=1.0)

    #m.own(merchant,sty)
    #m.learn(merchant,(il.keep,"keep('pig', 'sty')"))
    #m.learn(merchant,(il.sell,"sell_trade('pig', 'market')"))
    #piglet1 = m.make('pig', type='pig', desc='a pig', xyz=(-20,-111,village_height))
    #piglet2 = m.make('pig', type='pig', desc='a pig', xyz=(-21,-111,village_height))
    #m.learn(piglet1,(il.forage,"forage(self, 'acorn')"))
    #m.learn(piglet2,(il.forage,"forage(self, 'acorn')"))
    #piglet3 = m.make('pig', type='pig', desc='a pig', xyz=(-21,-110,village_height))
    #piglet4 = m.make('pig', type='pig', desc='a pig', xyz=(-20,-109,village_height))
    #m.own(merchant,piglet1)
    #m.own(merchant,piglet2)
    #m.own(merchant,piglet3)
    #m.own(merchant,piglet4)

    # generated entries
    # generated by forge/tools/iso_edit_tools/get_client_entities.pl from agrilan.map
    # agrilan.map was created by Pegasus
    m.make('birch_summer_1_us',type='birch_summer_1_us',desc='a dumb birch_summer_1_us object', xyz=(-72,85,village_height))
    m.make('birch_summer_1_us',type='birch_summer_1_us',desc='a dumb birch_summer_1_us object', xyz=(-72,81,village_height))
    m.make('poplar_summer_1_us',type='poplar_summer_1_us',desc='a dumb poplar_summer_1_us object', xyz=(-80,81,village_height))
    m.make('poplar_summer_1_us',type='poplar_summer_1_us',desc='a dumb poplar_summer_1_us object', xyz=(-76,71,village_height))
    m.make('birch_summer_1_us',type='birch_summer_1_us',desc='a dumb birch_summer_1_us object', xyz=(-84,71,village_height))
    m.make('poplar_summer_1_us',type='poplar_summer_1_us',desc='a dumb poplar_summer_1_us object', xyz=(-90,69,village_height))
    m.make('poplar_summer_1_us',type='poplar_summer_1_us',desc='a dumb poplar_summer_1_us object', xyz=(-74,67,village_height))
    m.make('poplar_summer_1_us',type='poplar_summer_1_us',desc='a dumb poplar_summer_1_us object', xyz=(-68,65,village_height))
    m.make('birch_summer_1_us',type='birch_summer_1_us',desc='a dumb birch_summer_1_us object', xyz=(-72,65,village_height))
    m.make('birch_summer_1_us',type='birch_summer_1_us',desc='a dumb birch_summer_1_us object', xyz=(-66,61,village_height))
    m.make('poplar_summer_1_us',type='poplar_summer_1_us',desc='a dumb poplar_summer_1_us object', xyz=(19,55,village_height))
    m.make('poplar_summer_1_us',type='poplar_summer_1_us',desc='a dumb poplar_summer_1_us object', xyz=(-70,55,village_height))
    m.make('fern_1_us',type='fern_1_us',desc='a dumb fern_1_us object', xyz=(-84,51,village_height))
    m.make('poplar_summer_1_us',type='poplar_summer_1_us',desc='a dumb poplar_summer_1_us object', xyz=(-75,41,village_height))
    m.make('poplar_summer_1_us',type='poplar_summer_1_us',desc='a dumb poplar_summer_1_us object', xyz=(-97,31,village_height))
    m.make('oak_summer_1_us',type='oak_summer_1_us',desc='a dumb oak_summer_1_us object', xyz=(-87,25,village_height))
    m.make('roses_flowering_2_us',type='roses_flowering_2_us',desc='a dumb roses_flowering_2_us object', xyz=(83,23,village_height))
    m.make('roses_flowering_2_us',type='roses_flowering_2_us',desc='a dumb roses_flowering_2_us object', xyz=(79,23,village_height))
    m.make('roses_flowering_2_us',type='roses_flowering_2_us',desc='a dumb roses_flowering_2_us object', xyz=(75,23,village_height))
    m.make('roses_flowering_2_us',type='roses_flowering_2_us',desc='a dumb roses_flowering_2_us object', xyz=(59,23,village_height))
    m.make('roses_flowering_2_us',type='roses_flowering_2_us',desc='a dumb roses_flowering_2_us object', xyz=(56,23,village_height))
    m.make('roses_flowering_2_us',type='roses_flowering_2_us',desc='a dumb roses_flowering_2_us object', xyz=(53,23,village_height))
    m.make('roses_flowering_2_us',type='roses_flowering_2_us',desc='a dumb roses_flowering_2_us object', xyz=(49,23,village_height))
    m.make('birch_summer_1_us',type='birch_summer_1_us',desc='a dumb birch_summer_1_us object', xyz=(-95,21,village_height))
    m.make('roses_flowering_2_us',type='roses_flowering_2_us',desc='a dumb roses_flowering_2_us object', xyz=(49,19,village_height))
    m.make('birch_summer_1_us',type='birch_summer_1_us',desc='a dumb birch_summer_1_us object', xyz=(35,17,village_height))
    m.make('birch_summer_1_us',type='birch_summer_1_us',desc='a dumb birch_summer_1_us object', xyz=(-79,17,village_height))
    m.make('roses_flowering_2_us',type='roses_flowering_2_us',desc='a dumb roses_flowering_2_us object', xyz=(49,15,village_height))
    m.make('birch_summer_1_us',type='birch_summer_1_us',desc='a dumb birch_summer_1_us object', xyz=(31,15,village_height))
    m.make('poplar_summer_1_us',type='poplar_summer_1_us',desc='a dumb poplar_summer_1_us object', xyz=(-95,15,village_height))
    m.make('birch_summer_1_us',type='birch_summer_1_us',desc='a dumb birch_summer_1_us object', xyz=(35,13,village_height))
    m.make('house_deco_1_us',type='house_deco_1_us',desc='a dumb house_deco_1_us object', xyz=(53,11,village_height))
    m.make('roses_flowering_2_us',type='roses_flowering_2_us',desc='a dumb roses_flowering_2_us object', xyz=(49,11,village_height))
    m.make('birch_summer_1_us',type='birch_summer_1_us',desc='a dumb birch_summer_1_us object', xyz=(97,7,village_height))
    m.make('birch_summer_1_us',type='birch_summer_1_us',desc='a dumb birch_summer_1_us object', xyz=(-95,6,village_height))
    m.make('house_deco_4_us',type='house_deco_4_us',desc='a dumb house_deco_4_us object', xyz=(-38,3,village_height))
    m.make('house_deco_4_us',type='house_deco_4_us',desc='a dumb house_deco_4_us object', xyz=(-57,3,village_height))
    m.make('roses_flowering_2_us',type='roses_flowering_2_us',desc='a dumb roses_flowering_2_us object', xyz=(27,-1,village_height))
    m.make('roses_flowering_2_us',type='roses_flowering_2_us',desc='a dumb roses_flowering_2_us object', xyz=(-2,-2,village_height))
    m.make('fence_study_ta_1',type='fence_study_ta_1',desc='a dumb fence_study_ta_1 object', xyz=(-27,-2,village_height))
    m.make('barrel_2_ta',type='barrel_2_ta',desc='a dumb barrel_2_ta object', xyz=(13,-3,village_height))
    m.make('roses_flowering_2_us',type='roses_flowering_2_us',desc='a dumb roses_flowering_2_us object', xyz=(27,-4,village_height))
    m.make('poplar_summer_1_us',type='poplar_summer_1_us',desc='a dumb poplar_summer_1_us object', xyz=(35,-5,village_height))
    m.make('barrel_2_ta',type='barrel_2_ta',desc='a dumb barrel_2_ta object', xyz=(13,-5,village_height))
    m.make('barrel_2_ta',type='barrel_2_ta',desc='a dumb barrel_2_ta object', xyz=(11,-5,village_height))
    m.make('box_wood_small_1_ta',type='box_wood_small_1_ta',desc='a dumb box_wood_small_1_ta object', xyz=(3,-5,village_height))
    m.make('barrel_2_ta',type='barrel_2_ta',desc='a dumb barrel_2_ta object', xyz=(1,-5,village_height))
    m.make('roses_flowering_2_us',type='roses_flowering_2_us',desc='a dumb roses_flowering_2_us object', xyz=(-2,-5,village_height))
    m.make('barrel_2_ta',type='barrel_2_ta',desc='a dumb barrel_2_ta object', xyz=(-29,-6,village_height))
    m.make('box_wood_small_1_ta',type='box_wood_small_1_ta',desc='a dumb box_wood_small_1_ta object', xyz=(-46,-6,village_height))
    m.make('box_wood_small_1_ta',type='box_wood_small_1_ta',desc='a dumb box_wood_small_1_ta object', xyz=(-47,-6,village_height))
    m.make('house_deco_1_us',type='house_deco_1_us',desc='a dumb house_deco_1_us object', xyz=(-75,-6,village_height))
    m.make('birch_summer_1_us',type='birch_summer_1_us',desc='a dumb birch_summer_1_us object', xyz=(-97,-6,village_height))
    m.make('roses_flowering_2_us',type='roses_flowering_2_us',desc='a dumb roses_flowering_2_us object', xyz=(27,-7,village_height))
    m.make('barrel_2_ta',type='barrel_2_ta',desc='a dumb barrel_2_ta object', xyz=(1,-7,village_height))
    m.make('barrel_2_ta',type='barrel_2_ta',desc='a dumb barrel_2_ta object', xyz=(-29,-7,village_height))
    m.make('barrel_2_ta',type='barrel_2_ta',desc='a dumb barrel_2_ta object', xyz=(-30,-7,village_height))
    m.make('jar_ornate_tall_med_1_ta',type='jar_ornate_tall_med_1_ta',desc='a dumb jar_ornate_tall_med_1_ta object', xyz=(-48,-7,village_height))
    m.make('maid_brown_sw_kl',type='maid_brown_sw_kl',desc='a dumb maid_brown_sw_kl object', xyz=(-49,-7,village_height))
    m.make('roses_flowering_2_us',type='roses_flowering_2_us',desc='a dumb roses_flowering_2_us object', xyz=(-2,-8,village_height))
    m.make('barrel_2_ta',type='barrel_2_ta',desc='a dumb barrel_2_ta object', xyz=(-29,-8,village_height))
    m.make('barrel_2_ta',type='barrel_2_ta',desc='a dumb barrel_2_ta object', xyz=(-30,-8,village_height))
    m.make('box_wood_small_1_ta',type='box_wood_small_1_ta',desc='a dumb box_wood_small_1_ta object', xyz=(-34,-8,village_height))
    m.make('box_wood_small_1_ta',type='box_wood_small_1_ta',desc='a dumb box_wood_small_1_ta object', xyz=(-36,-8,village_height))
    m.make('box_wood_small_1_ta',type='box_wood_small_1_ta',desc='a dumb box_wood_small_1_ta object', xyz=(-47,-8,village_height))
    m.make('jar_ornate_tall_med_1_ta',type='jar_ornate_tall_med_1_ta',desc='a dumb jar_ornate_tall_med_1_ta object', xyz=(-48,-8,village_height))
    m.make('jar_ornate_tall_med_1_ta',type='jar_ornate_tall_med_1_ta',desc='a dumb jar_ornate_tall_med_1_ta object', xyz=(-49,-8,village_height))
    m.make('poplar_summer_1_us',type='poplar_summer_1_us',desc='a dumb poplar_summer_1_us object', xyz=(35,-9,village_height))
    m.make('house_deco_4_us',type='house_deco_4_us',desc='a dumb house_deco_4_us object', xyz=(15,-9,village_height))
    m.make('chair_ne_wooden_dbrown_1_us',type='chair_ne_wooden_dbrown_1_us',desc='a dumb chair_ne_wooden_dbrown_1_us object', xyz=(5,-9,village_height))
    m.make('barrel_2_ta',type='barrel_2_ta',desc='a dumb barrel_2_ta object', xyz=(-29,-9,village_height))
    m.make('box_wood_small_1_ta',type='box_wood_small_1_ta',desc='a dumb box_wood_small_1_ta object', xyz=(-34,-9,village_height))
    m.make('box_wood_small_1_ta',type='box_wood_small_1_ta',desc='a dumb box_wood_small_1_ta object', xyz=(-35,-9,village_height))
    m.make('box_wood_small_1_ta',type='box_wood_small_1_ta',desc='a dumb box_wood_small_1_ta object', xyz=(-36,-9,village_height))
    m.make('mstall_blue_1_us',type='mstall_blue_1_us',desc='a dumb mstall_blue_1_us object', xyz=(-40,-9,village_height))
    m.make('barrel_2_ta',type='barrel_2_ta',desc='a dumb barrel_2_ta object', xyz=(-41,-9,village_height))
    m.make('mstall_blue_1_us',type='mstall_blue_1_us',desc='a dumb mstall_blue_1_us object', xyz=(-45,-9,village_height))
    m.make('barrel_2_ta',type='barrel_2_ta',desc='a dumb barrel_2_ta object', xyz=(-46,-9,village_height))
    m.make('box_wood_small_1_ta',type='box_wood_small_1_ta',desc='a dumb box_wood_small_1_ta object', xyz=(-47,-9,village_height))
    m.make('roses_flowering_2_us',type='roses_flowering_2_us',desc='a dumb roses_flowering_2_us object', xyz=(27,-10,village_height))
    m.make('box_wood_small_1_ta',type='box_wood_small_1_ta',desc='a dumb box_wood_small_1_ta object', xyz=(-36,-10,village_height))
    m.make('maid_red_se_kl',type='maid_red_se_kl',desc='a dumb maid_red_se_kl object', xyz=(-38,-10,village_height))
    m.make('barrel_2_ta',type='barrel_2_ta',desc='a dumb barrel_2_ta object', xyz=(-40,-10,village_height))
    m.make('barrel_2_ta',type='barrel_2_ta',desc='a dumb barrel_2_ta object', xyz=(-41,-10,village_height))
    m.make('barrel_2_ta',type='barrel_2_ta',desc='a dumb barrel_2_ta object', xyz=(-42,-10,village_height))
    m.make('barrel_2_ta',type='barrel_2_ta',desc='a dumb barrel_2_ta object', xyz=(-46,-10,village_height))
    m.make('barrel_2_ta',type='barrel_2_ta',desc='a dumb barrel_2_ta object', xyz=(-47,-10,village_height))
    m.make('house_deco_3_us',type='house_deco_3_us',desc='a dumb house_deco_3_us object', xyz=(57,-11,village_height))
    m.make('table_ne_wooden_dbrown_1_us',type='table_ne_wooden_dbrown_1_us',desc='a dumb table_ne_wooden_dbrown_1_us object', xyz=(5,-11,village_height))
    m.make('roses_flowering_2_us',type='roses_flowering_2_us',desc='a dumb roses_flowering_2_us object', xyz=(-2,-11,village_height))
    m.make('barrel_2_ta',type='barrel_2_ta',desc='a dumb barrel_2_ta object', xyz=(-29,-11,village_height))
    m.make('barrel_2_ta',type='barrel_2_ta',desc='a dumb barrel_2_ta object', xyz=(-30,-11,village_height))
    m.make('house_deco_3_us',type='house_deco_3_us',desc='a dumb house_deco_3_us object', xyz=(-27,-12,village_height))
    m.make('barrel_2_ta',type='barrel_2_ta',desc='a dumb barrel_2_ta object', xyz=(-29,-12,village_height))
    m.make('barrel_2_ta',type='barrel_2_ta',desc='a dumb barrel_2_ta object', xyz=(-30,-12,village_height))
    m.make('poplar_summer_1_us',type='poplar_summer_1_us',desc='a dumb poplar_summer_1_us object', xyz=(35,-13,village_height))
    m.make('roses_flowering_2_us',type='roses_flowering_2_us',desc='a dumb roses_flowering_2_us object', xyz=(27,-13,village_height))
    m.make('birch_summer_1_us',type='birch_summer_1_us',desc='a dumb birch_summer_1_us object', xyz=(-93,-15,village_height))
    m.make('roses_flowering_2_us',type='roses_flowering_2_us',desc='a dumb roses_flowering_2_us object', xyz=(27,-16,village_height))
    m.make('poplar_summer_1_us',type='poplar_summer_1_us',desc='a dumb poplar_summer_1_us object', xyz=(35,-17,village_height))
    m.make('box_wood_small_1_ta',type='box_wood_small_1_ta',desc='a dumb box_wood_small_1_ta object', xyz=(1,-17,village_height))
    m.make('birch_summer_1_us',type='birch_summer_1_us',desc='a dumb birch_summer_1_us object', xyz=(-88,-17,village_height))
    m.make('roses_flowering_2_us',type='roses_flowering_2_us',desc='a dumb roses_flowering_2_us object', xyz=(-2,-18,village_height))
    m.make('box_wood_small_1_ta',type='box_wood_small_1_ta',desc='a dumb box_wood_small_1_ta object', xyz=(-62,-19,village_height))
    m.make('box_wood_small_1_ta',type='box_wood_small_1_ta',desc='a dumb box_wood_small_1_ta object', xyz=(-63,-19,village_height))
    m.make('box_wood_small_1_ta',type='box_wood_small_1_ta',desc='a dumb box_wood_small_1_ta object', xyz=(-64,-19,village_height))
    m.make('box_wood_small_1_ta',type='box_wood_small_1_ta',desc='a dumb box_wood_small_1_ta object', xyz=(-66,-19,village_height))
    m.make('roses_flowering_2_us',type='roses_flowering_2_us',desc='a dumb roses_flowering_2_us object', xyz=(27,-20,village_height))
    m.make('box_wood_small_1_ta',type='box_wood_small_1_ta',desc='a dumb box_wood_small_1_ta object', xyz=(-65,-20,village_height))
    m.make('poplar_summer_1_us',type='poplar_summer_1_us',desc='a dumb poplar_summer_1_us object', xyz=(35,-21,village_height))
    m.make('roses_flowering_2_us',type='roses_flowering_2_us',desc='a dumb roses_flowering_2_us object', xyz=(-2,-21,village_height))
    m.make('box_wood_small_1_ta',type='box_wood_small_1_ta',desc='a dumb box_wood_small_1_ta object', xyz=(-63,-21,village_height))
    m.make('box_wood_small_1_ta',type='box_wood_small_1_ta',desc='a dumb box_wood_small_1_ta object', xyz=(-65,-21,village_height))
    m.make('house_deco_2_us',type='house_deco_2_us',desc='a dumb house_deco_2_us object', xyz=(6,-22,village_height))
    m.make('roses_flowering_2_us',type='roses_flowering_2_us',desc='a dumb roses_flowering_2_us object', xyz=(27,-23,village_height))
    m.make('roses_flowering_2_us',type='roses_flowering_2_us',desc='a dumb roses_flowering_2_us object', xyz=(-2,-24,village_height))
    m.make('house_deco_3_us',type='house_deco_3_us',desc='a dumb house_deco_3_us object', xyz=(57,-25,village_height))
    m.make('poplar_summer_1_us',type='poplar_summer_1_us',desc='a dumb poplar_summer_1_us object', xyz=(35,-25,village_height))
    m.make('roses_flowering_2_us',type='roses_flowering_2_us',desc='a dumb roses_flowering_2_us object', xyz=(-2,-27,village_height))
    m.make('oak_summer_1_us',type='oak_summer_1_us',desc='a dumb oak_summer_1_us object', xyz=(-98,-28,village_height))
    m.make('poplar_summer_1_us',type='poplar_summer_1_us',desc='a dumb poplar_summer_1_us object', xyz=(35,-29,village_height))
    m.make('box_wood_small_1_ta',type='box_wood_small_1_ta',desc='a dumb box_wood_small_1_ta object', xyz=(-37,-30,village_height))
    m.make('box_wood_small_1_ta',type='box_wood_small_1_ta',desc='a dumb box_wood_small_1_ta object', xyz=(-38,-30,village_height))
    m.make('jar_ornate_tall_med_1_ta',type='jar_ornate_tall_med_1_ta',desc='a dumb jar_ornate_tall_med_1_ta object', xyz=(-40,-30,village_height))
    m.make('box_wood_small_1_ta',type='box_wood_small_1_ta',desc='a dumb box_wood_small_1_ta object', xyz=(-53,-30,village_height))
    m.make('box_wood_small_1_ta',type='box_wood_small_1_ta',desc='a dumb box_wood_small_1_ta object', xyz=(-54,-30,village_height))
    m.make('house_deco_1_us',type='house_deco_1_us',desc='a dumb house_deco_1_us object', xyz=(-63,-30,village_height))
    m.make('barrel_2_ta',type='barrel_2_ta',desc='a dumb barrel_2_ta object', xyz=(-30,-31,village_height))
    m.make('box_wood_small_1_ta',type='box_wood_small_1_ta',desc='a dumb box_wood_small_1_ta object', xyz=(-36,-31,village_height))
    m.make('box_wood_small_1_ta',type='box_wood_small_1_ta',desc='a dumb box_wood_small_1_ta object', xyz=(-37,-31,village_height))
    m.make('box_wood_small_1_ta',type='box_wood_small_1_ta',desc='a dumb box_wood_small_1_ta object', xyz=(-38,-31,village_height))
    m.make('barrel_2_ta',type='barrel_2_ta',desc='a dumb barrel_2_ta object', xyz=(-39,-31,village_height))
    m.make('barrel_2_ta',type='barrel_2_ta',desc='a dumb barrel_2_ta object', xyz=(-40,-31,village_height))
    m.make('jar_ornate_tall_med_1_ta',type='jar_ornate_tall_med_1_ta',desc='a dumb jar_ornate_tall_med_1_ta object', xyz=(-41,-31,village_height))
    m.make('box_wood_small_1_ta',type='box_wood_small_1_ta',desc='a dumb box_wood_small_1_ta object', xyz=(-48,-31,village_height))
    m.make('box_wood_small_1_ta',type='box_wood_small_1_ta',desc='a dumb box_wood_small_1_ta object', xyz=(-54,-31,village_height))
    m.make('barrel_2_ta',type='barrel_2_ta',desc='a dumb barrel_2_ta object', xyz=(-29,-32,village_height))
    m.make('barrel_2_ta',type='barrel_2_ta',desc='a dumb barrel_2_ta object', xyz=(-30,-32,village_height))
    m.make('box_wood_small_1_ta',type='box_wood_small_1_ta',desc='a dumb box_wood_small_1_ta object', xyz=(-37,-32,village_height))
    m.make('box_wood_small_1_ta',type='box_wood_small_1_ta',desc='a dumb box_wood_small_1_ta object', xyz=(-38,-32,village_height))
    m.make('barrel_2_ta',type='barrel_2_ta',desc='a dumb barrel_2_ta object', xyz=(-40,-32,village_height))
    m.make('jar_ornate_tall_med_1_ta',type='jar_ornate_tall_med_1_ta',desc='a dumb jar_ornate_tall_med_1_ta object', xyz=(-41,-32,village_height))
    m.make('mstall_blue_1_us',type='mstall_blue_1_us',desc='a dumb mstall_blue_1_us object', xyz=(-45,-32,village_height))
    m.make('barrel_2_ta',type='barrel_2_ta',desc='a dumb barrel_2_ta object', xyz=(-46,-32,village_height))
    m.make('box_wood_small_1_ta',type='box_wood_small_1_ta',desc='a dumb box_wood_small_1_ta object', xyz=(-47,-32,village_height))
    m.make('box_wood_small_1_ta',type='box_wood_small_1_ta',desc='a dumb box_wood_small_1_ta object', xyz=(-48,-32,village_height))
    m.make('poplar_summer_1_us',type='poplar_summer_1_us',desc='a dumb poplar_summer_1_us object', xyz=(35,-33,village_height))
    m.make('barrel_2_ta',type='barrel_2_ta',desc='a dumb barrel_2_ta object', xyz=(-29,-33,village_height))
    m.make('barrel_2_ta',type='barrel_2_ta',desc='a dumb barrel_2_ta object', xyz=(-30,-33,village_height))
    m.make('barrel_2_ta',type='barrel_2_ta',desc='a dumb barrel_2_ta object', xyz=(-31,-33,village_height))
    m.make('barrel_2_ta',type='barrel_2_ta',desc='a dumb barrel_2_ta object', xyz=(-46,-33,village_height))
    m.make('box_wood_small_1_ta',type='box_wood_small_1_ta',desc='a dumb box_wood_small_1_ta object', xyz=(-48,-33,village_height))
    m.make('barrel_2_ta',type='barrel_2_ta',desc='a dumb barrel_2_ta object', xyz=(-29,-34,village_height))
    m.make('barrel_2_ta',type='barrel_2_ta',desc='a dumb barrel_2_ta object', xyz=(-30,-34,village_height))
    m.make('barrel_2_ta',type='barrel_2_ta',desc='a dumb barrel_2_ta object', xyz=(-31,-34,village_height))
    m.make('maid_red_sw_kl',type='maid_red_sw_kl',desc='a dumb maid_red_sw_kl object', xyz=(-42,-34,village_height))
    m.make('oak_summer_1_us',type='oak_summer_1_us',desc='a dumb oak_summer_1_us object', xyz=(-87,-34,village_height))
    m.make('barrel_2_ta',type='barrel_2_ta',desc='a dumb barrel_2_ta object', xyz=(-29,-35,village_height))
    m.make('barrel_2_ta',type='barrel_2_ta',desc='a dumb barrel_2_ta object', xyz=(-30,-35,village_height))
    m.make('house_deco_3_us',type='house_deco_3_us',desc='a dumb house_deco_3_us object', xyz=(-27,-36,village_height))
    m.make('barrel_2_ta',type='barrel_2_ta',desc='a dumb barrel_2_ta object', xyz=(-29,-36,village_height))
    m.make('poplar_summer_1_us',type='poplar_summer_1_us',desc='a dumb poplar_summer_1_us object', xyz=(35,-37,village_height))
    m.make('house_deco_3_us',type='house_deco_3_us',desc='a dumb house_deco_3_us object', xyz=(57,-39,village_height))
    m.make('poplar_summer_1_us',type='poplar_summer_1_us',desc='a dumb poplar_summer_1_us object', xyz=(35,-41,village_height))
    m.make('poplar_summer_1_us',type='poplar_summer_1_us',desc='a dumb poplar_summer_1_us object', xyz=(-97,-41,village_height))
    m.make('barrel_2_ta',type='barrel_2_ta',desc='a dumb barrel_2_ta object', xyz=(73,-45,village_height))
    m.make('poplar_summer_1_us',type='poplar_summer_1_us',desc='a dumb poplar_summer_1_us object', xyz=(35,-45,village_height))
    m.make('box_wood_small_1_ta',type='box_wood_small_1_ta',desc='a dumb box_wood_small_1_ta object', xyz=(55,-47,village_height))
    m.make('box_wood_small_1_ta',type='box_wood_small_1_ta',desc='a dumb box_wood_small_1_ta object', xyz=(55,-49,village_height))
    m.make('poplar_summer_1_us',type='poplar_summer_1_us',desc='a dumb poplar_summer_1_us object', xyz=(35,-49,village_height))
    m.make('house_deco_1_us',type='house_deco_1_us',desc='a dumb house_deco_1_us object', xyz=(-34,-50,village_height))
    m.make('house_deco_1_us',type='house_deco_1_us',desc='a dumb house_deco_1_us object', xyz=(-45,-50,village_height))
    m.make('house_deco_1_us',type='house_deco_1_us',desc='a dumb house_deco_1_us object', xyz=(-55,-50,village_height))
    m.make('barrel_2_ta',type='barrel_2_ta',desc='a dumb barrel_2_ta object', xyz=(55,-51,village_height))
    m.make('barrel_2_ta',type='barrel_2_ta',desc='a dumb barrel_2_ta object', xyz=(53,-51,village_height))
    m.make('house_deco_3_us',type='house_deco_3_us',desc='a dumb house_deco_3_us object', xyz=(57,-53,village_height))
    m.make('barrel_2_ta',type='barrel_2_ta',desc='a dumb barrel_2_ta object', xyz=(53,-53,village_height))
    m.make('poplar_summer_1_us',type='poplar_summer_1_us',desc='a dumb poplar_summer_1_us object', xyz=(35,-53,village_height))
    m.make('poplar_summer_1_us',type='poplar_summer_1_us',desc='a dumb poplar_summer_1_us object', xyz=(35,-57,village_height))
    m.make('poplar_summer_1_us',type='poplar_summer_1_us',desc='a dumb poplar_summer_1_us object', xyz=(35,-61,village_height))
    m.make('birch_summer_1_us',type='birch_summer_1_us',desc='a dumb birch_summer_1_us object', xyz=(9,-64,village_height))
    m.make('poplar_summer_1_us',type='poplar_summer_1_us',desc='a dumb poplar_summer_1_us object', xyz=(35,-65,village_height))
    m.make('stall_1_ta',type='stall_1_ta',desc='a dumb stall_1_ta object', xyz=(24,-65,village_height))
    m.make('birch_summer_1_us',type='birch_summer_1_us',desc='a dumb birch_summer_1_us object', xyz=(18,-65,village_height))
    m.make('birch_summer_1_us',type='birch_summer_1_us',desc='a dumb birch_summer_1_us object', xyz=(-98,-66,village_height))
    m.make('house_deco_4_us',type='house_deco_4_us',desc='a dumb house_deco_4_us object', xyz=(57,-67,village_height))
    m.make('chair_ne_wooden_dbrown_1_us',type='chair_ne_wooden_dbrown_1_us',desc='a dumb chair_ne_wooden_dbrown_1_us object', xyz=(51,-67,village_height))
    m.make('chair_ne_wooden_dbrown_1_us',type='chair_ne_wooden_dbrown_1_us',desc='a dumb chair_ne_wooden_dbrown_1_us object', xyz=(49,-67,village_height))
    m.make('birch_summer_1_us',type='birch_summer_1_us',desc='a dumb birch_summer_1_us object', xyz=(-93,-67,village_height))
    m.make('birch_summer_1_us',type='birch_summer_1_us',desc='a dumb birch_summer_1_us object', xyz=(9,-68,village_height))
    m.make('table_ne_wooden_dbrown_1_us',type='table_ne_wooden_dbrown_1_us',desc='a dumb table_ne_wooden_dbrown_1_us object', xyz=(49,-69,village_height))
    m.make('poplar_summer_1_us',type='poplar_summer_1_us',desc='a dumb poplar_summer_1_us object', xyz=(35,-69,village_height))
    m.make('birch_summer_1_us',type='birch_summer_1_us',desc='a dumb birch_summer_1_us object', xyz=(-97,-69,village_height))
    m.make('birch_summer_1_us',type='birch_summer_1_us',desc='a dumb birch_summer_1_us object', xyz=(25,-71,village_height))
    m.make('birch_summer_1_us',type='birch_summer_1_us',desc='a dumb birch_summer_1_us object', xyz=(9,-72,village_height))
    m.make('birch_summer_1_us',type='birch_summer_1_us',desc='a dumb birch_summer_1_us object', xyz=(-67,-72,village_height))
    m.make('poplar_summer_1_us',type='poplar_summer_1_us',desc='a dumb poplar_summer_1_us object', xyz=(35,-73,village_height))
    m.make('birch_summer_1_us',type='birch_summer_1_us',desc='a dumb birch_summer_1_us object', xyz=(12,-73,village_height))
    m.make('birch_summer_1_us',type='birch_summer_1_us',desc='a dumb birch_summer_1_us object', xyz=(25,-75,village_height))
    m.make('poplar_summer_1_us',type='poplar_summer_1_us',desc='a dumb poplar_summer_1_us object', xyz=(-97,-75,village_height))
    m.make('birch_summer_1_us',type='birch_summer_1_us',desc='a dumb birch_summer_1_us object', xyz=(-68,-76,village_height))
    m.make('poplar_summer_1_us',type='poplar_summer_1_us',desc='a dumb poplar_summer_1_us object', xyz=(-90,-77,village_height))
    m.make('birch_summer_1_us',type='birch_summer_1_us',desc='a dumb birch_summer_1_us object', xyz=(-98,-77,village_height))
    m.make('stall_1_ta',type='stall_1_ta',desc='a dumb stall_1_ta object', xyz=(16,-79,village_height))
    m.make('stall_1_ta',type='stall_1_ta',desc='a dumb stall_1_ta object', xyz=(13,-79,village_height))
    m.make('oak_summer_1_us',type='oak_summer_1_us',desc='a dumb oak_summer_1_us object', xyz=(-97,-80,village_height))
    m.make('house_deco_2_us',type='house_deco_2_us',desc='a dumb house_deco_2_us object', xyz=(51,-81,village_height))
    m.make('oak_summer_1_us',type='oak_summer_1_us',desc='a dumb oak_summer_1_us object', xyz=(-86,-81,village_height))
    m.make('birch_summer_1_us',type='birch_summer_1_us',desc='a dumb birch_summer_1_us object', xyz=(25,-82,village_height))
    m.make('birch_summer_1_us',type='birch_summer_1_us',desc='a dumb birch_summer_1_us object', xyz=(22,-82,village_height))
    m.make('birch_summer_1_us',type='birch_summer_1_us',desc='a dumb birch_summer_1_us object', xyz=(-21,-82,village_height))
    m.make('birch_summer_1_us',type='birch_summer_1_us',desc='a dumb birch_summer_1_us object', xyz=(-78,-82,village_height))
    m.make('birch_summer_1_us',type='birch_summer_1_us',desc='a dumb birch_summer_1_us object', xyz=(-13,-83,village_height))
    m.make('birch_summer_1_us',type='birch_summer_1_us',desc='a dumb birch_summer_1_us object', xyz=(-85,-83,village_height))
    m.make('birch_summer_1_us',type='birch_summer_1_us',desc='a dumb birch_summer_1_us object', xyz=(-34,-84,village_height))
    m.make('birch_summer_1_us',type='birch_summer_1_us',desc='a dumb birch_summer_1_us object', xyz=(-53,-84,village_height))
    m.make('poplar_summer_1_us',type='poplar_summer_1_us',desc='a dumb poplar_summer_1_us object', xyz=(-93,-84,village_height))
    m.make('birch_summer_1_us',type='birch_summer_1_us',desc='a dumb birch_summer_1_us object', xyz=(-98,-84,village_height))
    m.make('birch_summer_1_us',type='birch_summer_1_us',desc='a dumb birch_summer_1_us object', xyz=(1,-85,village_height))
    m.make('birch_summer_1_us',type='birch_summer_1_us',desc='a dumb birch_summer_1_us object', xyz=(-75,-85,village_height))
    m.make('birch_summer_1_us',type='birch_summer_1_us',desc='a dumb birch_summer_1_us object', xyz=(28,-86,village_height))
    m.make('birch_summer_1_us',type='birch_summer_1_us',desc='a dumb birch_summer_1_us object', xyz=(-60,-86,village_height))
    m.make('oak_summer_1_us',type='oak_summer_1_us',desc='a dumb oak_summer_1_us object', xyz=(-70,-86,village_height))
    m.make('poplar_summer_1_us',type='poplar_summer_1_us',desc='a dumb poplar_summer_1_us object', xyz=(-4,-87,village_height))
    m.make('oak_summer_1_us',type='oak_summer_1_us',desc='a dumb oak_summer_1_us object', xyz=(-10,-87,village_height))
    m.make('poplar_summer_1_us',type='poplar_summer_1_us',desc='a dumb poplar_summer_1_us object', xyz=(-28,-87,village_height))
    m.make('birch_summer_1_us',type='birch_summer_1_us',desc='a dumb birch_summer_1_us object', xyz=(-34,-88,village_height))
    m.make('birch_summer_1_us',type='birch_summer_1_us',desc='a dumb birch_summer_1_us object', xyz=(-69,-88,village_height))
    m.make('birch_summer_1_us',type='birch_summer_1_us',desc='a dumb birch_summer_1_us object', xyz=(-98,-88,village_height))
    m.make('barrel_2_ta',type='barrel_2_ta',desc='a dumb barrel_2_ta object', xyz=(81,-89,village_height))
    m.make('roses_flowering_2_us',type='roses_flowering_2_us',desc='a dumb roses_flowering_2_us object', xyz=(79,-89,village_height))
    m.make('birch_summer_1_us',type='birch_summer_1_us',desc='a dumb birch_summer_1_us object', xyz=(-28,-89,village_height))
    m.make('poplar_summer_1_us',type='poplar_summer_1_us',desc='a dumb poplar_summer_1_us object', xyz=(-66,-89,village_height))
    m.make('birch_summer_1_us',type='birch_summer_1_us',desc='a dumb birch_summer_1_us object', xyz=(-74,-89,village_height))
    m.make('barrel_2_ta',type='barrel_2_ta',desc='a dumb barrel_2_ta object', xyz=(36,-90,village_height))
    m.make('oak_summer_1_us',type='oak_summer_1_us',desc='a dumb oak_summer_1_us object', xyz=(-24,-90,village_height))
    m.make('oak_summer_1_us',type='oak_summer_1_us',desc='a dumb oak_summer_1_us object', xyz=(-49,-90,village_height))
    m.make('poplar_summer_1_us',type='poplar_summer_1_us',desc='a dumb poplar_summer_1_us object', xyz=(-83,-90,village_height))
    m.make('birch_summer_1_us',type='birch_summer_1_us',desc='a dumb birch_summer_1_us object', xyz=(1,-91,village_height))
    m.make('poplar_summer_1_us',type='poplar_summer_1_us',desc='a dumb poplar_summer_1_us object', xyz=(-12,-91,village_height))
    m.make('birch_summer_1_us',type='birch_summer_1_us',desc='a dumb birch_summer_1_us object', xyz=(-92,-91,village_height))
    m.make('stall_1_ta',type='stall_1_ta',desc='a dumb stall_1_ta object', xyz=(38,-92,village_height))
    m.make('birch_summer_1_us',type='birch_summer_1_us',desc='a dumb birch_summer_1_us object', xyz=(30,-92,village_height))
    m.make('poplar_summer_1_us',type='poplar_summer_1_us',desc='a dumb poplar_summer_1_us object', xyz=(-55,-92,village_height))
    m.make('poplar_summer_1_us',type='poplar_summer_1_us',desc='a dumb poplar_summer_1_us object', xyz=(-98,-92,village_height))
    m.make('roses_flowering_2_us',type='roses_flowering_2_us',desc='a dumb roses_flowering_2_us object', xyz=(79,-93,village_height))
    m.make('birch_summer_1_us',type='birch_summer_1_us',desc='a dumb birch_summer_1_us object', xyz=(23,-93,village_height))
    m.make('birch_summer_1_us',type='birch_summer_1_us',desc='a dumb birch_summer_1_us object', xyz=(-62,-93,village_height))
    m.make('birch_summer_1_us',type='birch_summer_1_us',desc='a dumb birch_summer_1_us object', xyz=(-77,-93,village_height))
    m.make('birch_summer_1_us',type='birch_summer_1_us',desc='a dumb birch_summer_1_us object', xyz=(41,-94,village_height))
    m.make('birch_summer_1_us',type='birch_summer_1_us',desc='a dumb birch_summer_1_us object', xyz=(12,-94,village_height))
    m.make('poplar_summer_1_us',type='poplar_summer_1_us',desc='a dumb poplar_summer_1_us object', xyz=(4,-94,village_height))
    m.make('birch_summer_1_us',type='birch_summer_1_us',desc='a dumb birch_summer_1_us object', xyz=(-46,-94,village_height))
    m.make('poplar_summer_1_us',type='poplar_summer_1_us',desc='a dumb poplar_summer_1_us object', xyz=(-60,-94,village_height))
    m.make('birch_summer_1_us',type='birch_summer_1_us',desc='a dumb birch_summer_1_us object', xyz=(-15,-95,village_height))
    m.make('birch_summer_1_us',type='birch_summer_1_us',desc='a dumb birch_summer_1_us object', xyz=(-26,-95,village_height))
    m.make('poplar_summer_1_us',type='poplar_summer_1_us',desc='a dumb poplar_summer_1_us object', xyz=(-89,-95,village_height))
    m.make('poplar_summer_1_us',type='poplar_summer_1_us',desc='a dumb poplar_summer_1_us object', xyz=(-1,-96,village_height))
    m.make('birch_summer_1_us',type='birch_summer_1_us',desc='a dumb birch_summer_1_us object', xyz=(-74,-96,village_height))
    m.make('poplar_summer_1_us',type='poplar_summer_1_us',desc='a dumb poplar_summer_1_us object', xyz=(-94,-96,village_height))
    m.make('roses_flowering_2_us',type='roses_flowering_2_us',desc='a dumb roses_flowering_2_us object', xyz=(79,-97,village_height))
    m.make('house_deco_1_us',type='house_deco_1_us',desc='a dumb house_deco_1_us object', xyz=(67,-97,village_height))
    m.make('roses_flowering_2_us',type='roses_flowering_2_us',desc='a dumb roses_flowering_2_us object', xyz=(61,-97,village_height))
    m.make('roses_flowering_2_us',type='roses_flowering_2_us',desc='a dumb roses_flowering_2_us object', xyz=(57,-97,village_height))
    m.make('birch_summer_1_us',type='birch_summer_1_us',desc='a dumb birch_summer_1_us object', xyz=(49,-97,village_height))
    m.make('birch_summer_1_us',type='birch_summer_1_us',desc='a dumb birch_summer_1_us object', xyz=(29,-97,village_height))
    m.make('poplar_summer_1_us',type='poplar_summer_1_us',desc='a dumb poplar_summer_1_us object', xyz=(-22,-97,village_height))
    m.make('birch_summer_1_us',type='birch_summer_1_us',desc='a dumb birch_summer_1_us object', xyz=(-25,-97,village_height))
    m.make('poplar_summer_1_us',type='poplar_summer_1_us',desc='a dumb poplar_summer_1_us object', xyz=(-45,-97,village_height))
    m.make('birch_summer_1_us',type='birch_summer_1_us',desc='a dumb birch_summer_1_us object', xyz=(-89,-97,village_height))
    m.make('birch_summer_1_us',type='birch_summer_1_us',desc='a dumb birch_summer_1_us object', xyz=(-98,-97,village_height))
    m.make('stall_1_ta',type='stall_1_ta',desc='a dumb stall_1_ta object', xyz=(12,-98,village_height))
    m.make('poplar_summer_1_us',type='poplar_summer_1_us',desc='a dumb poplar_summer_1_us object', xyz=(5,-98,village_height))
    m.make('birch_summer_1_us',type='birch_summer_1_us',desc='a dumb birch_summer_1_us object', xyz=(2,-98,village_height))
    m.make('birch_summer_1_us',type='birch_summer_1_us',desc='a dumb birch_summer_1_us object', xyz=(-3,-98,village_height))
    m.make('oak_summer_1_us',type='oak_summer_1_us',desc='a dumb oak_summer_1_us object', xyz=(-12,-98,village_height))
    m.make('poplar_summer_1_us',type='poplar_summer_1_us',desc='a dumb poplar_summer_1_us object', xyz=(-33,-98,village_height))
    m.make('birch_summer_1_us',type='birch_summer_1_us',desc='a dumb birch_summer_1_us object', xyz=(-36,-98,village_height))
    m.make('oak_summer_1_us',type='oak_summer_1_us',desc='a dumb oak_summer_1_us object', xyz=(-41,-98,village_height))
    m.make('poplar_summer_1_us',type='poplar_summer_1_us',desc='a dumb poplar_summer_1_us object', xyz=(-53,-98,village_height))
    m.make('birch_summer_1_us',type='birch_summer_1_us',desc='a dumb birch_summer_1_us object', xyz=(-65,-98,village_height))
    m.make('poplar_summer_1_us',type='poplar_summer_1_us',desc='a dumb poplar_summer_1_us object', xyz=(-84,-98,village_height))
    m.make('birch_summer_1_us',type='birch_summer_1_us',desc='a dumb birch_summer_1_us object', xyz=(45,-99,village_height))
    m.make('birch_summer_1_us',type='birch_summer_1_us',desc='a dumb birch_summer_1_us object', xyz=(-15,-99,village_height))
    m.make('birch_summer_1_us',type='birch_summer_1_us',desc='a dumb birch_summer_1_us object', xyz=(-44,-99,village_height))
    m.make('birch_summer_1_us',type='birch_summer_1_us',desc='a dumb birch_summer_1_us object', xyz=(-55,-99,village_height))
Example #43
0
def pmultiquery(
    path,
    option="c",
    query="any",
    sort_by="total",
    quicksave=False,
    num_proc="default",
    function_filter=False,
    just_speakers=False,
    root=False,
    note=False,
    print_info=True,
    **kwargs
):
    """Parallel process multiple queries or corpora.

    This function is used by interrogator if:

        a) path is a list of paths
        b) query is a dict of named queries
        c) function_filter is iterable
        d) just speakers == 'each'
    
    This function needs joblib 0.8.4 or above in order to run properly."""

    import collections
    import os
    import pandas
    import pandas as pd
    import collections
    from collections import namedtuple
    from time import strftime, localtime
    from interrogator import interrogator
    from editor import editor
    from other import save_result

    try:
        from joblib import Parallel, delayed
    except:
        pass
        # raise ValueError('joblib, the module used for multiprocessing, cannot be found. ' \
        #                 'Install with:\n\n        pip install joblib')
    import multiprocessing

    def best_num_parallel(num_cores, num_queries):
        import corpkit

        """decide how many parallel processes to run

        the idea, more or less, is to balance the load when possible"""
        if num_queries <= num_cores:
            return num_queries
        if num_queries > num_cores:
            if (num_queries / num_cores) == num_cores:
                return int(num_cores)
            if num_queries % num_cores == 0:
                return max([int(num_queries / n) for n in range(2, num_cores) if int(num_queries / n) <= num_cores])
            else:
                import math

                if (float(math.sqrt(num_queries))).is_integer():
                    square_root = math.sqrt(num_queries)
                    if square_root <= num_queries / num_cores:
                        return int(square_root)
        return num_cores

    num_cores = multiprocessing.cpu_count()

    # are we processing multiple queries or corpora?
    # find out optimal number of cores to use.
    multiple_option = False
    multiple_queries = False
    multiple_speakers = False
    multiple_corpora = False

    denom = 1
    if hasattr(path, "__iter__"):
        multiple_corpora = True
        num_cores = best_num_parallel(num_cores, len(path))
        denom = len(path)
    elif hasattr(query, "__iter__"):
        multiple_queries = True
        num_cores = best_num_parallel(num_cores, len(query))
        denom = len(query)
    elif hasattr(function_filter, "__iter__"):
        multiple_option = True
        num_cores = best_num_parallel(num_cores, len(function_filter.keys()))
        denom = len(function_filter.keys())
    elif just_speakers:
        from corpkit.build import get_speaker_names_from_xml_corpus

        multiple_speakers = True
        if just_speakers == "each":
            just_speakers = get_speaker_names_from_xml_corpus(path)
        if len(just_speakers) == 0:
            print "No speaker name data found."
            return
        num_cores = best_num_parallel(num_cores, len(just_speakers))
        denom = len(just_speakers)

    if num_proc != "default":
        num_cores = num_proc

    # make sure quicksaves are right type
    if quicksave is True:
        raise ValueError("quicksave must be string when using pmultiquery.")

    # the options that don't change
    d = {
        "option": option,
        #'paralleling': True,
        "function": "interrogator",
        "root": root,
        "note": note,
        "denominator": denom,
    }
    # add kwargs to query
    for k, v in kwargs.items():
        d[k] = v

    # make a list of dicts to pass to interrogator,
    # with the iterable unique in every one
    ds = []
    if multiple_corpora:
        path = sorted(path)
        for index, p in enumerate(path):
            name = os.path.basename(p)
            a_dict = dict(d)
            a_dict["path"] = p
            a_dict["query"] = query
            a_dict["outname"] = name
            a_dict["just_speakers"] = just_speakers
            a_dict["paralleling"] = index
            a_dict["printstatus"] = False
            ds.append(a_dict)
    elif multiple_queries:
        for index, (name, q) in enumerate(query.items()):
            a_dict = dict(d)
            a_dict["path"] = path
            a_dict["query"] = q
            a_dict["outname"] = name
            a_dict["just_speakers"] = just_speakers
            a_dict["paralleling"] = index
            a_dict["printstatus"] = False
            ds.append(a_dict)
    elif multiple_option:
        for index, (name, q) in enumerate(function_filter.items()):
            a_dict = dict(d)
            a_dict["path"] = path
            a_dict["query"] = query
            a_dict["outname"] = name
            a_dict["just_speakers"] = just_speakers
            a_dict["paralleling"] = index
            a_dict["function_filter"] = q
            a_dict["printstatus"] = False
            ds.append(a_dict)
    elif multiple_speakers:
        for index, name in enumerate(just_speakers):
            a_dict = dict(d)
            a_dict["path"] = path
            a_dict["query"] = query
            a_dict["outname"] = name
            a_dict["just_speakers"] = [name]
            a_dict["function_filter"] = function_filter
            a_dict["paralleling"] = index
            a_dict["printstatus"] = False
            ds.append(a_dict)

    time = strftime("%H:%M:%S", localtime())
    if multiple_corpora and not multiple_option:
        print (
            "\n%s: Beginning %d parallel corpus interrogations:\n              %s"
            "\n\n          Query: '%s'"
            "\n          Interrogating corpus ... \n" % (time, num_cores, "\n              ".join(path), query)
        )

    elif multiple_queries:
        print (
            "\n%s: Beginning %d parallel corpus interrogations: %s"
            "\n          Queries: '%s'"
            "\n          Interrogating corpus ... \n"
            % (time, num_cores, os.path.basename(path), "', '".join(query.values()))
        )

    elif multiple_option:
        print (
            "\n%s: Beginning %d parallel corpus interrogations (multiple options): %s"
            "\n\n          Query: '%s'"
            "\n          Interrogating corpus ... \n" % (time, num_cores, os.path.basename(path), query)
        )

    elif multiple_speakers:
        print (
            "\n%s: Beginning %d parallel corpus interrogations: %s"
            "\n\n          Query: '%s'"
            "\n          Interrogating corpus ... \n" % (time, num_cores, os.path.basename(path), query)
        )

    # run in parallel, get either a list of tuples (non-c option)
    # or a dataframe (c option)
    # import sys
    # reload(sys)
    # stdout=sys.stdout
    failed = False
    # ds = ds[::-1]
    if not root:
        from blessings import Terminal

        terminal = Terminal()
        print "\n" * (len(ds) - 2)
        for dobj in ds:
            linenum = dobj["paralleling"]
            with terminal.location(0, terminal.height - (linenum + 1)):
                # this is a really bad idea.
                thetime = strftime("%H:%M:%S", localtime())
                print "%s: [                      0%% (%s)                            ]" % (thetime, dobj["outname"])

        # res = Parallel(n_jobs=num_cores)(delayed(interrogator)(**x) for x in ds)
        try:
            # ds = sorted(ds, key=lambda k: k['paralleling'], reverse = True)
            res = Parallel(n_jobs=num_cores)(delayed(interrogator)(**x) for x in ds)
            print "\n\n\n"
        except:
            failed = True
            print "Multiprocessing failed."
            raise
        try:
            res = sorted(res)
        except:
            failed = True
            pass
    elif root or failed:
        res = []
        for index, d in enumerate(ds):
            d["startnum"] = (100 / denom) * index
            res.append(interrogator(**d))
        try:
            res = sorted(res)
        except:
            pass

    # multiprocessing way
    # from multiprocessing import Process
    # from corpkit.interrogator import interrogator
    # jobs = []
    ##for d in ds:
    ##    p = multiprocessing.Process(target=interrogator, kwargs=(**d,))
    ##    jobs.append(p)
    ##    p.start()
    ##    while p.is_alive():
    ##        import time
    ##        time.sleep(2)
    ##        if root:
    ##            root.update()
    # result_queue = multiprocessing.Queue()
    #
    # for d in ds:
    # funs = [interrogator(result_queue, **kwargs) for kwargs in ds]
    # jobs = [multiprocessing.Process(mc) for mc in funs]
    # for job in jobs: job.start()
    # for job in jobs: job.join()
    # results = [result_queue.get() for mc in funs]

    # turn list into dict of results, make query and total branches,
    # save and return
    if not option.startswith("c"):
        out = {}
        # print ''
        for (name, data), d in zip(res, ds):
            for unpicklable in ["note", "root"]:
                try:
                    del d[unpicklable]
                except KeyError:
                    pass
            if not option.startswith("k"):
                outputnames = collections.namedtuple("interrogation", ["query", "results", "totals"])
                try:
                    stotal = data.sum(axis=1)
                    stotal.name = u"Total"
                except ValueError:
                    stotal = data.sum()
                output = outputnames(d, data, stotal)
            else:
                outputnames = collections.namedtuple("interrogation", ["query", "results"])
                output = outputnames(d, data)
            out[name] = output

        # could be wrong for unstructured corpora?
        if quicksave:
            fullpath = os.path.join("saved_interrogations", quicksave)
            while os.path.isdir(fullpath):
                selection = raw_input(
                    "\nSave error: %s already exists in %s.\n\nType 'o' to overwrite, or enter a new name: "
                    % (quicksave, "saved_interrogations")
                )
                if selection == "o" or selection == "O":
                    import shutil

                    shutil.rmtree(fullpath)
                else:
                    import os

                    fullpath = os.path.join("saved_interrogations", selection)

            for k, v in out.items():
                save_result(v, k, savedir=fullpath, print_info=False)

            time = strftime("%H:%M:%S", localtime())
            print "\n%s: %d files saved to %s" % (time, len(out.keys()), fullpath)

        time = strftime("%H:%M:%S", localtime())
        print "\n\n%s: Finished! Output is a dictionary with keys:\n\n         '%s'\n" % (
            time,
            "'\n         '".join(sorted(out.keys())),
        )

        return out
    # make query and total branch, save, return
    else:
        out = pd.concat(res, axis=1)
        out = editor(out, sort_by=sort_by, print_info=False, keep_stats=False)
        time = strftime("%H:%M:%S", localtime())
        print "\n\n%s: Finished! %d unique results, %d total." % (time, len(out.results.columns), out.totals.sum())
        if quicksave:
            from other import save_result

            save_result(out, quicksave)
        return out
Example #44
0
    help='The path used to access the file to edit (Ex: ~/.bashrc')
parser.add_argument('-p',
                    nargs='?',
                    const='',
                    action='store',
                    type=str,
                    help='The prompt string to be used')


def split(word):
    return [char for char in word]


args = parser.parse_args()

e = editor(args.file)
p = args.p
if p == 'None':
    p = ''
while True:
    command = split(input(p))
    if command[0] == 'a':
        data = []
        txt = ""
        while txt != "`":
            data.append(txt)
            txt = input()
        data.remove(data[0])
        e.append(data)
    elif command[0] == 'w':
        e.write()
Example #45
0
    def edit(self, *args, **kwargs):
        """Edit results of interrogations, do keywording, sort, etc.

           >>> # rel. frequencies for words without initial capital
           >>> rel = data.edit('%', 'self', skip_entries = r'^[A-Z]')

        ``just/skip_entries`` and ``just/skip_subcorpora`` can take a few different kinds of input:

        * str: treated as regular expression to match
        * list: 

          * of integers: indices to match
          * of strings: entries/subcorpora to match

        ``merge_entries`` and ``merge_subcorpora``, however, are best entered as dicts:

        ``{newname: criteria, newname2: criteria2}```

        where criteria is a string, list, etc.

        :param operation: Kind of maths to do on inputted lists:

           ``'+'``, ``'-'``, ``'/'``, ``'*'``, ``'%'``: self explanatory

           ``'k'``: log likelihood (keywords)

           ``'a'``: get distance metric

           ``'d'``: get percent difference (alternative approach to keywording)

        :type operation: str
        
        :param denominator: List of results or totals.

           If list of results, for each entry in dataframe 1, locate
           entry with same name in dataframe 2, and do maths there
           if 'self', do all merging/keeping operations, then use
           edited dataframe1 as denominator

        :type denominator: pandas.Series/pandas.DataFrame/dict/`self`

        :param sort_by: Calculate slope, stderr, r, p values, then sort by.

           ``'increase'``: highest to lowest slope value
           ``'decrease'``: lowest to highest slope value
           ``'turbulent'``: most change in y axis values
           ``'static'``: least change in y axis values
           ``'total/most'``: largest number first
           ``'infreq/least'``: smallest number first
           ``'name'``: alphabetically

        :type sort_by: str

        :param keep_stats: Keep/drop stats values from dataframe after sorting
        :type keep_stats: bool
        
        :param keep_top: After sorting, remove all but the top *keep_top* results
        :type keep_top: int
        
        :param just_totals: Sum each column and work with sums
        :type just_totals: bool
        
        :param threshold: When using results list as dataframe 2, drop values occurring fewer than n times. If not keywording, you can use:
                                
           ``'high'``: ``denominator total / 2500``
           
           ``'medium'``: ``denominator total / 5000``
           
           ``'low'``: ``denominator total / 10000``
                            
           If keywording, there are smaller default thresholds

        :type threshold: int/bool
        :param just_entries: Keep matching entries
        :type just_entries: see above
        :param skip_entries: Skip matching entries
        :type skip_entries: see above
        :param merge_entries: Merge matching entries
        :type merge_entries: see above
        :param newname: New name for merged entries
        :type newname: str/``'combine'``
        :param just_subcorpora: Keep matching subcorpora
        :type just_subcorpora: see above
        :param skip_subcorpora: Skip matching subcorpora
        :type skip_subcorpora: see above
        :param span_subcorpora: If subcorpora are numerically named, span all from *int* to *int2*, inclusive
        :type span_subcorpora: tuple -- ``(int, int2)``
        :param merge_subcorpora: Merge matching subcorpora
        :type merge_subcorpora: see above
        :param new_subcorpus_name: Name for merged subcorpora
        :type new_subcorpus_name: str/``'combine'``

        :param replace_names: Edit result names and then merge duplicate names.
        :type replace_names: dict -- ``{criteria: replacement_text}``; str -- a regex to delete from names
        :param projection:         a  to multiply results in subcorpus by n
        :type projection: tuple -- ``(subcorpus_name, n)``
        :param remove_above_p: Delete any result over ``p``
        :type remove_above_p: bool
        :param p:                  set the p value
        :type p: float
        
        :param revert_year: When doing linear regression on years, turn annual subcorpora into 1, 2 ...
        :type revert_year: bool
        
        :param print_info: Print stuff to console showing what's being edited
        :type print_info: bool
        
        :param spelling: Convert/normalise spelling:
        :type spelling: str -- ``'US'``/``'UK'``
        
        :param selfdrop: When keywording, try to remove target corpus from reference corpus
        :type selfdrop: bool
        
        :param calc_all: When keywording, calculate words that appear in either corpus
        :type calc_all: bool

        :returns: :class:`corpkit.interrogation.Interrogation`
        """
        from editor import editor
        return editor(self, *args, **kwargs)
Example #46
0
		# making sure charcater is in middle of screen
		g.CORNERPOINT[0] = geo.maximum(player.pos[0] - SCREEN_WIDTH/2, 0)
		g.CORNERPOINT[1] = geo.maximum(player.pos[1] - SCREEN_HEIGHT/2, 0)

		scrollx = 0
		scrolly = 0



		# ---- update shit and draw allGroup ----------------
		background = bigmap.subsurface((g.CORNERPOINT[0], g.CORNERPOINT[1], SCREEN_WIDTH, SCREEN_HEIGHT))
		screen.blit(background, (0,0))
		allGroup.update(seconds)

		# destroy bodies out of the time step else issues
		for body in g.TO_DESTROY :
			_world.DestroyBody(body)
			g.TO_DESTROY.remove(body)
		g.TO_DESTROY = []

		for timer in g.TIMERS :
			timer.update(seconds)
		# take a time step in box2d engine
		_world.Step(TIME_STEP, 10, 10)
		gui.update()
		allGroup.draw(screen)
		pygame.display.flip()

editor.editor(FILEPATH, new = True)
main(FILEPATH)
Example #47
0
def editfunc(self, *args, **kwargs):
    from corpkit import editor
    return editor(self, *args, **kwargs)