Esempio n. 1
0
    def __populate(self):
        self.pop = [ Frog(function=self.ff,
                        constraints=self.constraints)
                        for i in range(self.n)]

        for idx, f in enumerate(self.pop):
            while f.current_fit.ret == 0:
                f = Frog(function=self.ff,
                        constraints=self.constraints)
            self.pop[idx] = f
    def morph_counts_old_version(self, words):
        #Word List to list of all morphisms
        print("len words: ")
        print(len(words))
        print("len unique words: ")
        print(len(set(words)))
        frog = Frog(
            FrogOptions(tok=True,
                        lemma=True,
                        morph=True,
                        daringmorph=False,
                        mwu=False,
                        chunking=False,
                        ner=False,
                        parser=False))
        morphisms = []
        print_counter = 1
        t0 = time.time()
        for word in words:
            output = frog.process(word)
            morphisms_word = output[0].get("morph")
            morphisms_word_list = morphisms_word.replace('[', '').split(']')
            #Momenteel GEEN GEHELE WOORDEN IN COUNT
            if len(morphisms_word_list) > 2:
                morphisms += morphisms_word_list
            total_length = len(words)
            print(str(print_counter) + " of " + str(total_length))
            print_counter += 1
        print("Frog Processing Time:")
        print(self.format_time(time.time() - t0))

        morphisms = list(filter(None, morphisms))
        morph_counts = Counter(morphisms)
        return morph_counts
Esempio n. 3
0
    def __init__(self, width, height, controller, weightIndex=None):
        self.justDied = False
        self.forceUpdate = False
        self.weightIndex = weightIndex
        self.localTrainMode = TRAIN_MODE or GATHER_STATS  # start in train mode if GATHER_STATS
        self.setUpdateIntervals(self.localTrainMode)
        self.width = width
        self.height = height
        self.boardHeight = int(1.5 * height)  # buffers 50% of board
        self.player = Frog(int(width / 2), int(height - 1))
        self.controller = controller
        self.controller.loadWeights()
        self.rowOptions = 2 * ["SAFE"] + 10 * ["ROAD"] + ["RIVER"]

        # open logging file
        if GATHER_STATS:
            self.logfile = open('log.txt', 'w')
            self.logfile.write("TRAINING DATA FOR " +
                               self.controller.id.upper() + " USING " +
                               FEATURE_EXTRACTOR.__name__.upper() + "\n")

        # initialize game
        self.startNewGame()

        # for drawing
        self.surf = pygame.display.set_mode(
            (self.width * BLOCK_SIZE, self.height * BLOCK_SIZE),
            pygame.HWSURFACE)
        pygame.font.init()
        self.score_font = pygame.font.SysFont("monospace", 20)

        # set game to running
        self.running = True
Esempio n. 4
0
def main():
    app = QApplication(sys.argv)
    frog = Frog(Point(900, 300))
    level = Level(5, Point(100, 100), Point(700, 700))
    game = Game(frog, level)
    a = MainGame(1700, 1000, game)
    sys.exit(app.exec_())
Esempio n. 5
0
    def morph_counts_new_version(self, words):
        #Word List to list of all morphisms
        frog = Frog(FrogOptions(tok=True, lemma=True, morph=True, daringmorph=False, mwu=False, chunking=False, ner=False,parser=False))
        words_string = ' '.join(words)
        morphisms = []
        print_counter = 1
        t0 = time.time()
        print("Starting Frog Processing..")
        output = frog.process(words_string)
        print("Process time:")
        process_time = self.format_time(time.time() - t0)
        print(process_time)
        t1 = time.time()
        for i in range(0,len(words)-1):
            morphisms_word = output[i].get("morph")
            morphisms_word_list = morphisms_word.replace('[', '').split(']')
            #Momenteel GEEN GEHELE WOORDEN IN COUNT
            if len(morphisms_word_list) > 2:
                morphisms += morphisms_word_list
            total_length = len(words)
            print(str(print_counter) + " of " + str(total_length))
            print_counter += 1
        print("Process Time:")
        print(process_time)
        print("Getting Morphisms Time:")
        print(self.format_time(time.time() - t1))
        print("Total Time:")
        print(self.format_time(time.time() - t0))



        morphisms = list(filter(None, morphisms))
        morph_counts = Counter(morphisms)
        return morph_counts
Esempio n. 6
0
    def __evolve(self, sub):
        xb = sub[0]
        xw = sub[-1]
        xs = self.pop[0]
        r = np.random.uniform(0, 1)

        # Try to learn from local best
        xt = xb - xw
        xt.p = xw.p + r * (xt.p)
        if (xt.current_fit.ret > xw.current_fit.ret):
            sub[-1] = xt
            return sub

        else:
            # Try to learn from local best
            xt = xs - xw
            xt.p = xw.p + r * (xt.p)
            if (xt.current_fit.ret > xw.current_fit.ret):
                sub[-1] = xt
                return sub
            
            else:
                # Randomize the worst frog in the submemeplex
                sub[-1] = Frog(self.ff, self.constraints)
                return sub
Esempio n. 7
0
def generate_dataset(
    N=100,
    sigma=0.1,
    mu=0,
    balanced_sample=True,  # equal number of each class
    p=[1. / 5] * 5,  # for multinomial distribution of classes
    datapath="/home/joel/datasets/csi5138-img/dataset1"
):  # do not add trailing /

    for i in range(N):
        if balanced_sample:
            c = i % 5
        else:
            c = np.random.multinomial(1, p)  # choose class from distribution p
            c = np.argmax(c)
        # construct vector of N(mu, sigma**2)
        var = sigma * np.random.randn(5) + mu
        # no switch statement in Python?#yes noswitch statement in python
        if c == 0:
            obj = Dog(*var)
        elif c == 1:
            obj = Truck(*var)
        elif c == 2:
            obj = Airplane(*var)
        elif c == 3:
            obj = Person(*var)
        else:
            obj = Frog(*var)

        obj.generate(datapath, i)
Esempio n. 8
0
def play_game(screen):
    frog = Frog(FROG_IMAGE)

    cars = create_cars()
    cars_2 = create_cars()
    cars.extend(cars_2)

    score = Display(color='white', x=-450, y=350)
    game_over = Display('white', 0, 0)

    while True:
        score.display_score(frog.lvl)

        for car in cars:
            car.forward(car.speed)
            frog.move(screen)
            teleport(car)

            if (frog.frog_passed_lvl(LIMIT_UP)):
                random_car = random.choice(cars)
                random_car.speed += 1

                change_car_positions(cars)
            if car.run_over_frog(frog):
                game_over.display_game_over()
                return

        screen.update()
        time.sleep(0.01)
Esempio n. 9
0
def main(window):
    # shortcuts for callbacks
    jump_callback = lambda event: move(event, frog, window.width, window.height)
    move_callback = lambda event: move(event, frog, window.width, window.height, draw=True)
    turn_callback = lambda event: move(event, frog, window.width, window.height, turnonly=True)

    # create a new frog
    frog = Frog(window)
    frog.shape = 'frog'
    frog.bodycolor = 'green'

    # let the frog jump and turn it, if necessary
    window.listen('<Key-Up>', jump_callback)
    window.listen('<Key-Down>', jump_callback)
    window.listen('<Key-Left>', jump_callback)
    window.listen('<Key-Right>', jump_callback)

    # move the frog and turn it, if necessary
    window.listen('<Shift-Key-Up>', move_callback)
    window.listen('<Shift-Key-Down>', move_callback)
    window.listen('<Shift-Key-Left>', move_callback)
    window.listen('<Shift-Key-Right>', move_callback)

    # turn the frog without moving it
    window.listen('<Control-Key-Up>', turn_callback)
    window.listen('<Control-Key-Down>', turn_callback)
    window.listen('<Control-Key-Left>', turn_callback)
    window.listen('<Control-Key-Right>', turn_callback)

    # "write" a dot with space
    window.listen('<space>', lambda event: frog.dot())

    # you can quit the game by clicking `q` or [Esc]
    window.listen('<Key-Escape>', lambda e: window.quit())
    window.listen('<Key-q>', lambda e: window.quit())
Esempio n. 10
0
def main():
    app = QApplication(sys.argv)
    frog = Frog(Point(200, 400))
    level = Level(1, Point(0, 0), Point(700, 700))
    game = Game(frog, level)
    g = Graphics(game, Point(900, 900))
    sys.exit(app.exec_())
Esempio n. 11
0
    def load(self, levelConfigPath):
        """Load the level.

        Args:
            levelConfigPath: Absolute path to the level configuration
                             file. String.
        """
        config = configparser.ConfigParser()
        config.read(levelConfigPath)

        cfg = config['general']
        self.name = cfg.get('name', '')

        # Level background image.
        path = cfg.get('background')
        self.background = StaticImage(os.path.join(self.imageDir, path))

        self.frogPosX = cfg.getint('frogPosX')
        self.frogPosY = cfg.getint('frogPosY')
        self.frogCollisionWidth = cfg.getint('frogCollisionWidth')
        self.frogCollisionHeight = cfg.getint('frogCollisionHeight')

        path = cfg.get('frog')
        self.frog = Frog(self.frogPosX, self.frogPosY, self.screenWidth,
                         self.screenHeight, self.configDir, self.imageDir)

        # Load finish image.
        filepath = cfg.get('finishImage')
        posX = cfg.getint('finishImageX')
        posY = cfg.getint('finishImageY')
        centerX = cfg.getint('finishCenterWidth')
        centerY = cfg.getint('finishcenterHeight')

        finish = StaticImage(os.path.join(self.imageDir, filepath),
                             useAlpha=True)
        finish.rect.topleft = (posX, posY)
        width = int((finish.rect.width - centerX) / 2)
        height = int((finish.rect.height - centerY) / 2)
        finish.collisionRect = pygame.Rect(finish.rect.left + width,
                                           finish.rect.top + height, centerX,
                                           centerY)
        self.finishImage = finish

        self.cars, self.shadows = self.loadCars(config,
                                                self.allowedTrackSections)

        riverTracks, floatingObjects = self.loadFloaters(
            config, self.allowedRiverSections)

        if riverTracks:
            riverTrackRects = []
            for track in riverTracks:
                rect = pygame.Rect(0, track['top'], self.screenWidth,
                                   track['bottom'] - track['top'])
                riverTrackRects.append(rect)

        self.riverTracks = riverTracks
        self.floaters = floatingObjects
        self.riverTrackRects = riverTrackRects
Esempio n. 12
0
def prep_nl(df, filename):
    from frog import Frog, FrogOptions

    print("Tokenizing, POS tagging, and lemmatizing the Dutch data...")

    # Create 'frog' instance. Turn off various options to save time.
    frog = Frog(
        FrogOptions(parser=False, morph=False, chunking=False, ner=False))

    # Define set of possible answers
    if not "STAT_C" in str(filename):
        answers = ['Answer']
    elif "STAT_C" in str(filename):
        answers = ['Answer4a', 'Answer2aDec', 'Answer2aCaus']

    # Loop through answers
    for question_type in answers:

        for index in df.index:
            ans = df.loc[index, question_type]

            # Logging
            if index % 20 == 0:
                print(index, "/", df.index[-1], question_type[6:])

            # Remove numbers
            ans = re.sub("\d+", "", ans)

            # Remove tags in spelling-corrected data
            ans = ans.replace("_abbreviation", "")

            # Remove non-Dutch and illegible words
            ans = re.sub("\w+_nonexistent", "", ans)
            ans = re.sub("\w+_nonexisting", "", ans)
            ans = re.sub("\w+_english", "", ans)
            ans = re.sub("\w+_german", "", ans)
            ans = re.sub("\?+_illegible", "", ans)

            # Preprocess the data with Frog
            ans_dict = frog.process(ans)

            tok_answer = []
            lem_answer = []
            pos_tags = []

            # Append outcomes to list
            for word_index in range(len(ans_dict)):
                if ans_dict[word_index][
                        'pos'] != "LET()":  # Exclude punctuation
                    tok_answer.append(ans_dict[word_index]['text'].lower())
                    lem_answer.append(ans_dict[word_index]['lemma'])
                    pos_tags.append(ans_dict[word_index]['pos'])

            # Fill in the dataframe
            df.at[index, 'Tokenized{}'.format(question_type[6:])] = tok_answer
            df.at[index, 'Lemmatized{}'.format(question_type[6:])] = lem_answer
            df.at[index, 'POS{}'.format(question_type[6:])] = pos_tags

    return df
Esempio n. 13
0
 def test_get_range_circle_returns_circle_of_correct_size(self):
     # arrange
     position = Point(2, 2)
     max_jump = 3
     frog = Frog(position, 3, 0)
     # act
     range_circle = frog.get_range_circle()
     # assert
     assert range_circle.radius == max_jump
Esempio n. 14
0
    def morph_counts_faster_version(self, words):
        #Word List to list of all morphisms

        frog = Frog(FrogOptions(tok=True, lemma=True, morph=True, daringmorph=False, mwu=False, chunking=False, ner=False,parser=False))
        batch_size = 400
        morphisms = []
        print_batch_number = 1
        start_time = time.time()
        total_batch_number = math.ceil(len(words)/batch_size)
        total_process_time = 0
        total_getting_morphisms_time = 0
        for i in range(0, len(words), batch_size):
            t0 = time.time()
            #print_counter = 1
            words_batch = words[i:i + batch_size]
            words_batch_string = ' '.join(words_batch)
            #print("Starting Frog Processing.. for batch = " + str(print_batch_number))
            output = frog.process(words_batch_string)
            #print("Process time:")
            process_time = time.time() - t0
            #print(self.format_time(process_time))
            #print(process_time)
            t1 = time.time()
            for j in range(0,len(words_batch)-1):
                morphisms_word = output[j].get("morph")
                morphisms_word_list = morphisms_word.replace('[', '').split(']')
                #Momenteel GEEN GEHELE WOORDEN IN COUNT
                if len(morphisms_word_list) > 2:
                    morphisms += morphisms_word_list
                total_batch_length = len(words_batch)
                #print(str(print_counter) + " of " + str(total_batch_length) + " -- of batch -- " + str(print_batch_number) + " of " + str(total_batch_number) )
                #print("batch" + " (batch_size: " + str(batch_size) + " words):    " +  str(print_batch_number) + " of " + str(total_batch_number))
                #print_counter += 1
            print_batch_number += 1
            getting_morphisms_time = time.time() - t1
            total_process_time += process_time
            total_getting_morphisms_time += getting_morphisms_time

        print("Total number of words: ")
        print(len(words))
        print("")
        print("Unique number words: ")
        print(len(set(words)))
        print("")
        print("Total Process Time:")
        print(self.format_time(total_process_time))
        print("")
        print("Total Getting Morphisms Time: ")
        print(self.format_time(total_getting_morphisms_time))
        print("")
        print("Total Time:")
        print(self.format_time(time.time() - start_time))
        print("")

        morphisms = list(filter(None, morphisms))
        morph_counts = Counter(morphisms)
        return morph_counts
Esempio n. 15
0
 def test_move_to_lilly_pad_updates_frog_current_lilly_pad(self):
     # arrange
     mock_pad = mock.create_autospec(LillyPad)
     mock_pad.circle = Circle(Point(0, 0), 3)
     position = Point(2, 2)
     frog = Frog(position, 1, 0)
     # act
     frog._move_to_lilly_pad(mock_pad)
     # assert
     assert frog.current_lilly_pad == mock_pad
Esempio n. 16
0
 def test_move_to_lilly_pad_calls_lilly_pad_visit_method(self):
     # arrange
     mock_pad = mock.create_autospec(LillyPad)
     mock_pad.circle = Circle(Point(0, 0), 3)
     position = Point(2, 2)
     frog = Frog(position, 1, 0)
     # act
     frog._move_to_lilly_pad(mock_pad)
     # assert
     assert mock_pad.visit.called
Esempio n. 17
0
 def test_find_possible_pads_returns_no_pads_if_nearby_pad_occupied(self):
     # arrange
     position = Point(2, 2)
     frog = Frog(position, 5, 0)
     pad = LillyPad(Point(2, 4), 1)
     pad.currently_occupied = True
     # act
     possible_pads = frog._find_possible_lilly_pads([pad])
     # assert
     assert len(possible_pads) == 0
Esempio n. 18
0
 def test_find_possible_lilly_pads_returns_empty_list_when_none_are_available(
         self):
     # arrange
     position = Point(20, 20)
     frog = Frog(position, 1, 0)
     pad = LillyPad(Point(2, 4), 1)
     # act
     possible_pads = frog._find_possible_lilly_pads([pad])
     # assert
     assert len(possible_pads) == 0
Esempio n. 19
0
 def test_find_possible_lilly_pads_returns_list_of_lilly_pads_when_some_are_available(
         self):
     # arrange
     position = Point(2, 2)
     frog = Frog(position, 1, 0)
     pad = LillyPad(Point(2, 4), 1)
     # act
     possible_pads = frog._find_possible_lilly_pads([pad])
     # assert
     assert pad in possible_pads
Esempio n. 20
0
    def __init__(self, window):
        self.hangman = Hangman()
        self.window = window

        # create a new pen to write the dashes
        self.pen = Frog(self.window)
        self.pen.visible = False
        self.pen.write(' '.join('_' for char in self.hangman.word))

        if SHOW_SOLUTION:
            # show the solution
            solution = Frog(self.window)
            solution.visible = False
            solution.jumpto(0, 50)
            solution.write(' '.join(char for char in self.hangman.word))

        # prepare a pen for writing the gallow
        self.gallow_writer = Frog(self.window)
        self.gallow_writer.visible = False
        self.gallow_writer.jump(-150)
Esempio n. 21
0
 def test_move_to_lilly_pad_calls_leave_on_current_lilly_pad(self):
     # arrange
     mock_current_pad = mock.create_autospec(LillyPad)
     mock_dest_pad = mock.create_autospec(LillyPad)
     mock_dest_pad.circle = Circle(Point(0, 0), 3)
     position = Point(2, 2)
     frog = Frog(position, 1, 0)
     frog.current_lilly_pad = mock_current_pad
     # act
     frog._move_to_lilly_pad(mock_dest_pad)
     # assert
     assert mock_current_pad.leave.called
Esempio n. 22
0
 def test_find_centre_lilly_pad_returns_lilly_pad_where_centre_is_true(
         self):
     # arrange
     frog = Frog(Point(2, 2), 3, 0)
     pad1 = mock.create_autospec(LillyPad)
     pad1.centre_pad = False
     pad2 = mock.create_autospec(LillyPad)
     pad2.centre_pad = True
     # act
     centre_pad = frog._find_centre_lilly_pad([pad1, pad2])
     # assert
     assert centre_pad == pad2
Esempio n. 23
0
def change_text_to_morphs(sentences,
                          frog_merge=False,
                          save=False,
                          filename=None):
    # sentence list to sentence list in frog morphism form
    morphSentences = []

    frog = Frog(
        FrogOptions(tok=True,
                    lemma=True,
                    morph=True,
                    daringmorph=False,
                    mwu=False,
                    chunking=False,
                    ner=False,
                    parser=False))

    for sentenceNumber in range(0, len(sentences)):
        print(sentenceNumber)
        print("of")
        print(len(sentences))
        sentenceToBeProcessed = sentences[sentenceNumber]
        sentenceToBeProcessed = sentenceToBeProcessed.replace("\n", " ")
        morphSentence = []
        output = frog.process(sentenceToBeProcessed)
        for i in range(0, len(output)):
            morphisms_word = output[i].get("morph")
            morphisms_word_list = morphisms_word.replace('[', '').split(']')
            if frog_merge:
                morphisms_word_list = list(filter(None, morphisms_word_list))
                morphisms_word_list = intersperse(morphisms_word_list,
                                                  "insertmergetoken")
                #print(morphisms_word_list)
            #print("EVET")
            #print(morphisms_word_list)
            morphSentence += morphisms_word_list
        #print("MORPHSENTENCE")
        #print(morphSentence)
        # Remove the empty strings
        morphSentence = list(filter(None, morphSentence))
        #print("ok")
        #print(morphSentence)
        morphSentence = ' '.join(morphSentence)
        #print("HERE")
        #print(morphSentence)
        morphSentences.append(morphSentence)

    if save is True:
        with open(filename, 'wb') as outputfile:
            pickle.dump(morphSentences, outputfile)
    return morphSentences
def change_text_to_morphs(sentences,
                          frog_merge=False,
                          save=False,
                          filename=None):
    # sentence list to sentence list in frog morphism form
    morphSentences = []

    frog = Frog(
        FrogOptions(tok=True,
                    lemma=True,
                    morph=True,
                    daringmorph=False,
                    mwu=False,
                    chunking=False,
                    ner=False,
                    parser=False))
    j = 0
    for sentenceToBeProcessed in sentences:

        if j % 1000 == 0:
            print(j + 1)
            print("of")
            print(len(sentences))

        j += 1
        sentenceToBeProcessed = sentenceToBeProcessed.rstrip('\n')
        morphSentence = []
        output = frog.process(sentenceToBeProcessed)

        for i in range(0, len(output)):
            morphisms_word = output[i].get("morph")
            morphisms_word_list = morphisms_word.replace('[', '').split(']')
            if frog_merge:
                morphisms_word_list = list(filter(None, morphisms_word_list))
                morphisms_word_list = intersperse(morphisms_word_list,
                                                  "__add_merge__")

            morphSentence += morphisms_word_list

        # Remove the empty strings
        morphSentence = list(filter(None, morphSentence))

        morphSentence = ' '.join(morphSentence)
        morphSentences.append(morphSentence)

    if save is True:
        with open(filename, 'wb') as outputfile:
            pickle.dump(morphSentences, outputfile)
    return morphSentences
Esempio n. 25
0
File: level.py Progetto: ikn/latof
 def init(self):
     self._changed = set()
     self._changed_rects = []
     self.overlays = []
     self.ui = {}
     self.dirty = True
     if self.ident != self._last_ident:
         self.game.clear_caches()
     data = conf.LEVELS[self.ident]
     sx, sy = LEVEL_SIZE
     self.objs = objs = [[[] for j in xrange(sx)] for i in xrange(sy)]
     self.road = Road(self)
     self.frog = Frog(self, data['frog pos'], data.get('frog dirn', 1))
     for pos, os in data['objs'].iteritems():
         if isinstance(os, basestring):
             os = (os, )
         objs[pos[0]][pos[1]] = [
             getattr(obj_module, obj)(self, pos) for obj in os
         ]
     self.update_held()
Esempio n. 26
0
def game_run():
    pygame.init()
    screen = pygame.display.set_mode((1200, 800))
    frog = Frog(screen)
    pygame.display.set_caption("Firing frog")
    bg_color = (255, 255, 255)
    screen.fill(
        bg_color)  # Using fill method of pygame.display on screen object

    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()

            elif event.type == pygame.KEYDOWN:
                if event.key == pygame.K_RIGHT:
                    moving_right = True
                elif event.key == pygame.K_LEFT:
                    moving_left = True
                elif event.key == pygame.K_UP:
                    moving_up = True
                elif event.key == pygame.K_DOWN:
                    moving_down = True

            elif event.type == pygame.KEYUP:
                if event.key == pygame.K_RIGHT:
                    moving_right = False
                elif event.key == pygame.K_LEFT:
                    moving_left = False
                elif event.key == pygame.K_UP:
                    moving_up = False
                elif event.key == pygame.K_DOWN:
                    moving_down = False
        frog.update()
        frog.blitme()
        pygame.display.flip()
Esempio n. 27
0
                                  line_txt)  # deal with d'rbij
                line_txt = re.sub(r'^\.', '', line_txt)
                line_txt = re.sub(
                    r'[!?\.,:;]', lambda m: " " + m.group(),
                    line_txt)  # prevent from being interpreted as SPEC(afk)
                #                    if re.search(r'"".+""', line_txt):
                #                        print(re.search(r'"".+""', line_txt).group())
                #                if len(line_txt) > 0:
                #                    if line_txt[-1] not in [".", ",", "!", "?", ":", ";"]:  # add . if chunk does not end in punctuation
                #                            if re.search(r' [A-Za-z]$', line_txt):  # prevent from being interpreted as SPEC(afk)
                #                                line_txt += "!"
                #                            else:
                #                        line_txt += " ."
                txt_dict[file_n][speakers[file_n][spkr]] += line_txt + " "

frog = Frog(FrogOptions(parser=True))


def tag_files(files):
    for fl in files:
        with open(tens_path + "Annotations/pos/" + fl + ".pos", "w") as g:
            for spkr in txt_dict[fl]:
                print(fl, spkr)
                text = txt_dict[fl][spkr]
                #                print(text)
                word_list = frog.process(text)
                print("BLA")
                s_counter = 0
                for word in word_list:
                    if word["index"] == "1":
                        s_counter += 1
Esempio n. 28
0
                    line_txt = re.sub(r'\\-', ' ', line_txt)  # spelling
                    line_txt = re.sub(r'"', '', line_txt)
                    line_txt = re.sub(r'[ ]+(?=[.,:;?!])', "", line_txt)
                    #                    line_txt = re.sub(r'[\.!]*[!]+[\.!]*', '!', line_txt)   # replace combos including at least 1 '!'
                    #                    line_txt = re.sub(r'[\.!?]*[?]+[\.!?]*', '?', line_txt)  # replace combos including at least 1 '?'
                    #                    line_txt = re.sub(r'\.+', '.', line_txt)   # replace clusters of '.' with a single '.'
                    line_txt = re.sub(r'[!.?]+', '!', line_txt)
                    line_txt = re.sub(r'[\x00-\x08\x0b\x0c\x0e-\x1f\x7f-\xff]',
                                      '', line_txt)
                    line_txt = re.sub(r" 's ", " ''s ", line_txt)
                    line_txt = re.sub(r"^'s ", "''s ", line_txt)
                    #                    if re.search(r'"".+""', line_txt):
                    #                        print(re.search(r'"".+""', line_txt).group())
                    txt_dict[pair][part][spkr] += line_txt + " "

frog = Frog(FrogOptions(mwu=False, ner=False))

for pair in txt_dict:
    for part in txt_dict[pair]:
        with open("{}pos/{}/{}_{}.pos".format(ecsd_path, pair, pair, part),
                  "w",
                  encoding="utf-8") as g:
            for spkr in txt_dict[pair][part]:
                print(pair, part, spkr)
                text = txt_dict[pair][part][spkr]
                word_list = frog.process(text)
                s_counter = 0
                w_counter = 0
                for word in word_list:
                    if word["index"] == "1":
                        s_counter += 1
Esempio n. 29
0
#!/usr/bin/env python3

from __future__ import print_function, unicode_literals

from frog import Frog, FrogOptions
import folia.main as folia

frog = Frog(FrogOptions(parser=True))
output = frog.process_raw("Dit is een test")
print("RAW OUTPUT=", output)

output = frog.process("Dit is nog een test.")
print("PARSED OUTPUT=", output)

frog = Frog(FrogOptions(parser=True, xmlout=True))
output = frog.process("Dit is een FoLiA test.")
assert isinstance(output, folia.Document)
assert isinstance(len(output.data), 1)
assert isinstance(
    next(output.data.select(folia.Sentence)).text(), "Dit is een FoLiA test.")
#output is now no longer a string but an instance of folia.Document, provided by the FoLiA library in PyNLPl (pynlpl.formats.folia)
print("FOLIA OUTPUT=")
print(output.xmlstring())

print("Inspecting FoLiA output (example):")
for word in output.words():
    print(word.text() + " " + word.pos() + " " + word.lemma())
assert len(output.words()) == 5
Esempio n. 30
0
from frog import Frog, FrogOptions
from polyglot.downloader import downloader
from polyglot.text import Text, Word
import morfessor
import pickle
import re

Processed_Sentence = " lezen optimaal liep europese unie gekregen spellen rugzak super allesinds boomhut ontwikkelende gemeenschappen vermeenigvuldigde getallen Vereenvoudigd. ....... is werken lopen een kleine test gewoon om te zien of het wel werkt."
#Processed_Sentence = "Ik spring wat rond in het rond"
#frog = Frog(FrogOptions(tok=True, lemma=True, morph = True, daringmorph=False, mwu=False, chunking=True, ner=True, parser=False))
frog = Frog(
    FrogOptions(tok=True,
                lemma=True,
                morph=True,
                daringmorph=False,
                mwu=False,
                chunking=False,
                ner=False,
                parser=False))
output = frog.process(Processed_Sentence)

print("")
print("RAW OUTPUT")
print(output)
print("length")
print(len(output))
print(output[0])
print(output[1])
print(output[2])
print(output[3])