当前位置: 首页>>代码示例>>Python>>正文


Python process.extractOne方法代码示例

本文整理汇总了Python中fuzzywuzzy.process.extractOne方法的典型用法代码示例。如果您正苦于以下问题:Python process.extractOne方法的具体用法?Python process.extractOne怎么用?Python process.extractOne使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在fuzzywuzzy.process的用法示例。


在下文中一共展示了process.extractOne方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: params_dict

# 需要导入模块: from fuzzywuzzy import process [as 别名]
# 或者: from fuzzywuzzy.process import extractOne [as 别名]
def params_dict(self):
        """
        function to get params dict for HTTP request
        """
        location_code = 'US'
        language_code = 'en'
        if len(self.location):
            location_code = locationMap[process.extractOne(self.location, self.locations)[0]]
        if len(self.language):
            language_code = langMap[process.extractOne(self.language, self.languages)[0]]
        params = {
            'hl': language_code,
            'gl': location_code,
            'ceid': '{}:{}'.format(location_code, language_code)
        }
        return params 
开发者ID:nikhilkumarsingh,项目名称:gnewsclient,代码行数:18,代码来源:gnewsclient.py

示例2: get

# 需要导入模块: from fuzzywuzzy import process [as 别名]
# 或者: from fuzzywuzzy.process import extractOne [as 别名]
def get(self, anime_name):
        animes = self._read_from_watch_file()

        if isinstance(anime_name, int):
            return animes[anime_name]

        match = process.extractOne(anime_name, animes, score_cutoff=40)
        if match:
            anime = match[0]
            logger.debug('Anime: {!r}, episodes_done: {}'.format(
                anime, anime.episodes_done))

            if (time() - anime._timestamp) > 4*24*60*60:
                anime = self.update_anime(anime)
            return anime 
开发者ID:vn-ki,项目名称:anime-downloader,代码行数:17,代码来源:watch.py

示例3: get_artist

# 需要导入模块: from fuzzywuzzy import process [as 别名]
# 或者: from fuzzywuzzy.process import extractOne [as 别名]
def get_artist(self, name):
        """
        Fetches information about an artist given its name
        """
        if self.use_store:
            search = self._search("artist", name)

            if len(search) == 0:
                return False

            return self._api.get_artist_info(search[0]['artistId'],
                                             max_top_tracks=100)
        else:
            search = {}
            search['topTracks'] = []
            # Find the best artist we have, and then match songs to that artist
            likely_artist, score = process.extractOne(name, self.artists)
            if score < 70:
                return False
            for song_id, song in self.library.items():
                if 'artist' in song and song['artist'].lower() == likely_artist.lower() and 'artistId' in song:
                    if not search['topTracks']:  # First entry
                        # Copy artist details from the first song into the general artist response
                        try:
                            search['artistArtRef'] = song['artistArtRef'][0]['url']
                        except KeyError:
                            pass
                        search['name'] = song['artist']
                        search['artistId'] = song['artistId']
                    search['topTracks'].append(song)
            random.shuffle(search['topTracks'])  # This is all music, not top, but the user probably would prefer it shuffled.
            if not search['topTracks']:
                return False

            return search 
开发者ID:stevenleeg,项目名称:geemusic,代码行数:37,代码来源:music.py

示例4: get_album

# 需要导入模块: from fuzzywuzzy import process [as 别名]
# 或者: from fuzzywuzzy.process import extractOne [as 别名]
def get_album(self, name, artist_name=None):
        if self.use_store:
            if artist_name:
                name = "%s %s" % (name, artist_name)

            search = self._search("album", name)

            if len(search) == 0:
                return False

            return self._api.get_album_info(search[0]['albumId'])
        else:
            search = {}
            search['tracks'] = []
            if artist_name:
                artist_name, score = process.extractOne(artist_name, self.artists)
                if score < 70:
                    return False
            name, score = process.extractOne(name, self.albums)
            if score < 70:
                return False
            for song_id, song in self.library.items():
                if 'album' in song and song['album'].lower() == name.lower():
                    if not artist_name or ('artist' in song and song['artist'].lower() == artist_name.lower()):
                        if not search['tracks']:  # First entry
                            search['albumArtist'] = song['albumArtist']
                            search['name'] = song['album']
                            try:
                                search['albumId'] = song['albumId']
                            except KeyError:
                                pass

                        search['tracks'].append(song)
            if not search['tracks']:
                return False

            return search 
开发者ID:stevenleeg,项目名称:geemusic,代码行数:39,代码来源:music.py

示例5: get_song

# 需要导入模块: from fuzzywuzzy import process [as 别名]
# 或者: from fuzzywuzzy.process import extractOne [as 别名]
def get_song(self, name, artist_name=None, album_name=None):
        if self.use_store:
            if artist_name:
                name = "%s %s" % (artist_name, name)
            elif album_name:
                name = "%s %s" % (album_name, name)

            search = self._search("song", name)

            if len(search) == 0:
                return False

            if album_name:
                for i in range(0, len(search) - 1):
                    if album_name in search[i]['album']:
                        return search[i]
            return search[0]
        else:
            search = {}
            if not name:
                return False
            if artist_name:
                artist_name, score = process.extractOne(artist_name, self.artists)
                if score < 70:
                    return False
            if album_name:
                album_name, score = process.extractOne(album_name, self.albums)
                if score < 70:
                    return False
            possible_songs = {song_id: song['title'] for song_id, song in self.library.items() if (not artist_name or ('artist' in song and song['artist'].lower() == artist_name.lower())) and (not album_name or ('album' in song and song['album'].lower() == album_name.lower()))}
            song, score, song_id = process.extractOne(name.lower(), possible_songs)
            if score < 70:
                return False
            else:
                return self.library[song_id] 
开发者ID:stevenleeg,项目名称:geemusic,代码行数:37,代码来源:music.py

示例6: get_stn_code

# 需要导入模块: from fuzzywuzzy import process [as 别名]
# 或者: from fuzzywuzzy.process import extractOne [as 别名]
def get_stn_code(self, query):
        """
        utility function to get correst station code
        """
        try:
            return self.stations[query.upper()]
        except KeyError:
            return process.extractOne(query, self.stations.values())[0] 
开发者ID:nikhilkumarsingh,项目名称:pyinrail,代码行数:10,代码来源:pyinrail.py

示例7: fuzzy_match

# 需要导入模块: from fuzzywuzzy import process [as 别名]
# 或者: from fuzzywuzzy.process import extractOne [as 别名]
def fuzzy_match(name, strings):
    global fuzzy_match_fun
    if fuzzy_match_fun is not None:
        return fuzzy_match_fun(name, strings)

    try:
        from fuzzywuzzy import process, fuzz
        fuzzy_match_fun = lambda name, strings: process.extractOne(name, strings, scorer=fuzz.partial_ratio)[0]
    except ImportError: # pragma: no cover
        import difflib
        fuzzy_match_fun = lambda name, strings: difflib.get_close_matches(name, strings, n=1, cutoff=0)[0]
    return fuzzy_match_fun(name, strings) 
开发者ID:CalebBell,项目名称:fluids,代码行数:14,代码来源:friction.py

示例8: get_news

# 需要导入模块: from fuzzywuzzy import process [as 别名]
# 或者: from fuzzywuzzy.process import extractOne [as 别名]
def get_news(self):
        """
        function to get news articles
        """
        if self.topic is None or self.topic == 'Top Stories':
            resp = requests.get(top_news_url, params=self.params_dict)
        else:
            topic_code = topicMap[process.extractOne(self.topic, self.topics)[0]]
            resp = requests.get(topic_url.format(topic_code), params=self.params_dict)
        return self.parse_feed(resp.content) 
开发者ID:nikhilkumarsingh,项目名称:gnewsclient,代码行数:12,代码来源:gnewsclient.py

示例9: query_song

# 需要导入模块: from fuzzywuzzy import process [as 别名]
# 或者: from fuzzywuzzy.process import extractOne [as 别名]
def query_song(self, song):
        best_found = None
        best_conf = 0
        library_type = None
        for t in self.track_names:
            found, conf = (extract_one(song, self.track_names[t].keys()) or
                           (None, 0))
            if conf > best_conf and conf > 50:
                best_conf = conf
                best_found = found
                library_type = t
        return best_found, best_conf, 'song', library_type 
开发者ID:forslund,项目名称:mopidy_skill,代码行数:14,代码来源:__init__.py

示例10: query_artist

# 需要导入模块: from fuzzywuzzy import process [as 别名]
# 或者: from fuzzywuzzy.process import extractOne [as 别名]
def query_artist(self, artist):
        best_found = None
        best_conf = 0.0
        library_type = None
        for t in self.artists:
            found, conf = (extract_one(artist, self.artists[t].keys()) or
                           (None, 0))
            if conf > best_conf and conf > 50:
                best_conf = conf
                best_found = found
                library_type = t
        return best_found, best_conf, 'artist', library_type 
开发者ID:forslund,项目名称:mopidy_skill,代码行数:14,代码来源:__init__.py

示例11: query_album

# 需要导入模块: from fuzzywuzzy import process [as 别名]
# 或者: from fuzzywuzzy.process import extractOne [as 别名]
def query_album(self, album):
        best_found = None
        best_conf = 0
        library_type = None
        for t in self.albums:
            self.log.info(self.albums[t].keys())
            found, conf = (extract_one(album, self.albums[t].keys()) or
                           (None, 0))
            if conf > best_conf and conf > 50:
                best_conf = conf
                best_found = found
                library_type = t
        self.log.info('ALBUMS')
        self.log.info((best_found, best_conf))
        return best_found, best_conf, 'album', library_type 
开发者ID:forslund,项目名称:mopidy_skill,代码行数:17,代码来源:__init__.py

示例12: generic_query

# 需要导入模块: from fuzzywuzzy import process [as 别名]
# 或者: from fuzzywuzzy.process import extractOne [as 别名]
def generic_query(self, phrase):
        found, conf = extract_one(phrase, self.playlist.keys())
        if conf > 50:
            return found, conf, 'generic', ''
        else:
            return NOTHING_FOUND 
开发者ID:forslund,项目名称:mopidy_skill,代码行数:8,代码来源:__init__.py

示例13: guess_id

# 需要导入模块: from fuzzywuzzy import process [as 别名]
# 或者: from fuzzywuzzy.process import extractOne [as 别名]
def guess_id(self, name):
        """@return: id, name, score"""
        name, score = process.extractOne(name, self._all_name_list)
        return self._roster[name], name, score 
开发者ID:Ice-Cirno,项目名称:HoshinoBot,代码行数:6,代码来源:chara.py

示例14: on_play_playlist

# 需要导入模块: from fuzzywuzzy import process [as 别名]
# 或者: from fuzzywuzzy.process import extractOne [as 别名]
def on_play_playlist(self, intent, session, pid=None):
        server = self._server
        try:
            slot = intent['slots']['Playlist']['value']
            print_d("Extracted playlist slot: {slot}", slot=slot)
        except KeyError:
            print_d("Couldn't process playlist from: {intent}", intent=intent)
            if not server.playlists:
                return speech_response(speech=_("There are no playlists"))
            pl = random.choice(server.playlists)
            text = _("Didn't hear a playlist there. "
                     "You could try the \"{name}\" playlist?").format(name=pl)
            return speech_response(speech=text)
        else:
            if not server.playlists:
                return speech_response(
                    speech=_("No Squeezebox playlists found"))
            result = process.extractOne(slot, server.playlists)
            print_d("{guess} was the best guess for '{slot}' from {choices}",
                    guess=str(result), slot=slot, choices=server.playlists)
            if result and int(result[1]) >= MinConfidences.PLAYLIST:
                pl = result[0]
                server.playlist_resume(pl, player_id=pid)
                name = sanitise_text(pl)
                return self.smart_response(
                    speech=_("Playing \"{name}\" playlist").format(name=name),
                    text=_("Playing \"{name}\" playlist").format(name=name))
            pl = random.choice(server.playlists)
            title = (_("Couldn't find a playlist matching \"{name}\".")
                     .format(name=slot))
            extra = (_("How about the \"{suggestion}\" playlist?")
                     .format(suggestion=pl))
            return speech_response(title=title, text=extra,
                                   speech=title + extra) 
开发者ID:declension,项目名称:squeeze-alexa,代码行数:36,代码来源:main.py

示例15: player_id_from

# 需要导入模块: from fuzzywuzzy import process [as 别名]
# 或者: from fuzzywuzzy.process import extractOne [as 别名]
def player_id_from(self, intent, defaulting=True):
        srv = self._server
        try:
            player_name = intent['slots']['Player']['value']
        except KeyError:
            pass
        else:
            by_name = {s.name: s for s in srv.players.values()}
            choices = by_name.keys()
            result = process.extractOne(player_name, choices)
            print_d("{guess} was the best guess for '{value}' from {choices}",
                    guess=result, value=player_name, choices=set(choices))
            if result and int(result[1]) >= MinConfidences.PLAYER:
                return by_name.get(result[0]).id
        return srv.cur_player_id if defaulting else None 
开发者ID:declension,项目名称:squeeze-alexa,代码行数:17,代码来源:main.py


注:本文中的fuzzywuzzy.process.extractOne方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。