Beispiel #1
0
def parse3From12():
    PcfgFileName = 'Corpus1+Corpus2-12-Corrected.pcfg'
    Directors= Directors1+Directors2

    try: nltk.corpus.set_basedir(system_corpora)
    except: system_corpora=nltk.corpus.get_basedir()
    
    logger.initLogger('ParseDirections',LogDir='MarcoLogs')
    import enchant
    from Sense import Lexicon
    spellchecker = enchant.DictWithPWL('en_US', Lexicon)
    DirParser = getDirParser(Directors, Maps, usePOSTagger, POSTaggerFileName,
                             PcfgFileName, SenseTaggerFileName, collectStats,
                             spellchecker=spellchecker)
    Directions = DirectionCorpusReader(constructItemRegexp(Directors3,Maps,mapversions='[01]'))
    parseTestSet(DirParser, Directions, list(Directions.items('CleanDirs')), 1)
            frames.append(SurfaceSemanticsStructure.parse(frame))
        except ValueError,e:
            CaughtErrorTxt = "Can't parse: " + str(e)
            logger.error("%s.",CaughtErrorTxt)
            if str(e).startswith("Error parsing field structure"):
                CaughtError = 'EOFError'
            else:
                CaughtError = 'ValueError'
    return frames,CaughtError,CaughtErrorTxt

def getSSS(instructID):
    if not instructID.endswith('txt'): instructID += '.txt'
    return readCorrFrame([],instructID)[0]

if __name__ == '__main__':
    logger.initLogger('Sense',LogDir='MarcoLogs')
    Directors = ['EDA','EMWC','KLS','KXP','TJS','WLH']
    Maps = ['Jelly','L','Grid']
    Corpus = DirectionCorpusReader(constructItemRegexp(Directors,Maps))
else: Corpus = None

def genCorrContentFrame(filename, Corpus=Corpus, TreePath='CorrFullTrees/'):
    if '-' in filename: instructionID = filename.split('-')[1]
    else: instructionID = filename
    print '\n',instructionID
    if not Corpus:
        Directors = ['EDA','EMWC','KLS','KXP','TJS','WLH']
        Maps = ['Jelly','L','Grid']
        Corpus = DirectionCorpusReader(constructItemRegexp(Directors,Maps))
    Trees=[tree['TREE'] for tree in Corpus.read(TreePath+'/FullTree-'+instructionID)]
    Frames = trees2frames(Trees)
Beispiel #3
0
            logger.error("%s.", CaughtErrorTxt)
            if str(e).startswith("Error parsing field structure"):
                CaughtError = "EOFError"
            else:
                CaughtError = "ValueError"
    return frames, CaughtError, CaughtErrorTxt


def getSSS(instructID):
    if not instructID.endswith("txt"):
        instructID += ".txt"
    return readCorrFrame([], instructID)[0]


if __name__ == "__main__":
    logger.initLogger("Sense", LogDir="MarcoLogs")
    Directors = ["EDA", "EMWC", "KLS", "KXP", "TJS", "WLH"]
    Maps = ["Jelly", "L", "Grid"]
    Corpus = DirectionCorpusReader(constructItemRegexp(Directors, Maps))
else:
    Corpus = None


def genCorrContentFrame(filename, Corpus=Corpus, TreePath="CorrFullTrees/"):
    if "-" in filename:
        instructionID = filename.split("-")[1]
    else:
        instructionID = filename
    print "\n", instructionID
    if not Corpus:
        Directors = ["EDA", "EMWC", "KLS", "KXP", "TJS", "WLH"]
Beispiel #4
0
                             spellchecker=spellchecker)
    Directions = DirectionCorpusReader(
        constructItemRegexp(Directors3, Maps, mapversions='[01]'))
    parseTestSet(DirParser, Directions, list(Directions.items('CleanDirs')), 1)


if __name__ == '__main__':
    if len(sys.argv) > 1 and sys.argv[1]:
        doParses = 'CommandLine'

    try:
        nltk.corpus.set_basedir(system_corpora)
    except:
        system_corpora = nltk.corpus.get_basedir()

    logger.initLogger('ParseDirections', LogDir='MarcoLogs')
    import enchant
    from Sense import Lexicon
    spellchecker = enchant.DictWithPWL('en_US', Lexicon)
    DirParser = getDirParser(Directors,
                             Maps,
                             usePOSTagger,
                             POSTaggerFileName,
                             PcfgFileName,
                             SenseTaggerFileName,
                             collectStats,
                             spellchecker=spellchecker)

    if doParses == 'Profile':
        import profile
        profile.run('testParses(DirParser)', 'parse.prof')
Beispiel #5
0
    def recNeedTurn(cls,desc,viewCache):
        return (len(viewCache) < 4 and
                (desc.type == Path and desc.side in ([Sides],[Right],[Left]))
                )
    recNeedTurn = classmethod(recNeedTurn)

def _test(verbose=False):
    import doctest, Recognizers_Compound, CompoundAction, ViewCache
    doctest.testmod(verbose=verbose)
    d= Recognizers_Compound.__dict__.copy()
    d['PomdpAntieSimRecognizer'] = PomdpAntieSimRecognizer
    d['ViewCache'] = ViewCache.ViewCache
    d['logger'] = logger
    d.update(CompoundAction.__dict__)
    doctest.testmod(Recognizers_Compound, globs=d, verbose=verbose)

def _profile():
    import hotshot, hotshot.stats
    prof = hotshot.Profile("recognizer.prof")
    prof.run('_test()')
    prof.close()
    stats = hotshot.stats.load("recognizer.prof")
    stats.strip_dirs()
    stats.sort_stats('time', 'calls')
    stats.print_stats(40)

if __name__ == '__main__':
    logger.initLogger('Recognizer',LogDir='../MarcoLogs')
    from CompoundAction import *

Beispiel #6
0
def setLog(logDir="/tmp"):
    logger.shutdownLogger()
    logger.initLogger("MARCO_Logs",
                      consoleLevel=logging.CRITICAL,
                      doTrace=False,
                      LogDir=logDir)
Beispiel #7
0
        match = cls.recDetails(desc, viewCache)
        if not match: return match
        for side in desc.side:
            match = False
            if desc.value == Wall and side in (Left, Right, Front, At,
                                               Back) and '0' in desc.dist:
                if side == At and desc.value == Wall: side = Front
                match = viewCache[Front].match(desc.value, side)
            if not match and not disjunct:
                return match  #If still no match, conjunction is impossible
        return match

    Recognizers['Obj'] = recObj
    Recognizers['Thing'] = recObj
    recObj = classmethod(recObj)

    def recNeedTurn(cls, desc, viewCache):
        return False

    recNeedTurn = classmethod(recNeedTurn)


def _test(verbose=False):
    import doctest
    doctest.testmod(verbose=verbose)


if __name__ == '__main__':
    logger.initLogger('Recognizer')
    from ViewCache import ViewCache
    from Sense import Lexicon
    spellchecker = enchant.DictWithPWL('en_US', Lexicon)
    DirParser = getDirParser(Directors, Maps, usePOSTagger, POSTaggerFileName,
                             PcfgFileName, SenseTaggerFileName, collectStats,
                             spellchecker=spellchecker)
    Directions = DirectionCorpusReader(constructItemRegexp(Directors3,Maps,mapversions='[01]'))
    parseTestSet(DirParser, Directions, list(Directions.items('CleanDirs')), 1)

if __name__ == '__main__':
    if len(sys.argv)>1 and sys.argv[1]:
        doParses = 'CommandLine'

    try: nltk.corpus.set_basedir(system_corpora)
    except: system_corpora=nltk.corpus.get_basedir()
    
    logger.initLogger('ParseDirections',LogDir='MarcoLogs')
    import enchant
    from Sense import Lexicon
    spellchecker = enchant.DictWithPWL('en_US', Lexicon)

    DirParser = getDirParser(Directors, Maps, usePOSTagger, POSTaggerFileName,
                             PcfgFileName, SenseTaggerFileName, collectStats,
                             spellchecker=spellchecker)
    
    if doParses == 'Profile':
        import profile
        profile.run('testParses(DirParser)','parse.prof')
    elif doParses == 'TestSet':
        Directions = DirectionCorpusReader(constructItemRegexp(Directors,Maps))
        parseTestSet(DirParser,Directions,TestSet,1)
    elif doParses == 'CommandLine':
    Robot.Recognizers_Compound.Options = Options
    if Percept.startswith('PomdpSim'):
        from Robot.POMDP_Sim import Robot_POMDP_Sim as Robot
    if Percept == 'PomdpSimViewVector':
        from Robot import Recognizers_POMDP_Antie_Periph_Sim as RecognizerModule
        Recognizer = RecognizerModule.PomdpAntiePeriphSimRecognizer
    elif Percept == 'PomdpSimSmallScaleStar':
        from Robot import Recognizers_HSSH as RecognizerModule
        Recognizer = RecognizerModule.HsshRecognizer
        for option in ('FaceDistance', 'FaceUntil', 'FacePast'):
            setattr(Options, option, False)
    RecognizerModule.Options = Options

    logger.shutdownLogger()
    logger.initLogger('Follower-' + str(Orientation),
                      26,
                      Ablate == [],
                      LogDir='MarcoLogs')
    executor = Executor.InstructionQueueExecutor()

    parser = ParseDirections.getDirParser(Directors, Maps, collectStats=False)

    class wrapper(object):
        def __init__(self, liveFn, cannedFn=''):
            self.cannedFn = cannedFn
            self.liveFn = liveFn

        def __call__(self, input, id):
            if id.startswith('INPUT') or CrossValidate:
                return self.liveFn(input), None, ''
            else:
                return self.cannedFn(input, id)
        >>> desc.side = [Right, Back]
        >>> R.recObj(desc, SmallScaleStarViewCache(obs=observation([(Cement, Empty, Wall, Butterfly, Cement, Butterfly), (BlueTile, Hatrack, BlueTile, End, Wall, End)])))
        False
        """
        logger.debug('recObj(%r, %r)',desc,viewCache)
        disjunct = False
        cls.checkDesc(desc,'recObj')
        match = cls.recDetails(desc,viewCache)
        if not match: return match
        for side in desc.side:
            match = False
            if desc.value == Wall and side in (Left,Right,Front,At,Back) and '0' in desc.dist:
                if side == At and desc.value == Wall: side = Front
                match = viewCache[Front].match(desc.value,side)
            if not match and not disjunct: return match #If still no match, conjunction is impossible
        return match
    Recognizers['Obj'] = recObj
    Recognizers['Thing'] = recObj
    recObj = classmethod(recObj)
    
    def recNeedTurn(cls,desc,viewCache): return False
    recNeedTurn = classmethod(recNeedTurn)

def _test(verbose=False):
    import doctest
    doctest.testmod(verbose=verbose)

if __name__ == '__main__':
    logger.initLogger('Recognizer')
    from ViewCache import ViewCache
Beispiel #11
0
        print >> sys.stderr, "for help use --help"
        sys.exit(2)

    if not Routes:
        if Start and Target:
            Routes = [(Map, Start, Target)]
        elif showGUI:
            Routes = [(Map, Start, Target) for Start in Positions
                      for Target in Positions if Start != Target]
        else:
            Routes = [(Map, Start, Target) for Map in Maps
                      for Start in Positions for Target in Positions
                      if Start != Target]

    logger.shutdownLogger()
    logger.initLogger('RouteRunner', 26, LogDir='.')

    if logdir:
        if AllLogs:
            directories = lstail(
                logdir, re.compile('.*_Direction(All|%s)[01]_\d$' % (Map)))
            executor = MultiLogRouteRunner(
                logdir,
                directories=directories,
                Map=Map,
            )
        else:
            executor = LogRouteRunner(
                logdir,
                Map=Map,
            )