示例#1
0
def extract_bisents(file1, lang1, file2, lang2, alignment_file):
    assert isinstance(lang1, (unicode, str)) and len(lang1)==2
    assert isinstance(lang2, (unicode, str)) and len(lang2)==2
    t1 = Text.from_file(file1, lang1)
    t2 = Text.from_file(file2, lang2)
    alignment = Alignment.from_file(alignment_file)
    bisents = alignment.as_pairs(t1.as_sentences_flat(),
                                 t2.as_sentences_flat())
    return bisents
示例#2
0
    def readFields(self, data_input):
        count = data_input.readInt()
        if count < 0:
            raise IOError("Invalid size: %d for file metadata object" % count)

        for i in xrange(count):
            key = Text.readString(data_input)
            value = Text.readString(data_input)
            self._meta[key] = value
示例#3
0
    def _initialize(self, path, start, length):
        self._stream = self.getStream(path)

        if length == 0:
            self._end = self._stream.getPos() + self._stream.length()
        else:
            self._end = self._stream.getPos() + length

        # Parse Header
        version_block = self._stream.read(len(VERSION))

        self._version = version_block[len(VERSION_PREFIX)]
        if not self._version.startswith(VERSION_PREFIX):
            raise VersionPrefixException(VERSION_PREFIX,
                                         self._version[0:len(VERSION_PREFIX)])

        if self._version > VERSION[len(VERSION_PREFIX)]:
            raise VersionMismatchException(VERSION[len(VERSION_PREFIX)],
                                           self._version)

        if self._version < BLOCK_COMPRESS_VERSION:
            # Same as below, but with UTF8 Deprecated Class
            raise NotImplementedError
        else:
            self._key_class_name = Text.readString(self._stream)
            self._value_class_name = Text.readString(self._stream)

        if ord(self._version) > 2:
            self._decompress = self._stream.readBoolean()
        else:
            self._decompress = False

        if self._version >= BLOCK_COMPRESS_VERSION:
            self._block_compressed = self._stream.readBoolean()
        else:
            self._block_compressed = False

        # setup compression codec
        if self._decompress:
            if self._version >= CUSTOM_COMPRESS_VERSION:
                codec_class = Text.readString(self._stream)
                self._codec = CodecPool().getDecompressor(codec_class)
            else:
                self._codec = CodecPool().getDecompressor()

        self._metadata = Metadata()
        if self._version >= VERSION_WITH_METADATA:
            self._metadata.readFields(self._stream)

        if self._version > 1:
            self._sync = self._stream.read(SYNC_HASH_SIZE)
            self._header_end = self._stream.getPos()
示例#4
0
def fetch_sentences(basename, lang):
    assert lang in ('pl', 'plm',
                    'cu', 'cum', 'cut', 'cue',
                    'el', 'elm', 'elt'), "invalid lang " + lang

    real_lang = lang[:2]
    transformation = lang[2:]

    basename_with_lang = ("%s/%s" % (basename, real_lang))

    try:
        #TODO maybe open ready metaphone files?
        with file("%s.sentences" % basename_with_lang) as f:
            t = [line.decode('utf-8').strip() for line in f.readlines()]
    except IOError:
        t = Text.from_file("%s.txt" % basename_with_lang,
                           lang=real_lang).as_sentences_flat()

    if transformation:
        if transformation == 'm':
            return [metaphone_text(s, lang=real_lang) for s in t]
        elif transformation == 't':
            return [translit_pl(s, real_lang) for s in t]
        elif transformation == 'e':
            return [expand_cu(s, numbers=True) for s in t]
    return t
示例#5
0
def main():
    consts = Constant.constant()
    smmry = Text.text(readfromfile(fname))
    smmry.parseSentences()
    smmry.debugSentencesToFile()
    smmry.debugSentenceContextToFile()
    smmry.debugTextFreqToFile()
    #smmry.getSummary()
    smmry.getSMMRY()
示例#6
0
def export_sentences(input_file, lang, export_type):
    from translit.metaphone import metaphone
    t = Text.from_file(input_file, lang)
    for s in t.as_sentences(paragraph_separator='¶'):
        if export_type == 'hunalign':
            if s == '¶':
                s = '<p>'
            else:
                s = ' '.join(metaphone(w) for w in s.split())
        print s.encode('utf-8')
示例#7
0
	def __init__(self, model, visitor, obj=None, config=None):
		self.model = model
		Generic.__init__(self, visitor, obj, config)
		GenericSerial.__init__(self, visitor, obj, config)
		Text.__init__(self, rows=model.rows, cols=model.cols, yres=8, xres=6, goto=model.goto, chars=model.chars, char0=model.char0)
		if obj is None:
			self.port = ''
			self.baud = 19200
			self.command_rate = .0165
			self.layout_timeout = 0
		else:
			self.port = obj.port
			self.baud = obj.baud
			self.command_rate = obj.command_rate
			self.layout_timeout = obj.layout_timeout

		self.command_thread = ThreadedTask(self.command_worker, None, 1)
		self.command_queue = Queue.Queue()
		self.command_time = time.time()
示例#8
0
文件: CFLCD.py 项目: Starlon/LCD4Py
	def __init__(self, darea, rows=4, cols=20, config=None):
		file = open('cfa635_fonts.dat', 'r')
		self.lcd_fonts = pickle.load(file)
		file.close()
		self.ch_data = []
		self.fontP = None
		self.interface = None
		self.current_state = None
		self.previous_state = None
		self.mode_flag = 0
		self.data_latch = None
		self.data_latch_phase = None
		self.debug = False
		self.cursor = {'row':0, 'col':0}
		self.lcd_gc = None
		self.rows = rows
		self.cols = cols
		self.dots = {'x':6, 'y':8} # Resolution in lcd pixels. e.g. 5x7
		self.pixels = {'x':4, 'y':4} # Resolution in crt pixels - scaled
		self.contrast = None
		self.dot_color = None
		self.title = None
		self.window = None
		self.darea = None
		self.w_width = None
		self.w_height = None
		self.disp_type = 0
		self.border = 5
		self.darea = darea
		self.darea.connect('expose-event', self.lcd_expose_event, self)
		self.darea.connect('button-press-event', self.cursor_event)
		self.bg_color = gtk.gdk.color_parse("#78a878")
		self.fg_color = gtk.gdk.color_parse("#113311")
		self.config = config
		Generic.__init__(self, None, config)
		Text.__init__(self, rows=rows, cols=cols, yres=8, xres=6, goto=0, chars=8, char0=0)
示例#9
0
	def __init__ ( self, visitor, obj=None, config=None):
		Generic.__init__(self, visitor, obj, config)
		GenericSerial.__init__(self, visitor, obj, config)
		Text.__init__(self, rows=4, cols=20, yres=8, xres=5, goto=2, chars=8, char0=0)
		if obj == None:
			self.name = 'noname'
			self.port = ''
			self.baud = 19200
			self.layout_timeout = 0 #Default layout timeout. 0 = no transitions. Override at layout level.
			self.layouts = {}
			self.write_rate = .0165
		else:
			self.name = obj.name
			self.port = obj.port
			self.baud = obj.baud
			self.layout_timeout = obj.layout_timeout
			self.layouts = obj.layouts
			self.write_rate = obj.write_rate
		self.app = visitor
		self.debug = visitor.debug
		self.AddFunction("backlight", 0, self.my_backlight)
		self.write_thread = threading.Thread(target=self.write_worker)
		self.write_active = False
		self.write_queue = Queue.Queue()
示例#10
0
    def _writeFileHeader(self):
        self._stream.write(VERSION)
        Text.writeString(self._stream, self.getKeyClassName())
        Text.writeString(self._stream, self.getValueClassName())

        self._stream.writeBoolean(self._compress)
        self._stream.writeBoolean(self._block_compress)

        if self._codec:
            Text.writeString(self._stream, 'org.apache.hadoop.io.compress.DefaultCodec')

        self._metadata.write(self._stream)
        self._stream.write(self._sync)
示例#11
0
    def _writeFileHeader(self):
        self._stream.write(VERSION)
        Text.writeString(self._stream, self.getKeyClassName())
        Text.writeString(self._stream, self.getValueClassName())

        self._stream.writeBoolean(self._compress)
        self._stream.writeBoolean(self._block_compress)

        if self._codec:
            Text.writeString(self._stream, hadoopClassName(self._codec.__class__))

        self._metadata.write(self._stream)
        self._stream.write(self._sync)
示例#12
0
    def __guess_key(self, min_len=1, max_len=9, display=False):
        keylen = self.guess_key_length(min_len, max_len, display)
        if keylen == 0:
            print "[!] No key length found."
            return -1
        if display:
            print "[*] Most probable key length : " + str(keylen) + "\n"
        freq_fr = {'e': 14.715, 's': 7.948, 'a': 7.636, 'i': 7.529, 't': 7.244, 'n': 7.095, 'r': 6.553, 'u': 6.311, 'l': 5.456, 'o': 5.378, 'd': 3.669, 'c': 3.260, 'p': 3.021, 'm': 2.968, 'v': 1.628, 'q': 1.362, 'f': 1.066, 'b': 0.901, 'g': 0.866, 'h': 0.737, 'j': 0.545, 'x': 0.387, 'y': 0.308, 'z': 0.136, 'w': 0.114, 'k': 0.049}
        password = ""
        for i in range(keylen):
            sub_alphabet = VigenereCipher(''.join([self._s[keylen*j + i] for j in range(self._len//keylen)]))
            min_differential = 99999
            password_letter = ""
            for c in range(65, 65+26):
                sub_alphabet.key = chr(c)
                decrypted = VigenereCipher(sub_alphabet.decipher().tostring())
                sub_alphabet.encipher()
                freq_s = { k:round((v/decrypted.len)*100, 3) for k,v in dict(decrypted.get_frequencies()).items()}
                differential = sum([abs(freq_fr[k.lower()]-v) for k,v in freq_s.items()])
                if differential < min_differential:
                    min_differential = differential
                    password_letter = chr(c)
            password += password_letter

        # Little hack for repetitive password due to frequency analysis
        for i in range(1, len(password)):
            if len(password) % i == 0:
                duplicate = True
                s = [password[j*i:(j+1)*i] for j in range(len(password)//i)]
                ex_prec = s[0]
                for ex in s:
                    if ex != ex_prec:
                        duplicate = False
                        break
                    ex_prec = ex
                if duplicate:
                    password = ex
                    if display:
                        print "[*] [UPDATE] Most probable key length : " + str(len(password)) + "\n"
                    break
        return Text.clean_string(password)
示例#13
0
        def start():
            worldGameObjects = []
            self.mainScene.objects["snake"] = Snake(self.mainScene,
                                                    Vector2(449, 449),
                                                    Vector2(30, 30),
                                                    pygame.Color(200, 0, 0))
            self.mainScene.objects["player"] = Player(
                self.mainScene.objects["snake"],
                0,
                Vector2(0, 0),
                atk=1,
                hp=10)
            food = Food(self.mainScene,
                        Vector2(30 * random.randint(2, 22) - 1,
                                30 * random.randint(2, 22) - 1),
                        1,
                        Vector2(30, 30),
                        pygame.Color(0, 247, 0),
                        None,
                        hp=1)
            enemy1 = Enemy(self.mainScene,
                           Vector2(30 * random.randint(2, 22) - 1,
                                   30 * random.randint(2, 22) - 1),
                           0,
                           Vector2(30, 30),
                           pygame.Color(100, 0, 100),
                           self.mainScene.objects["snake"].getHead(),
                           atk=1,
                           hp=2,
                           speed=30)
            enemy2 = Enemy(self.mainScene,
                           Vector2(30 * random.randint(2, 22) - 1,
                                   30 * random.randint(2, 22) - 1),
                           0,
                           Vector2(30, 30),
                           pygame.Color(100, 0, 100),
                           self.mainScene.objects["snake"].getHead(),
                           atk=1,
                           hp=2,
                           speed=30)
            self.mainScene.objects["scoreDisplay"] = Text(
                self.mainScene, Vector2(70, 1), Vector2(28, 30),
                pygame.Color(0, 0, 0), "Assets/Recreativos.otf", "")
            worldGameObjects = [food]
            enemys = [enemy1, enemy2]
            worldGameObjects.extend(enemys)

            for i in range(0, 24):
                topWallBlock = WallE(self.mainScene, Vector2((30 * i) - 1, -1),
                                     Vector2(30, 30),
                                     pygame.Color(0, 255, 255))
                bottomWallBlock = WallE(self.mainScene,
                                        Vector2((30 * i) + 29, 689),
                                        Vector2(30, 30),
                                        pygame.Color(0, 255, 255))
                leftWallBlock = WallE(self.mainScene,
                                      Vector2(-1,
                                              (30 * i) - 1), Vector2(30, 30),
                                      pygame.Color(0, 255, 255))
                rightWallBlock = WallE(self.mainScene,
                                       Vector2(689, (30 * i) + 29),
                                       Vector2(30, 30),
                                       pygame.Color(0, 255, 255))
                wall = [
                    rightWallBlock, leftWallBlock, topWallBlock,
                    bottomWallBlock
                ]
                worldGameObjects.extend(wall)

            objects["worldGameObjects"] = worldGameObjects
            self.mainScene.objects = objects
示例#14
0
    def main(self):
        count = 0
        self.create_audio()
        self.start_menu_init()
        while True:
            # Main Screen Menu
            if self.mainScreen:
                count += 1
                self.screen.blit(self.background, (0, 0))
                self.titleText.draw(self.screen)
                self.titleText1.draw(self.screen)
                self.titleText2.draw(self.screen)

                if count <= 700:
                    self.start_menu_chase()
                elif count <= 1500:
                    self.intro_animation()
                else:
                    self.start_menu_init()
                    count = 0

                pygame.display.update()
                for events in pygame.event.get():
                    if events.type == pygame.QUIT:
                        exit()
                    if pygame.key.get_pressed()[pygame.K_h]:
                        print('Accessing high scores...')
                        self.screen.blit(self.background, (0, 0))
                        scores = []
                        x = 0
                        with open('highscores.txt') as f:
                            for line in f:
                                name, score = line.split(',')
                                score = int(score)
                                scores.append((name, score))
                        scores = sorted(scores,
                                        key=itemgetter(1),
                                        reverse=True)[:10]
                        for name, score in scores:
                            if name == 'You':
                                Text(FONT, 15, name + ': ' + str(score), RED,
                                     195, 230 + (35 * x)).draw(self.screen)
                            else:
                                Text(FONT, 15, name + ': ' + str(score),
                                     YELLOW, 195,
                                     230 + (35 * x)).draw(self.screen)
                            pygame.display.update()
                            x += 1
                        self.mainScreen = False
                        self.highScore = True
                    if pygame.key.get_pressed()[pygame.K_p]:
                        self.mainScreen = False
                        self.startGame = True
                        self.reset()
                        print('Starting game...')
                        self.draw_chars(result())
                        self.draw_map(result())
                        self.draw_pellets(result())

                        self.set_position()
                        # self.player = Player(self.screen, self.position.x, self.position.y - 15)
                        # self.player_group.add(self.player)
                        self.sounds['pacman_beginning'].play()

            # High Score Menu
            elif self.highScore:
                self.hsText.draw(self.screen)
                self.hsText1.draw(self.screen)
                pygame.display.update()
                for events in pygame.event.get():
                    if events.type == pygame.QUIT:
                        exit()
                    if pygame.key.get_pressed()[pygame.K_ESCAPE]:
                        print('Returning to Main menu...')
                        self.mainScreen = True
                        self.highScore = False
                    if pygame.key.get_pressed()[pygame.K_p]:
                        print('Starting game...')
                        self.highScore = False
                        self.startGame = True

            # Start Game
            elif self.startGame:
                self.draw_stuff()

                # self.nodes.render(self.screen)

                self.vertical_wall.draw(self.screen)
                self.horizontal_wall.draw(self.screen)
                self.pellet_group.draw(self.screen)
                self.fruit_group.draw(self.screen)
                self.shield.draw(self.screen)
                self.power_group.draw(self.screen)
                self.portal_groupO.draw(self.screen)
                self.portal_groupB.draw(self.screen)
                self.draw_screen()
                self.check_events()
                pygame.display.update()

            # Game Over Menu
            elif self.gameOver:
                self.reset()
                self.screen.blit(self.background, (0, 0))
                self.loseText.draw(self.screen)
                self.hsText1.draw(self.screen)
                pygame.display.update()
                for events in pygame.event.get():
                    if events.type == pygame.QUIT:
                        exit()
                    if pygame.key.get_pressed()[pygame.K_ESCAPE]:
                        print('Returning to Main menu...')
                        self.mainScreen = True
                        self.highScore = False
                        self.gameOver = False
示例#15
0
 def get_text(self, lang):
     return Text.from_file(self._p(str(lang) + ".txt"), lang=str(lang))
示例#16
0
 def collision(self):
     super().collision()
     self.player.isDeath = True
     Text.set(self.screen, 'ぐふぅ!!', sprite=self.player)
示例#17
0
 def end(self, text):
     self.objects.append(Text(self.width() / 2, self.height() / 2, text))
     self.repaint()
     self.timer.stop()
     self.stuckTimer.stop()
     self.releaseKeyboard()
示例#18
0
def settings():
    """

    """
    maze_size = Settings.maze_size

    game_display.fill(Color.white)
    text_title = Text(
        (int(screen_size[0] * 0.5), int(screen_size[1] * 0.1)), 'Maze game',
        int(text_size * 3), text_color, text_color_light)

    game_mode_vertical = int(screen_size[1] * 0.3)

    text_mode = Text(
        (int(screen_size[0] * 0.3), game_mode_vertical), 'Game mode',
        int(text_size * 1.5), text_color, text_color_light)
    text_single_player = Text(
        (int(screen_size[0] * 0.58), game_mode_vertical), 'Single player',
        int(text_size * 1.25), text_color, text_color_light)

    text_multiplayer = Text(
        (int(screen_size[0] * 0.72), game_mode_vertical), 'Multiplayer',
        int(text_size * 1.25), text_color, text_color_light)
    text_slash = Text((int(screen_size[0] * 0.65), game_mode_vertical), '/',
                      int(text_size * 1.35), text_color, text_color_light)

    text_computer = Text(
        (int(screen_size[0] * 0.3), int(screen_size[1] * 0.4)), 'Computer',
        int(text_size * 1.5), text_color, text_color_light)
    ai_box = Box((int(screen_size[0] * 0.65), int(screen_size[1] * 0.4)),
                 int(text_size * 1.25), text_color, text_color_light,
                 Settings.ai_mode)

    text_visibility_vertical = int(screen_size[1] * 0.5)

    text_visibility = Text(
        (int(screen_size[0] * 0.3), text_visibility_vertical),
        'Invisible mode', int(text_size * 1.5), text_color, text_color_light)
    visibility_box = Box(
        (int(screen_size[0] * 0.65), text_visibility_vertical),
        int(text_size * 1.25), text_color, text_color_light,
        Settings.invisible_mode)

    # maze type
    maze_type_vertical = int(screen_size[1] * 0.6)

    text_type = Text(
        (int(screen_size[0] * 0.3), maze_type_vertical), 'Maze type',
        int(text_size * 1.5), text_color, text_color_light)
    text_square = Text(
        (int(screen_size[0] * 0.58), maze_type_vertical), 'Square',
        int(text_size * 1.25), text_color, text_color_light)

    text_hexagon = Text(
        (int(screen_size[0] * 0.72), maze_type_vertical), 'Hexagon',
        int(text_size * 1.25), text_color_light, text_color)
    text_slash2 = Text((int(screen_size[0] * 0.65), maze_type_vertical), '/',
                       int(text_size * 1.35), text_color, text_color_light)

    # maze size line
    maze_size_vertical = int(screen_size[1] * 0.7)
    text_maze_size = Text(
        (int(screen_size[0] * 0.3), maze_size_vertical), 'Maze size',
        int(text_size * 1.5), text_color, text_color_light)
    text_maze_size_actual = Text(
        (int(screen_size[0] * 0.65), maze_size_vertical),
        '{0}'.format(maze_size), int(text_size * 1.5), text_color,
        text_color_light)
    text_maze_minus = Text(
        (int(screen_size[0] * 0.62), maze_size_vertical), '-',
        int(text_size * 1.6), text_color_light, text_color)
    text_maze_plus = Text(
        (int(screen_size[0] * 0.68), maze_size_vertical), '+',
        int(text_size * 1.6), text_color_light, text_color)

    text_start = Text(
        (screen_size[0] // 2, int(screen_size[1] * 0.8)), 'Start',
        int(text_size * 2.5), text_color, text_color_light)
    text_back = Text((screen_size[0] // 8, int(screen_size[1] * 0.9)), 'Back',
                     text_size, text_color, text_color_light)

    text_title.show(game_display)
    text_mode.show(game_display)
    text_single_player.show(game_display)
    text_slash.show(game_display)
    text_multiplayer.show(game_display, text_color_light)

    text_computer.show(game_display)
    ai_box.show(game_display)
    text_visibility.show(game_display)
    visibility_box.show(game_display)

    text_type.show(game_display)
    text_square.show(game_display)
    text_slash2.show(game_display)
    text_hexagon.show(game_display)

    text_maze_size.show(game_display)
    text_maze_size_actual.show(game_display)
    text_maze_plus.show(game_display)
    text_maze_minus.show(game_display)

    text_start.show(game_display)
    text_back.show(game_display)

    Functions.mouse_reset()

    while True:
        Functions.buttonpress_detect()

        if text_maze_minus.is_clicked(
        ) and Settings.maze_size > 10 and Settings.maze_size <= 50:
            text_maze_minus.show_click(game_display)
            Settings.maze_size -= 1
            text_maze_size_actual.text = '{0}'.format(Settings.maze_size)
            text_maze_size_actual.show(game_display)
            Functions.mouse_reset()

        if text_maze_plus.is_clicked(
        ) and Settings.maze_size >= 10 and Settings.maze_size < 50:
            text_maze_plus.show_click(game_display)
            Settings.maze_size += 1
            text_maze_size_actual.text = '{0}'.format(Settings.maze_size)
            text_maze_size_actual.show(game_display)
            Functions.mouse_reset()

        if text_single_player.is_clicked() and not Settings.player_mode:
            text_single_player.show(game_display, text_color)
            text_multiplayer.show(game_display, text_color_light)

            text_computer.show(game_display, text_color)
            ai_box.show_click(game_display)

            Settings.player_mode = True
            Settings.game_mode = Settings.game_mode_calculate()

        if text_multiplayer.is_clicked() and Settings.player_mode:
            text_single_player.show(game_display, text_color_light)
            text_multiplayer.show(game_display, text_color)

            text_computer.show(game_display, Color.grey)
            ai_box.show(game_display, Color.grey)

            Settings.player_mode = False
            Settings.game_mode = Settings.game_mode_calculate()

        if ai_box.is_clicked() and Settings.player_mode:
            Settings.ai_mode = not Settings.ai_mode
            ai_box.is_active = not ai_box.is_active

            ai_box.show_click(game_display)
            Settings.game_mode = Settings.game_mode_calculate()

        if visibility_box.is_clicked():
            Settings.invisible_mode = not Settings.invisible_mode
            visibility_box.is_active = not visibility_box.is_active

            visibility_box.show_click(game_display)
            Settings.game_mode = Settings.game_mode_calculate()

        if text_start.is_clicked():
            text_start.show_click(game_display)
            Functions.mouse_reset()
            Game.generation()

        if text_back.is_clicked() or Settings.back_to_menu:
            text_back.show_click(game_display)
            Settings.back_to_menu = True
            break

        if text_square.is_clicked() and Settings.maze_type != 'square':
            text_hexagon.show(game_display, text_color_light)
            text_square.show(game_display, text_color)

            Settings.maze_type = 'square'

        if text_hexagon.is_clicked() and Settings.maze_type != 'hexagon':
            text_hexagon.show(game_display, text_color)
            text_square.show(game_display, text_color_light)

            Settings.maze_type = 'hexagon'

        Functions.mouse_reset()
        Functions.update_delay(10)
示例#19
0
def createText(x, y, base=''):
    ret = Text(x, y, str(base))
    all_drawable.add(ret)
    return ret
示例#20
0
 def urls(self):
     reg = r'<div class="content-list_item" data-reactid=".*?"><div class="content-list_item-info" data-reactid=".*?"><div class="media-preview" data-reactid=".*?"><a class="media-preview_img-wrap" href="(.*?)"'
     text = Text.create_by_url(self.url.url)
     urls = text.findall(reg)
     urls = self.url.concat_site_with_bodies(urls)
     return urls
示例#21
0
			text=raw_input(msg).strip()
		else:
			skip=False
	
		if text=="/exit":
			for k,v in dict.items():
				#dict[k].save_tabbed()
				dict[k].persist()
				dict[k].close()
			exit()
	
		elif text and text[0]!="/":
			## load line #######
			fn=os.path.join(dir_corpus,'.directinput.txt')
			write(fn,text.replace('//','\n\n').replace('/','\n'))
			obj = Text(fn)
			####################
	
		elif text=="/parse":
			obj.parse()
		
		elif text=="/plot":
			obj.plot()
		
		elif text=="/groom":
			obj.groom()
		
		elif text=="/report":
			obj.report()
	
		elif text=="/chart":
 def draw_text(self, points, text=None):
     points = self.convert(points)
     for point in points:
         if (text): Text(text, point).draw(self.screen)
示例#23
0
 def __init__(self, site, url):
     self.site = site
     self.url = url
     self.text = Text.create_by_url(url)
示例#24
0
setting = Bit()

setting.set(LOGGED_IN)

setting.set(FULL_PROFILE)

setting.unset(LOGGED_IN)

if setting.is_set(LOGGED_IN):
    pprint("Logged in")
else:
    pprint("Logged out")

if setting.is_set(IS_PREMIUM):
    pprint("Premium")
else:
    pprint("Not Premium")

pprint("Has Duplicate: " + str(Text.has_duplicate_char("Cody")))
pprint("Upper: " + Text.upper("Cody-&cODy"))
pprint("Lower: " + Text.lower("Cody-&cODy"))

pprint("Add: " + str(Math.add(5, 5)))

pprint("End")

pprint(ord('a'))
pprint(ord('z'))
pprint(ord('A'))
pprint(ord('Z'))
示例#25
0
white = (255, 255, 255)
black = (0, 0, 0)
green = (0, 255, 0)
red = (255, 0, 0)
blue = (0, 0, 128)
title_color = (48, 83, 198)
grey = (150, 150, 150)

# texts
text_font = font.Font('Good Unicorn - TTF.ttf', 30)
big_text_font = font.Font('Good Unicorn - TTF.ttf', 190)
menu_text_font = font.Font('Good Unicorn - TTF.ttf', 70)
_font = font.Font('Good Unicorn - TTF.ttf', 35)

white_texts = [
    Text("Money:", text_font, Vector2(500, 660), white),
    Text("1", text_font, Vector2(38, 760), white),
    Text("3", text_font, Vector2(105, 760), white),
    Text("3", text_font, Vector2(170, 760), white),
    Text("4", text_font, Vector2(237, 760), white),
    Text("7", text_font, Vector2(302, 760), white),
    Text("0", text_font, Vector2(368, 760), white)
]
black_texts = [
    Text("Money:", text_font, Vector2(500, 120), white),
    Text("1", text_font, Vector2(38, 100), white),
    Text("3", text_font, Vector2(105, 100), white),
    Text("3", text_font, Vector2(170, 100), white),
    Text("4", text_font, Vector2(237, 100), white),
    Text("7", text_font, Vector2(302, 100), white),
    Text("0", text_font, Vector2(368, 100), white)
示例#26
0
def start_interactive_mode():
    global lang, METER
    skip = False

    ## but do not go into interactive mode if only a single argument
    ## (which is later proven to be a real file or directory)
    ## ACTUALLY NVERMIND ABOVE: GO INTO INTERACTIVE MODE IF SINGLE ARGUMENT
    try:
        cmd = sys.argv[1]
        config['print_to_screen'] = 0
        being.config['print_to_screen'] = 0
        if not cmd.startswith('/'):
            cmd = ""
    except IndexError:
        cmd = "/exit"
        #cmd=""
        being.printout = True

    try:
        arg = sys.argv[1]
        if os.path.exists(arg):
            if os.path.isdir(arg):
                text = "/corpus " + arg
                #dir_corpus=sys.argv[1]
                skip = True
            else:
                #dir_corpus=os.path.dirname(sys.G[1])
                basename = os.path.basename(arg)
                text = "/text " + arg
                if basename[0:2] in languages and basename[2] == '.':
                    lang = basename[0:2]
                skip = True
        elif arg == 'install':
            try:
                arg2 = sys.argv[2]
            except IndexError:
                pass

            if arg2 == 'stanford_parser':
                dir_get_deps = os.path.join(dir_mtree, 'get-deps.sh')
                if not os.path.exists(dir_nlp_data): os.makedirs(dir_nlp_data)
                #cmd='cd '+dir_nlp_data+' && '+dir_get_deps+' && cd '+dir_prosodic
                cmd = f'{dir_get_deps} "{dir_nlp_data}"'
                print(cmd)
                os.system(cmd)

        else:
            #print("<error> file not found")
            obj = Text(' '.join(sys.argv[1:]), lang=lang)

    except:
        ## welcome
        print("")
        print("################################################")
        print("## welcome to prosodic!                  v1.5 ##")
        print("################################################")
        print("")
        text = ""
        cmd = ""

    ## start clock
    timestart = time.time()

    obj = None
    sameobj = None
    while (text != "/exit"):
        print(text)

        if being.om:
            being.omm = being.om
            being.om = ''
        #msg="\n########################################################################\n"
        msg = "\n\t[please type a line of text, or enter one of the following commands:]\n"
        #msg+="\t\t/text\t"+dir_corpus+"[folder/file.txt] or [blank for file-list]\n"
        #msg+="\t\t/corpus\t"+dir_corpus+"[folder] or [blank for dir-list]\n"
        msg += "\t\t/text\tload a text\n"
        msg += "\t\t/corpus\tload folder of texts\n"
        msg += "\t\t/paste\tenter multi-line text\n"

        msg += "\n"

        # try:
        # 	learner
        # except NameError:
        # 	pass
        # else:
        # 	if learner != None:
        # 		msg+="\t\t/weightsave\tsave the results of the last run of /weight or /weight2 \n"
        #
        #

        if obj:
            msg += "\t\t/show\tshow annotations on input\n"
            if config.get('parse_using_metrical_tree', False):
                msg += "\t\t/grid\tsee stress grids\n"
            msg += "\t\t/tree\tsee phonological structure\n"
            msg += "\t\t/query\tquery annotations\n\n"

            msg += "\t\t/parse\tparse metrically\n"
            msg += "\t\t/meter\tset the meter used for parsing\n"
            msg += "\t\t/eval\tevaluate this meter against a hand-tagged sample\n"
            msg += "\t\t/maxent\tlearn weights for meter using maxent\n\n"  # (pipe-delimited input file\n"
            msg += "\t\t/save\tsave previous output to file (except for /weight and /weight2; see /weightsave)\n"

            #msg+="\t\t/weight2\trun maximum entropy on a tab-delimited file\n"

        if obj and obj.isParsed():
            msg += "\t\t/scan\tprint out the scanned lines\n"
            msg += "\t\t/report\tlook over the parse outputs\n"
            msg += "\t\t/stats\tsave statistics from the parser\n"
            #msg+="\t\t/plot\tcompare features against positions\n"
            #if being.networkx:
            #	msg+="\t\t/draw\tdraw finite-state machines\n"

            msg += "\n"

        #msg+="\t\t/config\tchange settings\n"

        #"""
        if config['print_to_screen']:
            msg += "\t\t/mute\thide output from screen\n"
        else:
            msg += "\t\t/unmute\tunhide output from screen\n"
        #"""
        msg += "\t\t/exit\texit\n"
        #msg+="#######################################################################\n\n"
        msg += "\n>> [" + str(round(
            (time.time() - timestart), 2)) + "s] prosodic:" + lang + "$ "

        ## restart timer
        timestart = time.time()

        ## ask for input only if argument not received
        if not skip:
            try:
                text = input(msg).strip()  #.decode('utf-8',errors='ignore')
            except (KeyboardInterrupt, EOFError) as e:
                text = '/exit'
        else:
            skip = False

        if text == "/exit":
            # for k,v in list(dict.items()):
            # 	#dict[k].save_tabbed()
            # 	dict[k].persist()
            # 	dict[k].close()
            print()
            print(">> goodbye.")
            exit()

        elif text and text[0] != "/":
            ## load line #######
            obj = Text(text, lang=lang)
            ####################

        elif text.startswith('/paste'):
            print(
                ">> enter or paste your content here. press Ctrl-D when finished."
            )
            contents = []
            while True:
                try:
                    line = input("")  #.decode('utf-8',errors='ignore')
                    contents.append(line)
                except EOFError:
                    break
                except KeyboardInterrupt:
                    contents = []
                    break

            if contents:
                txt = "\n".join(contents)
                obj = Text(txt, lang=lang)

        elif text == "/parse":
            obj.parse(meter=METER)

        elif text.startswith("/maxent"):
            from MaxEnt2 import DataAggregator
            from MaxEnt2 import MaxEntAnalyzer

            # Check if learner is defined
            try:
                learner
            except NameError:
                learner = None

            data_path = text[len("/weight "):]
            if data_path == "" or data_path is None or not os.path.exists(
                    data_path):
                print(
                    "You must enter an existing filename after the command i.e., /maxent <filename>"
                )
                continue

            with open(data_path) as f:
                input_data = f.read()
                tab_not_pipe = input_data.count('|') < input_data.count('\t')

            data_aggregator = DataAggregator(METER,
                                             data_path,
                                             lang,
                                             is_tab_formatted=tab_not_pipe)
            learner = MaxEntAnalyzer(data_aggregator)

            step_size = float(config.get('maxent_step_size'))
            negative_weights_allowed = bool(
                config.get('maxent_negative_weights_allowed'))
            max_epochs = int(config.get('maxent_max_epochs'))
            gradient_norm_tolerance = float(
                config.get('maxent_gradient_norm_tolerance'))

            learner.train(step=step_size,
                          epochs=max_epochs,
                          tolerance=gradient_norm_tolerance,
                          only_positive_weights=not negative_weights_allowed)
            learner.report()

            ## save
            if not learner:
                print(
                    "Cannot save weights as no weights have been trained. First train the MaxEnt learner with /weight or /weight2"
                )
            else:
                # save the weights to a file
                # fn=text.replace('/weightsave','').strip()
                # if not fn:
                # 	fn=input('\n>> please enter a file name to save output to,\n\t- either as a simple filename in the default directory ['+config['folder_results']+'],\n\t- or as a full path.\n\n').strip()
                ofn = os.path.join(dir_results, 'maxent',
                                   os.path.basename(data_path) + '.txt')

                try:
                    dirname = os.path.dirname(ofn)
                    if not os.path.exists(dirname): os.makedirs(dirname)
                    with codecs.open(ofn, 'w') as of:
                        output_str = learner.generate_save_string()
                        of.write(output_str)
                        of.close()
                        print(">> saving weights to: " + ofn)
                except IOError as e:
                    print(e)
                    print("** [error: file not saved.]\n\n")

        elif text == "/plot":
            obj.plot()

        elif text == "/groom":
            obj.groom()

        elif text.startswith("/report") and obj.isParsed():
            arg = ' '.join(text.split()[1:]) if len(text.split()) > 1 else None
            include_bounded = arg == 'all'
            obj.report(meter=METER, include_bounded=include_bounded)
            print(
                '\t>> options:\n\t\t/report\t\treport unbounded, metrical parses\n\t\t/report all\treport all parses, including those bounded or unmetrical'
            )

        elif text == "/chart":
            obj.chart()

        elif text.startswith("/stats") and obj.isParsed():
            arg = ' '.join(text.split()[1:]) if len(text.split()) > 1 else None
            funcname = None
            if arg == 'lines':
                funcname = 'stats_lines'
            elif arg == 'pos':
                funcname = 'stats_positions'
            elif arg == 'all':
                funcname = 'stats'
            elif arg == 'ot':
                funcname = 'stats_lines_ot'

            if funcname:
                func = getattr(obj, funcname)
                for dx in func(meter=METER, all_parses=False):
                    pass

            print(
                '\t>> options:\n\t\t/stats all\t\tsave all stats\n\t\t/stats lines\t\tsave stats on lines\n\t\t/stats ot\t\tsave stats on lines in OT/maxent format\n\t\t/stats pos\t\tsave stats on positions'
            )

        elif text == "/scan" and obj.isParsed():
            obj.scansion(meter=METER)

        elif text == "/draw":
            try:
                obj.genfsms(meter=METER)
                #obj.genmetnet()
            except ImportError:
                raise Exception(
                    "Loading of networkx failed. Please install networkx: pip install networkx"
                )

        elif text == "/tree":
            obj.om(obj.tree() + "\n\n")
            #print obj.tree()
            print()

        elif text == "/grid":
            grid = obj.grid()
            obj.om("\n" + grid + "\n")
            print()

        elif text == "/show":
            obj.show()

        elif text.startswith("/meter"):
            tl = text.split()
            arg = None
            if len(tl) > 1:
                arg = ' '.join(tl[1:])
                if not arg.isdigit(): arg = None

            mnum2name = {}
            for mi, (mname,
                     mmeter) in enumerate(sorted(config['meters'].items())):
                mnum = mi + 1
                mnum2name[mnum] = mname
                #print '>> meter #'+str(mnum)+': '+mname
                if not arg:
                    print('[#' + str(mnum) + ']')
                    print(mmeter)
                    #print '\t>> id:',mname
                    #print '\t>> name:',msettings['name']
                    #print '\t>> constraints:'
                    #for cname in sorted(msettings['constraints']):
                    #	print '\t\t>>',cname
                    print()

            if arg and arg.isdigit():
                meteri = int(arg)
            else:
                try:
                    meteri = input(
                        '>> please type the number of the meter you would like to use.\n'
                    ).strip()
                except (KeyboardInterrupt, EOFError) as e:
                    continue

                if not meteri.isdigit():
                    print('>> not a number. meter not selected.')
                    continue

                meteri = int(meteri)
            config['meter'] = mnum2name[meteri]
            METER = config['meters'][config['meter']]
            print('>> meter set to [' + METER.id + ']: ' + METER.name)

        elif text == "/query":
            q = ""
            while (not q.startswith("/")):
                try:
                    q = input(
                        ">> please type the conjunction of features for which you are searching [type / to exit]:\neg: [-voice] (Syllable: (Onset: [+voice]) (Coda: [+voice]))\n\n"
                    ).strip()
                except (KeyboardInterrupt, EOFError) as e:
                    text = ''
                    break

                matchcount = 0
                try:
                    qq = SearchTerm(q)
                except:
                    break

                for words in obj.words(flattenList=False):
                    wordobj = words[0]
                    for match in wordobj.search(qq):
                        matchcount += 1
                        if "Word" in str(type(match)):
                            matchstr = ""
                        else:
                            matchstr = str(match)
                        wordobj.om(
                            makeminlength(str(matchcount),
                                          int(being.linelen / 6)) + "\t" +
                            makeminlength(str(wordobj), int(being.linelen)) +
                            "\t" + matchstr)

            cmd = q

        #elif text.startswith('/query'):
        #	print obj.search(SearchTerm(text.replace('/query','').strip()))

        elif text == "/try":
            obj = Text('corpora/corppoetry/fi.kalevala2.txt')
            #print obj.tree()
            self.parses = obj.parse()

        elif text.startswith('/text'):
            fn = text.replace('/text', '').strip()

            if not fn:
                for filename in os.listdir(dir_corpus):
                    if filename.startswith("."): continue
                    if os.path.isdir(os.path.join(dir_corpus, filename)):
                        print("\t" + filename + "/")
                        files = []
                        for filename2 in glob.glob(
                                os.path.join(
                                    os.path.join(dir_corpus, filename),
                                    "*.txt")):
                            files.append(
                                filename2.replace(dir_corpus, '').replace(
                                    filename + '/', ''))
                        print("\t\t" + " | ".join(files))
                        print()
                    else:
                        if filename[-4] == ".txt":
                            print("\t" + filename)

                print()
                print("\t" + hdrbar)
                #print ">> to load a text, please either:"
                print("\t>> select from one of the relative paths above:")
                print("\t     i.e. /text [foldername]/[filename.txt]")
                print("\t     e.g. /text shakespeare/sonnet-001.txt")
                print(
                    "\t>> or use an absolute path to a text file on your disk:"
                )
                print("\t     e.g. /text /absolute/path/to/file.txt")
                print("\t" + hdrbar)
                print()

            else:
                if os.path.exists(os.path.join(dir_corpus, fn)):
                    obj = Text(os.path.join(dir_corpus, fn))
                elif os.path.exists(fn):
                    obj = Text(fn)
                else:
                    print("<file not found>\n")
                    continue

        elif text.startswith('/corpus'):
            from Corpus import Corpus
            fn = text.replace('/corpus', '').strip()

            if not fn:
                for filename in os.listdir(dir_corpus):
                    if filename.startswith("."): continue
                    if os.path.isdir(os.path.join(dir_corpus, filename)):
                        print("\t" + filename)

                print()
                print("\t" + hdrbar)
                #print ">> to load a text, please either:"
                print("\t>> select from one of the relative paths above:")
                print("\t     i.e. /corpus [foldername]")
                print("\t     e.g. /corpus yeats")
                print(
                    "\t>> or use an absolute path to a folder of text files on your disk:"
                )
                print(
                    "\t     e.g. /corpus /absolute/path/to/folder/of/text/files"
                )
                print("\t" + hdrbar)
                print()

            else:
                if os.path.exists(os.path.join(dir_corpus, fn)):
                    obj = Corpus(os.path.join(dir_corpus, fn))
                elif os.path.exists(fn):
                    obj = Corpus(fn)
                else:
                    print("<path not found>\n")
                    continue

        elif text.startswith('/save'):
            fn = text.replace('/save', '').strip()
            if not fn:
                fn = input(
                    '\n>> please enter a file name to save output to,\n\t- either as a simple filename in the default directory ['
                    + config['folder_results'] +
                    '],\n\t- or as a full path.\n\n').strip()

            try:
                ofn = None
                dirname = os.path.dirname(fn)
                if dirname:
                    ofn = fn
                else:
                    dirname = config['folder_results']
                    ofn = os.path.join(dirname, fn)

                if not os.path.exists(dirname): os.makedirs(dirname)
                of = codecs.open(ofn, 'w', encoding='utf-8')
                if type(being.omm) in [str]:
                    being.omm = being.omm  #.decode('utf-8',errors='ignore')
                of.write(being.omm)
                of.close()
                print(">> saving previous output to: " + ofn)
            except IOError:
                print("** [error: file not saved.]\n\n")

        elif text.startswith('/eval'):
            path = os.path.join(dir_prosodic, config['folder_tagged_samples'])
            fn = None

            if not fn:
                fns = []
                for _fn in os.listdir(path):
                    if _fn.startswith('.'): continue
                    if '.evaluated.' in _fn: continue
                    fn_i = len(fns)
                    fns += [_fn]
                    print('[{0}] {1}'.format(fn_i + 1, _fn))
                inp = input(
                    '\n>> please enter the number of the file to use as evaluation data:\n'
                ).strip()
                if not inp.isdigit():
                    print('<<invalid: not a number>>')
                    continue

                fn_i = int(inp) - 1
                fn = fns[fn_i]

            key_line = input(
                '\n>> please enter the column name in the file for the column of lines to parse: [default: line]\n'
            ).strip()
            if not key_line: key_line = 'line'

            key_parse = input(
                '\n>> please enter the column name in the file for the column of hand-done parses (using "s" for metrically strong syllables, "w" for metrically weak ones): [default: parse]\n'
            ).strip()
            if not key_parse: key_parse = 'parse'

            key_meterscheme = input(
                '\n>> [optional, will use if present] please enter the column name in the file for the column indicating the metrical template in the poem (anapestic, dactylic, iambic, or trochaic): [default: Meter Scheme]\n'
            ).strip()
            if not key_meterscheme: key_meterscheme = 'Meter Scheme'

            assess(os.path.join(path, fn),
                   key_meterscheme=key_meterscheme,
                   key_parse=key_parse,
                   key_line=key_line,
                   meter=METER)

        elif text.startswith('/mute'):
            being.config['print_to_screen'] = 0

        elif text.startswith('/unmute'):
            being.config['print_to_screen'] = 1

        if cmd:
            text = cmd
            cmd = ""
示例#27
0
 def post(self, txt):
     text = Text(txt)
     return text.generate_analysis(word_list)
示例#28
0
def report(text):
	t=Text(text)
	t.parse()
	t.report()
示例#29
0
 def createTextNode(self, data):
     return Text(self, BeautifulSoup.NavigableString(data))
示例#30
0
 def write(self, data_output):
     data_output.writeInt(len(self._meta))
     for key, value in self._meta.iteritems():
         Text.writeString(data_output, key)
         Text.writeString(data_output, value)
示例#31
0
 def creat_text(self, text, color=(255, 0, 0), locationX=0, locationY=0):
     text = Text(self.screen, text, 80, color, locationX, locationY)
     text.show()
     pygame.display.update()
     return (text)
示例#32
0
 def createTextNode(self, data):
     from Text import Text
     return Text(self, data)
示例#33
0
 def collision(self):
     super().collision()
     Sound.play_SE('powerup')
     Text.set(self.screen, 'まずい…', sprite=self.player)
示例#34
0
	def __init__ ( self, visitor, obj=None, config=None):
		Generic.__init__(self, visitor, obj, config)
		GenericSerial.__init__(self, visitor, obj, config)
		Text.__init__(self, rows=self.model.rows, cols=self.model.cols, yres=8, xres=6, goto=self.model.goto, chars=self.model.chars, char0=self.model.char0)
		self.commands_sent = 0
		self.commands_received = 0
		self.commands_resent = 0
		self.tossed = 0
		self.errors = 0
		self.packet = Packet()
		self.fill_buffer_thread = ThreadedTask(self.fill_buffer, None, 1)
		self.check_thread = ThreadedTask(self.check_for_packet, None, 1)
		self.buffer = BufferedReader()
		if obj == None:
			self.port = ''
			self.baud = 115200
			self.display_name = ''
			self.device_name = ''
			self.serial_number = ''
			self.path = ''
			self.device_version = ""
			self.hardware_version = ""
			self.firmware_version = ""
			self.fans = []
			self.current_command = [-1, -1]
			for i in range(0, 4):
				self.fans.append(Fan())
			self.dallas = []
			self.contrast = 127
			self.backlight = 100
			self.memory = ReadLCDMemory(self)
			self.command_queue0 = Queue.Queue()
			self.command_queue1 = Queue.Queue()
			self.response_bin = Bin(self)
			self.response = None
			self.response_state = 0
			self.response_time_init = time.time()
			self.command_limit = 0 # 0 means 1 command every <command_rate> interval. 1 means 2 commands.
			self.command_rate = 1
			self.response_timeout = 0.25
			self.active = False
			self.layout_timeout = 0 #Default layout timeout. 0 = no transitions. Override at layout level.
			self.layouts = {}
			self.name = 'noname'
		else:
			self.name = obj.name
			self.port = obj.port
			self.baud = obj.baud
			self.display_name = obj.display_name
			self.device_name = obj.device_name
			self.serial_number = obj.serial_number
			self.path = obj.path
			self.device_version = obj.device_version
			self.hardware_version = obj.hardware_version
			self.firmware_version = obj.firmware_version
			self.books = obj.books
			self.fans = obj.fans
			self.current_command = obj.current_command
			self.command_limit = obj.command_limit
			self.dallas = obj.dallas
			self.contrast = obj.contrast
			self.backlight = obj.backlight
			self.memory = ReadLCDMemory(self)
			self.command_queue0 = obj.command_queue0
			self.command_queue1 = obj.command_queue1
			self.response_bin = Bin(self)
			self.response = obj.response
			self.response_state = obj.response_state
			self.response_time_init = obj.response_time_init
			self.command_rate = obj.command_rate
			self.response_timeout = obj.response_timeout
			self.active = obj.active
			self.layout_timeout = obj.layout_timeout
			self.layouts = obj.layouts
		self.app = visitor
		self.debug = visitor.debug
		self.waiting = False
		self.AddFunction("contrast", 0, self.my_contrast)
		self.AddFunction("backlight", 0, self.my_backlight)
		self.connect('packet-ready', self.response_bin.process_packet)
		self.command_thread = ThreadedTask(self.command_worker, None, self.command_rate)
		self.crcLookupTable = array ('H',  # Define the CRC lookup table
		[0x00000,0x01189,0x02312,0x0329B,0x04624,0x057AD,0x06536,0x074BF,
		 0x08C48,0x09DC1,0x0AF5A,0x0BED3,0x0CA6C,0x0DBE5,0x0E97E,0x0F8F7,
		 0x01081,0x00108,0x03393,0x0221A,0x056A5,0x0472C,0x075B7,0x0643E,
		 0x09CC9,0x08D40,0x0BFDB,0x0AE52,0x0DAED,0x0CB64,0x0F9FF,0x0E876,
		 0x02102,0x0308B,0x00210,0x01399,0x06726,0x076AF,0x04434,0x055BD,
		 0x0AD4A,0x0BCC3,0x08E58,0x09FD1,0x0EB6E,0x0FAE7,0x0C87C,0x0D9F5,
		 0x03183,0x0200A,0x01291,0x00318,0x077A7,0x0662E,0x054B5,0x0453C,
		 0x0BDCB,0x0AC42,0x09ED9,0x08F50,0x0FBEF,0x0EA66,0x0D8FD,0x0C974,
		 0x04204,0x0538D,0x06116,0x0709F,0x00420,0x015A9,0x02732,0x036BB,
		 0x0CE4C,0x0DFC5,0x0ED5E,0x0FCD7,0x08868,0x099E1,0x0AB7A,0x0BAF3,
		 0x05285,0x0430C,0x07197,0x0601E,0x014A1,0x00528,0x037B3,0x0263A,
		 0x0DECD,0x0CF44,0x0FDDF,0x0EC56,0x098E9,0x08960,0x0BBFB,0x0AA72,
		 0x06306,0x0728F,0x04014,0x0519D,0x02522,0x034AB,0x00630,0x017B9,
		 0x0EF4E,0x0FEC7,0x0CC5C,0x0DDD5,0x0A96A,0x0B8E3,0x08A78,0x09BF1,
		 0x07387,0x0620E,0x05095,0x0411C,0x035A3,0x0242A,0x016B1,0x00738,
		 0x0FFCF,0x0EE46,0x0DCDD,0x0CD54,0x0B9EB,0x0A862,0x09AF9,0x08B70,
		 0x08408,0x09581,0x0A71A,0x0B693,0x0C22C,0x0D3A5,0x0E13E,0x0F0B7,
		 0x00840,0x019C9,0x02B52,0x03ADB,0x04E64,0x05FED,0x06D76,0x07CFF,
		 0x09489,0x08500,0x0B79B,0x0A612,0x0D2AD,0x0C324,0x0F1BF,0x0E036,
		 0x018C1,0x00948,0x03BD3,0x02A5A,0x05EE5,0x04F6C,0x07DF7,0x06C7E,
		 0x0A50A,0x0B483,0x08618,0x09791,0x0E32E,0x0F2A7,0x0C03C,0x0D1B5,
		 0x02942,0x038CB,0x00A50,0x01BD9,0x06F66,0x07EEF,0x04C74,0x05DFD,
		 0x0B58B,0x0A402,0x09699,0x08710,0x0F3AF,0x0E226,0x0D0BD,0x0C134,
		 0x039C3,0x0284A,0x01AD1,0x00B58,0x07FE7,0x06E6E,0x05CF5,0x04D7C,
		 0x0C60C,0x0D785,0x0E51E,0x0F497,0x08028,0x091A1,0x0A33A,0x0B2B3,
		 0x04A44,0x05BCD,0x06956,0x078DF,0x00C60,0x01DE9,0x02F72,0x03EFB,
		 0x0D68D,0x0C704,0x0F59F,0x0E416,0x090A9,0x08120,0x0B3BB,0x0A232,
		 0x05AC5,0x04B4C,0x079D7,0x0685E,0x01CE1,0x00D68,0x03FF3,0x02E7A,
		 0x0E70E,0x0F687,0x0C41C,0x0D595,0x0A12A,0x0B0A3,0x08238,0x093B1,
		 0x06B46,0x07ACF,0x04854,0x059DD,0x02D62,0x03CEB,0x00E70,0x01FF9,
		 0x0F78F,0x0E606,0x0D49D,0x0C514,0x0B1AB,0x0A022,0x092B9,0x08330,
		 0x07BC7,0x06A4E,0x058D5,0x0495C,0x03DE3,0x02C6A,0x01EF1,0x00F78])
示例#35
0
    def __guess_key(self, min_len=1, max_len=9, display=False):
        keylen = self.guess_key_length(min_len, max_len, display)
        if keylen == 0:
            print "[!] No key length found."
            return -1
        if display:
            print "[*] Most probable key length : " + str(keylen) + "\n"
        freq_fr = {
            'e': 14.715,
            's': 7.948,
            'a': 7.636,
            'i': 7.529,
            't': 7.244,
            'n': 7.095,
            'r': 6.553,
            'u': 6.311,
            'l': 5.456,
            'o': 5.378,
            'd': 3.669,
            'c': 3.260,
            'p': 3.021,
            'm': 2.968,
            'v': 1.628,
            'q': 1.362,
            'f': 1.066,
            'b': 0.901,
            'g': 0.866,
            'h': 0.737,
            'j': 0.545,
            'x': 0.387,
            'y': 0.308,
            'z': 0.136,
            'w': 0.114,
            'k': 0.049
        }
        password = ""
        for i in range(keylen):
            sub_alphabet = VigenereCipher(''.join(
                [self._s[keylen * j + i] for j in range(self._len // keylen)]))
            min_differential = 99999
            password_letter = ""
            for c in range(65, 65 + 26):
                sub_alphabet.key = chr(c)
                decrypted = VigenereCipher(sub_alphabet.decipher().tostring())
                sub_alphabet.encipher()
                freq_s = {
                    k: round((v / decrypted.len) * 100, 3)
                    for k, v in dict(decrypted.get_frequencies()).items()
                }
                differential = sum(
                    [abs(freq_fr[k.lower()] - v) for k, v in freq_s.items()])
                if differential < min_differential:
                    min_differential = differential
                    password_letter = chr(c)
            password += password_letter

        # Little hack for repetitive password due to frequency analysis
        for i in range(1, len(password)):
            if len(password) % i == 0:
                duplicate = True
                s = [
                    password[j * i:(j + 1) * i]
                    for j in range(len(password) // i)
                ]
                ex_prec = s[0]
                for ex in s:
                    if ex != ex_prec:
                        duplicate = False
                        break
                    ex_prec = ex
                if duplicate:
                    password = ex
                    if display:
                        print "[*] [UPDATE] Most probable key length : " + str(
                            len(password)) + "\n"
                    break
        return Text.clean_string(password)
示例#36
0
 def __init__(self, ownerDocument, data):
     Text.__init__(self, ownerDocument, data)
     self.__dict__['__nodeName'] = "#cdata-section"
示例#37
0
 def __init__(self, ownerDocument, data):
     Text.__init__(self, ownerDocument, data)
     self.__dict__['__nodeName'] = "#cdata-section"
示例#38
0
            try:
                arg2 = sys.argv[2]
            except IndexError:
                pass

            if arg2 == 'stanford_parser':
                dir_get_deps = os.path.join(dir_mtree, 'get-deps.sh')
                if not os.path.exists(dir_nlp_data): os.makedirs(dir_nlp_data)
                #cmd='cd '+dir_nlp_data+' && '+dir_get_deps+' && cd '+dir_prosodic
                cmd = f'{dir_get_deps} "{dir_nlp_data}"'
                print(cmd)
                os.system(cmd)

        else:
            #print("<error> file not found")
            obj = Text(' '.join(sys.argv[1:]), lang=lang)

    except:
        ## welcome
        print("")
        print("################################################")
        print("## welcome to prosodic!                  v1.1 ##")
        print("################################################")
        print("")
        text = ""
        cmd = ""

    ## start clock
    timestart = time.time()

    obj = None
示例#39
0
from Text import Text

text = Text('test.txt')

words = []

while text.EOF == False:
    x = text.get_word()
    if x in words:
        continue
    words.append(x)
示例#40
0
 def write(self, data_output):
     data_output.writeInt(len(self._meta))
     for key, value in self._meta.iteritems():
         Text.writeString(data_output, key)
         Text.writeString(data_output, value)
示例#41
0
 def set_text_and_type(self, text, type):
     self.text = Text(text, 32, (WINDOW_W / 2, WINDOW_H / 2))
     self.loadingType = type
示例#42
0
clock = pygame.time.Clock()
ejeCoordenadas = [0,0]
clickMap = False

pantallita = pygame.display.set_mode( screen_size )
supmapa = pygame.Surface(map_size)
pantallita.blit(supmapa, (0,0))

#Unidades


'''
baseUnit = Unit('unitdad', base_image[0], [], 0)
'''

text = Text(pantallita, {'x' : 200, 'y' : 200, 'width' : 200, 'height' : 40}, 20, (255,255,255))

class game:

    def play():

        global run, move, zoomv, movex, movey, ejeCoordenadas, clicking, clicked, unClicked, baseEleccion, clickedMap, unClickedMap, clickedMapOrigin, clickMap, supmapa, selected, textActive
        menu_abierto = False
        while run : 

            #Pintamos la pantalla
            pantallita.fill(white)
            pantallita.blit(supmapa, (0 + movex, 0 + movey))
            supmapa.fill(white)
            mapaactual.create() 
            if textActive == True:
示例#43
0
if __name__ == '__main__':
    import sys
    import re
    from Text import Text

    try:
        alignment_filename = sys.argv[1]
        if sys.argv[2:]:
            [fn1, fn2] = sys.argv[2:]
            assert not fn1.endswith('.txt')
            assert not fn2.endswith('.txt')
            with open(fn1) as f:
                seq1 = [l.decode('utf-8').strip() for l in f.readlines()]
                with open(fn2) as f:
                    seq2 = [l.decode('utf-8').strip() for l in f.readlines()]
        else:
            m = re.match(r'(.*/)?(..)-(..)\.(.*)$', alignment_filename)
            t1 = Text.from_file("%s%s.txt" % (m.group(1), m.group(2)),
                                lang=m.group(2))
            t2 = Text.from_file("%s%s.txt" % (m.group(1), m.group(3)),
                                lang=m.group(3))
            seq1 = t1.as_sentences_flat()
            seq2 = t2.as_sentences_flat()
        a = Alignment.from_file(alignment_filename)
        a.pretty_print(seq1, seq2)
        print "Total cost: " + str(sum(c for (_, _, c) in a.data))
    except IndexError, ValueError:
        print >> sys.stderr, __doc__
    except IOError, e:
        print >> sys.stderr, e
示例#44
0
 def __init__(self, core):
     self.iTime = pg.time.get_ticks()
     self.loadingType = True
     self.bg = pg.Surface((WINDOW_W, WINDOW_H))
     self.text = Text('WORLD ' + core.oWorld.get_name(), 32, (WINDOW_W / 2, WINDOW_H / 2))
示例#45
0
    def gen():
        yield (0, 0, 0)
        prev_i2 = 0
        for (i1, i2) in al12:
            for _i2 in range(prev_i2+1, i2+1):
                try:
                    i3s = map23[_i2]
                    for i3 in i3s:
                        # if map31[i3] == i1:
                        yield (i1, _i2, i3)
                except KeyError:
                    pass
            prev_i2 = i2
    return Alignment(list(gen()), no_costs=True)

if __name__ == '__main__':
    import sys
    name = sys.argv[1]

    a1 = Alignment.from_file(name + '/pl-cu.my').as_ladder()
    a2 = Alignment.from_file(name + '/cu-el.my').as_ladder()
    a3 = Alignment.from_file(name + '/pl-el.my').as_ladder()
    a3 = [(b, a) for (a, b) in a3]

    ma = merge_3_alignments(a1, a2, a3)

    ma.pretty_print(Text.from_file(name + '/pl.txt', lang='pl').as_sentences_flat(),
                    Text.from_file(name + '/cu.txt', lang='cu').as_sentences_flat(),
                    Text.from_file(name + '/el.txt', lang='el').as_sentences_flat())
示例#46
0
文件: Main.py 项目: Steven-MJ/ITEM
import sys
from Prepare import Prepare
from Text import Text
from FileRW import FileRW
import datetime

start = datetime.datetime.now()

# 根据命令行参数初始化生成包含题目列表的对象
prepare = Prepare(sys.argv)
questionList = prepare.getQuestionList()

output = FileRW()
output.outputExercise(questionList)
output.outputAnswer(questionList)

text = Text(questionList)
text.begin()
text.printResult()
output.outputResult(questionList, text.inputAnswer)
# else:
#     print("无题目生成")
R, W = prepare.compareFile(prepare.exercisefile, prepare.answerfile)
output.outputCompare(R, W)

end = datetime.datetime.now()
print('Running time: %s Seconds' % (end - start))
示例#47
0
import Sentence
import enchant
from Text import Text
from Sentence import Sentence
from Word import Word
from Lemma import Lemma
#import pickle as pickle
import cPickle as dill
import sys
import threading

NotATextRawTitle = "NotAFile"
NotATextRawText = "NotAWord."
NotALemmaRawLemma = "NotALemma"

NotAText = Text(NotATextRawText, NotATextRawTitle)
NotASentence = NotAText.sentences[0]
NotAWord = NotASentence.words[0]
NotAWordLemma = Lemma(NotALemmaRawLemma, NotAWord)

allTexts = {NotAText.name: NotAText}
allSentences = {NotASentence.rawSentence: NotASentence}
allWords = {NotAWord.rawWord: NotAWord}
allLemmas = {NotAWordLemma.rawLemma: NotAWordLemma}

everything = {
    "texts": allTexts,
    "sentences": allSentences,
    "words": allWords,
    "lemmas": allLemmas
}
示例#48
0
    def block_animation(self, direction='', block=None):
        def add_block(function):
            self.item_animation_list.append(function)

        # 近づくとアニメーション開始
        if block is None:
            for block in Stage.block_object_list:
                # ジャンプするとビームを放つ
                if block.data == 9.3 and not Block.Beam.instance and not self.player.isGrounding:
                    if block.rect.left - self.player.rect.left < 82:
                        if block.y - self.player.y > -10:
                            block.isHide = False
                            add_block(Block.Beam(block))
                            Text.set(self.screen,
                                     'ビーー',
                                     sprite=block,
                                     tweak_x=10)

                # 近づくと落ちるブロック
                if block.data == 1.3 and not block.isAnimation:
                    if block.rect.left - self.player.rect.left < 0:
                        if block.rect.bottom - self.player.rect.bottom < 0:
                            add_block(Block.NearFall(block))

                # 近づくと敵出現イベント発生
                if block.data == 39 and not block.isAnimation:
                    if block.rect.left - self.player.rect.left < 25:
                        if self.player.rect.left - block.rect.left < 40:
                            add_block(Block.EventEnemy(block))

        # 当たるとアニメーション開始
        else:
            # 壊れるブロック
            if block.name == 'block1':
                # トゲを生やす
                if block.data == 1.1:
                    block.isThorns = True
                    self.player.isDeath = True
                    Text.set(self.screen, 'シャキーン', sprite=block)

                # 近づくと落ちるブロックの当たり判定
                if block.data == 1.3 and block.isAnimation and direction == 'TOP_BLOCK':
                    self.player.isDeath = True

                if direction == 'TOP':
                    # 叩くと壊れる
                    if block.data == 1:
                        add_block(Block.Break(self.screen, block))
                        block.remove()
                        Stage.block_object_list.remove(block)

                    # 叩くと大量のコインが出る
                    if block.data == 1.6:
                        add_block(Block.Coin(self.screen, block, isLot=True))

                    # 叩くとスター
                    if block.data == 2.1:
                        add_block(Block.Star(self.screen, block))

            # はてなブロック
            if block.name == 'block2':
                if direction == 'TOP':
                    # 叩くとコインが出る
                    if block.data == 3:
                        add_block(Block.Coin(self.screen, block))

                    # 叩くと赤キノコが出る
                    if block.data == 3.2:
                        add_block(Block.Kinoko(self.screen, block))

                    # 叩くと敵が出る
                    if block.data == 3.8:
                        add_block(Block.Enemy(self.screen, block, 'enemy'))

                # 叩けないブロック
                elif direction == 'TOP_BLOCK' and block.data == 3.1 and self.player.y_speed < 0:
                    block.rect.bottom = self.player.rect.top - 10

            # 隠しブロック
            if direction == 'TOP' and block.name == 'block3' and block.isHide:
                block.isHide = False

                # 叩くとコインが出る
                if block.data == 5:
                    add_block(Block.Coin(self.screen, block))

                # 叩くと大量の毒キノコが出る
                if block.data == 5.5:
                    add_block(
                        Block.PoisonKinoko(self.screen, block, isLot=True))

            # 土管に入る
            if block.name == 'dokan1':
                # 上から入る場合
                if direction == 'BOTTOM':
                    if block.data in [
                            20.2, 20.3, 20.5
                    ] and block.rect.left + 25 < self.player.rect.right - 5:
                        if block.rect.right - 25 > self.player.rect.left + 6 and pygame.key.get_pressed(
                        )[K_DOWN]:
                            self.player.dive_dokan = block

                # 横からはいる場合
                if direction == 'SIDE' and block.data in [
                        20.6, 20.8
                ] and self.player.isGrounding:
                    pass

            # うめぇ
            if block.data == 19.2:
                self.player.isDeath = True
                block.name = 'cloud3'
                block.image = LoadImage.image_list[block.name]
                Text.set(self.screen, 'うめぇ!!', sprite=block)

            # 透明のうめぇ
            if block.data == 19.3:
                self.player.isDeath = True
                block.isHide = False
                Text.set(self.screen, 'うめぇ!!', sprite=block)

            # 落ちる足場ブロック
            if direction == 'BOTTOM' and block.data == 8.1 and not block.isAnimation:
                add_block(Block.RideFall())

            # ビームの当たり判定
            if block.name == 'beam' and not block.isHide and self.player.y + self.player.height > block.y + 25:
                self.player.isDeath = True

            # 中間地点
            if block.name == 'halfway':
                SpritePlayer.initial_x = 210
                SpritePlayer.initial_y = block.y
                SpritePlayer.initial_scroll_sum = block.x - 210

                block.remove()
                Stage.block_object_list.remove(block)

            # ゴールポール
            if block.name == 'goal_pole':
                if block.data == 9.1 and not self.goal_isMove:
                    self.player.goal = block

            # ゴール塔
            if block.name == 'end' and self.goal_isMove:
                start_x = block.x - SpritePlayer.scroll_sum + 60
                start_y = block.rect.top + 45
                end_x = block.width - 80
                end_y = block.height - 45
                block_rect = Rect(start_x, start_y, end_x, end_y)
                player_rect = Rect(self.player.x, self.player.y,
                                   self.player.width, self.player.height)

                # ゴール塔の中に入る
                if player_rect.colliderect(block_rect):
                    self._inGoal_tower = True
                    self._goal_init = False
                    self.goal_isMove = False